Skip to content

Commit e74b0fd

Browse files
author
Johannes Gijsbers
committed
Fix mailer bug [SF#817470]...
...and add docstrings to prevent this from happening again.
1 parent 32010f3 commit e74b0fd

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

roundup/cgi/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.140 2003-09-24 14:53:58 jlgijsbers Exp $
1+
# $Id: client.py,v 1.141 2003-10-04 11:21:47 jlgijsbers Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -773,7 +773,7 @@ def registerAction(self):
773773
%(url)s?@action=confrego&otk=%(otk)s
774774
""" % {'name': props['username'], 'tracker': tracker_name, 'url': self.base,
775775
'otk': otk, 'tracker_email': tracker_email}
776-
if not self.standard_message(props['address'], subject, body,
776+
if not self.standard_message([props['address']], subject, body,
777777
tracker_email):
778778
return
779779

@@ -878,7 +878,7 @@ def passResetAction(self):
878878
879879
Your password is now: %(password)s
880880
'''%{'name': name, 'password': newpw}
881-
if not self.standard_message(address, subject, body):
881+
if not self.standard_message([address], subject, body):
882882
return
883883

884884
self.ok_message.append('Password reset and email sent to %s'%address)
@@ -921,7 +921,7 @@ def passResetAction(self):
921921
922922
You should then receive another email with the new password.
923923
'''%{'name': name, 'tracker': tracker_name, 'url': self.base, 'otk': otk}
924-
if not self.standard_message(address, subject, body):
924+
if not self.standard_message([address], subject, body):
925925
return
926926

927927
self.ok_message.append('Email sent to %s'%address)

roundup/mailer.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Sending Roundup-specific mail over SMTP."""
2-
# $Id: mailer.py,v 1.2 2003-09-08 21:08:59 jlgijsbers Exp $
2+
# $Id: mailer.py,v 1.3 2003-10-04 11:21:47 jlgijsbers Exp $
33

44
import time, quopri, os, socket, smtplib, re
55

@@ -27,7 +27,7 @@ def get_standard_message(self, to, subject, author=None):
2727
message = StringIO()
2828
writer = MimeWriter(message)
2929
writer.addheader('Subject', encode_header(subject))
30-
writer.addheader('To', to)
30+
writer.addheader('To', ', '.join(to))
3131
writer.addheader('From', author)
3232
writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000",
3333
time.gmtime()))
@@ -42,6 +42,14 @@ def get_standard_message(self, to, subject, author=None):
4242
return message, writer
4343

4444
def standard_message(self, to, subject, content, author=None):
45+
"""Send a standard message.
46+
47+
Arguments:
48+
- to: a list of addresses usable by rfc822.parseaddr().
49+
- subject: the subject as a string.
50+
- content: the body of the message as a string.
51+
- author: the sender as a string, suitable for a 'From:' header.
52+
"""
4553
message, writer = self.get_standard_message(to, subject, author)
4654

4755
writer.addheader('Content-Transfer-Encoding', 'quoted-printable')
@@ -53,7 +61,16 @@ def standard_message(self, to, subject, content, author=None):
5361

5462
def bounce_message(self, bounced_message, to, error,
5563
subject='Failed issue tracker submission'):
56-
message, writer = self.get_standard_message(', '.join(to), subject)
64+
"""Bounce a message, attaching the failed submission.
65+
66+
Arguments:
67+
- bounced_message: an RFC822 Message object.
68+
- to: a list of addresses usable by rfc822.parseaddr().
69+
- error: the reason of failure as a string.
70+
- subject: the subject as a string.
71+
72+
"""
73+
message, writer = self.get_standard_message(to, subject)
5774

5875
part = writer.startmultipartbody('mixed')
5976
part = writer.nextpart()
@@ -83,6 +100,12 @@ def bounce_message(self, bounced_message, to, error,
83100
self.smtp_send(to, message)
84101

85102
def smtp_send(self, to, message):
103+
"""Send a message over SMTP, using roundup's config.
104+
105+
Arguments:
106+
- to: a list of addresses usable by rfc822.parseaddr().
107+
- message: a StringIO instance with a full message.
108+
"""
86109
if self.debug:
87110
# don't send - just write to a file
88111
open(self.debug, 'a').write('FROM: %s\nTO: %s\n%s\n' %
@@ -95,7 +118,7 @@ def smtp_send(self, to, message):
95118
# send the message as admin so bounces are sent there
96119
# instead of to roundup
97120
smtp = SMTPConnection(self.config)
98-
smtp.sendmail(self.config.ADMIN_EMAIL, [to],
121+
smtp.sendmail(self.config.ADMIN_EMAIL, to,
99122
message.getvalue())
100123
except socket.error, value:
101124
raise MessageSendError("Error: couldn't send email: "

roundup/mailgw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.132 2003-09-08 21:27:16 jlgijsbers Exp $
76+
$Id: mailgw.py,v 1.133 2003-10-04 11:21:47 jlgijsbers Exp $
7777
"""
7878

7979
import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -440,7 +440,7 @@ def handle_message(self, message):
440440
self.db.confirm_registration(otk.group('otk'))
441441
subject = 'Your registration to %s is complete' % \
442442
self.instance.config.TRACKER_NAME
443-
sendto = message.getaddrlist('from')[0][1]
443+
sendto = [message.getheader('from')]
444444
self.mailer.standard_message(sendto, subject, '')
445445
return
446446
elif hasattr(self.instance.config, 'MAIL_DEFAULT_CLASS') and \

roundup/roundupdb.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: roundupdb.py,v 1.91 2003-09-16 16:12:38 kedder Exp $
18+
# $Id: roundupdb.py,v 1.92 2003-10-04 11:21:47 jlgijsbers Exp $
1919

2020
__doc__ = """
2121
Extending hyperdb with types specific to issue-tracking.
@@ -288,8 +288,7 @@ def send_message(self, nodeid, msgid, note, sendto, from_address=None):
288288

289289
# create the message
290290
mailer = Mailer(self.db.config)
291-
message, writer = mailer.get_standard_message(', '.join(sendto),
292-
subject, author)
291+
message, writer = mailer.get_standard_message(sendto, subject, author)
293292

294293
tracker_name = encode_header(self.db.config.TRACKER_NAME)
295294
writer.addheader('Reply-To', straddr((tracker_name, from_address)))

0 commit comments

Comments
 (0)