From c7907ffa244cf1a4d0d13399d792cc4e86aa6cb0 Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 2 Feb 2010 05:15:10 +0000 Subject: [PATCH] support CRAM-MD5 for IMAPS git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4449 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 3 +++ doc/acknowledgements.txt | 1 + roundup/mailgw.py | 8 ++++++-- roundup/scripts/roundup_mailgw.py | 18 ++++++++++++++---- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 96fedf3..6b66a3c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,9 @@ are given with the most recent entry first. 2010-XX-XX 1.4.12 (rXXXX) +Features: +- Support IMAP CRAM-MD5, thanks Jochen Maes + Fixes: - Proper handling of 'Create' permissions in both mail gateway (earlier commit r4405 by Richard), web interface, and xmlrpc. This used to diff --git a/doc/acknowledgements.txt b/doc/acknowledgements.txt index 13793dc..c7cdcc2 100644 --- a/doc/acknowledgements.txt +++ b/doc/acknowledgements.txt @@ -76,6 +76,7 @@ Henrik Levkowetz, David Linke, Martin v. Löwis, Fredrik Lundh, +Jochen Maes, Will Maier, Ksenia Marasanova, Georges Martin, diff --git a/roundup/mailgw.py b/roundup/mailgw.py index 97848a7..a098f85 100644 --- a/roundup/mailgw.py +++ b/roundup/mailgw.py @@ -569,7 +569,8 @@ class MailGW: fcntl.flock(f.fileno(), FCNTL.LOCK_UN) return 0 - def do_imap(self, server, user='', password='', mailbox='', ssl=0): + def do_imap(self, server, user='', password='', mailbox='', ssl=0, + cram=0): ''' Do an IMAP connection ''' import getpass, imaplib, socket @@ -595,7 +596,10 @@ class MailGW: return 1 try: - server.login(user, password) + if cram: + server.login_cram_md5(user, password) + else: + server.login(user, password) except imaplib.IMAP4.error, e: self.logger.exception('IMAP login failure') return 1 diff --git a/roundup/scripts/roundup_mailgw.py b/roundup/scripts/roundup_mailgw.py index 3325091..603af5f 100644 --- a/roundup/scripts/roundup_mailgw.py +++ b/roundup/scripts/roundup_mailgw.py @@ -105,6 +105,11 @@ IMAPS: This supports the same notation as IMAP. imaps username:password@server [mailbox] +IMAPS_CRAM: + Connect to an IMAP server over ssl using CRAM-MD5 authentication. + This supports the same notation as IMAP. + imaps_cram username:password@server [mailbox] + """)%{'program': args[0]} return 1 @@ -153,7 +158,7 @@ def main(argv): source, specification = args[1:3] # time out net connections after a minute if we can - if source not in ('mailbox', 'imaps'): + if source not in ('mailbox', 'imaps', 'imaps_cram'): if hasattr(socket, 'setdefaulttimeout'): socket.setdefaulttimeout(60) @@ -189,14 +194,19 @@ def main(argv): elif source == 'apop': return handler.do_apop(server, username, password) elif source.startswith('imap'): - ssl = source.endswith('s') + ssl = cram = 0 + if source.endswith('s'): + ssl = 1 + elif source.endswith('s_cram'): + ssl = cram = 1 mailbox = '' if len(args) > 3: mailbox = args[3] - return handler.do_imap(server, username, password, mailbox, ssl) + return handler.do_imap(server, username, password, mailbox, ssl, + cram) return usage(argv, _('Error: The source must be either "mailbox",' - ' "pop", "pops", "apop", "imap" or "imaps"')) + ' "pop", "pops", "apop", "imap", "imaps" or "imaps_cram')) def run(): sys.exit(main(sys.argv)) -- 2.30.2