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.
This commit is contained in:
Nikolaus Schulz 2010-07-30 19:13:14 +02:00
parent d99b4b4414
commit f22fe4decd
3 changed files with 31 additions and 0 deletions

View File

@ -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

View File

@ -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)

View File

@ -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):