Mercurial > p > roundup > code
comparison roundup/mailgw.py @ 2123:95da13c1bdbd
have bounce_message do the error_messages_to heavy-lifting
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 25 Mar 2004 22:52:12 +0000 |
| parents | cc4667ef3f12 |
| children | 3fd672293712 |
comparison
equal
deleted
inserted
replaced
| 2122:7109f83d5250 | 2123:95da13c1bdbd |
|---|---|
| 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.144 2004-03-25 19:27:15 eparker Exp $ | 75 $Id: mailgw.py,v 1.145 2004-03-25 22:52:12 richard 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 |
| 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 | 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 | |
| 437 sendto = message.getaddrlist('resent-from') | 433 sendto = message.getaddrlist('resent-from') |
| 438 if not sendto: | 434 if not sendto: |
| 439 sendto = message.getaddrlist('from') | 435 sendto = message.getaddrlist('from') |
| 440 if not sendto: | 436 if not sendto: |
| 441 # very bad-looking message - we don't even know who sent it | 437 # very bad-looking message - we don't even know who sent it |
| 442 # XXX we should use a log file here... | 438 # XXX we should use a log file here... |
| 443 | 439 |
| 444 # [EP] This section was originally only to admin.. Not sure if this should ever go to the user? | 440 sendto = [self.instance.config.ADMIN_EMAIL] |
| 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 | 441 |
| 453 m = ['Subject: badly formed message from mail gateway'] | 442 m = ['Subject: badly formed message from mail gateway'] |
| 454 m.append('') | 443 m.append('') |
| 455 m.append('The mail gateway retrieved a message which has no From:') | 444 m.append('The mail gateway retrieved a message which has no From:') |
| 456 m.append('line, indicating that it is corrupt. Please check your') | 445 m.append('line, indicating that it is corrupt. Please check your') |
| 466 try: | 455 try: |
| 467 return self.handle_message(message) | 456 return self.handle_message(message) |
| 468 except MailUsageHelp: | 457 except MailUsageHelp: |
| 469 # bounce the message back to the sender with the usage message | 458 # bounce the message back to the sender with the usage message |
| 470 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:]) | 459 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:]) |
| 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 | |
| 478 m = [''] | 460 m = [''] |
| 479 m.append('\n\nMail Gateway Help\n=================') | 461 m.append('\n\nMail Gateway Help\n=================') |
| 480 m.append(fulldoc) | 462 m.append(fulldoc) |
| 481 self.mailer.bounce_message(message, sendto, m, | 463 self.mailer.bounce_message(message, [sendto[0][1]], m, |
| 482 subject="Mail Gateway Help") | 464 subject="Mail Gateway Help") |
| 483 except MailUsageError, value: | 465 except MailUsageError, value: |
| 484 # bounce the message back to the sender with the usage message | 466 # bounce the message back to the sender with the usage message |
| 485 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:]) | 467 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:]) |
| 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]] | |
| 493 m = [''] | 468 m = [''] |
| 494 m.append(str(value)) | 469 m.append(str(value)) |
| 495 m.append('\n\nMail Gateway Help\n=================') | 470 m.append('\n\nMail Gateway Help\n=================') |
| 496 m.append(fulldoc) | 471 m.append(fulldoc) |
| 497 self.mailer.bounce_message(message, sendto, m) | 472 self.mailer.bounce_message(message, [sendto[0][1]], m) |
| 498 except Unauthorized, value: | 473 except Unauthorized, value: |
| 499 # just inform the user that he is not authorized | 474 # just inform the user that he is not authorized |
| 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]] | |
| 507 m = [''] | 475 m = [''] |
| 508 m.append(str(value)) | 476 m.append(str(value)) |
| 509 self.mailer.bounce_message(message, sendto, m) | 477 self.mailer.bounce_message(message, [sendto[0][1]], m) |
| 510 except IgnoreMessage: | 478 except IgnoreMessage: |
| 511 # XXX we should use a log file here... | 479 # XXX we should use a log file here... |
| 512 # do not take any action | 480 # do not take any action |
| 513 # this exception is thrown when email should be ignored | 481 # this exception is thrown when email should be ignored |
| 514 return | 482 return |
| 515 except: | 483 except: |
| 516 # bounce the message back to the sender with the error message | 484 # bounce the message back to the sender with the error message |
| 517 # XXX we should use a log file here... | 485 # XXX we should use a log file here... |
| 518 | 486 # let the admin know that something very bad is happening |
| 519 if(errorMessagesTo == "dispatcher"): | 487 sendto = [sendto[0][1], self.instance.config.ADMIN_EMAIL] |
| 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 | |
| 526 m = [''] | 488 m = [''] |
| 527 m.append('An unexpected error occurred during the processing') | 489 m.append('An unexpected error occurred during the processing') |
| 528 m.append('of your message. The tracker administrator is being') | 490 m.append('of your message. The tracker administrator is being') |
| 529 m.append('notified.\n') | 491 m.append('notified.\n') |
| 530 m.append('---- traceback of failure ----') | 492 m.append('---- traceback of failure ----') |
