Skip to content

Commit 5ef19c5

Browse files
author
Richard Jones
committed
Add use of username/password stored in ~/.netrc in mailgw
1 parent 7b38f17 commit 5ef19c5

File tree

4 files changed

+54
-32
lines changed

4 files changed

+54
-32
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ This file contains the changes to the Roundup system over time. The entries
22
are given with the most recent entry first.
33

44
2008-??-?? 1.4.5
5+
Feature:
6+
- Add use of username/password stored in ~/.netrc in mailgw (sf patch
7+
#1912105)
8+
59
Fixed:
610
- 'Make a Copy' failed with more than one person in nosy list (sf #1906147)
711
- xml-rpc security checks and tests across all backends (sf #1907211)

doc/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Tamer Fahmy,
9494
Vickenty Fesunov,
9595
Hernan Martinez Foffani,
9696
Stuart D. Gathman,
97+
Martin Geisler,
9798
Ajit George,
9899
Frank Gibbons,
99100
Johannes Gijsbers,

doc/roundup-mailgw.1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ emptied once all messages have been successfully handled. The file is
3434
specified as:
3535
\fImailbox /path/to/mailbox\fP
3636

37+
In all of the following the username and password can be stored in a
38+
~/.netrc file. In this case only the server name need be specified on
39+
the command-line.
40+
41+
The username and/or password will be prompted for if not supplied on
42+
the command-line or in ~/.netrc.
43+
3744
\fBPOP\fP
3845
.br
3946
In the third case, the gateway reads all messages from the POP server
@@ -45,8 +52,7 @@ The username and password may be omitted:
4552
\fIpop username@server\fP
4653
\fIpop server\fP
4754
.br
48-
are both valid. The username and/or password will be prompted for if
49-
not supplied on the command-line.
55+
are both valid.
5056

5157
\fBAPOP\fP
5258
Same as POP, but using Authenticated POP:

roundup/scripts/roundup_mailgw.py

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1515
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1616
#
17-
# $Id: roundup_mailgw.py,v 1.23 2006-12-13 23:32:39 richard Exp $
17+
# $Id: roundup_mailgw.py,v 1.24 2008-08-19 01:01:32 richard Exp $
1818

1919
"""Command-line script stub that calls the roundup.mailgw.
2020
"""
@@ -24,7 +24,7 @@
2424
from roundup import version_check
2525
from roundup import __version__ as roundup_version
2626

27-
import sys, os, re, cStringIO, getopt, socket
27+
import sys, os, re, cStringIO, getopt, socket, netrc
2828

2929
from roundup import mailgw
3030
from roundup.i18n import _
@@ -67,16 +67,22 @@ def usage(args, message=None):
6767
specified as:
6868
mailbox /path/to/mailbox
6969
70+
In all of the following the username and password can be stored in a
71+
~/.netrc file. In this case only the server name need be specified on
72+
the command-line.
73+
74+
The username and/or password will be prompted for if not supplied on
75+
the command-line or in ~/.netrc.
76+
7077
POP:
7178
In the third case, the gateway reads all messages from the POP server
7279
specified and submits each in turn to the roundup.mailgw module. The
7380
server is specified as:
7481
pop username:password@server
75-
The username and password may be omitted:
82+
Alternatively, one can omit one or both of username and password:
7683
pop username@server
7784
pop server
78-
are both valid. The username and/or password will be prompted for if
79-
not supplied on the command-line.
85+
are both valid.
8086
8187
POPS:
8288
Connect to a POP server over ssl. This requires python 2.4 or later.
@@ -158,33 +164,38 @@ def main(argv):
158164

159165
if source == 'mailbox':
160166
return handler.do_mailbox(specification)
161-
elif source == 'pop' or source == 'pops':
162-
m = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)',
163-
specification)
164-
if m:
165-
ssl = source.endswith('s')
166-
if ssl and sys.version_info<(2,4):
167-
return usage(argv, _('Error: a later version of python is required'))
168-
return handler.do_pop(m.group('server'), m.group('user'),
169-
m.group('pass'),ssl)
170-
return usage(argv, _('Error: pop specification not valid'))
167+
168+
# Try parsing the netrc file first.
169+
try:
170+
authenticator = netrc.netrc().authenticators(specification)
171+
username = authenticator[0]
172+
password = authenticator[2]
173+
server = specification
174+
# IOError if no ~/.netrc file, TypeError if the hostname
175+
# not found in the ~/.netrc file:
176+
except (IOError, TypeError):
177+
match = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)',
178+
specification)
179+
if match:
180+
username = match.group('user')
181+
password = match.group('pass')
182+
server = match.group('server')
183+
else:
184+
return usage(argv, _('Error: %s specification not valid') % source)
185+
186+
if source == 'pop' or source == 'pops':
187+
ssl = source.endswith('s')
188+
if ssl and sys.version_info<(2,4):
189+
return usage(argv, _('Error: a later version of python is required'))
190+
return handler.do_pop(server, username, password, ssl)
171191
elif source == 'apop':
172-
m = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)',
173-
specification)
174-
if m:
175-
return handler.do_apop(m.group('server'), m.group('user'),
176-
m.group('pass'))
177-
return usage(argv, _('Error: apop specification not valid'))
192+
return handler.do_apop(server, username, password)
178193
elif source == 'imap' or source == 'imaps':
179-
m = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)',
180-
specification)
181-
if m:
182-
ssl = source.endswith('s')
183-
mailbox = ''
184-
if len(args) > 3:
185-
mailbox = args[3]
186-
return handler.do_imap(m.group('server'), m.group('user'),
187-
m.group('pass'), mailbox, ssl)
194+
ssl = source.endswith('s')
195+
mailbox = ''
196+
if len(args) > 3:
197+
mailbox = args[3]
198+
return handler.do_imap(server, username, password, mailbox, ssl)
188199

189200
return usage(argv, _('Error: The source must be either "mailbox",'
190201
' "pop", "apop", "imap" or "imaps"'))

0 commit comments

Comments
 (0)