diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-02-11 18:49:51 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-02-11 18:49:51 -0500 |
commit | e72c0dd2e8909019cfa6118353652b2299f0d16c (patch) | |
tree | ee5f5455fd0f46064fec2bbc92b345d38b575e73 /.config/maildirproc/att.rc | |
parent | 83c71bfd686ae36b0483a8278303de7e5fe4924d (diff) | |
parent | 0283ec58b3f4e179c0d8f57e5fc9ecb6e7750e17 (diff) |
Merge branch 'master' into gluglugt60-par/master
Diffstat (limited to '.config/maildirproc/att.rc')
-rw-r--r-- | .config/maildirproc/att.rc | 471 |
1 files changed, 239 insertions, 232 deletions
diff --git a/.config/maildirproc/att.rc b/.config/maildirproc/att.rc index ecd9c20..67335e7 100644 --- a/.config/maildirproc/att.rc +++ b/.config/maildirproc/att.rc @@ -5,12 +5,9 @@ import os.path import subprocess import datetime import re +# +# Mail attribute utilities -processor.maildir_base = "~/Maildir" -processor.auto_reload_rcfile = True - -# FIXME: this doesn't handle the case where someone replies `To` you -# directly an `Cc`s the list. def mailman_domain(mail, domain): """ Return a string that is the list-name for a mailman domain @@ -38,7 +35,19 @@ def ezmlm_domain(mail, domain): return m.group(1) return None -def is_to_or_from(mail,address): +def majordomo_domain(mail, domain): + """ + Return a string that is the list-name for a majordomo domain + """ + m = mail["List-Id"].matches("^(.*<|)([^<]*)\."+re.escape(domain)) + if m: + return m.group(2) + for hdr in [ 'To', 'Cc', 'From' ]: + m = mail[hdr].matches("((\w|-)*)@"+re.escape(domain)) + if m: + return m.group(1) + +def is_to_or_from(mail, address): """ Return true if [mail] is to or from an address that contains [address]. """ @@ -47,7 +56,7 @@ def is_to_or_from(mail,address): or mail["From"].contains(address) or mail["Reply-To"].contains(address) or mail.target.contains(address)) -def is_to_or_from_re(mail,address): +def is_to_or_from_re(mail, address): """ Return true if [mail] is to or from an address that matches the regex [address]. @@ -55,17 +64,9 @@ def is_to_or_from_re(mail,address): return ( mail["From"].matches(address) or mail.target.matches(address)) -def move_ham(mail,folder): - y = datetime.datetime.now().year - folder = "FOLDERS.Ham."+str(y)+folder - dir = processor.maildir_base+"/"+folder - if not os.path.isfile(dir+"/maildirfolder"): - os.makedirs(dir+"/tmp", 0o777, True) - os.makedirs(dir+"/new", 0o777, True) - os.makedirs(dir+"/cur", 0o777, True) - open(dir+"/maildirfolder", 'a').close() - mail.move(folder) - +# +# bogofilter utilites + def bogofilter_auto(mail): p = subprocess.Popen( ["bogofilter", "-u", "-v", "-I", mail.path], @@ -82,26 +83,26 @@ def bogofilter_ham(mail): subprocess.call(["bogofilter", "-S", "-n", "-I", mail.path]) def bogofilter_spam(mail): subprocess.call(["bogofilter", "-N", "-s", "-I", mail.path]) +# +# The core of my filters -def handle_incoming_ham_training(mail): - bogofilter_ham(mail) - handle_incoming_ham(mail) -def handle_incoming_spam_training(mail): - bogofilter_spam(mail) - mail.move("FOLDERS.Spam") - -def handle_incoming_ham(mail): - my_filters(mail) -def handle_incoming_spam(mail): - mail.move("FOLDERS.Spam") - -def handle_incoming_unknown(mail): - # Filter spam +def move_ham(mail, folder): + y = datetime.datetime.now().year + folder = "FOLDERS.Ham."+str(y)+folder + dir = processor.maildir_base+"/"+folder + if not os.path.isfile(dir+"/maildirfolder"): + os.makedirs(dir+"/tmp", 0o777, True) + os.makedirs(dir+"/new", 0o777, True) + os.makedirs(dir+"/cur", 0o777, True) + open(dir+"/maildirfolder", 'a').close() + mail.move(folder) - # Whitelist - if ( +def my_whitelist(mail): + return ( False + or is_to_or_from(mail, "@opengroup.org") or is_to_or_from(mail, "@purestorage.com") + or is_to_or_from(mail, "@vger.kernel.org") or is_to_or_from(mail, "Bryan@ChankTunUnGi.onmicrosoft.com") or is_to_or_from(mail, "cacnedcomms@gmail.com") or is_to_or_from(mail, "fsf.org") @@ -110,6 +111,8 @@ def handle_incoming_unknown(mail): or is_to_or_from(mail, "parabolagnulinux.org") or mail["From"] == "3174451635@mms.att.net" or mail["From"] == "MAILER-DAEMON@yahoo.com" + or mail["From"].contains("@careereco.com") + or mail["From"].contains("@ciholas.com") or mail["From"].contains("@e.oldnational.com>") or mail["From"].contains("@facebookmail.com>") or mail["From"].contains("@gandi.net") @@ -126,8 +129,10 @@ def handle_incoming_unknown(mail): or mail["From"].contains("@post.oreilly.com>") or mail["From"].contains("@scouting.org>") or mail["From"].contains("@solutionsinplastic.com>") - or mail["From"].contains("@startcom.org>") + or mail["From"].contains("@startcom.org>") or mail["From"].contains("@usfirst.org>") + or mail["From"].contains("@vectren.com") + or mail["From"].contains("@vectrenemail.com") or mail["From"].contains("@wolframalpha.com>") or mail["From"].contains("Promo@email.newegg.com") or mail["From"].contains("info@email2.mysimplemobile.com") @@ -140,52 +145,38 @@ def handle_incoming_unknown(mail): or mail["Subject"].contains("[Maintenance]") or mail["Subject"].contains("[PATCH") or mail["Subject"].contains("[systemd-devel]") - ): - handle_incoming_ham_training(mail) - return - - spam = bogofilter_auto(mail) - if spam == 0: - handle_incoming_spam(mail) - return - elif spam == 1: - handle_incoming_ham(mail) - return - elif spam == 2: - mail.move("FOLDERS.MysteryMeat") - return - else: - mail.move("FOLDERS.BogoFail") - return + ) def my_filters(mail): - if is_to_or_from(mail,"@purestorage.com"): - move_ham(mail, ".purestorage") - return - - # Sort mail from various mailing lists - # https://lists.gnu.org/mailman/options/bug-librejs/lukeshu@sbcglobal.net - # https://lists.nongnu.org/mailman/options/libreboot/lukeshu@sbcglobal.net - # https://mail.gnome.org/mailman/options/networkmanager-list/lukeshu@sbcglobal.net - for pair in [ [ 'gnu.org', 'gnu' ], - [ 'nongnu.org', 'nongnu' ], - [ 'gnome.org', 'gnome' ], + # .software.* (GNU Mailman) + for pair in [ [ 'gnu.org', 'gnu' ], # https://lists.gnu.org/mailman/options/bug-librejs/lukeshu@sbcglobal.net + [ 'nongnu.org', 'nongnu' ], # https://lists.nongnu.org/mailman/options/libreboot/lukeshu@sbcglobal.net + [ 'gnome.org', 'gnome' ], # https://mail.gnome.org/mailman/options/networkmanager-list/lukeshu@sbcglobal.net [ 'archlinux.org', 'archlinux' ], [ 'lists.freedesktop.org', 'freedesktop' ], [ 'lists.fedorahosted.org', 'fedorahosted' ], [ 'lists.arthurdejong.org', 'arthurdejong' ], [ 'lists.stanford.edu', 'stanford' ], + [ 'mailman.stanford.edu', 'stanford' ], [ 'lists.parabola.nu', 'parabola' ], [ 'parabola.nu', 'parabola' ] ]: list = mailman_domain(mail, pair[0]) if list: move_ham(mail, ".software."+pair[1]+"."+list) return + # .software.* (EZMLM) for pair in [ [ 'list.cr.yp.to', 'djb' ] ]: list = ezmlm_domain(mail, pair[0]) if list: move_ham(mail, ".software."+pair[1]+"."+list) return + # .software.* (Majordomo) + for pair in [ [ 'vger.kernel.org', 'kernel' ] ]: + list = majordomo_domain(mail, pair[0]) + if list: + move_ham(mail, ".software."+pair[1]+"."+list) + return + # .software.parabola if ( False or is_to_or_from(mail, "parabolagnulinux.org") @@ -194,53 +185,75 @@ def my_filters(mail): ): move_ham(mail, ".software.parabola") return - - # Sort mail from some social websites - if mail["From"].matches("facebook(|mail)\.com"): - move_ham(mail, ".Social.Facebook") + # .software.POSIX + if is_to_or_from(mail, "austin-group-l@opengroup.org"): + move_ham(mail, ".software.POSIX") return - - if ( - False - or mail["From"].matches("identi\.ca") - or mail["From"].matches("statusnet") - ): - move_ham(mail, ".Social.Identica") + # .software.TravisCI + if mail["From"].contains("builds@travis-ci.org"): + move_ham(mail, ".software.TravisCI") return - + # .software + for address in [ + "@archlinux.org", + "@canonical.org", + "@cnuk.org", + "@core3.amsl.com", + "@defectivebydesign.org", + "@eff.org", + "@fedorahosted.org", + "@foocorp.net", + "@fsf.org", + "@github.com", + "@gitorious.org", + "@gnome.org", + "@gnu.org", + "@ietf.org", + "@kde.org", + "@lists.fedorahosted.org", + "@mozilla.org", + "@nongnu.org", + "@sourceforge.com", + "@thyrsus.com", + ]: + if is_to_or_from(mail, address): + move_ham(mail, ".software") + return + # .servers if ( False or mail["From"].contains("@gandi.net") or mail["From"].contains("@ramhost.us") or mail["From"].contains("@startcom.org") + or mail["From"].contains("@startssl.com") + or mail["From"].contains("@vultr.com") or (mail["From"].contains("@2co.com") and mail["Subject"].contains("RAM Host")) ): - move_ham(mail, ".lukeshu-com") + move_ham(mail, ".servers") + return + # .Social.* + if mail["From"].matches("facebook(|mail)\.com"): + move_ham(mail, ".Social.Facebook") + return + if mail["From"].matches("identi\.ca|statusnet"): + move_ham(mail, ".Social.Identica") return - if mail["From"].matches("twitter\.com"): move_ham(mail, ".Social.Twitter") return - if mail["From"].matches("@xkcd\.com"): move_ham(mail, ".Social.xkcd") return - - if mail["From"].matches("schwab\.com"): - move_ham(mail, ".schwab") - return - - if mail["From"].matches("@ebay\.com"): - move_ham(mail, ".ebay") + if is_to_or_from(mail, "linkedin.com"): + move_ham(mail, ".Social.LinkedIn") return - - # Sort mail related to Troop 276 + # .BSA if ( False or mail["List-Id"].contains("troopmailinglist.troop276.net") - or is_to_or_from(mail, "t276_announcements@att.net") or mail["Subject"].matches("troop") or mail["Subject"].matches("merit\s*badge") + or is_to_or_from(mail, "t276_announcements@att.net") or is_to_or_from(mail, "Bryan@ChankTunUnGi.onmicrosoft.com") or is_to_or_from(mail, "basu@maharjan.org") or is_to_or_from(mail, "cacnedcomms@gmail.com") @@ -259,10 +272,105 @@ def my_filters(mail): or is_to_or_from(mail, "trdindy@comcast.net") or is_to_or_from(mail, "wjensen111@aol.com") ): - move_ham(mail, ".BoyScouts") + move_ham(mail, ".BSA") + return + # .FRC + for address in [ "@ni.com", "@usfirst.org", "@firstinspires.org" ]: + if is_to_or_from(mail, address): + move_ham(mail, ".FRC") + return + # .FRC.829 + if ( + False + or mail["Subject"].matches("\b829\b") + or is_to_or_from(mail, "wcxctrack829@aim.com") # Pat + or is_to_or_from(mail, "william.walk@gmail.com") + ): + move_ham(mail, ".FRC.829") + return + # .FRC.1024 + if ( + False + or mail["Subject"].matches("\b1024\b") + or mail["Subject"].matches("kil-?a-?bytes") + or is_to_or_from(mail, "BBonahoom@stanleyworks.com") + or is_to_or_from(mail, "bryanbonahoom@gmail.com") + or is_to_or_from(mail, "allison.m.babcock@gmail.com") + or is_to_or_from(mail, "cdewalt3@yahoo.com") + or is_to_or_from(mail, "dave.nelson@ecolab.com") + or is_to_or_from(mail, "dickaustin190@yahoo.com") + or is_to_or_from(mail, "djnels1@comcast.net") # Dave and Julie Nelson + or is_to_or_from(mail, "gamefreak207@gmail.com") # Brett Leedy + or is_to_or_from(mail, "jason.zielke@gmail.com") + or is_to_or_from(mail, "jeffreysmith@msdlt.k12.in.us") + or is_to_or_from(mail, "sarahlittell@comcast.net") + or is_to_or_from(mail, "silioso@gmail.com") + or is_to_or_from(mail, "skiplittell@comcast.net") + or is_to_or_from(mail, "tswilson4801@att.net") + ): + move_ham(mail, ".FRC.1024") + return + # .FRC.4272 + if ( + False + or mail["Subject"].matches("\b4272\b") + or mail["Subject"].contains("[ME297]") + or is_to_or_from(mail, "firstteam4272@gmail.com") + or is_to_or_from(mail, "@tscstudents.net") + or is_to_or_from(mail, "abenyeho@purdue.edu") + or is_to_or_from(mail, "Henry65@purdue.edu") + or is_to_or_from(mail, "chang282@purdue.edu") + ): + move_ham(mail, ".FRC.4272") + return + # .Purdue.* + if ( + False + or mail["Subject"].contains("[PASE]") + or is_to_or_from(mail, "Purduealumni@purdue.edu") + or is_to_or_from(mail, "pase@purdue.edu") + ): + move_ham(mail, ".Purdue.PASE") + return + if mail["Subject"].contains("[PLUG]"): + move_ham(mail, ".Purdue.PLUG") + return + if is_to_or_from(mail, "@cerias.purdue.edu"): + move_ham(mail, ".Purdue.CERIAS") + return + if ( + False + or is_to_or_from(mail, "purduehackers@gmail.com") + or is_to_or_from(mail, "royfu@purdue.edu") + or is_to_or_from(mail, "usmannkhan@purdue.edu") + ): + move_ham(mail, ".Purdue.Hackers") + return + if ( + False + or mail["Subject"].contains("[CS Opportunity Update]") + or mail["Subject"].contains("[CS Majors]") + ): + move_ham(mail, ".Purdue.CS") + return + if ( + False + or is_to_or_from(mail, "askcco@purdue.edu") + or is_to_or_from_re(mail, "pmx-auto-approve\+.*@purdue\.edu") + or is_to_or_from(mail, "evertrue@purdue.edu") + or is_to_or_from(mail, "college.response@purdue.edu") + or is_to_or_from(mail, "purduepresident@purdue.edu") + or is_to_or_from(mail, "@prf.org") + ): + move_ham(mail, ".Purdue.misc") + return + # .misc.* + if mail["From"].matches("schwab\.com"): + move_ham(mail, ".misc.schwab") + return + if mail["From"].matches("@ebay\.com"): + move_ham(mail, ".misc.ebay") return - - # Sort mail from misc people if ( False or is_to_or_from(mail, "margieshu@sbcglobal.net") @@ -270,15 +378,6 @@ def my_filters(mail): ): move_ham(mail, ".misc.Mom") return - - for address in [ - "nintendo.com", - "nintendo-news.com", - ]: - if mail["From"].contains(address): - move_ham(mail, ".misc.Nintendo") - return - for address in [ "@lpi.org", "@pearson.com", @@ -288,96 +387,6 @@ def my_filters(mail): if mail["From"].contains(address): move_ham(mail, ".misc.CompTIA") return - - # Sort mail from FRC people - # Generic - for address in [ "@ni.com", "@usfirst.org" ]: - if is_to_or_from(mail,address): - move_ham(mail, ".FRC") - return - # FRC 829 - for address in [ - "wcxctrack829@aim.com", # Pat - "william.walk@gmail.com", - ]: - if is_to_or_from(mail,address): - move_ham(mail, ".FRC.829") - return - if mail["Subject"].matches("\b829\b"): - move_ham(mail, ".FRC.829") - return - # FRC 1024 - for address in [ - "BBonahoom@stanleyworks.com", - "bryanbonahoom@gmail.com", - "allison.m.babcock@gmail.com", - "cdewalt3@yahoo.com", - "dave.nelson@ecolab.com", - "dickaustin190@yahoo.com", - "djnels1@comcast.net", # Dave and Julie Nelson - "gamefreak207@gmail.com", # Brett Leedy - "jason.zielke@gmail.com", - "jeffreysmith@msdlt.k12.in.us", - "sarahlittell@comcast.net", - "silioso@gmail.com", - "skiplittell@comcast.net", - "tswilson4801@att.net", - ]: - if is_to_or_from(mail,address): - move_ham(mail, ".FRC.1024") - return - for subject_re in [ "\b1024\b", "kil-?a-?bytes" ]: - if mail["Subject"].matches(subject_re): - move_ham(mail, ".FRC.1024") - return - # FRC 4272 - if mail["Subject"].matches("\b4272\b"): - move_ham(mail, ".FRC.4272") - return - - # Catch BS things because of CS classes before the general - # software filters - if mail["Subject"].contains("[Quizroom]"): - mail.delete() - return - - # Sort mail from software people - for address in [ - "@archlinux.org", - "@canonical.org", - "@cnuk.org", - "@core3.amsl.com", - "@defectivebydesign.org", - "@eff.org", - "@fedorahosted.org", - "@foocorp.net", - "@fsf.org", - "@github.com", - "@gitorious.org", - "@gnome.org", - "@gnu.org", - "@ietf.org", - "@kde.org", - "@lists.fedorahosted.org", - "@mozilla.org", - "@nongnu.org", - "@sourceforge.com", - "@thyrsus.com", - ]: - if is_to_or_from(mail,address): - move_ham(mail, ".software") - return - - # Sort mail from the school newspaper - if ( - False - or is_to_or_from(mail, "@lnnorthstar.org") - or is_to_or_from(mail, "lnnorthstar.org@tigertech.net") - ): - move_ham(mail, ".HighSchool.Newspaper") - return - - # Sort misc newsletters if ( False or mail["From"].contains("newsletter") @@ -404,49 +413,10 @@ def my_filters(mail): or mail["From"].contains("sales@solutionsinplastic.com") or mail["From"].contains("social@goodwillindy.org") or mail["From"].contains("support@support.digitalocean.com") + or mail["From"].contains("@pardonsnowden.org") ): move_ham(mail, ".misc.Newsletters") return - - if ( - False - or mail["From"].contains("@msdlt.k12.in.us") - or mail["From"].contains("ltschoolfoundation@gmail.com") - or mail["From"].contains("naviance.com") - or is_to_or_from(mail, "ibwhite@comcast.net") - or mail["Subject"].contains("IOA") - or mail["From"].contains("nths.org") - or mail["Subject"].contains("NTHS") - or mail["Subject"].contains("National Technical Honor Society") - or mail["Subject"].contains("NHS") - or mail["Subject"].contains("National Honor Society") - ): - move_ham(mail, ".HighSchool") - return - - # from college stuff - if ( - False - or mail["Subject"].contains("NYLF") # National Youth Leadership Conference - or mail["Subject"].contains("NSHSS") - ): - move_ham(mail, ".College.Societies") - return - if ( - False - or mail["From"].contains("admissions@") - or mail["Subject"].contains("college") - # now we get to the BS - or mail["From"].contains("@dreamitdoitindiana.com") - or mail["From"].contains("@indianatechinfo.org") - ): - move_ham(mail, ".College") - return - - if mail["From"].contains("@projectwonderful.com"): - move_ham(mail, ".misc.ProjectWonderful") - return - if ( False or mail["From"].matches("@localhost") @@ -454,7 +424,7 @@ def my_filters(mail): or mail["From"].matches("@[^,>]*\.lan") or mail["To"].matches("luke@") ): - move_ham(mail, ".LocalSystems") + move_ham(mail, ".misc.LocalSystems") return if ( False @@ -466,10 +436,47 @@ def my_filters(mail): return move_ham(mail, "") +# +# call the above +def handle_incoming_ham_training(mail): + bogofilter_ham(mail) + handle_incoming_ham(mail) +def handle_incoming_spam_training(mail): + bogofilter_spam(mail) + mail.move("FOLDERS.Spam") + +def handle_incoming_ham(mail): + my_filters(mail) +def handle_incoming_spam(mail): + mail.move("FOLDERS.Spam") + +def handle_incoming_unknown(mail): + # Whitelist + if my_whitelist(mail): + handle_incoming_ham_training(mail) + return + + spam = bogofilter_auto(mail) + if spam == 0: + handle_incoming_spam(mail) + return + elif spam == 1: + handle_incoming_ham(mail) + return + elif spam == 2: + mail.move("FOLDERS.MysteryMeat") + return + else: + mail.move("FOLDERS.BogoFail") + return + +# hook the above functions into the maildirproc processor +processor.maildir_base = "~/Maildir" +processor.auto_reload_rcfile = True handle_mapping = { "Inbox": handle_incoming_unknown, - "Bulk Mail": handle_incoming_unknown, + "Bulk Mail": handle_incoming_unknown, # fucking Yahoo! "FOLDERS.Spam.training": handle_incoming_spam_training, "FOLDERS.Ham.training": handle_incoming_ham_training, } |