Code

Fix mailer (sf bug #817470) and add docstrings to prevent this from happening again.
authorjlgijsbers <jlgijsbers@57a73879-2fb5-44c3-a270-3262357dd7e2>
Sat, 4 Oct 2003 11:21:47 +0000 (11:21 +0000)
committerjlgijsbers <jlgijsbers@57a73879-2fb5-44c3-a270-3262357dd7e2>
Sat, 4 Oct 2003 11:21:47 +0000 (11:21 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1897 57a73879-2fb5-44c3-a270-3262357dd7e2

roundup/cgi/client.py
roundup/mailer.py
roundup/mailgw.py
roundup/roundupdb.py

index 575344cfba9f891ea82033a895e9943b2a3075c4..d4499bb334839aef8aa2abe05e2a15eebff01ca7 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: client.py,v 1.140 2003-09-24 14:53:58 jlgijsbers Exp $
+# $Id: client.py,v 1.141 2003-10-04 11:21:47 jlgijsbers Exp $
 
 __doc__ = """
 WWW request handler (also used in the stand-alone server).
 
 __doc__ = """
 WWW request handler (also used in the stand-alone server).
@@ -773,7 +773,7 @@ reply's additional "Re:" is ok),
    %(url)s?@action=confrego&otk=%(otk)s
 """ % {'name': props['username'], 'tracker': tracker_name, 'url': self.base,
        'otk': otk, 'tracker_email': tracker_email}
    %(url)s?@action=confrego&otk=%(otk)s
 """ % {'name': props['username'], 'tracker': tracker_name, 'url': self.base,
        'otk': otk, 'tracker_email': tracker_email}
-        if not self.standard_message(props['address'], subject, body,
+        if not self.standard_message([props['address']], subject, body,
                                      tracker_email):
             return
 
                                      tracker_email):
             return
 
@@ -878,7 +878,7 @@ The password has been reset for username "%(name)s".
 
 Your password is now: %(password)s
 '''%{'name': name, 'password': newpw}
 
 Your password is now: %(password)s
 '''%{'name': name, 'password': newpw}
-            if not self.standard_message(address, subject, body):
+            if not self.standard_message([address], subject, body):
                 return
 
             self.ok_message.append('Password reset and email sent to %s'%address)
                 return
 
             self.ok_message.append('Password reset and email sent to %s'%address)
@@ -921,7 +921,7 @@ the link below:
 
 You should then receive another email with the new password.
 '''%{'name': name, 'tracker': tracker_name, 'url': self.base, 'otk': otk}
 
 You should then receive another email with the new password.
 '''%{'name': name, 'tracker': tracker_name, 'url': self.base, 'otk': otk}
-        if not self.standard_message(address, subject, body):
+        if not self.standard_message([address], subject, body):
             return
 
         self.ok_message.append('Email sent to %s'%address)
             return
 
         self.ok_message.append('Email sent to %s'%address)
index 002861856fe9af4a6dc72c91ac7946e2ae6518ac..6d9e6c8d63438210e5d15aa16c7a67e3c761f4b2 100644 (file)
@@ -1,5 +1,5 @@
 """Sending Roundup-specific mail over SMTP."""
 """Sending Roundup-specific mail over SMTP."""
-# $Id: mailer.py,v 1.2 2003-09-08 21:08:59 jlgijsbers Exp $
+# $Id: mailer.py,v 1.3 2003-10-04 11:21:47 jlgijsbers Exp $
 
 import time, quopri, os, socket, smtplib, re
 
 
 import time, quopri, os, socket, smtplib, re
 
@@ -27,7 +27,7 @@ class Mailer:
         message = StringIO()
         writer = MimeWriter(message)
         writer.addheader('Subject', encode_header(subject))
         message = StringIO()
         writer = MimeWriter(message)
         writer.addheader('Subject', encode_header(subject))
-        writer.addheader('To', to)
+        writer.addheader('To', ', '.join(to))
         writer.addheader('From', author)
         writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000",
                                                time.gmtime()))
         writer.addheader('From', author)
         writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000",
                                                time.gmtime()))
@@ -42,6 +42,14 @@ class Mailer:
         return message, writer
 
     def standard_message(self, to, subject, content, author=None):
         return message, writer
 
     def standard_message(self, to, subject, content, author=None):
+        """Send a standard message.
+
+        Arguments:
+        - to: a list of addresses usable by rfc822.parseaddr().
+        - subject: the subject as a string.
+        - content: the body of the message as a string.
+        - author: the sender as a string, suitable for a 'From:' header.
+        """
         message, writer = self.get_standard_message(to, subject, author)
 
         writer.addheader('Content-Transfer-Encoding', 'quoted-printable')
         message, writer = self.get_standard_message(to, subject, author)
 
         writer.addheader('Content-Transfer-Encoding', 'quoted-printable')
@@ -53,7 +61,16 @@ class Mailer:
        
     def bounce_message(self, bounced_message, to, error,
                        subject='Failed issue tracker submission'):
        
     def bounce_message(self, bounced_message, to, error,
                        subject='Failed issue tracker submission'):
-        message, writer = self.get_standard_message(', '.join(to), subject)
+        """Bounce a message, attaching the failed submission.
+
+        Arguments:
+        - bounced_message: an RFC822 Message object.
+        - to: a list of addresses usable by rfc822.parseaddr().
+        - error: the reason of failure as a string.
+        - subject: the subject as a string.
+        
+        """
+        message, writer = self.get_standard_message(to, subject)
 
         part = writer.startmultipartbody('mixed')
         part = writer.nextpart()
 
         part = writer.startmultipartbody('mixed')
         part = writer.nextpart()
@@ -83,6 +100,12 @@ class Mailer:
         self.smtp_send(to, message)
         
     def smtp_send(self, to, message):
         self.smtp_send(to, message)
         
     def smtp_send(self, to, message):
+        """Send a message over SMTP, using roundup's config.
+
+        Arguments:
+        - to: a list of addresses usable by rfc822.parseaddr().
+        - message: a StringIO instance with a full message.
+        """
         if self.debug:
             # don't send - just write to a file
             open(self.debug, 'a').write('FROM: %s\nTO: %s\n%s\n' %
         if self.debug:
             # don't send - just write to a file
             open(self.debug, 'a').write('FROM: %s\nTO: %s\n%s\n' %
@@ -95,7 +118,7 @@ class Mailer:
                 # send the message as admin so bounces are sent there
                 # instead of to roundup
                 smtp = SMTPConnection(self.config)
                 # send the message as admin so bounces are sent there
                 # instead of to roundup
                 smtp = SMTPConnection(self.config)
-                smtp.sendmail(self.config.ADMIN_EMAIL, [to],
+                smtp.sendmail(self.config.ADMIN_EMAIL, to,
                               message.getvalue())
             except socket.error, value:
                 raise MessageSendError("Error: couldn't send email: "
                               message.getvalue())
             except socket.error, value:
                 raise MessageSendError("Error: couldn't send email: "
index 23e294315d474aeb23fd3760766311606f6f813c..8ec27fe983d0e0689a8dc9c233bfbff7369cd855 100644 (file)
@@ -73,7 +73,7 @@ are calling the create() method to create a new node). If an auditor raises
 an exception, the original message is bounced back to the sender with the
 explanatory message given in the exception. 
 
 an exception, the original message is bounced back to the sender with the
 explanatory message given in the exception. 
 
-$Id: mailgw.py,v 1.132 2003-09-08 21:27:16 jlgijsbers Exp $
+$Id: mailgw.py,v 1.133 2003-10-04 11:21:47 jlgijsbers Exp $
 """
 
 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
 """
 
 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -440,7 +440,7 @@ Emails to Roundup trackers must include a Subject: line!
                     self.db.confirm_registration(otk.group('otk'))
                     subject = 'Your registration to %s is complete' % \
                               self.instance.config.TRACKER_NAME
                     self.db.confirm_registration(otk.group('otk'))
                     subject = 'Your registration to %s is complete' % \
                               self.instance.config.TRACKER_NAME
-                    sendto = message.getaddrlist('from')[0][1]
+                    sendto = [message.getheader('from')]
                     self.mailer.standard_message(sendto, subject, '') 
                     return
                 elif hasattr(self.instance.config, 'MAIL_DEFAULT_CLASS') and \
                     self.mailer.standard_message(sendto, subject, '') 
                     return
                 elif hasattr(self.instance.config, 'MAIL_DEFAULT_CLASS') and \
index 7edc5af292bae7f483ba842d7dc15fa83b1e0850..953b4190bc69ec5de0dc023bccb892f526b04edc 100644 (file)
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: roundupdb.py,v 1.91 2003-09-16 16:12:38 kedder Exp $
+# $Id: roundupdb.py,v 1.92 2003-10-04 11:21:47 jlgijsbers Exp $
 
 __doc__ = """
 Extending hyperdb with types specific to issue-tracking.
 
 __doc__ = """
 Extending hyperdb with types specific to issue-tracking.
@@ -288,8 +288,7 @@ class IssueClass:
 
         # create the message
         mailer = Mailer(self.db.config)
 
         # create the message
         mailer = Mailer(self.db.config)
-        message, writer = mailer.get_standard_message(', '.join(sendto),
-                                                      subject, author)
+        message, writer = mailer.get_standard_message(sendto, subject, author)
 
         tracker_name = encode_header(self.db.config.TRACKER_NAME)
         writer.addheader('Reply-To', straddr((tracker_name, from_address)))
 
         tracker_name = encode_header(self.db.config.TRACKER_NAME)
         writer.addheader('Reply-To', straddr((tracker_name, from_address)))