aboutsummaryrefslogtreecommitdiffstats
path: root/archivemail.py
diff options
context:
space:
mode:
authorNikolaus Schulz <microschulz@web.de>2008-12-18 21:56:00 +0100
committerNikolaus Schulz <microschulz@web.de>2009-11-06 21:09:38 +0100
commitbd85cffe379c7f11e3b3e1423dd55e8e446dcb8c (patch)
tree32dce699464eb84937a38d11df27166a5d6148b5 /archivemail.py
parent9574c4f41c36143d72f738f50019e87dc8d6b61d (diff)
downloadarchivemail-bd85cffe379c7f11e3b3e1423dd55e8e446dcb8c.tar.gz
archivemail-bd85cffe379c7f11e3b3e1423dd55e8e446dcb8c.tar.bz2
archivemail-bd85cffe379c7f11e3b3e1423dd55e8e446dcb8c.zip
Simplify imap_get_namespace() and imap_guess_mailboxnames()
I don't think anybody wants to archive folders in shared or public IMAP namespaces, so we don't bother checking all possible namespaces. The code was ugly anyway.
Diffstat (limited to 'archivemail.py')
-rwxr-xr-xarchivemail.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/archivemail.py b/archivemail.py
index 6eee7db..5849b83 100755
--- a/archivemail.py
+++ b/archivemail.py
@@ -1533,9 +1533,13 @@ def imap_get_namespace(srv):
# ['(("INBOX." ".")) NIL (("#shared." ".")("shared." "."))'] or
# ['(("" ".")) NIL NIL'], see RFC 2342.
# Make a reasonable guess parsing this beast.
- ns = re.findall(r'\("([^"]*)" (?:"(.)"|NIL)', response[0])
- assert(ns)
- return ns
+ try:
+ m = re.match(r'\(\("([^"]*)" (?:"(.)"|NIL)', response[0])
+ nsprefix, hdelim = m.groups()
+ except:
+ print "Cannot parse IMAP NAMESPACE response %s" % repr(response)
+ raise
+ return nsprefix, hdelim
def imap_smart_select(srv, mailbox):
@@ -1600,25 +1604,21 @@ def imap_guess_mailboxnames(srv, mailbox):
of preference, compiled by prepending an IMAP namespace prefix if necessary,
and by translating hierarchy delimiters."""
if 'NAMESPACE' in srv.capabilities:
- namespace_response = imap_get_namespace(srv)
- for nsprefix, hdelim in namespace_response:
- if mailbox.startswith(nsprefix):
- mailbox = mailbox[len(nsprefix):]
- break
- else:
- # mailbox doesn't start with a namespace prefix;
- # choose private namespace, which is the first one.
- nsprefix, hdelim = namespace_response[0]
+ nsprefix, hdelim = imap_get_namespace(srv)
else:
vprint("Server doesn't support NAMESPACE command.")
nsprefix = ""
hdelim = imap_getdelim(srv)
vprint("IMAP namespace prefix: '%s', hierarchy delimiter: '%s'" % \
(nsprefix, hdelim))
- boxnames = [nsprefix + mailbox]
- if os.path.sep in mailbox and hdelim:
+ if mailbox.startswith(nsprefix):
+ boxnames = [mailbox]
+ else:
+ boxnames = [nsprefix + mailbox]
+ if os.path.sep in mailbox and hdelim is not None:
mailbox = mailbox.replace(os.path.sep, hdelim)
- boxnames.append(mailbox) # could have a valid namespace prefix now
+ if mailbox.startswith(nsprefix):
+ boxnames.append(mailbox)
if nsprefix:
boxnames.append(nsprefix + mailbox)
return boxnames