Skip to content

Commit a8cc641

Browse files
author
Richard Jones
committed
missed this part of the patch, added doc
1 parent f7a17fa commit a8cc641

File tree

3 files changed

+90
-27
lines changed

3 files changed

+90
-27
lines changed

doc/user_guide.txt

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
User Guide
33
==========
44

5-
:Version: $Revision: 1.12 $
5+
:Version: $Revision: 1.13 $
66

77
.. contents::
88

@@ -302,6 +302,51 @@ message is attached to, then the config var ``MESSAGES_TO_AUTHOR`` is queried
302302
to determine if they get a nosy list copy of the message too.
303303

304304

305+
Mail gateway script command line
306+
--------------------------------
307+
308+
The roundup mail gateway may be called in one of three ways:
309+
310+
. with an instance home as the only argument,
311+
. with both an instance home and a mail spool file, or
312+
. with both an instance home and a pop server account.
313+
314+
It also supports optional -C and -S arguments that allows you to set a
315+
fields for a class created by the roundup-mailgw. The default class if
316+
not specified is msg, but the other classes: issue, file, user can
317+
also be used. The -S or --set options uses the same
318+
property=value[;property=value] notation accepted by the command line
319+
roundup command or the commands that can be given on the Subject line
320+
of an email message.
321+
322+
It can let you set the type of the message on a per email address basis.
323+
324+
PIPE:
325+
In the first case, the mail gateway reads a single message from the
326+
standard input and submits the message to the roundup.mailgw module.
327+
328+
UNIX mailbox:
329+
In the second case, the gateway reads all messages from the mail spool
330+
file and submits each in turn to the roundup.mailgw module. The file is
331+
emptied once all messages have been successfully handled. The file is
332+
specified as::
333+
334+
mailbox /path/to/mailbox
335+
336+
POP:
337+
In the third case, the gateway reads all messages from the POP server
338+
specified and submits each in turn to the roundup.mailgw module. The
339+
server is specified as::
340+
pop username:password@server
341+
342+
The username and password may be omitted::
343+
pop username@server
344+
pop server
345+
346+
are both valid. The username and/or password will be prompted for if
347+
not supplied on the command-line.
348+
349+
305350
Command Line Tool
306351
=================
307352

roundup/mailgw.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.105 2003-01-11 23:52:27 richard Exp $
76+
$Id: mailgw.py,v 1.106 2003-01-12 00:03:10 richard Exp $
7777
'''
7878

7979
import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -139,9 +139,10 @@ def getPart(self):
139139
r'\s*(?P<title>[^[]+)?"?(\[(?P<args>.+?)\])?', re.I)
140140

141141
class MailGW:
142-
def __init__(self, instance, db):
142+
def __init__(self, instance, db, arguments={}):
143143
self.instance = instance
144144
self.db = db
145+
self.arguments = {}
145146

146147
# should we trap exceptions (normal usage) or pass them through
147148
# (for testing)
@@ -496,21 +497,18 @@ def handle_message(self, message):
496497
Subject was: "%s"
497498
'''%(nodeid, subject)
498499

499-
#
500-
# Handle the options specified by the email gateway
501-
# command line. I do this by looping over the list of
502-
# self.options looking for a -C to tell me what class
503-
# I add the -S setting string to.
504-
#
500+
501+
# Handle the arguments specified by the email gateway command line.
502+
# We do this by looping over the list of self.arguments looking for
503+
# a -C to tell us what class then the -S setting string.
505504
msg_props = {}
506505
user_props = {}
507506
file_props = {}
508507
issue_props = {}
509-
# this should be true if options are set on command
510-
# line
511-
if hasattr(self, 'options'):
508+
# so, if we have any arguments, use them
509+
if self.arguments:
512510
current_class = 'msg'
513-
for option, propstring in self.options:
511+
for option, propstring in self.arguments:
514512
if option in ( '-C', '--class'):
515513
current_class = propstring.strip()
516514
if current_class not in ('msg', 'file', 'user', 'issue'):

roundup/scripts/roundup_mailgw.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,37 @@
1414
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1515
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1616
#
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 $
1818

1919
# python version check
2020
from roundup import version_check
2121

22-
import sys, os, re, cStringIO
22+
import sys, os, re, cStringIO, getopt
2323

2424
from roundup.mailgw import Message
2525
from roundup.i18n import _
2626

2727
def usage(args, message=None):
2828
if message is not None:
2929
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]}
3132
print _('''
3233
3334
The roundup mail gateway may be called in one of three ways:
3435
. with an instance home as the only argument,
3536
. with both an instance home and a mail spool file, or
3637
. 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.
3748
3849
PIPE:
3950
In the first case, the mail gateway reads a single message from the
@@ -59,16 +70,25 @@ def usage(args, message=None):
5970
''')
6071
return 1
6172

62-
def main(args):
73+
def main(argv):
6374
'''Handle the arguments to the program and initialise environment.
6475
'''
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+
6585
# figure the instance home
66-
if len(args) > 1:
67-
instance_home = args[1]
86+
if len(args) > 0:
87+
instance_home = args[0]
6888
else:
6989
instance_home = os.environ.get('ROUNDUP_INSTANCE', '')
7090
if not instance_home:
71-
return usage(args)
91+
return usage(argv)
7292

7393
# get the instance
7494
import roundup.instance
@@ -79,16 +99,16 @@ def main(args):
7999

80100
# now wrap in try/finally so we always close the database
81101
try:
82-
handler = instance.MailGW(instance, db)
102+
handler = instance.MailGW(instance, db, optionsList)
83103

84104
# if there's no more arguments, read a single message from stdin
85-
if len(args) == 2:
105+
if len(args) == 1:
86106
return handler.do_pipe()
87107

88108
# 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:]
109+
if len(args) < 3:
110+
return usage(argv, _('Error: not enough source specification information'))
111+
source, specification = args[1:]
92112
if source == 'mailbox':
93113
return handler.do_mailbox(specification)
94114
elif source == 'pop':
@@ -97,9 +117,9 @@ def main(args):
97117
if m:
98118
return handler.do_pop(m.group('server'), m.group('user'),
99119
m.group('pass'))
100-
return usage(args, _('Error: pop specification not valid'))
120+
return usage(argv, _('Error: pop specification not valid'))
101121

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"'))
103123
finally:
104124
db.close()
105125

0 commit comments

Comments
 (0)