Created
September 10, 2009 04:25
-
-
Save akrito/184297 to your computer and use it in GitHub Desktop.
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 | |
import mailbox | |
import os | |
import sys | |
import time | |
my_maildir = 'Maildir' | |
expire_dates = { | |
'Logs': 60, | |
'Django': 0.1, | |
'Cron': 7} | |
maildir = os.path.join(os.environ['HOME'], my_maildir) | |
# None causes the mailbox to return Maildir instances | |
trash = mailbox.Maildir(os.path.join(maildir, 'Trash'), None) | |
now = time.time() | |
for box_subdir, max_age in expire_dates.iteritems(): | |
box = mailbox.Maildir(os.path.join(maildir, box_subdir), None) | |
for k, m in box.iteritems(): | |
if now - m.get_date() > 86400 * max_age: | |
if not 'F' in m.get_flags(): | |
# Move it to the trash | |
sys.stdout.write('T') | |
trash.add(m) | |
box.discard(k) | |
else: | |
sys.stdout.write('.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment