From 65986632deaebc08d6d308604ac4680099838b8f Mon Sep 17 00:00:00 2001 From: Stuart Gathman <stuart@gathman.org> Date: Mon, 11 Oct 2010 00:29:47 +0000 Subject: [PATCH] Handle multiple recipients. For CBV or auto whitelist of multiple emails. --- Milter/dsn.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Milter/dsn.py b/Milter/dsn.py index 64ab8a2..df8dded 100644 --- a/Milter/dsn.py +++ b/Milter/dsn.py @@ -5,6 +5,9 @@ # Send DSNs, do call back verification, # and generate DSN messages from a template # $Log$ +# Revision 1.19 2009/07/02 19:41:12 customdesigned +# Handle @ in localpart. +# # Revision 1.18 2009/06/10 18:01:59 customdesigned # Doxygen updates # @@ -116,13 +119,23 @@ def send_dsn(mailfrom,receiver,msg=None,timeout=600,session=None,ourfrom=''): code,resp = smtp.docmd('MAIL FROM: <%s>'%ourfrom) if code != 250: raise smtplib.SMTPSenderRefused(code, resp, '<%s>'%ourfrom) - code,resp = smtp.rcpt(mailfrom) - if code not in (250,251): - return (code,resp) # permanent error + if isinstance(mailfrom,basestring): + mailfrom = [mailfrom] + badrcpts = {} + for rcpt in mailfrom: + code,resp = smtp.rcpt(mailfrom) + if code not in (250,251): + badrcpts[rcpt] = (code,resp)# permanent error smtp.quit() + if len(badrcpts) == 1: + return badrcpts.values()[0] # permanent error + if badrcpts: + return badrcpts return None # success except smtplib.SMTPRecipientsRefused,x: - return x.recipients[mailfrom] # permanent error + if len(x.recipients) == 1: + return x.recipients.values()[0] # permanent error + return x.recipients except smtplib.SMTPSenderRefused,x: return x.args[:2] # does not accept DSN except smtplib.SMTPDataError,x: -- GitLab