1# Example Sieve Script 2# Author: Matthew Johnson 3# URL: http://wiki.fastmail.fm/index.php?title=MatthewJohnson 4 5########################################################################## 6####### SIEVE SCRIPT by Matthew Johnson - MRJ Solutions, Inc. ########### 7####### Email me at mailto:mattjohnson2005@gmail.com ## 8####### Code Version: 12JUN2004 ########### 9########################################################################## 10require ["envelope", "fileinto", "reject", "vacation", "regex", "relational", 11 "comparator-i;ascii-numeric"]; 12# 13# todo: 14# change to a nested format with 15# allof()s and nots. 16# add "in address book" check. ex:"header :is :comparator "i;octet" "X-Spam-Known-Sender" "yes"" 17# finish reformating lines to <= 75 col (for web edit box) 18# and delete rulers. 19# Mine Michael Klose script for ideas. 20# Check out the update to the Sieve pages on the Fastmail Wiki. 21# 22 23#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+ 24require ["envelope", "fileinto", "reject", "vacation", "regex", 25 "relational", "comparator-i;ascii-numeric"]; 26 27 28 29# BLACKLIST - Mails to discard, drop on the floor. 30# -high spam values except those delivered to me 31# -Chinese content except for low spam values 32# -virus rejected notifications 33# -known spam addresses 34# -newsletters that refuse my removal requests 35# -twit-list 36# -double twit-list 37# -other 38 39 40#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+ 41if anyof 42 ( 43 allof # combo test one - high spam values except for mail to/from me 44 ( 45 # spam score is greater or equal to 14 46 header :value "ge" :comparator "i;ascii-numeric" 47 ["X-Spam-score"] ["14"], 48 not header :contains "X-Spam-Score" "-", 49 not header :contains "X-Spam-Score" "0.0", 50 not header :contains ["to","from","cc","bcc","received"] 51 [ 52 # do not discard email to me, will file or discard 53 # as spam later if needed 54 "matt@zeta.net", 55 "matthew@bigsc.com", 56 "matthew_johnson@bigsmallcompany.com", 57 "mmm@spend.com", 58 "finger@spend.com", 59 "myyaacct@yahoo.com" 60 ] 61 ), # end allof 62 allof #combo test two - chinese content except for low spam values 63 ( 64 anyof 65 ( 66 header :regex "Subject" "^=\\?(gb|GB)2312\\?", # Chinese ecoding at subject 67 header :regex "Subject" "^=\\?big5\\?", # Other kind of Chinese mail 68 69 # Chinese content type 70 header :contains "Content-Type" 71 [ 72 "GB2312", 73 "big5" 74 ] 75 ), #end anyof 76 not anyof 77 ( 78 #We have to check the sign and the value separately: ascii-numeric, defined at 79 #header :contains "X-Spam-Score" "-", 80 header :value "lt" :comparator "i;ascii-numeric" "X-Spam-Score" "3" 81 ) #end not anyof 82 ), # end allof - test two 83 84 # single tests 85 86 # discard fastmail virus notifications 87 header :is ["subject"] ["Infected file rejected"], 88 89 # black list, invalid addresses receiving a large amount of spam 90 # or spam bounces,rejected zeta.net accounts. 91 header :contains ["X-Delivered-to"] 92 93 ["eagleeye@zeta.net","ealgeeye@zeta.net", 94 "alica.thiele@zeta.net", "2005@theta.com", 95 "jimlovingu2@zeta.net", 96 "alpha@zeta.net", 97 "JoshuaS@zeta.net", 98 "donnaf@zeta.net", 99 "pspinks@zeta.net", 100 "jsherman@zeta.net", 101 "holly@zeta.net", 102 "clabarca@zeta.net", 103 "meghanr@zeta.net", 104 "rtaylor@zeta.net", 105 "lboone@zeta.net", 106 "brower@zeta.net", 107 "jenj@zeta.net", 108 "cbackus@zeta.net", 109 "spengles@zeta.net", 110 "adams@zeta.net", 111 "dsmith@zeta.net", 112 "jwilderman@zeta.net", 113 "TimF@zeta.net", 114 "zd@zeta.net", 115 "louise@zeta.net"] 116 117 # single 'not' tests 118 # ---out for testing--- not header :is :comparator "i;octet" "X-Spam-Known-Sender" "yes" 119 ) # end anyof() 120{ 121 discard; 122 stop; 123} 124 125 126# 127# WHITELIST - Keep these mails and put them in the inbox 128# (some kept getting put in Junk Mail) 129# Family, Friends, Current Vendors, Customers 130# Contents of fastmail address book. 131# 132#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+ 133if anyof ( header :contains ["from","to","cc","bcc"] 134 [ "notification@eBay.com", 135 "MAILER-DAEMON@zeta.net", 136 "USPS_Track_Confirm@usps.com", 137 "credit.services@target.com", 138 "Comcast_Paydirect@comcast.net", 139 "mary@zeta.net", 140 "betty@zeta.net", 141 "andmanymore@zeta.net" 142 ], 143 header :is :comparator "i;octet" "X-Spam-Known-Sender" "yes" 144 ) 145{ 146 fileinto "INBOX"; 147 stop; 148} 149 150# redirects 151if header :contains ["to", "cc"] "mary1@zeta.net" 152 { 153 redirect "mary@zeta.net"; 154 stop; 155 } 156 157 158# 159# +Spam filtering by score on 3, 5 and 14(above). 160# 161# 162if header :value "ge" :comparator "i;ascii-numeric" ["X-Spam-score"] ["5"] { 163 fileinto "INBOX.Junk Mail.ge5"; 164 stop; 165#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+ 166} elsif header :value "ge" :comparator "i;ascii-numeric" ["X-Spam-score"] ["3"] { 167 fileinto "INBOX.Junk Mail.ge3"; 168 stop; 169} 170 171 172# Potential Blacklist, start with soft discard, then migrate to full discard above 173# 174# Blacklist (2nd) During testing, throw into "Junk Mail.discard" until 175# ready to discard. 176# 177if anyof 178 ( 179 # rejects for accounts across all domains 180 header :contains ["X-Delivered-to"] 181 [ 182 "drjoe@","VX@", 183 "alfa@zeta.net", 184 "media@zeta.net", 185 "zeta@zeta.net", 186 "xyz@zeta.net" 187 ], 188 189 # other criteria - weird message from this account 190 header :contains ["from"] ["Charlie Root"], 191 # mailers that are always sending spam returns to me 192 header :contains ["from"] ["MAILER-DAEMON@aol.com"] , 193 header :contains ["from"] ["MAILER-DAEMON@otenet.gr"] , 194 195 # common account names that I don't use in any of my domains and that spammers like 196 header :contains ["X-Delivered-to"] 197 [ "biz@","sales@","support@", "service@", "reg@", 198 "registration@", "regisration@", "root@", "webmaster@", "noreply@" 199 ], 200 # zeta.net common account names to reject 201 header :contains ["X-Delivered-to"] ["info@zeta.net"], 202 # bigsc.com rejects 203 header :contains ["X-Delivered-to"] ["info@bigsc.com"], 204 # theta.com rejects 205 header :contains ["X-Delivered-to"] ["info@theta.com"], 206 header :contains ["X-Delivered-to"] ["reg@theta.com"] 207#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+ 208 # saves for use maybe later 209 # header :contains ["X-Delivered-to"] ["webmaster@zeta.net"], 210 # header :contains ["X-Delivered-to"] ["webmaster@theta.com"], 211 # header :contains ["X-Delivered-to"] ["sales@bs.com"], 212 # header :contains ["X-Delivered-to"] ["sales@theta.com"], 213 # header :contains ["X-Delivered-to"] ["sales@bigsc.com"], 214 # header :contains ["X-Delivered-to"] "root@zeta.net", 215 216 ) #end anyof() 2nd blacklist 217{ 218 219 fileinto "INBOX.Junk Mail.discard"; 220 stop; 221} 222 223 224# +Greylist, move to "INBOX.Junk Mail.greylist" 225# 226# 'Soft' Blacklist ?Greylist? 227# 228 229#annoying person(s) that send questionable attachments 230# look at occationally 231if header :contains "from" "alex@yahoo.com" 232{ 233 fileinto "INBOX.Junk Mail.greylist"; 234} elsif header :contains "subject" "MAILER-DAEMON@fastmail.fm" 235 # non-person, but might 236 # want to look at it while 237 # figuring issues 238{ 239 fileinto "INBOX.Junk Mail.greylist"; 240 stop; 241} 242 243# +Spammy domains to filter 244# 245# domains that are known to be present in spam 246# 247if header :contains ["from", "received"] [".ru",".jp", ".kr", ".pt", 248 ".pl",".at",".cz",".cn",".lu" ] 249{ 250 fileinto "INBOX.Junk Mail.discard"; 251 stop; 252} 253 254 255# 256# Annoying newsletters that won't unsubscribe me, reject 257# 258 259if anyof ( 260 #annoying newsletters 261 header :contains ["from"] "VistaPrintNews", # 2003 262 header :contains ["from"] "newsletter@briantracyintl.com", # 2003 263 header :contains ["from"] "info@yogalist.com", # 2003 264 header :contains ["from"] "The Angela Larson Real Estate Team", 265 header :contains ["from"] "Brian Tracy" 266 ) 267#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+ 268{ 269 reject "I HAVE TRIED TO UNSUBSCRIBE; I DO NOT WANT YOUR NEWSLETTER; PLEASE UNSUBSCRIBE ME"; 270 stop; 271} 272 273 274 275 276# 277# Suspected zeta.net user from/to Zeta Institute, NY - reject 278# 279# 280# 281if header :contains ["X-Delivered-to","from"] 282 [ 283 # aaaaNEW_ENTRIES_ABOVE ################################### 284 "neville@zeta.net", 285 "animika@zeta.net", 286 "linda@zeta.net", 287 "jerry@zeta.net", 288 "adamS@zeta.net", 289 "lkdamon@zeta.net", 290 "AdamS@zeta.net", 291 "DConnor@zeta.net", 292 "LOUISR@zeta.net", 293 294 # Start of Alpha ############################################# 295 "Allanv@zeta.net", 296 "AmberJ@zeta.net", 297 "DANDERSON@zeta.net", 298 "Jonas@zeta.net", 299 "KarenE@zeta.net", 300 "J.R.C.@zeta.net", # check to see if this is working 301 "PMackey@zeta.net", 302 303 "adrienne@zeta.net","alpha@zeta.net","amina@zeta.net", 304 "anamika@zeta.net", 305 "claborca@zeta.net","communications@zeta.net", 306 "cz241@zeta.net", 307 "dee@zeta.net", 308 "ellenb@zeta.net","evis@zeta.net", 309 "frivera@zeta.net", 310 "gblack@zeta.net","gbrown@zeta.net","george@zeta.net","grace@zeta.net", 311 "happygolucky@zeta.net","hsp@zeta.net", 312 "ila@zeta.net", 313 "jacqueline_fenatifa@zeta.net","jlengler@zeta.net", 314 "joel@zeta.net","jolsen@zeta.net", "jsherman@zeta.net", 315 "kronjeklandish@zeta.net","kwilcox@zeta.net","bettyb@zeta.net", 316 "laurie@zeta.net","llmansell@zeta.net", 317 "louise@zeta.net","lzollo@zeta.net", 318 "mcraft@zeta.net","meganB@zeta.net","mwezi@zeta.net", 319 "nanwile@zeta.net", 320 "zetasound@zeta.net", 321 "peter@zeta.net", 322 "randi@zeta.net", "rcbackus@zeta.net", "registration@zeta.net", 323 "registration@omgea.org", 324 "rtaylor@zeta.net", 325 "sdonnarumma@zeta.net","stephanR@zeta.net","suzanne@zeta.net","suzzane@zeta.net", 326 "taryngaughan_dn@zeta.net" 327 # zzzzEND_OF_LIST#### 328 ] #end of Xdelivered-to list for possible zeta institute users 329 330{ 331 reject text: 332 ERROR: Your email has not been delivered. 333 334 You have reached the mailer at zeta.net 335 336 Perhaps you want to send to Zeta Institute in DillyDally, NY, USA? 337 338 Use USER@zeta.net for them 339 340 or try registration@zeta.net 341 Check the website at http://www.zeta.net/zeta/contact/ 342 Call Registration at 1 800 944 1001. 343 344 or use this information: 345 346 Zeta Institute 347 150 River Drive 348 DillyDally, NY 12666 349 Registration: 800-900-0000 350 Ph: 845-200-0000 351 Fax: 845-200-0001 352 registration@zeta.net 353 354 sincerely, POSTMASTER 355. 356; 357 fileinto "Inbox.Junk Mail.ezeta"; 358 stop; 359 } 360#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+ 361# +Move messages into folders 362# 363# Process other messages into separate folders 364# 365 # newsletters and mail lists 366if header :contains ["subject"] 367 [ "newsletter", "[tc-ieee-", "[icntc", 368 "JUG News", "Xdesksoftware", 369 "announcement" ] 370{ 371 fileinto "INBOX.Newsletters"; 372} elsif header :contains ["from","subject"] ["Anthony Robbins"] { 373 fileinto "INBOX.Newsletters"; 374} elsif header :contains ["from","subject"] ["MN Entrepreneurs","ME!"] { 375 fileinto "INBOX.Newsletters"; 376} elsif header :contains ["from","received"] "adc.apple.com" { 377 fileinto "INBOX.Newsletters"; 378} elsif header :contains "from" "wnewadmn@ieee.org" { 379 fileinto "INBOX.Newsletters"; 380} elsif header :contains "from" "@lb.bcentral.com" { # techworthy@lb.bcentral.com 381 fileinto "INBOX.Newsletters"; 382} elsif header :contains "from" "announcement@netbriefings.com" { #st paul company 383 fileinto "INBOX.Newsletters"; 384} elsif header :contains "from" "newsletter@eletters.extremetech.com" { #semi-annoying rag 385 fileinto "INBOX.Newsletters"; 386#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+ 387# my newsletter throw-away addresses 388} elsif header :contains "to" ["microcenter@zeta.net","nmha@zeta.net"] { 389 fileinto "INBOX.Newsletters"; 390 391#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+ 392# 393# Alerts mailbox 394} elsif header :contains ["subject", "from"] 395 [ 396 "Alert", # F-Prot virus alert service, matches: 397 # "FRISK Virus Alert" 398 # or use s:FRISK Virus Alert: 399 # or use f:support@f-prot.com 400 "Payment", # Alerts from other payments 401 "credit.services@target.com", # Target Card Payments 402 "notify@quickbase.com" # Tic Talkers Database changes 403 ] 404{ 405 fileinto "INBOX.Alerts"; 406 stop; 407} 408 409# +Announcements from Dave Rolm, forward 410# 411# Perl Announcements from Dave Rolm 412if header :contains "from" "dave@other.org" 413{ 414 fileinto "Inbox"; 415 keep; 416} 417#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+ 418####################################################################### 419#### END OF SIEVE SCRIPT by Matthew Johnson - MRJ Solutions, Inc. ##### 420################ email me at mailto:mattjohnson2005@gmail.com # 421 422