4040import email .message
4141from email .message import Message
4242
43- import Mailman . mm_cfg
43+ from Mailman import mm_cfg
4444import Mailman .Utils
4545import Mailman .Errors
4646from Mailman .Message import Message
@@ -64,21 +64,21 @@ def __init__(self):
6464 def __connect (self ):
6565 try :
6666 self .__conn = smtplib .SMTP ()
67- self .__conn .set_debuglevel (Mailman . mm_cfg .SMTPLIB_DEBUG_LEVEL )
67+ self .__conn .set_debuglevel (mm_cfg .SMTPLIB_DEBUG_LEVEL )
6868 # Ensure we have a valid hostname for TLS
69- helo_host = Mailman . mm_cfg .SMTP_HELO_HOST
69+ helo_host = mm_cfg .SMTP_HELO_HOST
7070 if not helo_host or helo_host .startswith ('.' ):
71- helo_host = Mailman . mm_cfg .SMTPHOST
71+ helo_host = mm_cfg .SMTPHOST
7272 if not helo_host or helo_host .startswith ('.' ):
7373 # If we still don't have a valid hostname, use localhost
7474 helo_host = 'localhost'
7575 mailman_log ('smtp' , 'Connecting to SMTP server %s:%s with HELO %s' ,
76- Mailman . mm_cfg .SMTPHOST , Mailman . mm_cfg .SMTPPORT , helo_host )
77- self .__conn .connect (Mailman . mm_cfg .SMTPHOST , Mailman . mm_cfg .SMTPPORT )
76+ mm_cfg .SMTPHOST , mm_cfg .SMTPPORT , helo_host )
77+ self .__conn .connect (mm_cfg .SMTPHOST , mm_cfg .SMTPPORT )
7878 # Set the hostname for TLS
7979 self .__conn ._host = helo_host
80- if Mailman . mm_cfg .SMTP_AUTH :
81- if Mailman . mm_cfg .SMTP_USE_TLS :
80+ if mm_cfg .SMTP_AUTH :
81+ if mm_cfg .SMTP_USE_TLS :
8282 mailman_log ('smtp' , 'Using TLS with hostname: %s' , helo_host )
8383 try :
8484 # Use native TLS support
@@ -89,7 +89,7 @@ def __connect(self):
8989 self .quit ()
9090 raise
9191 try :
92- self .__conn .login (Mailman . mm_cfg .SMTP_USER , Mailman . mm_cfg .SMTP_PASSWD )
92+ self .__conn .login (mm_cfg .SMTP_USER , mm_cfg .SMTP_PASSWD )
9393 except smtplib .SMTPHeloError as e :
9494 mailman_log ('smtp-failure' , 'SMTP HELO error: %s\n Traceback:\n %s' ,
9595 str (e ), traceback .format_exc ())
@@ -111,7 +111,7 @@ def __connect(self):
111111 self .quit ()
112112 raise
113113
114- self .__numsessions = Mailman . mm_cfg .SMTP_MAX_SESSIONS_PER_CONNECTION
114+ self .__numsessions = mm_cfg .SMTP_MAX_SESSIONS_PER_CONNECTION
115115
116116 def sendmail (self , envsender , recips , msgtext ):
117117 if self .__conn is None :
@@ -206,7 +206,7 @@ def process(mlist, msg, msgdata):
206206 return
207207
208208 # Chunkify the recipients
209- chunks = chunkify (recips , Mailman . mm_cfg .SMTP_MAX_RCPTS_PER_CHUNK )
209+ chunks = chunkify (recips , mm_cfg .SMTP_MAX_RCPTS_PER_CHUNK )
210210 # Choose the delivery function based on VERP settings
211211 if msgdata .get ('verp' ):
212212 deliveryfunc = verpdeliver
@@ -254,9 +254,9 @@ def process(mlist, msg, msgdata):
254254 'listname' : listname ,
255255 'sender' : origsender ,
256256 })
257- if Mailman . mm_cfg .SMTP_LOG_EVERY_MESSAGE :
258- mailman_log (Mailman . mm_cfg .SMTP_LOG_EVERY_MESSAGE [0 ],
259- Mailman . mm_cfg .SMTP_LOG_EVERY_MESSAGE [1 ] % d .copy ())
257+ if mm_cfg .SMTP_LOG_EVERY_MESSAGE :
258+ mailman_log (mm_cfg .SMTP_LOG_EVERY_MESSAGE [0 ],
259+ mm_cfg .SMTP_LOG_EVERY_MESSAGE [1 ] % d .copy ())
260260
261261 except Exception as e :
262262 mailman_log ('error' , 'Error in SMTPDirect.process: %s\n Traceback:\n %s' ,
@@ -341,7 +341,7 @@ def verpdeliver(mlist, msg, msgdata, envsender, failures, conn):
341341 'mailbox' : rmailbox ,
342342 'host' : DOT .join (rdomain ),
343343 }
344- envsender = '%s@%s' % ((Mailman . mm_cfg .VERP_FORMAT % d ), DOT .join (bdomain ))
344+ envsender = '%s@%s' % ((mm_cfg .VERP_FORMAT % d ), DOT .join (bdomain ))
345345 except Exception as e :
346346 mailman_log ('error' , 'Failed to parse email addresses for VERP: %s' , e )
347347 continue
@@ -380,9 +380,9 @@ def verpdeliver(mlist, msg, msgdata, envsender, failures, conn):
380380 if recip in msgdata .get ('add-dup-header' , {}):
381381 msgcopy ['X-Mailman-Copy' ] = 'yes'
382382 # If desired, add the RCPT_BASE64_HEADER_NAME header
383- if len (Mailman . mm_cfg .RCPT_BASE64_HEADER_NAME ) > 0 :
384- del msgcopy [Mailman . mm_cfg .RCPT_BASE64_HEADER_NAME ]
385- msgcopy [Mailman . mm_cfg .RCPT_BASE64_HEADER_NAME ] = b64encode (recip )
383+ if len (mm_cfg .RCPT_BASE64_HEADER_NAME ) > 0 :
384+ del msgcopy [mm_cfg .RCPT_BASE64_HEADER_NAME ]
385+ msgcopy [mm_cfg .RCPT_BASE64_HEADER_NAME ] = b64encode (recip )
386386 # For the final delivery stage, we can just bulk deliver to a party of
387387 # one. ;)
388388 bulkdeliver (mlist , msgcopy , msgdata , envsender , failures , conn )
@@ -451,7 +451,7 @@ def bulkdeliver(mlist, msg, msgdata, envsender, failures, conn):
451451 e , msgid )
452452 refused = e .recipients
453453 # Move message to bad queue since all recipients were refused
454- badq = get_switchboard (Mailman . mm_cfg .BADQUEUE_DIR )
454+ badq = get_switchboard (mm_cfg .BADQUEUE_DIR )
455455 badq .enqueue (msg , msgdata )
456456 except smtplib .SMTPResponseException as e :
457457 mailman_log ('smtp-failure' , 'SMTP session failure: %s, %s, msgid: %s' ,
@@ -461,7 +461,7 @@ def bulkdeliver(mlist, msg, msgdata, envsender, failures, conn):
461461 # Permanent failure - add to refused and move to bad queue
462462 for r in recips :
463463 refused [r ] = (e .smtp_code , e .smtp_error )
464- badq = get_switchboard (Mailman . mm_cfg .BADQUEUE_DIR )
464+ badq = get_switchboard (mm_cfg .BADQUEUE_DIR )
465465 badq .enqueue (msg , msgdata )
466466 else :
467467 # Temporary failure - don't add to refused
@@ -473,7 +473,7 @@ def bulkdeliver(mlist, msg, msgdata, envsender, failures, conn):
473473 for r in recips :
474474 refused [r ] = (- 1 , error )
475475 # Move message to bad queue for low level errors
476- badq = get_switchboard (Mailman . mm_cfg .BADQUEUE_DIR )
476+ badq = get_switchboard (mm_cfg .BADQUEUE_DIR )
477477 badq .enqueue (msg , msgdata )
478478 failures .update (refused )
479479 except Exception as e :
0 commit comments