#!/usr/bin/env python from email.utils import parsedate import mailbox def extract_date(email): date = email.get('Date') return parsedate(date) # the_mailbox = mailbox.mbox('cypherpunks-1999-2015-fixedbetter.mbox') the_mailbox = mailbox.mbox('cyp-unified.sorted') sorted_mails = sorted(the_mailbox, key=extract_date) print 'after sorted' the_mailbox.update(enumerate(sorted_mails)) print 'after update' the_mailbox.flush() print 'after flush'