Created
July 15, 2013 22:52
-
-
Save wujiang/6004210 to your computer and use it in GitHub Desktop.
Archive old Maildir type messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Archive old Maildir type messages | |
# Wu Jiang ([email protected]) | |
import argparse | |
from datetime import timedelta | |
import mailbox | |
import time | |
parser = argparse.ArgumentParser(description="Archive Maildir messages.") | |
parser.add_argument("-d", "--days", default=14, type=int, | |
help="archive messages older than how many days") | |
parser.add_argument("-v", "--verbose", action="store_true") | |
parser.add_argument("path", help="path to maildir") | |
args = parser.parse_args() | |
threshold = timedelta(args.days).total_seconds() | |
maildir = mailbox.Maildir(args.path, factory=None, create=False) | |
# get the archive folder | |
try: | |
archive = maildir.get_folder("archive") | |
except mailbox.NoSuchMailboxError: | |
archive = maildir.add_folder("archive") | |
for key, message in maildir.iteritems(): | |
if time.time() - message.get_date() >= threshold: | |
archive.add(message) | |
maildir.remove(key) | |
if args.verbose: | |
print("Moved message {} to the archive folder.".format(key)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For mutt, you can run this when you are on index:
Explanation:
T-01/07/13
: tag all messages received before July 01, 2013;
: prefix to apply following macros to tagged messagess
: save to~/mail/.archive
: wherever your archive folder is