# vim: ft=python IMAP_SERVER = 'imap://username:******@localhost/' pop('localhost', None, 'username', '******') pop('pop3.isp.net', None, 'username', '******') def deliver(message): MAXSPAMCSIZE = 200000 def spam(): if size() < MAXSPAMCSIZE: cc("|spamc -L spam", 1) to('INBOX.Junk') def spam2(): if size() < MAXSPAMCSIZE: to("|spamc -L spam", 1) else: kill() def ham(): if size() < MAXSPAMCSIZE: cc("|spamc -L ham", 1) pass def ml(list): ham() to('INBOX.' + list) if (match('^From: news ') \ and match('^To: usenet@realh.co.uk')) \ or match('^Subject: Cron ') \ or match('^From: Anacron '): to("INBOX.NoisyLogs") if size() < MAXSPAMCSIZE: xfilter("spamc") # Automatically deal with newsstar spam if match(r'^Subject: Newsstar-general post from .* requires approval'): print "newsstar post" if match(r'Reason:.*Message has implicit destination', match = 'body'): m = match(r'Subject: confirm ([0-9a-f]+)', match = 'body') if m and m.groups()[0]: print "Group" import email import subprocess import sys reply = "From h@realh.co.uk " + email.Utils.formatdate()+"\n"+\ "From: h@realh.co.uk\n" + \ "To: newsstar-general-request@lists.sourceforge.net\n"+\ "Subject: Re: confirm " + m.groups()[0] + "\n" + \ "Date: " + email.Utils.formatdate() + "\n\n" try: sendmail = subprocess.Popen(['sendmail', '-t'], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE) sendmail.stdin.write(reply) sendmail.stdin.close() o1 = sendmail.stdout.readlines() o2 = sendmail.stderr.readlines() if o1: print "sendmail stdout:" print o1 if o2: print >>sys.stderr, "sendmail stderr:" print >>sys.stderr, o2 except: print >>sys.stderr, "Failed to send newsstar spam " + \ "confirmation message" else: to("INBOX.Junk") to("INBOX") # Mails with a score of 15 or higher are almost certainly spam (with 0.05% # false positives according to rules/STATISTICS.txt). Let's put them in a # different mbox. (This one is optional.) if match(r'^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*'): kill() # Not sent to a real address if match(r'^X-Original-To: unknown@realh\.ukfsn\.org'): if not match(r'for ') and not \ match(r'^(Received: from|From:|To:) .*[.@]asus\.com\.tw\>'): spam() # Not exactly spam, but not wanted if match('^From: .*sales@heartinternet'): kill() # Common spamming addresses if match(r'^From: .*(kazaa|k-lite|allcoolmusic\.com|koffi.wilson|crazy-offer\.com|lastminoffers\.com|clubpenguin\.com)'): spam2() if match('^Subject: Re: Hi'): # If it matches all of these it's definitely med spam if match('^V[a-zA-Z]{1,2}A[a-zA-Z]{1,2}GRA', False, 'body') \ and match('^AMB[a-zA-Z]{1,2}EN', False, 'body') \ and match('^VAL[a-zA-Z]{1,2}UM', False, 'body') \ and match('^C[a-zA-Z]{1,2}A[a-zA-Z]{1,2}LIS', False, 'body'): spam2() if match('^Subject: Re: ED[0-9][0-9]*$'): spam2() if match('^Subject: Re: (your )?(PHA[a-z]*RMACY|VIA[a-z]*GRA)$'): spam2() # This detects stuff like: # From: Xxx Yyy # Subject: Xxx wrote # or # Subject: hi it's Yyy m = match('^From: "?([a-z]+) ([a-z]+)') if m: m1, m2 = m.group(1, 2) # Filter through false positives if (match('^Subject:.*[ :]' + m1 + r'\b') \ or match('^Subject:.*[ :]' + m2 + r'\b')) \ and m1 != "eBay" and m1 != "Friends" and m1 != "Vodafone" \ and not (m1 == "Richer" and m2 == "Sounds") \ and not (m1 == "Superior" and m2 == "Interactive") \ and not (m1 == "Ebuyer") \ and not match('^List-Id: ') \ and not match('^X-Trac-Project: ' + m1 + ' ' + m2): if match('^From:.* ')): spam() # Stuff that's not addressed correctly to me #m = match(r'for ') if m: m = m.group(2) if m != "Houghton" and m != "Tony" and m != "h" and m != "for" \ and m != "Anthony": spam() # Mailing lists if match('^List-Id: .*linux-dvb'): ml("DVB") if match('^List-Id: .*mythtv'): ml("mythtv") if match('^List-Id: .*VDR'): ml("VDR") if match('^List-Id: .*UKFSN'): ml("UKFSN") if match('^List-Id: .*livtech'): ml("LWT") if match('^(To|List-Id|Cc): .*newsstar'): ml("newsstar") if match('^List-Id: .*pkg-rox-devel'): ml("RoxDebPkg") if match('^List-Id: .*HantsME'): ml("HantsME") if match('^List-Id: .*MPlayer'): ml("MPlayer") if match('^List-Id: .*dbus'): ml("DBus") if match('^List-Id: .*gtk'): ml("Gtk") if match('^List-Id: .*xorg'): ml("xorg") if match(r'^(To|Cc): .*pkg-rox-devel@lists\.alioth\.debian\.org'): ml("RoxDebPkg") # This has to come after the MPlayer and pkg-rox rules to avoid catching the # "rox" in them. if match('^List-Id: .*rox'): ml("Rox") if match(r'^Sender: owner-mechat-l@LISTSERV\.AOL\.COM'): ml("MECHAT") if size() < MAXSPAMCSIZE: ham()