Attachment 'throttle.patch'

Download

   1 --- test-mailman-2.1/Mailman/Handlers/SMTPDirect.py	2010-07-03 14:12:22.000000000 -0700
   2 +++ test-mailman/Mailman/Handlers/SMTPDirect.py	2011-02-04 19:29:49.234375000 -0800
   3 @@ -52,6 +52,37 @@
   4      True = 1
   5      False = 0
   6  
   7 +# Throttling settings.  Do not send to more than THROTTLE_LIMIT recipients
   8 +# within THROTTLE_TIME seconds.  Set THROTTLE_LIMIT to 0 to not throttle.
   9 +THROTTLE_TIME = 3600
  10 +THROTTLE_LIMIT = 500
  11 +THROTTLE_DATA = []
  12 +
  13 +# check throttling.  Doesn't return until total recipients in THROTTLE_TIME
  14 +# <= THROTTLE_LIMIT.
  15 +# 
  16 +def check_throttle(count):
  17 +    global THROTTLE_DATA
  18 +    if THROTTLE_LIMIT <= 0:
  19 +        return
  20 +    if count <= 0 or count > THROTTLE_LIMIT:
  21 +        syslog('error', 'check_throttle: count=%d; THROTTLE_LIMIT=%d',
  22 +               count, THROTTLE_LIMIT)
  23 +        return
  24 +    now = time.time()
  25 +    total = 0
  26 +    THROTTLE_DATA = [(num, tim) for (num, tim) in THROTTLE_DATA
  27 +                     if tim > now - THROTTLE_TIME]
  28 +    for num, tim in THROTTLE_DATA:
  29 +        total += num
  30 +    total += count
  31 +    if total > THROTTLE_LIMIT:
  32 +        time.sleep(THROTTLE_TIME - now + THROTTLE_DATA[0][1])
  33 +        check_throttle(count)
  34 +    else:
  35 +        THROTTLE_DATA.append((count, now))
  36 +        return
  37 +
  38  
  39  
  40  # Manage a connection to the SMTP server
  41 @@ -118,10 +149,14 @@
  42          chunks = [[recip] for recip in recips]
  43          msgdata['personalize'] = 1
  44          deliveryfunc = verpdeliver
  45 -    elif mm_cfg.SMTP_MAX_RCPTS <= 0:
  46 +    elif mm_cfg.SMTP_MAX_RCPTS <= 0 and (THROTTLE_LIMIT <=0 or
  47 +                                         THROTTLE_LIMIT >= len(recips)):
  48          chunks = [recips]
  49      else:
  50 -        chunks = chunkify(recips, mm_cfg.SMTP_MAX_RCPTS)
  51 +        if THROTTLE_LIMIT <= 0 or THROTTLE_LIMIT > mm_cfg.SMTP_MAX_RCPTS:
  52 +            chunks = chunkify(recips, mm_cfg.SMTP_MAX_RCPTS)
  53 +        else:
  54 +            chunks = chunkify(recips, THROTTLE_LIMIT)
  55      # See if this is an unshunted message for which some were undelivered
  56      if msgdata.has_key('undelivered'):
  57          chunks = msgdata['undelivered']
  58 @@ -384,6 +419,8 @@
  59      msgid = msg['message-id']
  60      try:
  61          # Send the message
  62 +        # but wait if necessary for throttling
  63 +        check_throttle(len(recips))
  64          refused = conn.sendmail(envsender, recips, msgtext)
  65      except smtplib.SMTPRecipientsRefused, e:
  66          syslog('smtp-failure', 'All recipients refused: %s, msgid: %s',

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2011-02-04 19:39:08, 2.4 KB) [[attachment:throttle.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.