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
44import 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\n TO: %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: "
0 commit comments