comparison roundup/mailgw.py @ 1788:e5a17d4dd2c2

Normalize multiline strings for emacs.
author Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
date Fri, 05 Sep 2003 20:56:39 +0000
parents f686c73fc5d1
children 2cd528577108
comparison
equal deleted inserted replaced
1786:7752267776cc 1788:e5a17d4dd2c2
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
18 18
19 ''' 19 """
20 An e-mail gateway for Roundup. 20 An e-mail gateway for Roundup.
21 21
22 Incoming messages are examined for multiple parts: 22 Incoming messages are examined for multiple parts:
23 . In a multipart/mixed message or part, each subpart is extracted and 23 . In a multipart/mixed message or part, each subpart is extracted and
24 examined. The text/plain subparts are assembled to form the textual 24 examined. The text/plain subparts are assembled to form the textual
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.126 2003-06-25 08:02:51 neaj Exp $ 76 $Id: mailgw.py,v 1.127 2003-09-05 20:56:39 jlgijsbers 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, rfc822 81 import traceback, MimeWriter, rfc822
82 82
92 92
93 class MailUsageHelp(Exception): 93 class MailUsageHelp(Exception):
94 pass 94 pass
95 95
96 class MailLoop(Exception): 96 class MailLoop(Exception):
97 ''' We've seen this message before... ''' 97 """ We've seen this message before... """
98 pass 98 pass
99 99
100 class Unauthorized(Exception): 100 class Unauthorized(Exception):
101 """ Access denied """ 101 """ Access denied """
102 102
213 # should we trap exceptions (normal usage) or pass them through 213 # should we trap exceptions (normal usage) or pass them through
214 # (for testing) 214 # (for testing)
215 self.trapExceptions = 1 215 self.trapExceptions = 1
216 216
217 def do_pipe(self): 217 def do_pipe(self):
218 ''' Read a message from standard input and pass it to the mail handler. 218 """ Read a message from standard input and pass it to the mail handler.
219 219
220 Read into an internal structure that we can seek on (in case 220 Read into an internal structure that we can seek on (in case
221 there's an error). 221 there's an error).
222 222
223 XXX: we may want to read this into a temporary file instead... 223 XXX: we may want to read this into a temporary file instead...
224 ''' 224 """
225 s = cStringIO.StringIO() 225 s = cStringIO.StringIO()
226 s.write(sys.stdin.read()) 226 s.write(sys.stdin.read())
227 s.seek(0) 227 s.seek(0)
228 self.main(s) 228 self.main(s)
229 return 0 229 return 0
230 230
231 def do_mailbox(self, filename): 231 def do_mailbox(self, filename):
232 ''' Read a series of messages from the specified unix mailbox file and 232 """ Read a series of messages from the specified unix mailbox file and
233 pass each to the mail handler. 233 pass each to the mail handler.
234 ''' 234 """
235 # open the spool file and lock it 235 # open the spool file and lock it
236 import fcntl 236 import fcntl
237 # FCNTL is deprecated in py2.3 and fcntl takes over all the symbols 237 # FCNTL is deprecated in py2.3 and fcntl takes over all the symbols
238 if hasattr(fcntl, 'LOCK_EX'): 238 if hasattr(fcntl, 'LOCK_EX'):
239 FCNTL = fcntl 239 FCNTL = fcntl
312 ''' fp - the file from which to read the Message. 312 ''' fp - the file from which to read the Message.
313 ''' 313 '''
314 return self.handle_Message(Message(fp)) 314 return self.handle_Message(Message(fp))
315 315
316 def handle_Message(self, message): 316 def handle_Message(self, message):
317 '''Handle an RFC822 Message 317 """Handle an RFC822 Message
318 318
319 Handle the Message object by calling handle_message() and then cope 319 Handle the Message object by calling handle_message() and then cope
320 with any errors raised by handle_message. 320 with any errors raised by handle_message.
321 This method's job is to make that call and handle any 321 This method's job is to make that call and handle any
322 errors in a sane manner. It should be replaced if you wish to 322 errors in a sane manner. It should be replaced if you wish to
323 handle errors in a different manner. 323 handle errors in a different manner.
324 ''' 324 """
325 # in some rare cases, a particularly stuffed-up e-mail will make 325 # in some rare cases, a particularly stuffed-up e-mail will make
326 # its way into here... try to handle it gracefully 326 # its way into here... try to handle it gracefully
327 sendto = message.getaddrlist('from') 327 sendto = message.getaddrlist('from')
328 if sendto: 328 if sendto:
329 if not self.trapExceptions: 329 if not self.trapExceptions:
521 else: 521 else:
522 # fail 522 # fail
523 m = None 523 m = None
524 524
525 if not m: 525 if not m:
526 raise MailUsageError, ''' 526 raise MailUsageError, """
527 The message you sent to roundup did not contain a properly formed subject 527 The message you sent to roundup did not contain a properly formed subject
528 line. The subject must contain a class name or designator to indicate the 528 line. The subject must contain a class name or designator to indicate the
529 "topic" of the message. For example: 529 'topic' of the message. For example:
530 Subject: [issue] This is a new issue 530 Subject: [issue] This is a new issue
531 - this will create a new issue in the tracker with the title "This is 531 - this will create a new issue in the tracker with the title 'This is
532 a new issue". 532 a new issue'.
533 Subject: [issue1234] This is a followup to issue 1234 533 Subject: [issue1234] This is a followup to issue 1234
534 - this will append the message's contents to the existing issue 1234 534 - this will append the message's contents to the existing issue 1234
535 in the tracker. 535 in the tracker.
536 536
537 Subject was: "%s" 537 Subject was: '%s'
538 '''%subject 538 """%subject
539 539
540 # get the class 540 # get the class
541 try: 541 try:
542 cl = self.db.getclass(classname) 542 cl = self.db.getclass(classname)
543 except KeyError: 543 except KeyError:

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