commit 73b33348b081fb798f1cbbe104b77dbfbe8e2c22 Author: Jochen Maes Date: Fri Oct 16 09:29:35 2009 +0200 IMAP cram_md5 login fix Signed-off-by: Jochen Maes diff --git a/roundup/mailgw.py b/roundup/mailgw.py index 61470ae..0b030a0 100644 --- a/roundup/mailgw.py +++ b/roundup/mailgw.py @@ -586,7 +586,7 @@ 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 @@ -612,7 +612,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..4d331fb 100644 --- a/roundup/scripts/roundup_mailgw.py +++ b/roundup/scripts/roundup_mailgw.py @@ -105,6 +105,13 @@ IMAPS: This supports the same notation as IMAP. imaps username:password@server [mailbox] +IMAPS_CRAM: + Connect to an IMAP server over ssl. but support the CRAM_MD5 authentication. + This supports the same notation as IMAP. + imaps_cram username:password@server [mailbox] + + + """)%{'program': args[0]} return 1 @@ -153,7 +160,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 +196,21 @@ def main(argv): elif source == 'apop': return handler.do_apop(server, username, password) elif source.startswith('imap'): - ssl = source.endswith('s') + ssl=0 + cram=0 + if source.endswith('s'): + ssl=1 + elif source.endswith('s_cram'): + ssl=1 + 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))