comparison roundup/mailgw.py @ 1281:284a9d6b3cf9

bugfixes to pipe bugfix
author Richard Jones <richard@users.sourceforge.net>
date Tue, 15 Oct 2002 07:25:49 +0000
parents 8b766547d4b8
children 3a38af77b87c
comparison
equal deleted inserted replaced
1280:8b766547d4b8 1281:284a9d6b3cf9
71 set() method to add the message to the item's spool; in the second case we 71 set() method to add the message to the item's spool; in the second case we
72 are calling the create() method to create a new node). If an auditor raises 72 are calling the create() method to create a new node). If an auditor raises
73 an exception, the original message is bounced back to the sender with the 73 an exception, the original message is bounced back to the sender with the
74 explanatory message given in the exception. 74 explanatory message given in the exception.
75 75
76 $Id: mailgw.py,v 1.96 2002-10-15 06:51:32 richard Exp $ 76 $Id: mailgw.py,v 1.97 2002-10-15 07:25:49 richard Exp $
77 ''' 77 '''
78 78
79 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri 79 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
80 import time, random, sys 80 import time, random, sys
81 import traceback, MimeWriter 81 import traceback, MimeWriter
151 151
152 XXX: we may want to read this into a temporary file instead... 152 XXX: we may want to read this into a temporary file instead...
153 ''' 153 '''
154 s = cStringIO.StringIO() 154 s = cStringIO.StringIO()
155 s.write(sys.stdin.read()) 155 s.write(sys.stdin.read())
156 s.seek(0)
156 self.main(s) 157 self.main(s)
157 return 0 158 return 0
158 159
159 def do_mailbox(self, filename): 160 def do_mailbox(self, filename):
160 ''' Read a series of messages from the specified unix mailbox file and 161 ''' Read a series of messages from the specified unix mailbox file and
326 part = writer.startmultipartbody('mixed') 327 part = writer.startmultipartbody('mixed')
327 part = writer.nextpart() 328 part = writer.nextpart()
328 body = part.startbody('text/plain') 329 body = part.startbody('text/plain')
329 body.write('\n'.join(error)) 330 body.write('\n'.join(error))
330 331
331 # reconstruct the original message 332 # attach the original message to the returned message
332 m = cStringIO.StringIO() 333 part = writer.nextpart()
333 w = MimeWriter.MimeWriter(m) 334 part.addheader('Content-Disposition','attachment')
334 # default the content_type, just in case... 335 part.addheader('Content-Description','Message you sent')
335 content_type = 'text/plain' 336 body = part.startbody('text/plain')
336 # add the headers except the content-type
337 for header in message.headers: 337 for header in message.headers:
338 header_name = header.split(':')[0] 338 body.write(header)
339 if header_name.lower() == 'content-type': 339 body.write('\n')
340 content_type = message.getheader(header_name)
341 elif message.getheader(header_name):
342 w.addheader(header_name, message.getheader(header_name))
343 # now attach the message body
344 body = w.startbody(content_type)
345 try: 340 try:
346 message.rewindbody() 341 message.rewindbody()
347 except IOError, message: 342 except IOError, message:
348 body.write("*** couldn't include message body: %s ***"%message) 343 body.write("*** couldn't include message body: %s ***"%message)
349 else: 344 else:
350 body.write(message.fp.read()) 345 body.write(message.fp.read())
351
352 # attach the original message to the returned message
353 part = writer.nextpart()
354 part.addheader('Content-Disposition','attachment')
355 part.addheader('Content-Description','Message you sent')
356 part.addheader('Content-Transfer-Encoding', '7bit')
357 body = part.startbody('message/rfc822')
358 body.write(m.getvalue())
359 346
360 writer.lastpart() 347 writer.lastpart()
361 return msg 348 return msg
362 349
363 def get_part_data_decoded(self,part): 350 def get_part_data_decoded(self,part):

Roundup Issue Tracker: http://roundup-tracker.org/