Mercurial > p > roundup > code
annotate roundup/scripts/roundup_mailgw.py @ 8205:4993e122235e
chore(ruff): suppress combine branches with one or expression
I want to keep the comment on datetime and expressing the whole thing
as on big or statement would prevent that.
Also it reads better since I can't get formatting of multiple or
statemnts to occur one element per line.
if (a or
b or
c or ...):
wants to be reformated to (a or b or ...)
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 11 Dec 2024 15:18:36 -0500 |
| parents | f0d39308819f |
| children | 24e867f846dd |
| 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 """ |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4990
diff
changeset
|
19 from __future__ import print_function |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1606
diff
changeset
|
20 __docformat__ = 'restructuredtext' |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
21 |
|
4766
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
22 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
23 # --- 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
|
24 import sys |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
25 import os.path as osp |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
26 from argparse import ArgumentParser, RawDescriptionHelpFormatter |
|
4766
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
27 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
28 thisdir = osp.dirname(osp.abspath(__file__)) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
29 rootdir = osp.dirname(osp.dirname(thisdir)) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
30 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
|
31 osp.exists(rootdir + '/roundup/__init__.py')): |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
32 # 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
|
33 sys.path.insert(0, rootdir) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
34 # --/ |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
35 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
36 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
37 # python version check |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
38 from roundup import version_check |
|
2186
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
39 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
|
40 |
|
5418
55f09ca366c4
Python 3 preparation: StringIO.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5376
diff
changeset
|
41 import sys, os, re, 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
|
42 |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2372
diff
changeset
|
43 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
|
44 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
|
45 |
|
6041
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
46 |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
47 usage_epilog = """ |
|
4990
63574f1f3570
closed issue2550884 roundup-mailgw --help text improved to explain the allowed parameters better. Suggested by by Karl-Philipp Richter.
Bernhard Reiter <bernhard@intevation.de>
parents:
4766
diff
changeset
|
48 The roundup mail gateway may be called in one of the following ways: |
|
63574f1f3570
closed issue2550884 roundup-mailgw --help text improved to explain the allowed parameters better. Suggested by by Karl-Philipp Richter.
Bernhard Reiter <bernhard@intevation.de>
parents:
4766
diff
changeset
|
49 . without arguments. Then the env var ROUNDUP_INSTANCE will be tried. |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
50 . with an instance home as the only argument, |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
51 . with both an instance home and a mail spool file, or |
|
4990
63574f1f3570
closed issue2550884 roundup-mailgw --help text improved to explain the allowed parameters better. Suggested by by Karl-Philipp Richter.
Bernhard Reiter <bernhard@intevation.de>
parents:
4766
diff
changeset
|
52 . with an instance home, a mail source type and its specification. |
|
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
|
53 |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
54 It also supports optional -S (or --set-value) arguments that allows you |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
55 to set fields for a class created by the roundup-mailgw. The format for |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
56 this option is [class.]property=value where class can be omitted and |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
57 defaults to msg. The -S options uses the same |
|
1359
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
58 property=value[;property=value] notation accepted by the command line |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
59 roundup command or the commands that can be given on the Subject line of |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
60 an email message (if you're using multiple properties delimited with a |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
61 semicolon the class must be specified only once in the beginning). |
|
1359
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
62 |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
63 It can let you set the type of the message on a per email address basis |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
64 by calling roundup-mailgw with different email addresses and other |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
65 settings. |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
66 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
67 PIPE: |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
68 If there is no mail source specified, the mail gateway reads a single |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
69 message from the standard input and submits the message to the |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
70 roundup.mailgw module. |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
71 |
|
4990
63574f1f3570
closed issue2550884 roundup-mailgw --help text improved to explain the allowed parameters better. Suggested by by Karl-Philipp Richter.
Bernhard Reiter <bernhard@intevation.de>
parents:
4766
diff
changeset
|
72 Mail source "mailbox": |
|
63574f1f3570
closed issue2550884 roundup-mailgw --help text improved to explain the allowed parameters better. Suggested by by Karl-Philipp Richter.
Bernhard Reiter <bernhard@intevation.de>
parents:
4766
diff
changeset
|
73 In this case, the gateway reads all messages from the UNIX mail spool |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
74 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
|
75 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
|
76 specified as: |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
77 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
|
78 |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
79 In all of the following mail source types, the username and password |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
80 can be stored in a ~/.netrc file. If done so, only the server name |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
81 needs to be specified on the command-line. |
|
4000
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
82 |
|
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
83 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
|
84 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
|
85 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
86 POP: |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
87 For the mail source "pop", the gateway reads all messages from the POP |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
88 server specified and submits each in turn to the roundup.mailgw module. |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
89 The server is specified as: |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
90 pop username:password@server |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
91 The username and password may be omitted: |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
92 pop username@server |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
93 pop server |
|
4000
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
94 are both valid. |
|
1547
f478c236b1f6
roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents:
1359
diff
changeset
|
95 |
|
3779
ee73abcc95d2
Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents:
3638
diff
changeset
|
96 POPS: |
|
7082
f0d39308819f
Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7081
diff
changeset
|
97 Connect to a POP server over ssl/tls. |
|
3779
ee73abcc95d2
Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents:
3638
diff
changeset
|
98 This supports the same notation as POP. |
|
ee73abcc95d2
Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents:
3638
diff
changeset
|
99 |
|
1547
f478c236b1f6
roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents:
1359
diff
changeset
|
100 APOP: |
|
1548
c36df13925f9
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
1547
diff
changeset
|
101 Same as POP, but using Authenticated POP: |
|
c36df13925f9
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
1547
diff
changeset
|
102 apop username:password@server |
|
1547
f478c236b1f6
roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents:
1359
diff
changeset
|
103 |
|
2210
b61640273061
added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents:
2186
diff
changeset
|
104 IMAP: |
|
2211
272b654b1227
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
2210
diff
changeset
|
105 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
|
106 POP mail. |
|
2210
b61640273061
added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents:
2186
diff
changeset
|
107 imap username:password@server |
|
2211
272b654b1227
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
2210
diff
changeset
|
108 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
|
109 this format: |
|
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 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
|
111 |
|
2210
b61640273061
added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents:
2186
diff
changeset
|
112 IMAPS: |
|
7082
f0d39308819f
Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7081
diff
changeset
|
113 Connect to an IMAP server over ssl/tls. |
|
2210
b61640273061
added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents:
2186
diff
changeset
|
114 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
|
115 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
|
116 |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
117 IMAPS_CRAM: |
|
7082
f0d39308819f
Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7081
diff
changeset
|
118 Connect to an IMAP server over ssl/tls using CRAM-MD5 authentication. |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
119 This supports the same notation as IMAP. |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
120 imaps_cram username:password@server [mailbox] |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
121 |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
122 IMAPS_OAUTH: |
|
7082
f0d39308819f
Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7081
diff
changeset
|
123 Connect to an IMAP server over ssl/tls using OAUTH authentication. |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
124 Note that this does not support a password in imaps URLs. |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
125 Instead it uses only the user and server and a command-line option for |
|
7081
f918351a0fe6
Put oauth client secret into a file
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7066
diff
changeset
|
126 the directory with the files 'access_token', 'refresh_token', |
|
f918351a0fe6
Put oauth client secret into a file
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7066
diff
changeset
|
127 'client_secret', and 'client_id'. |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
128 By default this directory is 'oauth' in your tracker home directory. The |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
129 access token is tried first and, if expired, the refresh token together |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
130 with the client secret is used to retrieve a new access token. Note that |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
131 both token files need to be *writeable*, the access token is |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
132 continuously replaced and some cloud providers may also renew the |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
133 refresh token from time to time: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
134 imaps_oauth username@server [mailbox] |
|
7081
f918351a0fe6
Put oauth client secret into a file
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7066
diff
changeset
|
135 The refresh and access tokens (the latter can be left empty), the |
|
f918351a0fe6
Put oauth client secret into a file
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7066
diff
changeset
|
136 client id and the client secret need to be retrieved via cloud provider |
|
f918351a0fe6
Put oauth client secret into a file
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7066
diff
changeset
|
137 specific protocols or websites. |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
138 |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
139 |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
140 |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
141 """ |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
142 |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
143 def parse_arguments(argv): |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
144 '''Handle the arguments to the program |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
145 ''' |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
146 # take the argv array and parse it leaving the non-option |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
147 # arguments in the list 'args'. |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
148 cmd = ArgumentParser(epilog=usage_epilog, |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
149 formatter_class=RawDescriptionHelpFormatter) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
150 cmd.add_argument('args', nargs='*') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
151 cmd.add_argument('-v', '--version', action='store_true', |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
152 help='print version and exit') |
|
7082
f0d39308819f
Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7081
diff
changeset
|
153 cmd.add_argument('-c', '--default-class', default='', |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
154 help="Default class of item to create (else the tracker's " |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
155 "MAILGW_DEFAULT_CLASS)") |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
156 cmd.add_argument('-O', '--oauth-directory', |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
157 help='Directory with OAUTH credentials, default "oauth" in ' |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
158 'tracker home') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
159 cmd.add_argument('-S', '--set-value', action='append', |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
160 help="Set additional properties on some classes", default=[]) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
161 cmd.add_argument('-T', '--oauth-token-endpoint', |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
162 help="OAUTH token endpoint for access_token renew, default=%(default)s", |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
163 default='https://login.microsoftonline.com/' |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
164 'organizations/oauth2/v2.0/token') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
165 return cmd, cmd.parse_args(argv) |
|
6041
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
166 |
|
1359
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
167 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
|
168 '''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
|
169 ''' |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
170 cmd, args = parse_arguments(argv) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
171 if args.version: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
172 print('%s (python %s)' % (roundup_version, sys.version.split()[0])) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
173 return |
|
2186
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
174 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
175 # figure the instance home |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
176 if len(args.args) > 0: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
177 instance_home = args.args[0] |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
178 else: |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
179 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
|
180 if not (instance_home and os.path.isdir(instance_home)): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
181 cmd.print_help(sys.stderr) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
182 return _('\nError: The instance home must be specified') |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
183 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
184 # get the instance |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
185 import roundup.instance |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
186 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
|
187 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
188 if hasattr(instance, 'MailGW'): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
189 handler = instance.MailGW(instance, args) |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
190 else: |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
191 handler = mailgw.MailGW(instance, args) |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
192 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
193 # if there's no more arguments, read a single message from stdin |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
194 if len(args.args) == 1: |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
195 return handler.do_pipe() |
|
1133
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1107
diff
changeset
|
196 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
197 # otherwise, figure what sort of mail source to handle |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
198 if len(args.args) < 3: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
199 cmd.print_help(sys.stderr) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
200 return _('\nError: not enough source specification information') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
201 |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
202 source, specification = args.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
|
203 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
204 # time out net connections after a minute if we can |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
205 if source not in ('mailbox', 'imaps', 'imaps_cram', 'imaps_oauth'): |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
206 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
|
207 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
|
208 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
209 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
|
210 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
|
211 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
212 # 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
|
213 # 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
|
214 try: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
215 # 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
|
216 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
|
217 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
|
218 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
|
219 server = specification |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
220 # 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
|
221 # 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
|
222 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
|
223 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
|
224 specification) |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
225 if match: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 else: |
| 7066 | 230 cmd.print_help(sys.stderr) |
| 231 return _('\nError: %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
|
232 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
233 # 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 elif source.startswith('imap'): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
240 d = {} |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
241 if source.endswith('s'): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
242 d.update(ssl = 1) |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
243 elif source.endswith('s_cram'): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
244 d.update(ssl = 1, cram = 1) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
245 elif source == 'imaps_oauth': |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
246 d.update(ssl = 1, oauth = 1, oauth_path = args.oauth_directory) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
247 d.update(token_endpoint = args.oauth_token_endpoint) |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
248 mailbox = '' |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
249 if len(args.args) > 3: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
250 mailbox = args.args[3] |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
251 return handler.do_imap(server, username, password, mailbox, **d) |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
252 |
| 7066 | 253 cmd.print_help(sys.stderr) |
| 254 return _('\nError: The source must be either "mailbox",' | |
| 255 ' "pop", "pops", "apop", "imap", "imaps", ' | |
| 256 ' "imaps_cram", or "imaps_oauth"') | |
|
6041
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
257 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
258 |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
259 def run(): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
260 sys.exit(main(sys.argv [1:])) |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
261 |
|
6041
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
262 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
263 # call main |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
264 if __name__ == '__main__': |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
265 run() |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
266 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
267 # vim: set filetype=python ts=4 sw=4 et si |
