Skip to content

Commit a317e4e

Browse files
Mailer: Improves diagnostic messages for DEBUG.
* Adds logger and debug output to mailer.py. This is especially interesting for crypto mails.
1 parent 0f8962a commit a317e4e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ Features:
207207
when calling the method. Also restructured code that implemented
208208
issue1714899 moving it from the templating class to the hyperdb.
209209
(John Rouillard)
210+
- Improves diagnostics for mail processing: When using logging level = DEBUG,
211+
bounces and bounce problems are logged. (Bernhard Reiter)
210212

211213
Fixed:
212214

roundup/mailer.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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

77
from 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

Comments
 (0)