aboutsummaryrefslogtreecommitdiffstats
path: root/archivemail.py
diff options
context:
space:
mode:
authorNikolaus Schulz <microschulz@web.de>2006-10-12 01:02:35 +0000
committerNikolaus Schulz <microschulz@web.de>2006-10-12 01:02:35 +0000
commit539894ced45f2cdbae3a9765473a3dd1557a7c99 (patch)
treecaa6523bb9190804c1640058a03e8f5996554b8e /archivemail.py
parent800a957b59b4ef9cecd110bea6b6bdcf224d4add (diff)
downloadarchivemail-539894ced45f2cdbae3a9765473a3dd1557a7c99.tar.gz
archivemail-539894ced45f2cdbae3a9765473a3dd1557a7c99.tar.bz2
archivemail-539894ced45f2cdbae3a9765473a3dd1557a7c99.zip
Implemented --dry-run and --delete for IMAP, both do no not download messages.
Stats are still missing.
Diffstat (limited to 'archivemail.py')
-rwxr-xr-xarchivemail.py50
1 files changed, 25 insertions, 25 deletions
diff --git a/archivemail.py b/archivemail.py
index 988bc72..97acea6 100755
--- a/archivemail.py
+++ b/archivemail.py
@@ -1266,32 +1266,32 @@ def _archive_imap(mailbox_name, final_archive_name):
message_list = response[0].split()
vprint("%d messages found matching filter" % len(message_list))
- for msg_id in message_list:
- result, response = imap_srv.fetch(msg_id, '(RFC822 FLAGS)')
- if result != 'OK': unexpected_error("Failed to fetch message")
- if "\r\n" == os.linesep:
- msg_str = response[0][1]
- else:
- msg_str = response[0][1].replace("\r\n", os.linesep)
- msg_flags = imaplib.ParseFlags(response[1])
- msg = rfc822.Message(cStringIO.StringIO(msg_str))
- add_status_headers_imap(msg, msg_flags)
- vprint("processing message '%s'" % msg.get('Message-ID'))
- if options.warn_duplicates:
- cache.warn_if_dupe(msg)
- if not options.dry_run:
- if not archive:
- archive = ArchiveMbox(final_archive_name)
- archive.write(msg)
- stats.another_archived()
-
if not options.dry_run:
- if archive:
- archive.close()
- archive.finalise()
- # do not delete more than a certain number of messages at a time, because the
- # command length is limited. This avoids that servers terminate the connection with
- # EOF or TCP RST.
+ if not options.delete_old_mail:
+ for msg_id in message_list:
+ result, response = imap_srv.fetch(msg_id, '(RFC822 FLAGS)')
+ if result != 'OK': unexpected_error("Failed to fetch message")
+ if "\r\n" == os.linesep:
+ msg_str = response[0][1]
+ else:
+ msg_str = response[0][1].replace("\r\n", os.linesep)
+ msg_flags = imaplib.ParseFlags(response[1])
+ msg = rfc822.Message(cStringIO.StringIO(msg_str))
+ add_status_headers_imap(msg, msg_flags)
+ vprint("processing message '%s'" % msg.get('Message-ID'))
+ if options.warn_duplicates:
+ cache.warn_if_dupe(msg)
+ if not archive:
+ archive = ArchiveMbox(final_archive_name)
+ archive.write(msg)
+ # FIXME: stats are not complete yet.
+ #stats.another_archived()
+ if archive:
+ archive.close()
+ archive.finalise()
+ # do not delete more than a certain number of messages at a time,
+ # because the command length is limited. This avoids that servers
+ # terminate the connection with EOF or TCP RST.
vprint("Deleting %s messages" % len(message_list))
max_delete = 100
for i in range(0, len(message_list), max_delete):