Skip to content

Commit 9dafe26

Browse files
committed
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.
1 parent 316effd commit 9dafe26

File tree

6 files changed

+355
-164
lines changed

6 files changed

+355
-164
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ Features:
7171
list all template names, location and descriptions. Should help
7272
find where /usr/share/roundup/templates is buried during some
7373
install mechanisms. (John Rouillard)
74+
- Add OAuth authentication to the mailgw script. Now IMAPS can be used
75+
with OAuth as required by several large cloud providers. Move command
76+
line processing of the mailgw script to ``argparse``. Note that the
77+
command line options of the mailgw have changed, see upgrading.txt for
78+
details. (Ralf Schlatterbeck)
7479

7580
2022-07-13 2.2.0
7681

doc/upgrading.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,36 @@ You can then merge any local comments from the tracker's
6666
``config.ini`` to ``newconfig.ini`` and replace
6767
``config.ini`` with ``newconfig.ini``.
6868

69+
Using the roundup-mailgw script
70+
-------------------------------
71+
72+
In previous versions the roundup-mailgw script had a ``-C`` (or
73+
``--class``) option for specifying a class to be used with ``-S`` (or
74+
``--set``) option(s). In the latest version the ``-C`` option is gone,
75+
the class for this option is specified as a prefix, e.g. instead of ::
76+
77+
roundup-mailgw -C issue -S issueprop=value
78+
79+
You now specify ::
80+
81+
roundup-mailgw -S issue.issueprop=value
82+
83+
If multiple values need to be set, this can be achieved with multiple
84+
``-S`` options or with delimiting multiple values with a semicolon (in
85+
that case the string needs to be quoted because semicolon is a shell
86+
special character)::
87+
88+
roundup-mailgw -S 'issue.issueprop1=value1;issueprop2=value2'
89+
roundup-mailgw -S issue.issueprop1=value1 -S issue.issueprop2=value2
90+
91+
are equivalent. Note that the class is provided as a prefix for the
92+
set-string, not for each property. The class can be omitted altogether
93+
in which case it defaults to ``msg`` (this default existed in previous
94+
versions).
95+
96+
If you do not use the ``-C`` (or ``--class``) option in your current
97+
setup of mailgw you don't need to change anything.
98+
6999
Rdbms version change from 7 to 8 (required)
70100
-------------------------------------------
71101

doc/user_guide.txt

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Issue life cycles in Roundup
5858
New issues may be submitted via the web or e-mail.
5959

6060
By default, the issue will have the status "unread". If another message
61-
is received for the issue, its status will change to "chatting".
61+
is received for the issue, its status will change to "chatting".
6262

6363
The "home" page for a tracker will generally display all issues which
6464
are not "resolved".
@@ -217,7 +217,7 @@ Other possible examples (consider local time is 2003-03-08.22:07:48):
217217
<Range from 2003-01-01.00:00:00 to 2003-12-31.23:59:59>
218218
- "2003-04" means
219219
<Range from 2003-04-01.00:00:00 to 2003-04-30.23:59:59>
220-
220+
221221

222222
Interval properties
223223
~~~~~~~~~~~~~~~~~~~
@@ -357,7 +357,7 @@ Argument Description
357357
in descending or nothing for ascending order. The group
358358
argument can have several props separated with comma.
359359
@columns selects the columns that should be displayed. Default is
360-
all.
360+
all.
361361
@filter indicates which properties are being used in filtering.
362362
Default is none.
363363
propname selects the values the item properties given by propname must
@@ -602,7 +602,7 @@ the message may be added to the `nosy list`_ depending on:
602602
followups too. If 'no', they're never added to the nosy.
603603

604604
Some organisations might prefer to have someone moderate emails before
605-
they are delivered into Roundup. Those might want to set the
605+
they are delivered into Roundup. Those might want to set the
606606
configuration option ``EMAIL_KEEP_REAL_FROM`` to ``'yes'`` to avoid
607607
having the moderators address appearing as the creator of issues.
608608

@@ -628,40 +628,55 @@ Mail gateway script command line
628628

629629
Usage::
630630

631-
roundup-mailgw [[-C class] -S field=value]* <instance home> [method]
631+
usage: roundup_mailgw.py [-h] [-v] [-c DEFAULT_CLASS] [-I OAUTH_CLIENT_ID]
632+
[-O OAUTH_DIRECTORY] [-S SET_VALUE]
633+
[-T OAUTH_TOKEN_ENDPOINT]
634+
[args ...]
635+
632636

633637
The roundup mail gateway may be called in one of three ways:
634638

639+
- without arguments. Then the env var ROUNDUP_INSTANCE will be tried.
635640
- with an instance home as the only argument,
636641
- with both an instance home and a mail spool file, or
637-
- with both an instance home and a pop server account.
638-
639-
It also supports optional -C and -S arguments that allows you to set a
640-
fields for a class created by the roundup-mailgw. The default class if
641-
not specified is msg, but the other classes: issue, file, user can also
642-
be used. The -S or --set options uses the same
642+
- with an instance home, a mail source type and its specification.
643+
644+
It also supports optional ``-S`` (or ``--set-value``) arguments that allows you
645+
to set fields for a class created by the roundup-mailgw. The format for
646+
this option is [class.]property=value where class can be omitted and
647+
defaults to msg. The ``-S`` options uses the same
643648
property=value[;property=value] notation accepted by the command line
644649
roundup command or the commands that can be given on the Subject line of
645-
an e-mail message.
650+
an email message (if you're using multiple properties delimited with a
651+
semicolon the class must be specified only once in the beginning).
646652

647-
It can let you set the type of the message on a per e-mail address basis.
653+
It can let you set the type of the message on a per e-mail address basis
654+
by calling roundup-mailgw with different email addresses and other
655+
settings.
648656

649657
PIPE:
650-
In the first case, the mail gateway reads a single message from the
651-
standard input and submits the message to the roundup.mailgw module.
658+
If there is no mail source specified, the mail gateway reads a single
659+
message from the standard input and submits the message to the
660+
roundup.mailgw module.
652661

653662
UNIX mailbox:
654-
In the second case, the gateway reads all messages from the mail spool
663+
In this case, the gateway reads all messages from the UNIX mail spool
655664
file and submits each in turn to the roundup.mailgw module. The file is
656665
emptied once all messages have been successfully handled. The file is
657666
specified as::
658667

659668
mailbox /path/to/mailbox
660669

670+
In all of the following mail source types, the username and password
671+
can be stored in a ``~/.netrc`` file. If done so, only the server name
672+
needs to be specified on the command-line.
673+
The username and/or password will be prompted for if not supplied on
674+
the command-line or in ``~/.netrc``.
675+
661676
POP:
662-
In the third case, the gateway reads all messages from the POP server
663-
specified and submits each in turn to the roundup.mailgw module. The
664-
server is specified as::
677+
For the mail source "pop", the gateway reads all messages from the POP
678+
server specified and submits each in turn to the roundup.mailgw module.
679+
The server is specified as::
665680

666681
pop username:password@server
667682

@@ -670,8 +685,7 @@ POP:
670685
pop username@server
671686
pop server
672687

673-
are both valid. The username and/or password will be prompted for if
674-
not supplied on the command-line.
688+
are both valid.
675689

676690
POPS:
677691
Connect to a POP server over ssl.
@@ -707,6 +721,30 @@ IMAPS_CRAM:
707721

708722
imaps_cram username:password@server [mailbox]
709723

724+
IMAPS_OAUTH:
725+
Connect to an IMAP server over ssl using OAUTH authentication.
726+
Note that this does not support a password in imaps URLs.
727+
Instead it uses only the user and server and a command-line option for
728+
the directory with the files ``access_token``, ``refresh_token``, and
729+
``client_secret``.
730+
By default this directory is ``oauth`` in your tracker home directory. The
731+
access token is tried first and, if expired, the refresh token together
732+
with the client secret is used to retrieve a new access token. Note that
733+
both token files need to be *writeable*, the access token is
734+
continuously replaced and some cloud providers may also renew the
735+
refresh token from time to time::
736+
737+
imaps_oauth username@server [mailbox]
738+
739+
Note that you also have to specify the OAuth client id with the
740+
``--oauth-client-id`` option on the command line. The refresh and
741+
access tokens (the latter can be left empty) and the client secret need
742+
to be retrieved via cloud provider specific protocols or websites.
743+
744+
You need the requests_ library installed for OAuth.
745+
746+
.. _requests: https://requests.readthedocs.io/en/latest/
747+
710748
.. index:: ! roundup-admin
711749
single: roundup-admin; usage
712750
single: roundup-admin; data formats
@@ -737,7 +775,7 @@ The basic usage is::
737775
roundup-admin help <command> -- command-specific help
738776
roundup-admin help all -- all available help
739777

740-
Commands:
778+
Commands:
741779
commit
742780
create classname property=value ...
743781
display designator[,designator]*
@@ -778,7 +816,7 @@ arguments and in the printed results:
778816
- Date values are printed in the full date format in the local time
779817
zone, and accepted in the full format or any of the partial formats
780818
explained below.::
781-
819+
782820
Input of... Means...
783821
"2000-04-17.03:45" 2000-04-17.03:45:00
784822
"2000-04-17" 2000-04-17.00:00:00
@@ -790,14 +828,14 @@ arguments and in the printed results:
790828
"2003" 2003-01-01.00:00:00
791829
"2003-04" 2003-04-01.00:00:00
792830
"." "right now"
793-
831+
794832
- Link values are printed as item designators. When given as an
795833
argument, item designators and key strings are both accepted.
796834
- Multilink values are printed as lists of item designators joined by
797835
commas. When given as an argument, item designators and key strings
798836
are both accepted; an empty string, a single item, or a list of items
799837
joined by commas is accepted.
800-
838+
801839
When multiple items are specified to the roundup get or roundup set
802840
commands, the specified properties are retrieved or set on all the
803841
listed items. When multiple results are returned by the roundup get or
@@ -877,8 +915,8 @@ You can also display issue contents::
877915
author: 1
878916
date: 2003-02-15.01:59:11
879917
messageid: None
880-
summary: jlkfjadsf
881-
918+
summary: jlkfjadsf
919+
882920
or status::
883921

884922
shell% roundup-admin get name `/tools/roundup/bin/roundup-admin \

0 commit comments

Comments
 (0)