Mercurial > p > roundup > code
comparison roundup/mailgw.py @ 544:d32977eb8bd4
simple help command for mailgw
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 16 Jan 2002 07:20:54 +0000 |
| parents | ad6dbc21a570 |
| children | d276d72ebdaf |
comparison
equal
deleted
inserted
replaced
| 543:22e0edf7da6e | 544:d32977eb8bd4 |
|---|---|
| 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.52 2002-01-15 00:12:40 richard Exp $ | 76 $Id: mailgw.py,v 1.53 2002-01-16 07:20:54 richard Exp $ |
| 77 ''' | 77 ''' |
| 78 | 78 |
| 79 | 79 |
| 80 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri | 80 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri |
| 81 import time, random | 81 import time, random |
| 86 | 86 |
| 87 class MailGWError(ValueError): | 87 class MailGWError(ValueError): |
| 88 pass | 88 pass |
| 89 | 89 |
| 90 class MailUsageError(ValueError): | 90 class MailUsageError(ValueError): |
| 91 pass | |
| 92 | |
| 93 class MailUsageHelp(Exception): | |
| 91 pass | 94 pass |
| 92 | 95 |
| 93 class UnAuthorized(Exception): | 96 class UnAuthorized(Exception): |
| 94 """ Access denied """ | 97 """ Access denied """ |
| 95 | 98 |
| 143 # its way into here... try to handle it gracefully | 146 # its way into here... try to handle it gracefully |
| 144 sendto = message.getaddrlist('from') | 147 sendto = message.getaddrlist('from') |
| 145 if sendto: | 148 if sendto: |
| 146 try: | 149 try: |
| 147 return self.handle_message(message) | 150 return self.handle_message(message) |
| 151 except MailUsageHelp: | |
| 152 # bounce the message back to the sender with the usage message | |
| 153 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:]) | |
| 154 sendto = [sendto[0][1]] | |
| 155 m = [''] | |
| 156 m.append('\n\nMail Gateway Help\n=================') | |
| 157 m.append(fulldoc) | |
| 158 m = self.bounce_message(message, sendto, m, | |
| 159 subject="Mail Gateway Help") | |
| 148 except MailUsageError, value: | 160 except MailUsageError, value: |
| 149 # bounce the message back to the sender with the usage message | 161 # bounce the message back to the sender with the usage message |
| 150 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:]) | 162 fulldoc = '\n'.join(string.split(__doc__, '\n')[2:]) |
| 151 sendto = [sendto[0][1]] | 163 sendto = [sendto[0][1]] |
| 152 m = [''] | 164 m = [''] |
| 236 body.write(message.fp.read()) | 248 body.write(message.fp.read()) |
| 237 | 249 |
| 238 # attach the original message to the returned message | 250 # attach the original message to the returned message |
| 239 part = writer.nextpart() | 251 part = writer.nextpart() |
| 240 part.addheader('Content-Disposition','attachment') | 252 part.addheader('Content-Disposition','attachment') |
| 241 part.addheader('Content-Description','Message that caused the error') | 253 part.addheader('Content-Description','Message you sent') |
| 242 part.addheader('Content-Transfer-Encoding', '7bit') | 254 part.addheader('Content-Transfer-Encoding', '7bit') |
| 243 body = part.startbody('message/rfc822') | 255 body = part.startbody('message/rfc822') |
| 244 body.write(m.getvalue()) | 256 body.write(m.getvalue()) |
| 245 | 257 |
| 246 writer.lastpart() | 258 writer.lastpart() |
| 251 | 263 |
| 252 Parse the message as per the module docstring. | 264 Parse the message as per the module docstring. |
| 253 ''' | 265 ''' |
| 254 # handle the subject line | 266 # handle the subject line |
| 255 subject = message.getheader('subject', '') | 267 subject = message.getheader('subject', '') |
| 268 | |
| 269 if subject.strip() == 'help': | |
| 270 raise MailUsageHelp | |
| 271 | |
| 256 m = subject_re.match(subject) | 272 m = subject_re.match(subject) |
| 257 if not m: | 273 if not m: |
| 258 raise MailUsageError, ''' | 274 raise MailUsageError, ''' |
| 259 The message you sent to roundup did not contain a properly formed subject | 275 The message you sent to roundup did not contain a properly formed subject |
| 260 line. The subject must contain a class name or designator to indicate the | 276 line. The subject must contain a class name or designator to indicate the |
| 729 l.append(section) | 745 l.append(section) |
| 730 return summary, '\n\n'.join(l) | 746 return summary, '\n\n'.join(l) |
| 731 | 747 |
| 732 # | 748 # |
| 733 # $Log: not supported by cvs2svn $ | 749 # $Log: not supported by cvs2svn $ |
| 750 # Revision 1.52 2002/01/15 00:12:40 richard | |
| 751 # #503340 ] creating issue with [asignedto=p.ohly] | |
| 752 # | |
| 734 # Revision 1.51 2002/01/14 02:20:15 richard | 753 # Revision 1.51 2002/01/14 02:20:15 richard |
| 735 # . changed all config accesses so they access either the instance or the | 754 # . changed all config accesses so they access either the instance or the |
| 736 # config attriubute on the db. This means that all config is obtained from | 755 # config attriubute on the db. This means that all config is obtained from |
| 737 # instance_config instead of the mish-mash of classes. This will make | 756 # instance_config instead of the mish-mash of classes. This will make |
| 738 # switching to a ConfigParser setup easier too, I hope. | 757 # switching to a ConfigParser setup easier too, I hope. |
