Skip to content

Commit 9b0fbf5

Browse files
author
Richard Jones
committed
have bounce_message do the error_messages_to heavy-lifting
1 parent 7c97e4c commit 9b0fbf5

File tree

2 files changed

+21
-48
lines changed

2 files changed

+21
-48
lines changed

roundup/mailer.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Sending Roundup-specific mail over SMTP.
22
"""
33
__docformat__ = 'restructuredtext'
4-
# $Id: mailer.py,v 1.7 2004-02-29 00:35:55 richard Exp $
4+
# $Id: mailer.py,v 1.8 2004-03-25 22:52:12 richard Exp $
55

66
import time, quopri, os, socket, smtplib, re
77

@@ -92,13 +92,24 @@ def bounce_message(self, bounced_message, to, error,
9292
9393
Arguments:
9494
- bounced_message: an RFC822 Message object.
95-
- to: a list of addresses usable by rfc822.parseaddr().
95+
- to: a list of addresses usable by rfc822.parseaddr(). Might be
96+
extended or overridden according to the config
97+
ERROR_MESSAGES_TO setting.
9698
- error: the reason of failure as a string.
9799
- subject: the subject as a string.
98-
100+
99101
"""
100102
message, writer = self.get_standard_message(to, subject)
101103

104+
# see whether we should send to the dispatcher or not
105+
dispatcher_email = getattr(self.config, "DISPATCHER_EMAIL",
106+
getattr(self.config, "ADMIN_EMAIL"))
107+
error_messages_to = getattr(self.config, "ERROR_MESSAGES_TO", "user")
108+
if error_messages_to == "dispatcher":
109+
to = [dispatcher_email]
110+
elif error_messages_to == "both":
111+
to.append(dispatcher_email)
112+
102113
part = writer.startmultipartbody('mixed')
103114
part = writer.nextpart()
104115
part.addheader('Content-Transfer-Encoding', 'quoted-printable')

roundup/mailgw.py

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class node. Any parts of other types are each stored in separate files
7272
an exception, the original message is bounced back to the sender with the
7373
explanatory message given in the exception.
7474
75-
$Id: mailgw.py,v 1.144 2004-03-25 19:27:15 eparker Exp $
75+
$Id: mailgw.py,v 1.145 2004-03-25 22:52:12 richard Exp $
7676
"""
7777
__docformat__ = 'restructuredtext'
7878

@@ -430,25 +430,14 @@ def handle_Message(self, message):
430430
# in some rare cases, a particularly stuffed-up e-mail will make
431431
# its way into here... try to handle it gracefully
432432

433-
# Setting the dispatcher e-mail here, so as not to clutter things. Defaulting to ADMIN_EMAIL, if not set.
434-
dispatcherEmail = getattr(self.instance.config, "DISPATCHER_EMAIL", getattr(self.instance.config, "ADMIN_EMAIL"))
435-
errorMessagesTo = getattr(self.instance.config, "ERROR_MESSAGES_TO", "user")
436-
437433
sendto = message.getaddrlist('resent-from')
438434
if not sendto:
439435
sendto = message.getaddrlist('from')
440436
if not sendto:
441437
# very bad-looking message - we don't even know who sent it
442438
# XXX we should use a log file here...
443439

444-
# [EP] This section was originally only to admin.. Not sure if this should ever go to the user?
445-
446-
if(errorMessagesTo == "dispatcher"):
447-
sendto = [dispatcherEmail]
448-
elif(errorMessagesTo == "both"):
449-
sendto = [dispatcherEmail, self.instance.config.ADMIN_EMAIL]
450-
else:
451-
sendto = [self.instance.config.ADMIN_EMAIL]
440+
sendto = [self.instance.config.ADMIN_EMAIL]
452441

453442
m = ['Subject: badly formed message from mail gateway']
454443
m.append('')
@@ -468,45 +457,24 @@ def handle_Message(self, message):
468457
except MailUsageHelp:
469458
# bounce the message back to the sender with the usage message
470459
fulldoc = '\n'.join(string.split(__doc__, '\n')[2:])
471-
if(errorMessagesTo == "dispatcher"):
472-
sendto = [dispatcherEmail]
473-
elif(errorMessagesTo == "both"):
474-
sendto = [dispatcherEmail, sendto[0][1]]
475-
else:
476-
sendto = [sendto[0][1]]
477-
478460
m = ['']
479461
m.append('\n\nMail Gateway Help\n=================')
480462
m.append(fulldoc)
481-
self.mailer.bounce_message(message, sendto, m,
463+
self.mailer.bounce_message(message, [sendto[0][1]], m,
482464
subject="Mail Gateway Help")
483465
except MailUsageError, value:
484466
# bounce the message back to the sender with the usage message
485467
fulldoc = '\n'.join(string.split(__doc__, '\n')[2:])
486-
487-
if(errorMessagesTo == "dispatcher"):
488-
sendto = [dispatcherEmail]
489-
elif(errorMessagesTo == "both"):
490-
sendto = [dispatcherEmail, sendto[0][1]]
491-
else:
492-
sendto = [sendto[0][1]]
493468
m = ['']
494469
m.append(str(value))
495470
m.append('\n\nMail Gateway Help\n=================')
496471
m.append(fulldoc)
497-
self.mailer.bounce_message(message, sendto, m)
472+
self.mailer.bounce_message(message, [sendto[0][1]], m)
498473
except Unauthorized, value:
499474
# just inform the user that he is not authorized
500-
501-
if(errorMessagesTo == "dispatcher"):
502-
sendto = [dispatcherEmail]
503-
elif(errorMessagesTo == "both"):
504-
sendto = [dispatcherEmail, sendto[0][1]]
505-
else:
506-
sendto = [sendto[0][1]]
507475
m = ['']
508476
m.append(str(value))
509-
self.mailer.bounce_message(message, sendto, m)
477+
self.mailer.bounce_message(message, [sendto[0][1]], m)
510478
except IgnoreMessage:
511479
# XXX we should use a log file here...
512480
# do not take any action
@@ -515,14 +483,8 @@ def handle_Message(self, message):
515483
except:
516484
# bounce the message back to the sender with the error message
517485
# XXX we should use a log file here...
518-
519-
if(errorMessagesTo == "dispatcher"):
520-
sendto = [dispatcherEmail]
521-
elif(errorMessagesTo == "both"):
522-
sendto = [dispatcherEmail, sendto[0][1], self.instance.config.ADMIN_EMAIL]
523-
else:
524-
sendto = [sendto[0][1], self.instance.config.ADMIN_EMAIL]
525-
486+
# let the admin know that something very bad is happening
487+
sendto = [sendto[0][1], self.instance.config.ADMIN_EMAIL]
526488
m = ['']
527489
m.append('An unexpected error occurred during the processing')
528490
m.append('of your message. The tracker administrator is being')

0 commit comments

Comments
 (0)