Mercurial > p > roundup > code
annotate roundup/scripts/roundup_mailgw.py @ 7064:3359dc1dabb0
Add OAuth authentication to the mailgw script
Now IMAPS can be used with OAuth as required by several large cloud
providers. Move command line processing of the mailgw script to
``argparse``. Note that the command line options of the mailgw have
changed, see upgrading.txt for details.
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Wed, 23 Nov 2022 10:13:48 +0100 |
| parents | c7a9f9c1801d |
| children | 27c2d7295ba2 |
| 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: |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
97 Connect to a POP server over ssl. |
|
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: |
|
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
|
113 Connect to an IMAP server over ssl. |
|
2210
b61640273061
added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents:
2186
diff
changeset
|
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: |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
118 Connect to an IMAP server over ssl using CRAM-MD5 authentication. |
|
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
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: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
123 Connect to an IMAP server over ssl using OAUTH authentication. |
|
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 |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
126 the directory with the files 'access_token', 'refresh_token', and |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
127 'client_secret'. |
|
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] |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
135 Note that you also have to specify the OAuth client id with the |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
136 ``--oauth-client-id`` option on the command line. The refresh and |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
137 access tokens (the latter can be left empty) and the client secret need |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
138 to be retrieved via cloud provider specific protocols or websites. |
|
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 |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
142 """ |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
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') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
154 cmd.add_argument('-c', '--default_class', default='', |
|
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)") |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
157 cmd.add_argument('-I', '--oauth-client-id', |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
158 help='ID for OAUTH token refresh') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
159 cmd.add_argument('-O', '--oauth-directory', |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
160 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
|
161 'tracker home') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
162 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
|
163 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
|
164 cmd.add_argument('-T', '--oauth-token-endpoint', |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
165 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
|
166 default='https://login.microsoftonline.com/' |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
167 'organizations/oauth2/v2.0/token') |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
168 return cmd, cmd.parse_args(argv) |
|
6041
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
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])) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
176 return |
|
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 |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
217 try: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
218 # 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
|
219 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
|
220 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
|
221 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
|
222 server = specification |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
223 # 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
|
224 # 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
|
225 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
|
226 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
|
227 specification) |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
228 if match: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 else: |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
233 return usage(argv, _('Error: %s specification not valid') % source) |
|
4000
39af38d6f77d
Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents:
3779
diff
changeset
|
234 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
235 # 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 elif source.startswith('imap'): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
242 d = {} |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
243 if source.endswith('s'): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
244 d.update(ssl = 1) |
|
4345
38265325492a
support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents:
4211
diff
changeset
|
245 elif source.endswith('s_cram'): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
246 d.update(ssl = 1, cram = 1) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
247 elif source == 'imaps_oauth': |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
248 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
|
249 d.update(token_endpoint = args.oauth_token_endpoint) |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
250 d.update(oauth_client_id = args.oauth_client_id) |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
251 mailbox = '' |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
252 if len(args.args) > 3: |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
253 mailbox = args.args[3] |
|
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
254 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
|
255 |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4001
diff
changeset
|
256 return usage(argv, _('Error: The source must be either "mailbox",' |
|
6041
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
257 ' "pop", "pops", "apop", "imap", "imaps" or' |
|
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
258 ' "imaps_cram')) |
|
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
259 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
260 |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
261 def run(): |
|
7064
3359dc1dabb0
Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6041
diff
changeset
|
262 sys.exit(main(sys.argv [1:])) |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
263 |
|
6041
c7a9f9c1801d
Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents:
5418
diff
changeset
|
264 |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
265 # call main |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
266 if __name__ == '__main__': |
|
593
2256f81293c1
Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
592
diff
changeset
|
267 run() |
|
592
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
268 |
|
326388b8604a
Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff
changeset
|
269 # vim: set filetype=python ts=4 sw=4 et si |
