22"""
33__docformat__ = 'restructuredtext'
44
5- import time , quopri , os , socket , smtplib , re , sys , traceback , email
5+ import time , quopri , os , socket , smtplib , re , sys , traceback , email , logging
66
77from cStringIO import StringIO
88
@@ -57,6 +57,7 @@ class Mailer:
5757 """Roundup-specific mail sending."""
5858 def __init__ (self , config ):
5959 self .config = config
60+ self .logger = logging .getLogger ('roundup.mailer' )
6061
6162 # set to indicate to roundup not to actually _send_ email
6263 # this var must contain a file to write the mail to
@@ -197,16 +198,19 @@ def bounce_message(self, bounced_message, to, error,
197198 part = MIMEText ('' .join (body ))
198199 message .attach (part )
199200
201+ self .logger .debug ("bounce_message: to=%s, crypt_to=%s" , to , crypt_to )
202+
200203 if to :
201204 # send
202205 self .set_message_attributes (message , to , subject )
203206 try :
204207 self .smtp_send (to , message .as_string ())
205- except MessageSendError :
208+ except MessageSendError as e :
206209 # squash mail sending errors when bouncing mail
207210 # TODO this *could* be better, as we could notify admin of the
208211 # problem (even though the vast majority of bounce errors are
209212 # because of spam)
213+ self .logger .debug ("MessageSendError: %s" , str (e ))
210214 pass
211215 if crypt_to :
212216 plain = pyme .core .Data (message .as_string ())
@@ -223,6 +227,9 @@ def bounce_message(self, bounced_message, to, error,
223227 adrs .append (adr )
224228 keys .append (k )
225229 ctx .op_keylist_end ()
230+ if not adrs :
231+ self .logger .debug ("bounce_message: no keys found for %s" ,
232+ crypt_to )
226233 crypt_to = adrs
227234 if crypt_to :
228235 try :
@@ -237,13 +244,16 @@ def bounce_message(self, bounced_message, to, error,
237244 part .set_payload (cipher .read ())
238245 message .attach (part )
239246 except pyme .GPGMEError :
247+ self .logger .debug ("bounce_message: Cannot encrypt to %s" ,
248+ str (crypto_to ))
240249 crypt_to = None
241250 if crypt_to :
242251 self .set_message_attributes (message , crypt_to , subject )
243252 try :
244253 self .smtp_send (crypt_to , message .as_string ())
245- except MessageSendError :
254+ except MessageSendError as e :
246255 # ignore on error, see above.
256+ self .logger .debug ("MessageSendError: %s" , str (e ))
247257 pass
248258
249259 def exception_message (self ):
0 commit comments