Mercurial > p > roundup > code
annotate roundup/scripts/roundup_mailgw.py @ 8566:e4191aa7b402 default tip
doc: issue2551415 correct doc for change input->input_payload
in 2.5 the rest interface changed a variable name from input to
input_payload. An earlier commit changed the rest docs. This commit
adds an item for it to the upgrading 2.4.0->2.5.0 section. Also cross
reference added to the rest docs with the updated examples.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 09 Apr 2026 00:19:06 -0400 |
| parents | 9c3ec0a5c7fc |
| children |
| 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 |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
22 import netrc |
|
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
23 import os |
|
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
24 import os.path as osp |
|
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
25 import re |
|
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
26 import socket |
|
4766
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
27 import sys |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
28 from argparse import ArgumentParser, RawDescriptionHelpFormatter |
|
4766
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
29 |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
30 # --- patch sys.path to make sure 'import roundup' finds correct version |
|
4766
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
31 thisdir = osp.dirname(osp.abspath(__file__)) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
32 rootdir = osp.dirname(osp.dirname(thisdir)) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
33 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
|
34 osp.exists(rootdir + '/roundup/__init__.py')): |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
35 # 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
|
36 sys.path.insert(0, rootdir) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
37 # --/ |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
38 |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
39 # Python version check run for side effect. |
|
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
40 # Aborts program if Python version too old. |
|
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
41 from roundup import version_check # noqa: E402 F401 I001 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
42 |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
43 from roundup import __version__ as roundup_version # noqa: E402 |
|
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
44 from roundup import mailgw # noqa: E402 |
|
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
45 from roundup.i18n import _ # noqa: E402 |
|
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 |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
143 |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
144 def parse_arguments(argv): |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
145 '''Handle the arguments to the program |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
146 ''' |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
147 # 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
|
148 # arguments in the list 'args'. |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
149 cmd = ArgumentParser(epilog=usage_epilog, |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
150 formatter_class=RawDescriptionHelpFormatter) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
151 cmd.add_argument('args', nargs='*') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
152 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
|
153 help='print version and exit') |
|
7082
f0d39308819f
Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents:
7081
diff
changeset
|
154 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
|
155 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
|
156 "MAILGW_DEFAULT_CLASS)") |
|
8552
dbe30d5032b8
doc: move OAUTH settings together, add set-value and OAUTH docs
John Rouillard <rouilj@ieee.org>
parents:
8522
diff
changeset
|
157 cmd.add_argument('-S', '--set-value', action='append', |
|
dbe30d5032b8
doc: move OAUTH settings together, add set-value and OAUTH docs
John Rouillard <rouilj@ieee.org>
parents:
8522
diff
changeset
|
158 help="Set additional properties for classes. Format of SET_VALUE: '[class.]property=value[;property=value]'. Class defaults to DEFAULT_CLASS.", default=[]) |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
159 cmd.add_argument('-O', '--oauth-directory', |
|
8552
dbe30d5032b8
doc: move OAUTH settings together, add set-value and OAUTH docs
John Rouillard <rouilj@ieee.org>
parents:
8522
diff
changeset
|
160 help='Directory with OAUTH credentials, default "oauth/" in ' |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
161 'tracker home') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
162 cmd.add_argument('-T', '--oauth-token-endpoint', |
|
8552
dbe30d5032b8
doc: move OAUTH settings together, add set-value and OAUTH docs
John Rouillard <rouilj@ieee.org>
parents:
8522
diff
changeset
|
163 help="URL of the OAUTH token endpoint when renewing access_token, " |
|
dbe30d5032b8
doc: move OAUTH settings together, add set-value and OAUTH docs
John Rouillard <rouilj@ieee.org>
parents:
8522
diff
changeset
|
164 "default=%(default)s", |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
165 default='https://login.microsoftonline.com/' |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
166 'organizations/oauth2/v2.0/token') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
167 return cmd, cmd.parse_args(argv) |
|
6041
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
168 |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
169 |
|
1359
ebfd8dd1cce7
missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents:
1133
diff
changeset
|
170 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
|
171 '''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
|
172 ''' |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
173 cmd, args = parse_arguments(argv) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
174 if args.version: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
175 print('%s (python %s)' % (roundup_version, sys.version.split()[0])) |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
176 return None |
|
2186
3f89c8ffe4f1
version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
177 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
178 # figure the instance home |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
179 if len(args.args) > 0: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
180 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
|
181 else: |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
182 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
|
183 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
|
184 cmd.print_help(sys.stderr) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
185 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
|
186 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
187 # get the instance |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
188 import roundup.instance |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
189 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
|
190 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
191 if hasattr(instance, 'MailGW'): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
192 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
|
193 else: |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
194 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
|
195 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
196 # 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
|
197 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
|
198 return handler.do_pipe() |
|
1133
36ec30d286ea
Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents:
1107
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 # 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
|
201 if len(args.args) < 3: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
202 cmd.print_help(sys.stderr) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
203 return _('\nError: not enough source specification information') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
204 |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
205 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
|
206 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
207 # 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
|
208 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
|
209 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
|
210 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
|
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 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
|
213 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
|
214 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
215 # 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
|
216 # use in connecting to the server |
|
8522
82fc69e6d9d7
refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents:
8521
diff
changeset
|
217 authenticator = None |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
218 try: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
219 # attempt to obtain credentials from a ~/.netrc file |
|
8522
82fc69e6d9d7
refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents:
8521
diff
changeset
|
220 # returns None if host not found |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
221 authenticator = netrc.netrc().authenticators(specification) |
|
8522
82fc69e6d9d7
refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents:
8521
diff
changeset
|
222 except FileNotFoundError: |
|
82fc69e6d9d7
refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents:
8521
diff
changeset
|
223 # FileNotFoundError if no ~/.netrc file |
|
82fc69e6d9d7
refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents:
8521
diff
changeset
|
224 pass |
|
82fc69e6d9d7
refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents:
8521
diff
changeset
|
225 |
|
82fc69e6d9d7
refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents:
8521
diff
changeset
|
226 if authenticator: |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
227 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
|
228 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
|
229 server = specification |
|
8522
82fc69e6d9d7
refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents:
8521
diff
changeset
|
230 else: |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
231 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
|
232 specification) |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
233 if match: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
234 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
|
235 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
|
236 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
|
237 else: |
| 7066 | 238 cmd.print_help(sys.stderr) |
| 239 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
|
240 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
241 # 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
|
242 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
|
243 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
|
244 return handler.do_pop(server, username, password, ssl) |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
245 if source == 'apop': |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
246 return handler.do_apop(server, username, password) |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
247 if source.startswith('imap'): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
248 d = {} |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
249 if source.endswith('s'): |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
250 d.update(ssl=1) |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
251 elif source.endswith('s_cram'): |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
252 d.update(ssl=1, cram=1) |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
253 elif source == 'imaps_oauth': |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
254 d.update(ssl=1, oauth=1, oauth_path=args.oauth_directory) |
|
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
255 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
|
256 mailbox = '' |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
257 if len(args.args) > 3: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
258 mailbox = args.args[3] |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
259 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
|
260 |
| 7066 | 261 cmd.print_help(sys.stderr) |
| 262 return _('\nError: The source must be either "mailbox",' | |
| 263 ' "pop", "pops", "apop", "imap", "imaps", ' | |
| 264 ' "imaps_cram", or "imaps_oauth"') | |
|
6041
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
265 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
266 |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
267 def run(): |
|
8521
24e867f846dd
chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents:
7082
diff
changeset
|
268 sys.exit(main(sys.argv[1:])) |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
269 |
|
6041
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
270 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
271 # call main |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
272 if __name__ == '__main__': |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
273 run() |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
274 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
275 # vim: set filetype=python ts=4 sw=4 et si |
