Last active
November 15, 2016 20:40
-
-
Save markuman/b4f079bf2cbbcfa14d05032d609bb2ec 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/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