1
0
Fork 0
mirror of https://git.code.sf.net/p/archivemail/code synced 2024-12-21 23:32:54 +00:00

IMAP: support servers listening on non-standard ports

This commit is contained in:
Nikolaus Schulz 2011-07-09 17:47:06 +02:00
parent f9f9eacd88
commit eb07611fae
2 changed files with 21 additions and 8 deletions

View file

@ -7,6 +7,7 @@ version 0.?.? - UNRELEASED
FixedGzipFile.seek() return the new absolute file position.
Closes: #3314293.
* IMAP: support international mailbox names containing non-ASCII characters.
* IMAP: support servers listening on non-standard ports. Closes: #3168416.
version 0.8.2 - 16 October 2010

View file

@ -1290,9 +1290,9 @@ def _archive_imap(mailbox_name):
vprint("Setting imaplib.Debug = %d" % options.debug_imap)
imaplib.Debug = options.debug_imap
archive = None
imap_str = mailbox_name[mailbox_name.find('://') + 3:]
imap_username, imap_password, imap_server, imap_folder_pattern = \
parse_imap_url(imap_str)
imap_username, imap_password, \
imap_server, imap_server_port, \
imap_folder_pattern = parse_imap_url(mailbox_name)
if not imap_password:
if options.pwfile:
imap_password = open(options.pwfile).read().rstrip()
@ -1303,11 +1303,13 @@ def _archive_imap(mailbox_name):
is_ssl = mailbox_name[:5].lower() == 'imaps'
if is_ssl:
vprint("establishing secure connection to server %s" % imap_server)
imap_srv = imaplib.IMAP4_SSL(imap_server)
vprint("establishing secure connection to server %s, port %s" %
(imap_server, imap_server_port))
imap_srv = imaplib.IMAP4_SSL(imap_server, imap_server_port)
else:
vprint("establishing connection to server %s" % imap_server)
imap_srv = imaplib.IMAP4(imap_server)
vprint("establishing connection to server %s, port %s" %
(imap_server, imap_server_port))
imap_srv = imaplib.IMAP4(imap_server, imap_server_port)
if "AUTH=CRAM-MD5" in imap_srv.capabilities:
vprint("authenticating (cram-md5) to server as %s" % imap_username)
result, response = imap_srv.login_cram_md5(imap_username, imap_password)
@ -1551,6 +1553,7 @@ def parse_imap_url(url):
a, b = string.split(delim, 1)
return a, b
scheme, url = url.split('://')
password = None
try:
if options.pwfile:
@ -1566,7 +1569,16 @@ def parse_imap_url(url):
server, folder = url.split('/', 1)
except ValueError:
unexpected_error("Invalid IMAP connection string")
return username, password, server, folder
try:
server, port = server.split(':')
except ValueError:
if scheme.lower() == 'imap':
port = 143
else:
port = 993
else:
port = int(port)
return username, password, server, port, folder
def imap_getdelim(imap_server):