annotate roundup/scripts/roundup_mailgw.py @ 3696:790363e96852

Sorting/grouping by multiple properties. - Implement sorting/grouping by multiple properties for the web interface. I'm now using @sort0/@sortdir0,@sort1/@sortdir1,... and @group0/@groupdir0,... when generating URLs from a search template. These are converted to a list internally. When saving URLs (e.g. when storing queries) I'm using @sort=prop1,prop2,... and @group=... with optional '-' prepended to individual props. This means saved URLs are backward compatible with existing trackers (and yes, this was a design goal). I need the clumsy version with @sort0,@sort1 etc, because I'm currently using several selectors and checkboxes (as the classic template does, too). I don't think there is a way around that in HTML? - Updated (hopefully all) documentation to reflect the new URL format and the consequences in the web-interface. - I've set the number of sort/group properties in the classic template to two -- this can easily be reverted by changing n_sort to 1. Richard, would you look over these changes? I've set a tag before and (will set) after commit, so that it would be easy to merge out. Don't be too scared about the size of the change, most is documentation, the guts are in cgi/templating.py and small changes in the classic template.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Wed, 30 Aug 2006 20:28:26 +0000
parents 22ec8e91da2b
children ee73abcc95d2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
1 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
2 # This module is free software, and you may redistribute it and/or modify
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
3 # under the same terms as Python, so long as this copyright message and
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
4 # disclaimer are retained in their original form.
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
5 #
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
6 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
7 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
8 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
9 # POSSIBILITY OF SUCH DAMAGE.
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
10 #
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
11 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
12 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
13 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
2284
3be606e3f58e print usage and exit if first non-option argument is not a directory
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2256
diff changeset
16 #
3638
22ec8e91da2b Fix -c option (default class) for roundup-mailgw
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3386
diff changeset
17 # $Id: roundup_mailgw.py,v 1.22 2006-07-15 10:08:01 schlatterbeck Exp $
2005
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1606
diff changeset
18
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1606
diff changeset
19 """Command-line script stub that calls the roundup.mailgw.
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1606
diff changeset
20 """
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1606
diff changeset
21 __docformat__ = 'restructuredtext'
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
22
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
23 # python version check
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
24 from roundup import version_check
2186
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
25 from roundup import __version__ as roundup_version
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
26
3386
263e8f485db5 don't try to set a timeout for IMAPS (thanks Paul Jimenez)
Richard Jones <richard@users.sourceforge.net>
parents: 2672
diff changeset
27 import sys, os, re, cStringIO, getopt, socket
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
28
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2372
diff changeset
29 from roundup import mailgw
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
30 from roundup.i18n import _
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
31
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
32 def usage(args, message=None):
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
33 if message is not None:
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
34 print message
2328
b54ad9ed394a join adjacent translatable strings
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2284
diff changeset
35 print _(
3638
22ec8e91da2b Fix -c option (default class) for roundup-mailgw
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3386
diff changeset
36 """Usage: %(program)s [-v] [-c class] [[-C class] -S field=value]* <instance home> [method]
2328
b54ad9ed394a join adjacent translatable strings
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2284
diff changeset
37
2186
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
38 Options:
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
39 -v: print version and exit
2672
437775793d8e mailgw can override the MAIL_DEFUALT_CLASS
Richard Jones <richard@users.sourceforge.net>
parents: 2633
diff changeset
40 -c: default class of item to create (else the tracker's MAIL_DEFAULT_CLASS)
2186
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
41 -C / -S: see below
1107
1c1ccfc9673d reorganised mailgw code
Richard Jones <richard@users.sourceforge.net>
parents: 1092
diff changeset
42
2211
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
43 The roundup mail gateway may be called in one of four ways:
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
44 . with an instance home as the only argument,
2328
b54ad9ed394a join adjacent translatable strings
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2284
diff changeset
45 . with both an instance home and a mail spool file,
b54ad9ed394a join adjacent translatable strings
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2284
diff changeset
46 . with both an instance home and a POP/APOP server account, or
2211
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
47 . with both an instance home and a IMAP/IMAPS server account.
2284
3be606e3f58e print usage and exit if first non-option argument is not a directory
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2256
diff changeset
48
1359
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
49 It also supports optional -C and -S arguments that allows you to set a
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
50 fields for a class created by the roundup-mailgw. The default class if
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
51 not specified is msg, but the other classes: issue, file, user can
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
52 also be used. The -S or --set options uses the same
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
53 property=value[;property=value] notation accepted by the command line
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
54 roundup command or the commands that can be given on the Subject line
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
55 of an email message.
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
56
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
57 It can let you set the type of the message on a per email address basis.
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
58
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
59 PIPE:
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
60 In the first case, the mail gateway reads a single message from the
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
61 standard input and submits the message to the roundup.mailgw module.
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
62
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
63 UNIX mailbox:
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
64 In the second case, the gateway reads all messages from the mail spool
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
65 file and submits each in turn to the roundup.mailgw module. The file is
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
66 emptied once all messages have been successfully handled. The file is
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
67 specified as:
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
68 mailbox /path/to/mailbox
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
69
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
70 POP:
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
71 In the third case, the gateway reads all messages from the POP server
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
72 specified and submits each in turn to the roundup.mailgw module. The
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
73 server is specified as:
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
74 pop username:password@server
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
75 The username and password may be omitted:
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
76 pop username@server
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
77 pop server
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
78 are both valid. The username and/or password will be prompted for if
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
79 not supplied on the command-line.
1547
f478c236b1f6 roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents: 1359
diff changeset
80
f478c236b1f6 roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents: 1359
diff changeset
81 APOP:
1548
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
82 Same as POP, but using Authenticated POP:
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
83 apop username:password@server
1547
f478c236b1f6 roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents: 1359
diff changeset
84
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
85 IMAP:
2211
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
86 Connect to an IMAP server. This supports the same notation as that of
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
87 POP mail.
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
88 imap username:password@server
2211
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
89 It also allows you to specify a specific mailbox other than INBOX using
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
90 this format:
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
91 imap username:password@server mailbox
2284
3be606e3f58e print usage and exit if first non-option argument is not a directory
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2256
diff changeset
92
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
93 IMAPS:
2284
3be606e3f58e print usage and exit if first non-option argument is not a directory
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2256
diff changeset
94 Connect to an IMAP server over ssl.
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
95 This supports the same notation as IMAP.
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
96 imaps username:password@server [mailbox]
2284
3be606e3f58e print usage and exit if first non-option argument is not a directory
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2256
diff changeset
97
2328
b54ad9ed394a join adjacent translatable strings
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2284
diff changeset
98 """)%{'program': args[0]}
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
99 return 1
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
100
1359
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
101 def main(argv):
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
102 '''Handle the arguments to the program and initialise environment.
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
103 '''
1359
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
104 # take the argv array and parse it leaving the non-option
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
105 # arguments in the args array.
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
106 try:
3638
22ec8e91da2b Fix -c option (default class) for roundup-mailgw
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 3386
diff changeset
107 optionsList, args = getopt.getopt(argv[1:], 'vc:C:S:', ['set=',
2211
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
108 'class='])
1359
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
109 except getopt.GetoptError:
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
110 # print help information and exit:
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
111 usage(argv)
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
112 sys.exit(2)
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
113
2186
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
114 for (opt, arg) in optionsList:
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
115 if opt == '-v':
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
116 print '%s (python %s)'%(roundup_version, sys.version.split()[0])
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
117 return
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
118
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
119 # figure the instance home
1359
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
120 if len(args) > 0:
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
121 instance_home = args[0]
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
122 else:
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
123 instance_home = os.environ.get('ROUNDUP_INSTANCE', '')
2284
3be606e3f58e print usage and exit if first non-option argument is not a directory
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2256
diff changeset
124 if not (instance_home and os.path.isdir(instance_home)):
1359
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
125 return usage(argv)
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
126
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
127 # get the instance
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
128 import roundup.instance
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
129 instance = roundup.instance.open(instance_home)
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
130
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
131 # get a mail handler
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
132 db = instance.open('admin')
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
133
1133
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
134 # now wrap in try/finally so we always close the database
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
135 try:
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2372
diff changeset
136 if hasattr(instance, 'MailGW'):
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2372
diff changeset
137 handler = instance.MailGW(instance, db, optionsList)
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2372
diff changeset
138 else:
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2372
diff changeset
139 handler = mailgw.MailGW(instance, db, optionsList)
1133
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
140
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
141 # if there's no more arguments, read a single message from stdin
1359
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
142 if len(args) == 1:
1133
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
143 return handler.do_pipe()
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
144
1133
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
145 # otherwise, figure what sort of mail source to handle
1359
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
146 if len(args) < 3:
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
147 return usage(argv, _('Error: not enough source specification information'))
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
148 source, specification = args[1:3]
3386
263e8f485db5 don't try to set a timeout for IMAPS (thanks Paul Jimenez)
Richard Jones <richard@users.sourceforge.net>
parents: 2672
diff changeset
149
263e8f485db5 don't try to set a timeout for IMAPS (thanks Paul Jimenez)
Richard Jones <richard@users.sourceforge.net>
parents: 2672
diff changeset
150 # time out net connections after a minute if we can
263e8f485db5 don't try to set a timeout for IMAPS (thanks Paul Jimenez)
Richard Jones <richard@users.sourceforge.net>
parents: 2672
diff changeset
151 if source not in ('mailbox', 'imaps'):
263e8f485db5 don't try to set a timeout for IMAPS (thanks Paul Jimenez)
Richard Jones <richard@users.sourceforge.net>
parents: 2672
diff changeset
152 if hasattr(socket, 'setdefaulttimeout'):
263e8f485db5 don't try to set a timeout for IMAPS (thanks Paul Jimenez)
Richard Jones <richard@users.sourceforge.net>
parents: 2672
diff changeset
153 socket.setdefaulttimeout(60)
263e8f485db5 don't try to set a timeout for IMAPS (thanks Paul Jimenez)
Richard Jones <richard@users.sourceforge.net>
parents: 2672
diff changeset
154
1133
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
155 if source == 'mailbox':
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
156 return handler.do_mailbox(specification)
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
157 elif source == 'pop':
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
158 m = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)',
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
159 specification)
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
160 if m:
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
161 return handler.do_pop(m.group('server'), m.group('user'),
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
162 m.group('pass'))
1359
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
163 return usage(argv, _('Error: pop specification not valid'))
1548
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
164 elif source == 'apop':
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
165 m = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)',
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
166 specification)
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
167 if m:
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
168 return handler.do_apop(m.group('server'), m.group('user'),
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
169 m.group('pass'))
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
170 return usage(argv, _('Error: apop specification not valid'))
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
171 elif source == 'imap' or source == 'imaps':
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
172 m = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)',
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
173 specification)
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
174 if m:
2256
0b198ed096af fixes for py2.1 (booleans, sigh)
Richard Jones <richard@users.sourceforge.net>
parents: 2211
diff changeset
175 ssl = 0
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
176 if source == 'imaps':
2256
0b198ed096af fixes for py2.1 (booleans, sigh)
Richard Jones <richard@users.sourceforge.net>
parents: 2211
diff changeset
177 ssl = 1
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
178 mailbox = ''
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
179 if len(args) > 3:
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
180 mailbox = args[3]
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
181 return handler.do_imap(m.group('server'), m.group('user'),
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
182 m.group('pass'), mailbox, ssl)
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
183
2211
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
184 return usage(argv, _('Error: The source must be either "mailbox",'
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
185 ' "pop", "apop", "imap" or "imaps"'))
1133
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
186 finally:
2372
c26bb78d2f0c couple of bugfixes
Richard Jones <richard@users.sourceforge.net>
parents: 2328
diff changeset
187 # handler might have closed the initial db and opened a new one
c26bb78d2f0c couple of bugfixes
Richard Jones <richard@users.sourceforge.net>
parents: 2328
diff changeset
188 handler.db.close()
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
189
593
2256f81293c1 Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents: 592
diff changeset
190 def run():
2256f81293c1 Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents: 592
diff changeset
191 sys.exit(main(sys.argv))
2256f81293c1 Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents: 592
diff changeset
192
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
193 # call main
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
194 if __name__ == '__main__':
593
2256f81293c1 Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents: 592
diff changeset
195 run()
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
196
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
197 # vim: set filetype=python ts=4 sw=4 et si

Roundup Issue Tracker: http://roundup-tracker.org/