-
Notifications
You must be signed in to change notification settings - Fork 2
/
spam.py
25 lines (20 loc) · 780 Bytes
/
spam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import shutil
from subprocess import Popen
from config import BASEDIR
# format is one bad word per line, all lowercase
blacklisted = [w.strip() for w in open(os.path.join(BASEDIR, 'badwords.txt')).readlines()]
def spamc(mail):
# run spam filtering on all new mails in the INBOX
# annotate the mail headers
failure = True
backup = ".".join([mail, "bak"])
with open(mail, 'r') as f:
# run through spamc
# create a temporary file
with open(backup, 'w') as bak:
# run the mail through spamc
spamc = Popen(["/usr/bin/vendor_perl/spamc"], stdin=f, stdout=bak)
failure = spamc.wait() != 0
if failure: print("error: spamc failed on %s" % mail)
else: shutil.move(backup, mail)