From 539894ced45f2cdbae3a9765473a3dd1557a7c99 Mon Sep 17 00:00:00 2001 From: Nikolaus Schulz Date: Thu, 12 Oct 2006 01:02:35 +0000 Subject: Implemented --dry-run and --delete for IMAP, both do no not download messages. Stats are still missing. --- archivemail.py | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'archivemail.py') 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): -- cgit v1.2.3