Skip to content

Instantly share code, notes, and snippets.

@akrito
Created September 10, 2009 04:25
Show Gist options
  • Save akrito/184297 to your computer and use it in GitHub Desktop.
Save akrito/184297 to your computer and use it in GitHub Desktop.
#!/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