From f22fe4decd9a70a2eb826ecdd14f9d1bb3b4e394 Mon Sep 17 00:00:00 2001 From: Nikolaus Schulz Date: Fri, 30 Jul 2010 19:13:14 +0200 Subject: Detect and never archive IMAP server pseudo mbox messages IMAP servers (Dovecot and UW-IMAP at least) may store mailbox meta data for mboxes in a pseudo message. Such messages are now detected and never archived. This commit includes a test case in the test suite. --- CHANGELOG | 3 +++ archivemail | 6 ++++++ test_archivemail | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 1aca43f..bdef7c3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -51,6 +51,9 @@ Version 0.8.0 - UNRELEASED boolean constants). * Added a lot of test cases for maildir archiving to the test suite. Maildir testing should now be roughly on par with mbox testing. + * IMAP servers (Dovecot and UW-IMAP at least) may store mailbox meta data + for mboxes in a pseudo message. Such messages are now detected and never + archived. Obsoletes: patch #2210707. (Thanks, "tlhackque") Version 0.7.2 - 9 November 2007 diff --git a/archivemail b/archivemail index ec05171..52ec06b 100755 --- a/archivemail +++ b/archivemail @@ -1156,6 +1156,12 @@ def _archive_mbox(mailbox_name, final_archive_name): msg = original.next() if not msg and (original.starting_size > 0): user_error("'%s' is not a valid mbox-format mailbox" % mailbox_name) + if msg and 'X-IMAP' in msg: + # Dovecot and UW-IMAP pseudo message for mailbox meta data + vprint("detected IMAP pseudo message") + if retain: + retain.write(msg) + msg = original.next() while (msg): msg_size = sizeof_message(msg) stats.another_message(msg_size) diff --git a/test_archivemail b/test_archivemail index 2d63d78..fda2d63 100755 --- a/test_archivemail +++ b/test_archivemail @@ -1103,6 +1103,28 @@ class TestArchiveSize(unittest.TestCase): archivemail.options.min_size = None +class TestXIMAPMessage(TestArchive): + """Test if IMAP pseudo messages in mboxes are properly handled.""" + def setUp(self): + super(TestXIMAPMessage, self).setUp() + archivemail.options.quiet = True + + def testXIMAPMbox(self): + """IMAP pseudo messages in an mbox are always preserved.""" + self.good_mbox = make_mbox(hours_old=181*24, headers={'X-IMAP': 'dummytext'}, + messages=1) + self.good_archive = make_mbox(hours_old=181*24, messages=3) + self.mbox = tempfile.mkstemp()[-1] + shutil.copyfile(self.good_mbox, self.mbox) + append_file(self.good_archive, self.mbox) + archivemail.archive(self.mbox) + self.verify() + + def tearDown(self): + super(TestXIMAPMessage, self).tearDown() + archivemail.options.quiet = False + + ############# Test archiving maildirs ############### class TestArchiveMailboxdir(TestCaseInTempdir): -- cgit v1.2.3