1require ["regex", "relational", "comparator-i;ascii-numeric", "subaddress", 2 "envelope", "date", "index", "imap4flags", "variables"]; 3 4#this is for the extra things we have added to sieve 5#test extensions 6#envelope regex relational comparators subaddress(user and detail) 7 8/* 9#need better relational and comparator tests... 10 11if header :value "gt" 12 :comparator "i;ascii-numeric" 13 ["number"] ["10"] 14{redirect "me+numberover10@blah.com";} 15 16 17if header :count "gt" 18 :comparator "i;ascii-numeric" 19 ["X"] ["3"] 20{redirect "me+X@blah.com";} 21 22#header regex 23 24if header :regex "Date" "Tue,(.*)Feb(.*)" 25{redirect "me+goodheaderregex@blah.com";} 26 27 28 29#address Regex 30 31if address :all :regex "from" "cook(.)Monster(\\+.*)@cookie\\...." 32{redirect "me+goodaallregex@blah.com";} 33 34if address :domain :regex "from" "c..kie\\.com" 35{redirect "me+goodadomainregex@blah.com";} 36 37if address :localpart :regex "from" "c.{2,4}Monster(\\+.*)" 38{redirect "me+goodalocalpartregex@blah.com";} 39 40if address :user :regex "from" "cookyM.....r" 41{redirect "me+goodauserregex@blah.com";} 42 43if address :detail :regex "from" "whe*" 44{redirect "me+goodadetailregex@blah.com";} 45 46 47#address user 48 49if address :user :is "from" "mymonster" 50{redirect "me+goodauseris@blah.com";} 51 52if address :user :contains "from" "mym" 53{redirect "me+goodausercontains@blah.com";} 54 55if address :user :matches "from" "my*r" 56{redirect "me+goodausermatches@blah.com";} 57 58 59#address detail 60 61if address :detail :is "from" "underbed" 62{redirect "me+goodadetailis@blah.com";} 63 64if address :detail :contains "from" "bed" 65{redirect "me+goodadetailcontains@blah.com";} 66 67if address :detail :matches "from" "under*" 68{redirect "me+goodadetailmatches@blah.com";} 69 70###################################################################### 71#ENVELOPE 72###################################################################### 73 74 75#envelope all 76 77if envelope :all :is "from" "WERT+erk@true.com" 78{redirect "me+eallis@blah.com";} 79 80if envelope :all :contains "from" "true.com" 81{redirect "me+eallcontains@blah.com";} 82 83if envelope :all :matches "from" "WERT*.com" 84{redirect "me+eallmatches@blah.com";} 85 86 87#envelope domain 88 89if envelope :domain :is "from" "true.com" 90{redirect "me+edomainis@blah.com";} 91 92if envelope :domain :contains "from" "true" 93{redirect "me+edomaincontains@blah.com";} 94 95if envelope :domain :matches "from" "*true.com" 96{redirect "me+edomainmatches@blah.com";} 97 98 99#envelope localpart 100 101if envelope :localpart :is "from" "WERT+erk" 102{redirect "me+elocalpartis@blah.com";} 103 104if envelope :localpart :contains "from" "WE" 105{redirect "me+elocalpartcontains@blah.com";} 106 107if envelope :localpart :matches "from" "WE?T*" 108{redirect "me+elocalpartmatches@blah.com";} 109 110#envelope regex 111 112if envelope :all :regex "from" "true.com" 113{redirect "me+goodeallregex@blah.com";} 114 115if envelope :domain :regex "from" "true.com" 116{redirect "me+goodedomainregex@blah.com";} 117 118if envelope :localpart :regex "from" "true.com" 119{redirect "me+goodelocalpartregex@blah.com";} 120 121if envelope :user :regex "from" "true.com" 122{redirect "me+goodeuserregex@blah.com";} 123 124if envelope :detail :regex "from" "true.com" 125{redirect "me+goodedetailregex@blah.com";} 126 127#envelope user 128 129if envelope :user :is "from" "WERT" 130{redirect "me+goodeuseris@blah.com";} 131 132if envelope :user :contains "from" "WE" 133{redirect "me+goodeusercontains@blah.com";} 134 135if envelope :user :matches "from" "*RT" 136{redirect "me+goodeusermatches@blah.com";} 137 138 139#envelope detail 140 141if envelope :detail :is "from" "erk" 142{redirect "me+goodedetailis@blah.com";} 143 144if envelope :detail :contains "from" "k" 145{redirect "me+goodedetailcontains@blah.com";} 146 147if envelope :detail :matches "from" "e*k" 148{redirect "me+goodedetailmatches@blah.com";} 149 150###################################################################### 151#DATE 152###################################################################### 153 154if allof(header :is "from" "boss@example.com", 155 date :value "ge" :originalzone "date" "hour" "09", 156 date :value "lt" :originalzone "date" "hour" "17") 157{redirect "me+urgent@blah.com";} 158 159if anyof(date :is "received" "weekday" "0", 160 date :is "received" "weekday" "6") 161{redirect "me+weekend@blah.com";} 162 163if anyof(date :is :zone "-0800" "received" "weekday" "0", 164 date :is :zone "-0800" "received" "weekday" "6") 165{redirect "me+weekend(pst)@blah.com";} 166 167if date :is "received" "year" [ "1983", "1993", "2003", "2013" ] 168{redirect "me+yearsofthree@blah.com";} 169 170if date :is :index 2 "received" "day" "01" 171{redirect "me+firstofthemonth@blah.com";} 172 173if date :is :index 1 :last "received" "day" "01" 174{redirect "me+firstofthemonth@blah.com";} 175 176if currentdate :zone "-0800" :is "year" ["2003", "2013", "2023"] 177{redirect "me+currentdateis@blah.com";} 178 179if allof(currentdate :value "ge" "date" "2014-01-01", 180 currentdate :value "lt" "date" "2015-01-01") 181{redirect "me+cd2014@blah.com";} 182*/ 183###################################################################### 184#HASFLAG 185###################################################################### 186 187if allof ( 188header :matches "subject" "*i*?*?s", 189header :matches "subject" "*i?*?*s", 190header :matches "subject" "*i*??*s", 191header :matches "subject" "*i?**?s" 192) 193{ 194 195# 196# Positive :count tests 197# 198setflag ""; 199 200if hasflag :count "lt" :comparator "i;ascii-numeric" ["1"] 201{redirect "me+good.hasflag.count.lt.1.pos@blah.com";} 202else 203{redirect "me+bad.hasflag.count.lt.1.pos@blah.com";} 204 205if hasflag :count "le" :comparator "i;ascii-numeric" ["0"] 206{redirect "me+good.hasflag.count.le.0.pos@blah.com";} 207else 208{redirect "me+bad.hasflag.count.le.0.pos@blah.com";} 209 210setflag "flag1 flag2"; 211 212if hasflag :count "le" :comparator "i;ascii-numeric" ["2"] 213{redirect "me+good.hasflag.count.le.2.pos@blah.com";} 214else 215{redirect "me+bad.hasflag.count.le.2.pos@blah.com";} 216 217# 218# Negative :count tests 219# 220setflag ""; 221 222if hasflag :count "lt" :comparator "i;ascii-numeric" ["0"] 223{redirect "me+bad.hasflag.count.lt.0.neg@blah.com";} 224else 225{redirect "me+good.hasflag.count.lt.0.neg@blah.com";} 226 227if hasflag :count "ge" :comparator "i;ascii-numeric" ["1"] 228{redirect "me+bad.hasflag.count.ge.1.neg@blah.com";} 229else 230{redirect "me+good.hasflag.count.ge.1.neg@blah.com";} 231 232setflag "flag1 flag2"; 233 234if hasflag :count "lt" :comparator "i;ascii-numeric" ["2"] 235{redirect "me+bad.hasflag.count.lt.2.neg@blah.com";} 236else 237{redirect "me+good.hasflag.count.lt.2.neg@blah.com";} 238 239# 240# Positive tests 241# 242setflag "there"; 243 244if hasflag :matches ["m?*?g", "*h??e*"] 245{redirect "me+good.hasflag.contains.pos@blah.com";} 246else 247{redirect "me+bad.hasflag.contains.pos@blah.com";} 248 249if hasflag :matches "**" 250{redirect "me+good.hasflag.contains.null.pos@blah.com";} 251else 252{redirect "me+bad.hasflag.contains.null.pos@blah.com";} 253 254# 255# Negative tests 256# 257setflag "flag"; 258 259if hasflag :matches "?*?*?*?*?*?" 260{redirect "me+bad.hasflag.null.neg@blah.com";} 261else 262{redirect "me+good.hasflag.null.neg@blah.com";} 263 264if hasflag :contains "flags" 265{redirect "me+bad.hasflag.contains.neg@blah.com";} 266else 267{redirect "me+good.hasflag.contains.neg@blah.com";} 268 269if hasflag :matches "?la?g*" 270{redirect "me+bad.hasflag.neg@blah.com";} 271else 272{redirect "me+good.hasflag.neg@blah.com";} 273 274 275 set "state" "${state} pending"; 276 if string :matches " ${state} " "* pending *" { 277redirect "string.matches.true+good@blah.com"; 278 } else 279{redirect "string.matches.false+bad@blah.com";} 280 if string :matches " ${state}" "* pending *" { 281redirect "string.matches.true+bad@blah.com"; 282 } else { 283redirect "string.matches.false+good@blah.com"; 284} 285 286if string " mystring pending" "* pending *" 287{redirect "me+bad.string.false@blah.com";} 288else 289{redirect "me+good.string.false@blah.com";} 290 291 292if hasflag :matches "state" "?*?*?*?*?*?" 293{redirect "me+good.hasflag.match.pos@blah.com";} 294else 295{redirect "me+bad.hasflag.match.pos@blah.com";} 296 297if hasflag :contains "state" "pend" 298{redirect "me+good.hasflag.contains.pos@blah.com";} 299else 300{redirect "me+bad.hasflag.contains.pos@blah.com";} 301 302if hasflag "state" "pending" 303{redirect "me+good.hasflag.is.pos@blah.com";} 304else 305{redirect "me+bad.hasflag.is.pos@blah.com";} 306 307if hasflag :matches "?la?g*" 308{redirect "me+bad.hasflag.neg@blah.com";} 309else 310{redirect "me+good.hasflag.neg@blah.com";} 311 312} 313 314