annotate roundup/scripts/roundup_mailgw.py @ 8552:dbe30d5032b8

doc: move OAUTH settings together, add set-value and OAUTH docs
author John Rouillard <rouilj@ieee.org>
date Thu, 02 Apr 2026 12:26:13 -0400
parents 82fc69e6d9d7
children 9c3ec0a5c7fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
1 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
2 # This module is free software, and you may redistribute it and/or modify
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
3 # under the same terms as Python, so long as this copyright message and
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
4 # disclaimer are retained in their original form.
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
5 #
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
6 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
7 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
8 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
9 # POSSIBILITY OF SUCH DAMAGE.
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
10 #
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
11 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
12 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
13 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
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
8521
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
20
2005
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1606
diff changeset
21 __docformat__ = 'restructuredtext'
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
22
4766
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
23
8521
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
24 import netrc
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
25 import os
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
26 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
27 import re
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
28 import socket
4766
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
29 import sys
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
30 from argparse import ArgumentParser, RawDescriptionHelpFormatter
4766
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
31
8521
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
32 # --- 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
33 thisdir = osp.dirname(osp.abspath(__file__))
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
34 rootdir = osp.dirname(osp.dirname(thisdir))
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
35 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
36 osp.exists(rootdir + '/roundup/__init__.py')):
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
37 # 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
38 sys.path.insert(0, rootdir)
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
39 # --/
86ef4ab17dc5 Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents: 4570
diff changeset
40
8521
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
41 # 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
42 # 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
43 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
44
8521
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
45 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
46 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
47 from roundup.i18n import _ # noqa: E402
6041
c7a9f9c1801d Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
48
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
49 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
50 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
51 . 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
52 . 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
53 . 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
54 . 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
55
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
65 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
66 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
67 settings.
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
68
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
69 PIPE:
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
70 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
71 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
72 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
73
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
74 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
75 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
76 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
77 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
78 specified as:
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
79 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
80
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
81 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
82 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
83 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
84
39af38d6f77d Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents: 3779
diff changeset
85 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
86 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
87
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
88 POP:
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
89 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
90 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
91 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
92 pop username:password@server
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
93 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
94 pop username@server
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
95 pop server
4000
39af38d6f77d Add use of username/password stored in ~/.netrc in mailgw
Richard Jones <richard@users.sourceforge.net>
parents: 3779
diff changeset
96 are both valid.
1547
f478c236b1f6 roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents: 1359
diff changeset
97
3779
ee73abcc95d2 Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents: 3638
diff changeset
98 POPS:
7082
f0d39308819f Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7081
diff changeset
99 Connect to a POP server over ssl/tls.
3779
ee73abcc95d2 Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents: 3638
diff changeset
100 This supports the same notation as POP.
ee73abcc95d2 Sorry, another mega-patch:
Richard Jones <richard@users.sourceforge.net>
parents: 3638
diff changeset
101
1547
f478c236b1f6 roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents: 1359
diff changeset
102 APOP:
1548
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
103 Same as POP, but using Authenticated POP:
c36df13925f9 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1547
diff changeset
104 apop username:password@server
1547
f478c236b1f6 roundup mailgw now handles apop
Richard Jones <richard@users.sourceforge.net>
parents: 1359
diff changeset
105
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
106 IMAP:
2211
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
107 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
108 POP mail.
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
109 imap username:password@server
2211
272b654b1227 *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 2210
diff changeset
110 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
111 this format:
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
112 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
113
2210
b61640273061 added IMAP support to mail gateway (rfe [SF#934000])
Richard Jones <richard@users.sourceforge.net>
parents: 2186
diff changeset
114 IMAPS:
7082
f0d39308819f Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7081
diff changeset
115 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
116 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
117 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
118
4345
38265325492a support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents: 4211
diff changeset
119 IMAPS_CRAM:
7082
f0d39308819f Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7081
diff changeset
120 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
121 This supports the same notation as IMAP.
38265325492a support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents: 4211
diff changeset
122 imaps_cram username:password@server [mailbox]
38265325492a support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents: 4211
diff changeset
123
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
124 IMAPS_OAUTH:
7082
f0d39308819f Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7081
diff changeset
125 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
126 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
127 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
128 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
129 'client_secret', and 'client_id'.
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
130 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
131 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
132 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
133 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
134 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
135 refresh token from time to time:
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
136 imaps_oauth username@server [mailbox]
7081
f918351a0fe6 Put oauth client secret into a file
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7066
diff changeset
137 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
138 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
139 specific protocols or websites.
7064
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
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
143 """
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
144
8521
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
145
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
146 def parse_arguments(argv):
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
147 '''Handle the arguments to the program
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
148 '''
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
149 # 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
150 # arguments in the list 'args'.
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
151 cmd = ArgumentParser(epilog=usage_epilog,
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
152 formatter_class=RawDescriptionHelpFormatter)
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
153 cmd.add_argument('args', nargs='*')
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
154 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
155 help='print version and exit')
7082
f0d39308819f Update manpage of mailgw
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7081
diff changeset
156 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
157 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
158 "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
159 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
160 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
161 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
162 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
163 'tracker home')
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',
8552
dbe30d5032b8 doc: move OAUTH settings together, add set-value and OAUTH docs
John Rouillard <rouilj@ieee.org>
parents: 8522
diff changeset
165 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
166 "default=%(default)s",
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
167 default='https://login.microsoftonline.com/'
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
168 'organizations/oauth2/v2.0/token')
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
169 return cmd, cmd.parse_args(argv)
6041
c7a9f9c1801d Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
170
8521
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
171
1359
ebfd8dd1cce7 missed this part of the patch, added doc
Richard Jones <richard@users.sourceforge.net>
parents: 1133
diff changeset
172 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
173 '''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
174 '''
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
175 cmd, args = parse_arguments(argv)
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
176 if args.version:
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
177 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
178 return None
2186
3f89c8ffe4f1 version info in scripts
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
179
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
180 # figure the instance home
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
181 if len(args.args) > 0:
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
182 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
183 else:
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
184 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
185 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
186 cmd.print_help(sys.stderr)
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
187 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
188
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
189 # get the instance
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
190 import roundup.instance
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
191 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
192
4211
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
193 if hasattr(instance, 'MailGW'):
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
194 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
195 else:
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
196 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
197
4211
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
198 # 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
199 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
200 return handler.do_pipe()
1133
36ec30d286ea Cleaned up CHANGES/TODO
Richard Jones <richard@users.sourceforge.net>
parents: 1107
diff changeset
201
4211
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
202 # 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
203 if len(args.args) < 3:
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
204 cmd.print_help(sys.stderr)
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
205 return _('\nError: not enough source specification information')
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
206
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
207 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
208
4211
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
209 # 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
210 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
211 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
212 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
213
4211
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
214 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
215 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
216
4211
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
217 # 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
218 # 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
219 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
220 try:
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
221 # 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
222 # 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
223 authenticator = netrc.netrc().authenticators(specification)
8522
82fc69e6d9d7 refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents: 8521
diff changeset
224 except FileNotFoundError:
82fc69e6d9d7 refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents: 8521
diff changeset
225 # FileNotFoundError if no ~/.netrc file
82fc69e6d9d7 refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents: 8521
diff changeset
226 pass
82fc69e6d9d7 refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents: 8521
diff changeset
227
82fc69e6d9d7 refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents: 8521
diff changeset
228 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
229 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
230 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
231 server = specification
8522
82fc69e6d9d7 refactor/bug: handle case where netrc returns None.
John Rouillard <rouilj@ieee.org>
parents: 8521
diff changeset
232 else:
4211
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
233 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
234 specification)
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
235 if match:
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
236 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
237 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
238 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
239 else:
7066
27c2d7295ba2 Changes from review
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7064
diff changeset
240 cmd.print_help(sys.stderr)
27c2d7295ba2 Changes from review
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7064
diff changeset
241 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
242
4211
61cf00ca920a Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents: 4001
diff changeset
243 # 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
244 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
245 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
246 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
247 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
248 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
249 if source.startswith('imap'):
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
250 d = {}
4345
38265325492a support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents: 4211
diff changeset
251 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
252 d.update(ssl=1)
4345
38265325492a support CRAM-MD5 for IMAPS
Richard Jones <richard@users.sourceforge.net>
parents: 4211
diff changeset
253 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
254 d.update(ssl=1, cram=1)
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
255 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
256 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
257 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
258 mailbox = ''
7064
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
259 if len(args.args) > 3:
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
260 mailbox = args.args[3]
3359dc1dabb0 Add OAuth authentication to the mailgw script
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6041
diff changeset
261 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
262
7066
27c2d7295ba2 Changes from review
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7064
diff changeset
263 cmd.print_help(sys.stderr)
27c2d7295ba2 Changes from review
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7064
diff changeset
264 return _('\nError: The source must be either "mailbox",'
27c2d7295ba2 Changes from review
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7064
diff changeset
265 ' "pop", "pops", "apop", "imap", "imaps", '
27c2d7295ba2 Changes from review
Ralf Schlatterbeck <rsc@runtux.com>
parents: 7064
diff changeset
266 ' "imaps_cram", or "imaps_oauth"')
6041
c7a9f9c1801d Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
267
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
268
593
2256f81293c1 Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents: 592
diff changeset
269 def run():
8521
24e867f846dd chore: ruff spacing fixups, flow control and import reordering/removal
John Rouillard <rouilj@ieee.org>
parents: 7082
diff changeset
270 sys.exit(main(sys.argv[1:]))
593
2256f81293c1 Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents: 592
diff changeset
271
6041
c7a9f9c1801d Flake8 whitespace fixes, remove obsolete version check.
John Rouillard <rouilj@ieee.org>
parents: 5418
diff changeset
272
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
273 # call main
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
274 if __name__ == '__main__':
593
2256f81293c1 Conversion to generated script stubs
Jürgen Hermann <jhermann@users.sourceforge.net>
parents: 592
diff changeset
275 run()
592
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
276
326388b8604a Moved scripts from top-level dir to roundup.scripts subpackage
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
diff changeset
277 # vim: set filetype=python ts=4 sw=4 et si

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