From 0b24aeb77f0f4ebcf13ad7cc0354b8959aefcdf1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 25 Nov 2010 13:57:35 -0700 Subject: [PATCH] Email sending: Set rate limit to 5 minutes for gmail and hotmail and one second other wise --- src/calibre/gui2/email.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/email.py b/src/calibre/gui2/email.py index 8e4ce3b4a4..14752f073b 100644 --- a/src/calibre/gui2/email.py +++ b/src/calibre/gui2/email.py @@ -66,7 +66,6 @@ class EmailJob(BaseJob): # {{{ class Emailer(Thread): # {{{ MAX_RETRIES = 1 - RATE_LIMIT = 65 # seconds between connections to the SMTP server def __init__(self, job_manager): Thread.__init__(self) @@ -74,7 +73,14 @@ class Emailer(Thread): # {{{ self.jobs = Queue() self.job_manager = job_manager self._run = True - self.last_send_time = time.time() - self.RATE_LIMIT + self.rate_limit = 1 + opts = email_config().parse() + rh = opts.relay_host + if rh and ( + 'gmail.com' in rh or 'live.com' in rh): + self.rate_limit = 301 + + self.last_send_time = time.time() - self.rate_limit def stop(self): self._run = False @@ -102,7 +108,7 @@ class Emailer(Thread): # {{{ failed = False if try_count > 0: job.log_write('\nRetrying in %d seconds...\n' % - self.RATE_LIMIT) + self.rate_limit) try: self.sendmail(job) break @@ -140,7 +146,7 @@ class Emailer(Thread): # {{{ self.jobs.put(job) def sendmail(self, job): - while time.time() - self.last_send_time <= self.RATE_LIMIT: + while time.time() - self.last_send_time <= self.rate_limit: time.sleep(1) try: opts = email_config().parse()