Mercurial > p > roundup > code
comparison roundup/scripts/roundup_mailgw.py @ 1133:36ec30d286ea
Cleaned up CHANGES/TODO
Added try/finally to enforce db.close()
Changed default classic issue item display to only show message summary
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 13 Sep 2002 00:08:44 +0000 |
| parents | 1c1ccfc9673d |
| children | ebfd8dd1cce7 de4fa8bed9d3 |
comparison
equal
deleted
inserted
replaced
| 1132:77581d5309f2 | 1133:36ec30d286ea |
|---|---|
| 12 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 12 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 13 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 13 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 16 # | 16 # |
| 17 # $Id: roundup_mailgw.py,v 1.5 2002-09-11 01:19:16 richard Exp $ | 17 # $Id: roundup_mailgw.py,v 1.6 2002-09-13 00:08:44 richard Exp $ |
| 18 | 18 |
| 19 # python version check | 19 # python version check |
| 20 from roundup import version_check | 20 from roundup import version_check |
| 21 | 21 |
| 22 import sys, os, re, cStringIO | 22 import sys, os, re, cStringIO |
| 74 import roundup.instance | 74 import roundup.instance |
| 75 instance = roundup.instance.open(instance_home) | 75 instance = roundup.instance.open(instance_home) |
| 76 | 76 |
| 77 # get a mail handler | 77 # get a mail handler |
| 78 db = instance.open('admin') | 78 db = instance.open('admin') |
| 79 handler = instance.MailGW(instance, db) | |
| 80 | 79 |
| 81 # if there's no more arguments, read a single message from stdin | 80 # now wrap in try/finally so we always close the database |
| 82 if len(args) == 2: | 81 try: |
| 83 return handler.do_pipe() | 82 handler = instance.MailGW(instance, db) |
| 84 | 83 |
| 85 # otherwise, figure what sort of mail source to handle | 84 # if there's no more arguments, read a single message from stdin |
| 86 if len(args) < 4: | 85 if len(args) == 2: |
| 87 return usage(args, _('Error: not enough source specification information')) | 86 return handler.do_pipe() |
| 88 source, specification = args[2:] | |
| 89 if source == 'mailbox': | |
| 90 return handler.do_mailbox(specification) | |
| 91 elif source == 'pop': | |
| 92 m = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)', | |
| 93 specification) | |
| 94 if m: | |
| 95 return handler.do_pop(m.group('server'), m.group('user'), | |
| 96 m.group('pass')) | |
| 97 return usage(args, _('Error: pop specification not valid')) | |
| 98 | 87 |
| 99 return usage(args, _('Error: The source must be either "mailbox" or "pop"')) | 88 # otherwise, figure what sort of mail source to handle |
| 89 if len(args) < 4: | |
| 90 return usage(args, _('Error: not enough source specification information')) | |
| 91 source, specification = args[2:] | |
| 92 if source == 'mailbox': | |
| 93 return handler.do_mailbox(specification) | |
| 94 elif source == 'pop': | |
| 95 m = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)', | |
| 96 specification) | |
| 97 if m: | |
| 98 return handler.do_pop(m.group('server'), m.group('user'), | |
| 99 m.group('pass')) | |
| 100 return usage(args, _('Error: pop specification not valid')) | |
| 101 | |
| 102 return usage(args, _('Error: The source must be either "mailbox" or "pop"')) | |
| 103 finally: | |
| 104 db.close() | |
| 100 | 105 |
| 101 def run(): | 106 def run(): |
| 102 sys.exit(main(sys.argv)) | 107 sys.exit(main(sys.argv)) |
| 103 | 108 |
| 104 # call main | 109 # call main |
