Mercurial > p > roundup > code
comparison roundup/scripts/roundup_mailgw.py @ 1359:ebfd8dd1cce7
missed this part of the patch, added doc
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sun, 12 Jan 2003 00:03:11 +0000 |
| parents | 36ec30d286ea |
| children | f478c236b1f6 |
comparison
equal
deleted
inserted
replaced
| 1358:e0bf31867fa5 | 1359:ebfd8dd1cce7 |
|---|---|
| 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.6 2002-09-13 00:08:44 richard Exp $ | 17 # $Id: roundup_mailgw.py,v 1.7 2003-01-12 00:03:11 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, getopt |
| 23 | 23 |
| 24 from roundup.mailgw import Message | 24 from roundup.mailgw import Message |
| 25 from roundup.i18n import _ | 25 from roundup.i18n import _ |
| 26 | 26 |
| 27 def usage(args, message=None): | 27 def usage(args, message=None): |
| 28 if message is not None: | 28 if message is not None: |
| 29 print message | 29 print message |
| 30 print _('Usage: %(program)s <instance home> [method]')%{'program': args[0]} | 30 print _('Usage: %(program)s [[-C class] -S field=value]* <instance ' |
| 31 'home> [method]')%{'program': args[0]} | |
| 31 print _(''' | 32 print _(''' |
| 32 | 33 |
| 33 The roundup mail gateway may be called in one of three ways: | 34 The roundup mail gateway may be called in one of three ways: |
| 34 . with an instance home as the only argument, | 35 . with an instance home as the only argument, |
| 35 . with both an instance home and a mail spool file, or | 36 . with both an instance home and a mail spool file, or |
| 36 . with both an instance home and a pop server account. | 37 . with both an instance home and a pop server account. |
| 38 | |
| 39 It also supports optional -C and -S arguments that allows you to set a | |
| 40 fields for a class created by the roundup-mailgw. The default class if | |
| 41 not specified is msg, but the other classes: issue, file, user can | |
| 42 also be used. The -S or --set options uses the same | |
| 43 property=value[;property=value] notation accepted by the command line | |
| 44 roundup command or the commands that can be given on the Subject line | |
| 45 of an email message. | |
| 46 | |
| 47 It can let you set the type of the message on a per email address basis. | |
| 37 | 48 |
| 38 PIPE: | 49 PIPE: |
| 39 In the first case, the mail gateway reads a single message from the | 50 In the first case, the mail gateway reads a single message from the |
| 40 standard input and submits the message to the roundup.mailgw module. | 51 standard input and submits the message to the roundup.mailgw module. |
| 41 | 52 |
| 57 are both valid. The username and/or password will be prompted for if | 68 are both valid. The username and/or password will be prompted for if |
| 58 not supplied on the command-line. | 69 not supplied on the command-line. |
| 59 ''') | 70 ''') |
| 60 return 1 | 71 return 1 |
| 61 | 72 |
| 62 def main(args): | 73 def main(argv): |
| 63 '''Handle the arguments to the program and initialise environment. | 74 '''Handle the arguments to the program and initialise environment. |
| 64 ''' | 75 ''' |
| 76 # take the argv array and parse it leaving the non-option | |
| 77 # arguments in the args array. | |
| 78 try: | |
| 79 optionsList, args = getopt.getopt(argv[1:], 'C:S:', ['set=', 'class=']) | |
| 80 except getopt.GetoptError: | |
| 81 # print help information and exit: | |
| 82 usage(argv) | |
| 83 sys.exit(2) | |
| 84 | |
| 65 # figure the instance home | 85 # figure the instance home |
| 66 if len(args) > 1: | 86 if len(args) > 0: |
| 67 instance_home = args[1] | 87 instance_home = args[0] |
| 68 else: | 88 else: |
| 69 instance_home = os.environ.get('ROUNDUP_INSTANCE', '') | 89 instance_home = os.environ.get('ROUNDUP_INSTANCE', '') |
| 70 if not instance_home: | 90 if not instance_home: |
| 71 return usage(args) | 91 return usage(argv) |
| 72 | 92 |
| 73 # get the instance | 93 # get the instance |
| 74 import roundup.instance | 94 import roundup.instance |
| 75 instance = roundup.instance.open(instance_home) | 95 instance = roundup.instance.open(instance_home) |
| 76 | 96 |
| 77 # get a mail handler | 97 # get a mail handler |
| 78 db = instance.open('admin') | 98 db = instance.open('admin') |
| 79 | 99 |
| 80 # now wrap in try/finally so we always close the database | 100 # now wrap in try/finally so we always close the database |
| 81 try: | 101 try: |
| 82 handler = instance.MailGW(instance, db) | 102 handler = instance.MailGW(instance, db, optionsList) |
| 83 | 103 |
| 84 # if there's no more arguments, read a single message from stdin | 104 # if there's no more arguments, read a single message from stdin |
| 85 if len(args) == 2: | 105 if len(args) == 1: |
| 86 return handler.do_pipe() | 106 return handler.do_pipe() |
| 87 | 107 |
| 88 # otherwise, figure what sort of mail source to handle | 108 # otherwise, figure what sort of mail source to handle |
| 89 if len(args) < 4: | 109 if len(args) < 3: |
| 90 return usage(args, _('Error: not enough source specification information')) | 110 return usage(argv, _('Error: not enough source specification information')) |
| 91 source, specification = args[2:] | 111 source, specification = args[1:] |
| 92 if source == 'mailbox': | 112 if source == 'mailbox': |
| 93 return handler.do_mailbox(specification) | 113 return handler.do_mailbox(specification) |
| 94 elif source == 'pop': | 114 elif source == 'pop': |
| 95 m = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)', | 115 m = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)', |
| 96 specification) | 116 specification) |
| 97 if m: | 117 if m: |
| 98 return handler.do_pop(m.group('server'), m.group('user'), | 118 return handler.do_pop(m.group('server'), m.group('user'), |
| 99 m.group('pass')) | 119 m.group('pass')) |
| 100 return usage(args, _('Error: pop specification not valid')) | 120 return usage(argv, _('Error: pop specification not valid')) |
| 101 | 121 |
| 102 return usage(args, _('Error: The source must be either "mailbox" or "pop"')) | 122 return usage(argv, _('Error: The source must be either "mailbox" or "pop"')) |
| 103 finally: | 123 finally: |
| 104 db.close() | 124 db.close() |
| 105 | 125 |
| 106 def run(): | 126 def run(): |
| 107 sys.exit(main(sys.argv)) | 127 sys.exit(main(sys.argv)) |
