Skip to content

Instantly share code, notes, and snippets.

@markuman
Last active November 15, 2016 20:40
Show Gist options
  • Save markuman/b4f079bf2cbbcfa14d05032d609bb2ec to your computer and use it in GitHub Desktop.
Save markuman/b4f079bf2cbbcfa14d05032d609bb2ec to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python3
import sys, mailbox
MAILDIR = sys.argv[1]
THIS_MAIL = ""
RECEIPT_FOUND = False
SUBJECT_FOUND = False
FILTER = {'[email protected]': 'markus', '[email protected]': 'fuckbook', '[email protected]': 'ebay'}
DESTINATION = None
for line in sys.stdin:
THIS_MAIL += line
if not RECEIPT_FOUND and line.find("To:") == 0:
RECEIPT_FOUND = True
for key in FILTER.keys():
if line.find(key) > -1:
DESTINATION = 'INBOX.' + FILTER[key]
if not SUBJECT_FOUND and line.find("Subject:") == 0:
SUBJECT_FOUND = True
if line.find("CANOPUS_SPAM") > -1:
DESTINATION = "SPAM"
md = mailbox.Maildir(MAILDIR, factory = None, create = True)
if DESTINATION is not None:
md = md.get_folder(DESTINATION)
md.add(THIS_MAIL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment