Code

Added 'Users may only edit their issues' customisation example.
[roundup.git] / roundup / mailer.py
index 002861856fe9af4a6dc72c91ac7946e2ae6518ac..6d9e6c8d63438210e5d15aa16c7a67e3c761f4b2 100644 (file)
@@ -1,5 +1,5 @@
 """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
 
@@ -27,7 +27,7 @@ class Mailer:
         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()))
@@ -42,6 +42,14 @@ class Mailer:
         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')
@@ -53,7 +61,16 @@ class Mailer:
        
     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()
@@ -83,6 +100,12 @@ class Mailer:
         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' %
@@ -95,7 +118,7 @@ class Mailer:
                 # 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: "