comparison roundup/mailgw.py @ 2119:cc4667ef3f12

Added the ability to toggle where error messages go. They either go to the user (default, for backwards compatibility), the dispatcher, or both. These are able to be toggled via settings in config.py. Please refer to upgrading.txt for more details. (And Richard, let me know if I've done anything wrong with this checkin. :))
author Eddie Parker <eparker@users.sourceforge.net>
date Thu, 25 Mar 2004 19:27:15 +0000
parents fc52d57c6c3e
children 95da13c1bdbd
comparison
equal deleted inserted replaced
2118:917826e3fb54 2119:cc4667ef3f12
70 set() method to add the message to the item's spool; in the second case we 70 set() method to add the message to the item's spool; in the second case we
71 are calling the create() method to create a new node). If an auditor raises 71 are calling the create() method to create a new node). If an auditor raises
72 an exception, the original message is bounced back to the sender with the 72 an exception, the original message is bounced back to the sender with the
73 explanatory message given in the exception. 73 explanatory message given in the exception.
74 74
75 $Id: mailgw.py,v 1.143 2004-02-11 23:55:08 richard Exp $ 75 $Id: mailgw.py,v 1.144 2004-03-25 19:27:15 eparker Exp $
76 """ 76 """
77 __docformat__ = 'restructuredtext' 77 __docformat__ = 'restructuredtext'
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
427 errors in a sane manner. It should be replaced if you wish to 427 errors in a sane manner. It should be replaced if you wish to
428 handle errors in a different manner. 428 handle errors in a different manner.
429 """ 429 """
430 # in some rare cases, a particularly stuffed-up e-mail will make 430 # in some rare cases, a particularly stuffed-up e-mail will make
431 # its way into here... try to handle it gracefully 431 # its way into here... try to handle it gracefully
432
433 # Setting the dispatcher e-mail here, so as not to clutter things. Defaulting to ADMIN_EMAIL, if not set.
434 dispatcherEmail = getattr(self.instance.config, "DISPATCHER_EMAIL", getattr(self.instance.config, "ADMIN_EMAIL"))
435 errorMessagesTo = getattr(self.instance.config, "ERROR_MESSAGES_TO", "user")
436
432 sendto = message.getaddrlist('resent-from') 437 sendto = message.getaddrlist('resent-from')
433 if not sendto: 438 if not sendto:
434 sendto = message.getaddrlist('from') 439 sendto = message.getaddrlist('from')
435 if not sendto: 440 if not sendto:
436 # very bad-looking message - we don't even know who sent it 441 # very bad-looking message - we don't even know who sent it
437 # XXX we should use a log file here... 442 # XXX we should use a log file here...
438 sendto = [self.instance.config.ADMIN_EMAIL] 443
444 # [EP] This section was originally only to admin.. Not sure if this should ever go to the user?
445
446 if(errorMessagesTo == "dispatcher"):
447 sendto = [dispatcherEmail]
448 elif(errorMessagesTo == "both"):
449 sendto = [dispatcherEmail, self.instance.config.ADMIN_EMAIL]
450 else:
451 sendto = [self.instance.config.ADMIN_EMAIL]
452
439 m = ['Subject: badly formed message from mail gateway'] 453 m = ['Subject: badly formed message from mail gateway']
440 m.append('') 454 m.append('')
441 m.append('The mail gateway retrieved a message which has no From:') 455 m.append('The mail gateway retrieved a message which has no From:')
442 m.append('line, indicating that it is corrupt. Please check your') 456 m.append('line, indicating that it is corrupt. Please check your')
443 m.append('mail gateway source. Failed message is attached.') 457 m.append('mail gateway source. Failed message is attached.')
452 try: 466 try:
453 return self.handle_message(message) 467 return self.handle_message(message)
454 except MailUsageHelp: 468 except MailUsageHelp:
455 # bounce the message back to the sender with the usage message 469 # bounce the message back to the sender with the usage message
456 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:]) 470 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:])
457 sendto = [sendto[0][1]] 471 if(errorMessagesTo == "dispatcher"):
472 sendto = [dispatcherEmail]
473 elif(errorMessagesTo == "both"):
474 sendto = [dispatcherEmail, sendto[0][1]]
475 else:
476 sendto = [sendto[0][1]]
477
458 m = [''] 478 m = ['']
459 m.append('\n\nMail Gateway Help\n=================') 479 m.append('\n\nMail Gateway Help\n=================')
460 m.append(fulldoc) 480 m.append(fulldoc)
461 self.mailer.bounce_message(message, sendto, m, 481 self.mailer.bounce_message(message, sendto, m,
462 subject="Mail Gateway Help") 482 subject="Mail Gateway Help")
463 except MailUsageError, value: 483 except MailUsageError, value:
464 # bounce the message back to the sender with the usage message 484 # bounce the message back to the sender with the usage message
465 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:]) 485 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:])
466 sendto = [sendto[0][1]] 486
487 if(errorMessagesTo == "dispatcher"):
488 sendto = [dispatcherEmail]
489 elif(errorMessagesTo == "both"):
490 sendto = [dispatcherEmail, sendto[0][1]]
491 else:
492 sendto = [sendto[0][1]]
467 m = [''] 493 m = ['']
468 m.append(str(value)) 494 m.append(str(value))
469 m.append('\n\nMail Gateway Help\n=================') 495 m.append('\n\nMail Gateway Help\n=================')
470 m.append(fulldoc) 496 m.append(fulldoc)
471 self.mailer.bounce_message(message, sendto, m) 497 self.mailer.bounce_message(message, sendto, m)
472 except Unauthorized, value: 498 except Unauthorized, value:
473 # just inform the user that he is not authorized 499 # just inform the user that he is not authorized
474 sendto = [sendto[0][1]] 500
501 if(errorMessagesTo == "dispatcher"):
502 sendto = [dispatcherEmail]
503 elif(errorMessagesTo == "both"):
504 sendto = [dispatcherEmail, sendto[0][1]]
505 else:
506 sendto = [sendto[0][1]]
475 m = [''] 507 m = ['']
476 m.append(str(value)) 508 m.append(str(value))
477 self.mailer.bounce_message(message, sendto, m) 509 self.mailer.bounce_message(message, sendto, m)
478 except IgnoreMessage: 510 except IgnoreMessage:
479 # XXX we should use a log file here... 511 # XXX we should use a log file here...
481 # this exception is thrown when email should be ignored 513 # this exception is thrown when email should be ignored
482 return 514 return
483 except: 515 except:
484 # bounce the message back to the sender with the error message 516 # bounce the message back to the sender with the error message
485 # XXX we should use a log file here... 517 # XXX we should use a log file here...
486 sendto = [sendto[0][1], self.instance.config.ADMIN_EMAIL] 518
519 if(errorMessagesTo == "dispatcher"):
520 sendto = [dispatcherEmail]
521 elif(errorMessagesTo == "both"):
522 sendto = [dispatcherEmail, sendto[0][1], self.instance.config.ADMIN_EMAIL]
523 else:
524 sendto = [sendto[0][1], self.instance.config.ADMIN_EMAIL]
525
487 m = [''] 526 m = ['']
488 m.append('An unexpected error occurred during the processing') 527 m.append('An unexpected error occurred during the processing')
489 m.append('of your message. The tracker administrator is being') 528 m.append('of your message. The tracker administrator is being')
490 m.append('notified.\n') 529 m.append('notified.\n')
491 m.append('---- traceback of failure ----') 530 m.append('---- traceback of failure ----')

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