comparison roundup/mailgw.py @ 1383:f19dde90e473

applied unicode patch
author Andrey Lebedev <kedder@users.sourceforge.net>
date Wed, 15 Jan 2003 22:17:20 +0000
parents ebfd8dd1cce7
children 27586da5557c
comparison
equal deleted inserted replaced
1382:87143c3d7156 1383:f19dde90e473
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.106 2003-01-12 00:03:10 richard Exp $ 76 $Id: mailgw.py,v 1.107 2003-01-15 22:17:19 kedder 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
82 import hyperdb, date, password 82 import hyperdb, date, password
83
84 import rfc2822
83 85
84 SENDMAILDEBUG = os.environ.get('SENDMAILDEBUG', '') 86 SENDMAILDEBUG = os.environ.get('SENDMAILDEBUG', '')
85 87
86 class MailGWError(ValueError): 88 class MailGWError(ValueError):
87 pass 89 pass
132 if not s.getvalue().strip(): 134 if not s.getvalue().strip():
133 return None 135 return None
134 s.seek(0) 136 s.seek(0)
135 return Message(s) 137 return Message(s)
136 138
139 def getheader(self, name, default=None):
140 hdr = mimetools.Message.getheader(self, name, default)
141 return rfc2822.decode_header(hdr)
142
137 subject_re = re.compile(r'(?P<refwd>\s*\W?\s*(fw|fwd|re|aw)\W\s*)*' 143 subject_re = re.compile(r'(?P<refwd>\s*\W?\s*(fw|fwd|re|aw)\W\s*)*'
138 r'\s*(?P<quote>")?(\[(?P<classname>[^\d\s]+)(?P<nodeid>\d+)?\])?' 144 r'\s*(?P<quote>")?(\[(?P<classname>[^\d\s]+)(?P<nodeid>\d+)?\])?'
139 r'\s*(?P<title>[^[]+)?"?(\[(?P<args>.+?)\])?', re.I) 145 r'\s*(?P<title>[^[]+)?"?(\[(?P<args>.+?)\])?', re.I)
140 146
141 class MailGW: 147 class MailGW:
337 writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000", 343 writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000",
338 time.gmtime())) 344 time.gmtime()))
339 writer.addheader('MIME-Version', '1.0') 345 writer.addheader('MIME-Version', '1.0')
340 part = writer.startmultipartbody('mixed') 346 part = writer.startmultipartbody('mixed')
341 part = writer.nextpart() 347 part = writer.nextpart()
342 body = part.startbody('text/plain') 348 body = part.startbody('text/plain; charset=utf-8')
343 body.write('\n'.join(error)) 349 body.write('\n'.join(error))
344 350
345 # attach the original message to the returned message 351 # attach the original message to the returned message
346 part = writer.nextpart() 352 part = writer.nextpart()
347 part.addheader('Content-Disposition','attachment') 353 part.addheader('Content-Disposition','attachment')
375 elif encoding == 'uuencoded': 381 elif encoding == 'uuencoded':
376 data = binascii.a2b_uu(part.fp.read()) 382 data = binascii.a2b_uu(part.fp.read())
377 else: 383 else:
378 # take it as text 384 # take it as text
379 data = part.fp.read() 385 data = part.fp.read()
380 return data 386
387 # Encode message to unicode
388 charset = rfc2822.unaliasCharset(part.getparam("charset"))
389 if charset:
390 # Do conversion only if charset specified
391 edata = unicode(data, charset).encode('utf-8')
392 # Convert from dos eol to unix
393 edata = edata.replace('\r\n', '\n')
394 else:
395 # Leave message content as is
396 edata = data
397
398 return edata
381 399
382 def handle_message(self, message): 400 def handle_message(self, message):
383 ''' message - a Message instance 401 ''' message - a Message instance
384 402
385 Parse the message as per the module docstring. 403 Parse the message as per the module docstring.

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