diff options
author | Nikolaus Schulz <microschulz@web.de> | 2008-04-08 19:06:42 +0000 |
---|---|---|
committer | Nikolaus Schulz <microschulz@web.de> | 2008-04-08 19:06:42 +0000 |
commit | e5b6397dd52e8ce0214a3a18801f61bb5a5fe261 (patch) | |
tree | ff8ef7d6e3e578f887b0b02c4b7d60a6dc10b35a | |
parent | 78b4923832a9cb469d4782b5eb1d2bca971254a7 (diff) | |
download | archivemail-e5b6397dd52e8ce0214a3a18801f61bb5a5fe261.tar.gz archivemail-e5b6397dd52e8ce0214a3a18801f61bb5a5fe261.tar.bz2 archivemail-e5b6397dd52e8ce0214a3a18801f61bb5a5fe261.zip |
Moved IMAP SELECT code into a separate function.
-rwxr-xr-x | archivemail.py | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/archivemail.py b/archivemail.py index afd532a..13e6ffb 100755 --- a/archivemail.py +++ b/archivemail.py @@ -1371,21 +1371,8 @@ def _archive_imap(mailbox_name, final_archive_name): user_error("imap server %s has login disabled (hint: " "try ssl/imaps)" % imap_server) - imap_folder = imap_find_mailbox(imap_srv, imap_folder) - roflag = options.dry_run or options.copy_old_mail - # Work around python bug #1277098 (still pending in python << 2.5) - if not roflag: - roflag = None - if roflag: - vprint("examining imap folder '%s' read-only" % imap_folder) - else: - vprint("selecting imap folder '%s'" % imap_folder) - result, response = imap_srv.select(imap_folder, roflag) - if result != 'OK': - unexpected_error("selecting '%s' failed; server says: '%s'." \ - % (imap_folder, response[0])) - # response is e.g. ['1016'] for 1016 messages in folder - total_msg_count = int(response[0]) + imap_smart_select(imap_srv, imap_folder) + total_msg_count = int(imap_srv.response("EXISTS")[1][0]) vprint("folder has %d message(s)" % total_msg_count) # IIUIC the message sequence numbers are stable for the whole session, since @@ -1552,6 +1539,24 @@ def imap_get_namespace(srv): return ns +def imap_smart_select(imap_srv, imap_folder): + """Select the given mailbox on the IMAP server, correcting an invalid + mailbox path if possible.""" + imap_folder = imap_find_mailbox(imap_srv, imap_folder) + roflag = options.dry_run or options.copy_old_mail + # Work around python bug #1277098 (still pending in python << 2.5) + if not roflag: + roflag = None + if roflag: + vprint("examining imap folder '%s' read-only" % imap_folder) + else: + vprint("selecting imap folder '%s'" % imap_folder) + result, response = imap_srv.select(imap_folder, roflag) + if result != 'OK': + unexpected_error("selecting '%s' failed; server says: '%s'." \ + % (imap_folder, response[0])) + + def imap_find_mailbox(srv, mailbox): """Find the given mailbox on the IMAP server, correcting an invalid mailbox path if possible. Return the found mailbox name.""" |