Skip to content

Commit 46f5984

Browse files
author
Richard Jones
committed
support CRAM-MD5 for IMAPS
1 parent fb43eca commit 46f5984

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ are given with the most recent entry first.
33

44
2010-XX-XX 1.4.12 (rXXXX)
55

6+
Features:
7+
- Support IMAP CRAM-MD5, thanks Jochen Maes
8+
69
Fixes:
710
- Proper handling of 'Create' permissions in both mail gateway (earlier
811
commit r4405 by Richard), web interface, and xmlrpc. This used to

doc/acknowledgements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Henrik Levkowetz,
7676
David Linke,
7777
Martin v. Löwis,
7878
Fredrik Lundh,
79+
Jochen Maes,
7980
Will Maier,
8081
Ksenia Marasanova,
8182
Georges Martin,

roundup/mailgw.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ def do_mailbox(self, filename):
569569
fcntl.flock(f.fileno(), FCNTL.LOCK_UN)
570570
return 0
571571

572-
def do_imap(self, server, user='', password='', mailbox='', ssl=0):
572+
def do_imap(self, server, user='', password='', mailbox='', ssl=0,
573+
cram=0):
573574
''' Do an IMAP connection
574575
'''
575576
import getpass, imaplib, socket
@@ -595,7 +596,10 @@ def do_imap(self, server, user='', password='', mailbox='', ssl=0):
595596
return 1
596597

597598
try:
598-
server.login(user, password)
599+
if cram:
600+
server.login_cram_md5(user, password)
601+
else:
602+
server.login(user, password)
599603
except imaplib.IMAP4.error, e:
600604
self.logger.exception('IMAP login failure')
601605
return 1

roundup/scripts/roundup_mailgw.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ def usage(args, message=None):
105105
This supports the same notation as IMAP.
106106
imaps username:password@server [mailbox]
107107
108+
IMAPS_CRAM:
109+
Connect to an IMAP server over ssl using CRAM-MD5 authentication.
110+
This supports the same notation as IMAP.
111+
imaps_cram username:password@server [mailbox]
112+
108113
""")%{'program': args[0]}
109114
return 1
110115

@@ -153,7 +158,7 @@ def main(argv):
153158
source, specification = args[1:3]
154159

155160
# time out net connections after a minute if we can
156-
if source not in ('mailbox', 'imaps'):
161+
if source not in ('mailbox', 'imaps', 'imaps_cram'):
157162
if hasattr(socket, 'setdefaulttimeout'):
158163
socket.setdefaulttimeout(60)
159164

@@ -189,14 +194,19 @@ def main(argv):
189194
elif source == 'apop':
190195
return handler.do_apop(server, username, password)
191196
elif source.startswith('imap'):
192-
ssl = source.endswith('s')
197+
ssl = cram = 0
198+
if source.endswith('s'):
199+
ssl = 1
200+
elif source.endswith('s_cram'):
201+
ssl = cram = 1
193202
mailbox = ''
194203
if len(args) > 3:
195204
mailbox = args[3]
196-
return handler.do_imap(server, username, password, mailbox, ssl)
205+
return handler.do_imap(server, username, password, mailbox, ssl,
206+
cram)
197207

198208
return usage(argv, _('Error: The source must be either "mailbox",'
199-
' "pop", "pops", "apop", "imap" or "imaps"'))
209+
' "pop", "pops", "apop", "imap", "imaps" or "imaps_cram'))
200210

201211
def run():
202212
sys.exit(main(sys.argv))

0 commit comments

Comments
 (0)