1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: roundupdb.py,v 1.17 2001-11-12 22:01:06 richard Exp $
18+ # $Id: roundupdb.py,v 1.18 2001-11-15 10:36:17 richard Exp $
1919
2020import re , os , smtplib , socket
21+ import mimetools , MimeWriter , cStringIO
22+ import binascii , mimetypes
2123
2224import hyperdb , date
2325
@@ -316,33 +318,69 @@ def sendmessage(self, nodeid, msgid):
316318 authaddr = '<%s> ' % authaddr
317319 else :
318320 authaddr = ''
319- # TODO attachments
320- m = ['Subject: [%s%s] %s' % (cn , nodeid , title )]
321- m .append ('To: %s' % ', ' .join (sendto ))
322- m .append ('From: %s' % self .ISSUE_TRACKER_EMAIL )
323- m .append ('Reply-To: %s' % self .ISSUE_TRACKER_EMAIL )
324- m .append ('' )
321+ # make the message body
322+ m = []
325323 # add author information
326324 m .append ("%s %sadded the comment:" % (authname , authaddr ))
327325 m .append ('' )
328326 # add the content
329327 m .append (self .db .msg .get (msgid , 'content' ))
330328 # "list information" footer
331329 m .append (self .email_footer (nodeid , msgid ))
330+
331+ # get the files for this message
332+ files = self .db .msg .get (msgid , 'files' )
333+
334+ # create the message
335+ message = cStringIO .StringIO ()
336+ writer = MimeWriter .MimeWriter (message )
337+ writer .addheader ('Subject' , '[%s%s] %s' % (cn , nodeid , title ))
338+ writer .addheader ('To' , ', ' .join (sendto ))
339+ writer .addheader ('Form' , self .ISSUE_TRACKER_EMAIL )
340+ writer .addheader ('Reply-To:' , self .ISSUE_TRACKER_EMAIL )
341+ if files :
342+ part = writer .startmultipartbody ('mixed' )
343+ part = writer .nextpart ()
344+ body = part .startbody ('text/plain' )
345+ body .write ('\n ' .join (m ))
346+ for fileid in files :
347+ name = self .db .file .get (fileid , 'name' )
348+ type = self .db .file .get (fileid , 'type' )
349+ content = self .db .file .get (fileid , 'content' )
350+ part = writer .nextpart ()
351+ if type == 'text/plain' :
352+ part .addheader ('Content-Disposition' ,
353+ 'attachment;\n filename="%s"' % name )
354+ part .addheader ('Content-Transfer-Encoding' , '7bit' )
355+ body = part .startbody ('text/plain' )
356+ body .write (content )
357+ else :
358+ type = mimetypes .guess_type (name )[0 ]
359+ part .addheader ('Content-Disposition' ,
360+ 'attachment;\n filename="%s"' % name )
361+ part .addheader ('Content-Transfer-Encoding' , 'base64' )
362+ body = part .startbody (type )
363+ body .write (binascii .b2a_base64 (content ))
364+ writer .lastpart ()
365+ else :
366+ body = writer .startbody ('text/plain' )
367+ body .write ('\n ' .join (m ))
368+
369+ # now try to send the message
332370 try :
333371 smtp = smtplib .SMTP (self .MAILHOST )
334- smtp .sendmail (self .ISSUE_TRACKER_EMAIL , sendto , ' \n ' . join ( m ))
372+ smtp .sendmail (self .ISSUE_TRACKER_EMAIL , sendto , message . getvalue ( ))
335373 except socket .error , value :
336374 raise MessageSendError , \
337375 "Couldn't send confirmation email: mailhost %s" % value
338376 except smtplib .SMTPException , value :
339377 raise MessageSendError , \
340- "Couldn't send confirmation email: %s" % value
378+ "Couldn't send confirmation email: %s" % value
341379
342380 def email_footer (self , nodeid , msgid ):
343381 ''' Add a footer to the e-mail with some useful information
344382 '''
345- web = self .ISSUE_TRACKER_WEB
383+ web = self .ISSUE_TRACKER_WEB + 'issue' + nodeid
346384 return '''%s
347385Roundup issue tracker
348386%s
@@ -351,6 +389,9 @@ def email_footer(self, nodeid, msgid):
351389
352390#
353391# $Log: not supported by cvs2svn $
392+ # Revision 1.17 2001/11/12 22:01:06 richard
393+ # Fixed issues with nosy reaction and author copies.
394+ #
354395# Revision 1.16 2001/10/30 00:54:45 richard
355396# Features:
356397# . #467129 ] Lossage when username=e-mail-address
0 commit comments