Mercurial > p > roundup > code
annotate roundup/scripts/roundup_mailgw.py @ 4796:f61bd780892e 1.5.0
Release preparation
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Sat, 06 Jul 2013 12:50:52 +0200 |
| parents | 86ef4ab17dc5 |
| children | 63574f1f3570 |
| 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. |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1606
diff
changeset
|
16 |
|
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1606
diff
changeset
|
17 """Command-line script stub that calls the roundup.mailgw. |
|
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 __docformat__ = 'restructuredtext' |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
20 |
|
4766
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
21 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
22 # --- patch sys.path to make sure 'import roundup' finds correct version |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
23 import sys |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
24 import os.path as osp |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
25 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
26 thisdir = osp.dirname(osp.abspath(__file__)) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
27 rootdir = osp.dirname(osp.dirname(thisdir)) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
28 if (osp.exists(thisdir + '/__init__.py') and |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
29 osp.exists(rootdir + '/roundup/__init__.py')): |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
30 # the script is located inside roundup source code |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
31 sys.path.insert(0, rootdir) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
32 # --/ |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
33 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
34 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
35 # python version check |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
36 from roundup import version_check |
|
2186
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
37 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
|
38 |
|
4000
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
39 import sys, os, re, cStringIO, getopt, socket, netrc |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
40 |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2372
diff
changeset
|
41 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
|
42 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
|
43 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
44 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
|
45 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
|
46 print message |
|
2328
b54ad9ed394a
join adjacent translatable strings
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2284
diff
changeset
|
47 print _( |
|
3638
22ec8e91da2b
Fix -c option (default class) for roundup-mailgw
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3386
diff
changeset
|
48 """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
|
49 |
|
2186
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
50 Options: |
|
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
51 -v: print version and exit |
|
2672
437775793d8e
mailgw can override the MAIL_DEFUALT_CLASS
Richard Jones <richard@users.sourceforge.net>
parents:
2633
diff
changeset
|
52 -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
|
53 -C / -S: see below |
|
1107
1c1ccfc9673d
reorganised mailgw code
Richard Jones <richard@users.sourceforge.net>
parents:
1092
diff
changeset
|
54 |
|
2211
272b654b1227
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
2210
diff
changeset
|
55 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
|
56 . with an instance home as the only argument, |
|
2328
b54ad9ed394a
join adjacent translatable strings
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2284
diff
changeset
|
57 . 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
|
58 . 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
|
59 . 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
|
60 |
|
1359
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 of an email message. |
|
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
68 |
|
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
69 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
|
70 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
71 PIPE: |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
72 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
|
73 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
|
74 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
75 UNIX mailbox: |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 specified as: |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
80 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
|
81 |
|
4000
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
82 In all of the following the username and password can be stored in a |
|
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
83 ~/.netrc file. In this case only the server name need be specified on |
|
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
84 the command-line. |
|
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
85 |
|
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
86 The username and/or password will be prompted for if not supplied on |
|
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
87 the command-line or in ~/.netrc. |
|
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
88 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
89 POP: |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 pop username:password@server |
|
4000
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
94 Alternatively, one can omit one or both of username and password: |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
95 pop username@server |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
96 pop server |
|
4000
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
97 are both valid. |
|
1547
f478c236b1f6
roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents:
1359
diff
changeset
|
98 |
|
3779
ee73abcc95d2
Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents:
3638
diff
changeset
|
99 POPS: |
|
ee73abcc95d2
Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents:
3638
diff
changeset
|
100 Connect to a POP server over ssl. This requires python 2.4 or later. |
|
ee73abcc95d2
Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents:
3638
diff
changeset
|
101 This supports the same notation as POP. |
|
ee73abcc95d2
Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents:
3638
diff
changeset
|
102 |
|
1547
f478c236b1f6
roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents:
1359
diff
changeset
|
103 APOP: |
|
1548
c36df13925f9
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
1547
diff
changeset
|
104 Same as POP, but using Authenticated POP: |
|
c36df13925f9
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
1547
diff
changeset
|
105 apop username:password@server |
|
1547
f478c236b1f6
roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents:
1359
diff
changeset
|
106 |
|
2210
b61640273061
added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents:
2186
diff
changeset
|
107 IMAP: |
|
2211
272b654b1227
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
2210
diff
changeset
|
108 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
|
109 POP mail. |
|
2210
b61640273061
added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents:
2186
diff
changeset
|
110 imap username:password@server |
|
2211
272b654b1227
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
2210
diff
changeset
|
111 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
|
112 this format: |
|
2210
b61640273061
added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents:
2186
diff
changeset
|
113 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
|
114 |
|
2210
b61640273061
added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents:
2186
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
120 IMAPS_CRAM: |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
121 Connect to an IMAP server over ssl using CRAM-MD5 authentication. |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
122 This supports the same notation as IMAP. |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
123 imaps_cram username:password@server [mailbox] |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
124 |
|
2328
b54ad9ed394a
join adjacent translatable strings
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2284
diff
changeset
|
125 """)%{'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
|
126 return 1 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
127 |
|
1359
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
128 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
|
129 '''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
|
130 ''' |
|
1359
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
131 # 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
|
132 # arguments in the args array. |
|
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
133 try: |
|
3638
22ec8e91da2b
Fix -c option (default class) for roundup-mailgw
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3386
diff
changeset
|
134 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
|
135 'class=']) |
|
1359
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
136 except getopt.GetoptError: |
|
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
137 # print help information and exit: |
|
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
138 usage(argv) |
|
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
139 sys.exit(2) |
|
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
140 |
|
2186
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
141 for (opt, arg) in optionsList: |
|
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
142 if opt == '-v': |
|
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
143 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
|
144 return |
|
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
145 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
146 # figure the instance home |
|
1359
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
147 if len(args) > 0: |
|
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
148 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
|
149 else: |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
154 # get the instance |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
155 import roundup.instance |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
156 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
|
157 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
158 if hasattr(instance, 'MailGW'): |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
159 handler = instance.MailGW(instance, optionsList) |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
160 else: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
161 handler = mailgw.MailGW(instance, optionsList) |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
162 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
163 # if there's no more arguments, read a single message from stdin |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
164 if len(args) == 1: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
165 return handler.do_pipe() |
|
1133
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1107
diff
changeset
|
166 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
167 # otherwise, figure what sort of mail source to handle |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
168 if len(args) < 3: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
169 return usage(argv, _('Error: not enough source specification information')) |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
170 source, specification = args[1:3] |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
171 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
172 # time out net connections after a minute if we can |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
173 if source not in ('mailbox', 'imaps', 'imaps_cram'): |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
174 if hasattr(socket, 'setdefaulttimeout'): |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
175 socket.setdefaulttimeout(60) |
|
3386
263e8f485db5
don't try to set a timeout for IMAPS (thanks Paul Jimenez)
Richard Jones <richard@users.sourceforge.net>
parents:
2672
diff
changeset
|
176 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
177 if source == 'mailbox': |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
178 return handler.do_mailbox(specification) |
|
4000
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
179 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
180 # the source will be a network server, so obtain the credentials to |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
181 # use in connecting to the server |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
182 try: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
183 # attempt to obtain credentials from a ~/.netrc file |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
184 authenticator = netrc.netrc().authenticators(specification) |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
185 username = authenticator[0] |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
186 password = authenticator[2] |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
187 server = specification |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
188 # IOError if no ~/.netrc file, TypeError if the hostname |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
189 # not found in the ~/.netrc file: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
190 except (IOError, TypeError): |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
191 match = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)', |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
192 specification) |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
193 if match: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
194 username = match.group('user') |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
195 password = match.group('pass') |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
196 server = match.group('server') |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
197 else: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
198 return usage(argv, _('Error: %s specification not valid') % source) |
|
4000
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
199 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
200 # now invoke the mailgw handler depending on the server handler requested |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
201 if source.startswith('pop'): |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
202 ssl = source.endswith('s') |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
203 if ssl and sys.version_info<(2,4): |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
204 return usage(argv, _('Error: a later version of python is required')) |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
205 return handler.do_pop(server, username, password, ssl) |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
206 elif source == 'apop': |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
207 return handler.do_apop(server, username, password) |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
208 elif source.startswith('imap'): |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
209 ssl = cram = 0 |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
210 if source.endswith('s'): |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
211 ssl = 1 |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
212 elif source.endswith('s_cram'): |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
213 ssl = cram = 1 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
214 mailbox = '' |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
215 if len(args) > 3: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
216 mailbox = args[3] |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
217 return handler.do_imap(server, username, password, mailbox, ssl, |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
218 cram) |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
219 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
220 return usage(argv, _('Error: The source must be either "mailbox",' |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
221 ' "pop", "pops", "apop", "imap", "imaps" or "imaps_cram')) |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
222 |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
223 def run(): |
|
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
224 sys.exit(main(sys.argv)) |
|
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
225 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
226 # call main |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
227 if __name__ == '__main__': |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
228 run() |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
229 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
230 # vim: set filetype=python ts=4 sw=4 et si |
