Warning, /frameworks/syntax-highlighting/autotests/input/test.sieve is written in an unsupported language. File is not indexed.

0001 # Sieve syntax highlighting test
0002 # see RFC 5228
0003 
0004 # comments §2.3.
0005 
0006 # Single line with alerts TODO ###
0007 /*
0008  Multiline comment with alerts FIXME
0009  this also should be folding region
0010  */
0011 
0012 # literal data §2.4.
0013 # numbers §2.4.1.
0014 42
0015 100K
0016 10M
0017 3G
0018 
0019 # strings §2.4.2.
0020 "string"
0021 "string\nwith\"special chars"
0022 # not a string
0023 "multi \
0024  line \
0025  #with\a \
0026  continuation"
0027 # not a string
0028 text:
0029 Multiline
0030 string\" "with quotes"
0031 or # comments
0032 this should also be a folding region
0033 .dot
0034 ..dot
0035 dotstuffed dot:
0036 ..
0037 ending with a single .
0038 .
0039 
0040 # encoded characters §2.4.2.4.
0041 # valid
0042 "$${hex:24 24}"
0043 "${unicode:40}"
0044 "$${hex:40}"
0045 "${hex: da }"
0046 "${hex:FE }"
0047 "${HEX: 40}"
0048 "${unicode:40}"
0049 "${UNICODE:40}"
0050 "${UnICoDE:0000040}"
0051 "${Unicode:ff}"
0052 #invalid
0053 "${hex:40"
0054 "${hex:4${hex:30}}"
0055 "${ unicode:40}"
0056 "${Unicode:Cool}"
0057 # semantic errors, syntactically correct
0058 "${hex:400}"
0059 "${unicode:200000}"
0060 "${Unicode:DF01}"
0061 
0062 # test lists §2.5.1
0063 if anyof (not exists ["From", "Date"],
0064           header :contains "from" "fool@example.com") {
0065     discard;
0066 }
0067 if allof (not exists ["From", "Date"],
0068           header :contains "from" "fool@example.com") {
0069     discard;
0070 }
0071 
0072 # match types §2.7.1.
0073 :contains
0074 :matches
0075 :is
0076 
0077 # comparators §2.7.3.
0078 if header :contains :comparator "i;octet" "Subject" "MAKE MONEY FAST" {
0079     discard;
0080 }
0081 
0082 # comparison against addresses §2.7.4.
0083 :localpart
0084 :domain
0085 :all
0086 
0087 # commands §2.9.
0088 keep;
0089 fileinto "inbox.bla";
0090 redirect "test@kde.org";
0091 discard;
0092 
0093 # control if §3.1.
0094 # this also should create folding regions
0095 if header :contains "from" "foo" {
0096     discard;
0097 } elsif header :contains ["subject"] ["$$$"] {
0098     discard;
0099 } else {
0100     fileinto "INBOX";
0101 }
0102 
0103 # control require §3.2.
0104 require "fileinto";
0105 require ["vacation", "imapflags"];
0106 
0107 # control stop §3.3.
0108 stop;
0109 
0110 # test commands §5.
0111 address
0112 allof
0113 anyof
0114 exists
0115 false
0116 header
0117 not
0118 size
0119 true
0120 
0121 # test address §5.1.
0122 if address :is :all "from" "kde@example.com" {
0123     discard;
0124 } elsif address :domain :is ["From", "To"] "example.com" { # comment
0125     keep; # comment
0126 }
0127 
0128 # test envelope §5.4.
0129 if envelope :all :is "from" "kde@example.com" {
0130     discard;
0131 }
0132 
0133 # test exists §5.5.
0134 if not exists ["From","Date"] {
0135     discard;
0136 }
0137 
0138 # test header §5.7.
0139 not header :matches "Cc" "?*"
0140 
0141 # test size §5.9.
0142 if size :over 500K { discard; }
0143 if size :under 1M { keep; } else { discard; }
0144 
0145 
0146 /*
0147  * Extensions
0148  * see https://www.iana.org/assignments/sieve-extensions/sieve-extensions.xhtml
0149  */
0150 
0151 # Body RFC5173
0152 :raw
0153 :content
0154 :text
0155 if body :raw :contains "MAKE MONEY FAST" {
0156     discard;
0157 }
0158 if body :content "text" :contains ["bla", "blub"] {
0159     fileinto "inbox.foo";
0160 }
0161 
0162 # Convert RFC6558
0163 require ["convert"];
0164 convert "image/tiff" "image/jpeg" ["pix-x=320","pix-y=240"];
0165 
0166 # Copy RFC3894
0167 require ["copy", "fileinto"];
0168 fileinto :copy "incoming";
0169 
0170 # Date RFC5260
0171 require ["date", "relational", "fileinto"];
0172 if allof(header :is "from" "boss@example.com",
0173          date :value "ge" :originalzone "date" "hour" "09",
0174          date :value "lt" :originalzone "date" "hour" "17")
0175     { fileinto "urgent"; }
0176 if anyof(date :is "received" "weekday" "0",
0177          date :is "received" "weekday" "6")
0178 { fileinto "weekend"; }
0179 if anyof(currentdate :is "weekday" "0",
0180          currentdate :is "weekday" "6",
0181          currentdate :value "lt" "hour" "09",
0182          currentdate :value "ge" "hour" "17")
0183 { redirect "pager@example.com"; }
0184 if allof(currentdate :value "ge" "date" "2007-06-30",
0185          currentdate :value "le" "date" "2007-07-07")
0186 { vacation :days 7  "I'm away during the first week in July."; }
0187 
0188 require ["date", "variables", "fileinto"];
0189 if currentdate :matches "month" "*" { set "month" "${1}"; }
0190 if currentdate :matches "year"  "*" { set "year"  "${1}"; }
0191 fileinto "${month}-${year}";
0192 
0193 require ["variables", "date", "editheader"];
0194 if currentdate :matches "std11" "*" {addheader "Processing-date" "${0}";}
0195 
0196 require ["date", "relational", "index"];
0197 if date :value "gt" :index 2 :zone "-0500" "received" "iso8601" "2007-02-26T09:00:00-05:00"
0198 { redirect "aftercutoff@example.org"; }
0199 
0200 if header :index 1 :matches "received" "*(* [*.*.*.*])*" {}
0201 
0202 # Duplicate RFC7352
0203 require ["duplicate", "variables"];
0204 if duplicate { discard; }
0205 if duplicate :header "message-id" { discard; }
0206 if header :matches "message-id" "*" {
0207     if duplicate :uniqueid "${0}" { discard; }
0208 }
0209 
0210 # Editheader RFC5293
0211 addheader "X-Hello" "World";
0212 deleteheader :index 1 "X-Hello";
0213 
0214 # Enclose RFC5703
0215 :mime
0216 :anychild
0217 :type
0218 :subtype
0219 :contenttype
0220 :param
0221 replace
0222 enclose
0223 extracttext
0224 if header :mime :type "Content-Type" "image" {}
0225 replace "Executable attachment removed by user filter";
0226 foreverypart {
0227     if header :mime :param "filename" :matches ["Content-Type", "Content-Disposition"]
0228         ["*.com", "*.exe", "*.vbs", "*.scr", "*.pif", "*.hta", "*.bat", "*.zip" ] {
0229         # these attachment types are executable
0230         enclose :subject "Warning" text:
0231 WARNING! The enclosed message contains executable attachments.
0232 These attachment types may contain a computer virus program
0233 that can infect your computer and potentially damage your data.
0234 .
0235 ;
0236         break;
0237     }
0238 }
0239 extracttext :first 100 "msgcontent";
0240 
0241 # Notify RFC5435
0242 notify :importance "1" :message "This is probably very important" "mailto:kde@example.com";
0243 notify :message "${from_addr}${env_from}: ${subject}" "mailto:kde@example.com";
0244 if not valid_notify_method ["mailto:", "http://gw.example.net/notify?test"] { stop; }
0245 if notify_method_capability "xmpp:tim@example.com?message;subject=SIEVE" "Online" "yes" {}
0246 set :encodeurl "body_param" "stuff";
0247 
0248 # Envelope DSN RFC6009
0249 if envelope "notify" "SUCCESS" {}
0250 if allof (envelope "notify" "FAILURE", envelope :comparator "i;ascii-numeric" :count "eq" "notify" "1") {}
0251 if envelope :matches "orcpt" "rfc822;*@example.com" {}
0252 if anyof (envelope :contains "bytimerelative" "-", envelope :value "eq" :comparator "i;ascii-numeric" "bytimerelative" "0") {}
0253 redirect :copy :notify "NEVER" "elsewhere@example.com";
0254 redirect :copy :bytimerelative 600 "cellphone@example.com";
0255 redirect :copy :bytimeabsolute "${date}T20:00:00${zone}" :bymode "return" "cellphone@example.com";
0256 
0257 # Environment RFC5183
0258 if environment :contains "item" "" {}
0259 
0260 # Reject RFC5429
0261 ereject "I no longer accept mail from this address";
0262 reject text:
0263 Your message is too big.  If you want to send me a big attachment,
0264 put it on a public web site and send me a URL.
0265 .
0266 ;
0267 
0268 # External Lists RFC6134
0269 if envelope :list "from" ":addrbook:default" {}
0270 if currentdate :list "date" "tag:example.com,2011-01-01:localHolidays" {}
0271 if allof (envelope :detail "to" "mylist", header :list "from" "tag:example.com,2010-05-28:mylist") {
0272     redirect :list "tag:example.com,2010-05-28:mylist";
0273 }
0274 if string :list "${ip}" "tag:example.com,2011-04-10:DisallowedIPs" {}
0275 if header :mime :param "filename" :list ["Content-Type", "Content-Disposition"] "tag:example.com,2011-04-10:BadFileNameExts" {}
0276 
0277 # ihave RFC5463
0278 if ihave "fileinto" {}
0279 error "failed!";
0280 
0281 # IMAP Sieve RFC6785
0282 if anyof (environment :is "imap.cause" "APPEND", environment :is "imap.cause" "COPY")  {
0283     if environment :is "imap.mailbox" "ActionItems" {
0284         redirect :copy "actionitems@example.com";
0285     }
0286 }
0287 
0288 # IMAP4 Flags RFC5232
0289 setflag "\\Deleted";
0290 setflag "flagvar" "\\Flagged";
0291 addflag "flagvar" "\\Deleted";
0292 addflag "flagvar" ["\\Deleted", "\\Answered"];
0293 removeflag "flagvar" "$MDNRequired";
0294 hasflag :contains "MyVar" "Junk"
0295 hasflag :contains "${MyVar}" ["label", "forward"]
0296 hasflag :count "ge" :comparator "i;ascii-numeric" "MyFlags" 2
0297 fileinto :flags "\\Deleted" "INBOX.bla";
0298 
0299 # Include RFC6609
0300 include :personal "always_allow";
0301 include :global "spam_tests";
0302 return;
0303 global "i_am_on_vacation";
0304 set "global.i_am_on_vacation" "1";
0305 
0306 # Mailbox RFC5490
0307 if mailboxexists "bla" {}
0308 fileinto :create "inbox.bla";
0309 if metadata :is "INBOX" "/private/vendor/vendor.isode/auto-replies" "on" {}
0310 if metadataexists "INBOX" "/private/vendor/foo" {}
0311 if servermetadata :matches "/private/vendor/vendor.isode/notification-uri" "*" {}
0312 if servermetadataexists "/private/vendor/foo" {}
0313 
0314 # Regexp (draft)
0315 if not address :regex ["to", "cc", "bcc"] "me(\\+.*)?@company\\.com" {}
0316 
0317 # Relational RFC5231
0318 if address :count "ge" :comparator "i;ascii-numeric" ["to", "cc"] ["3"] {}
0319 if header :value "lt" :comparator "i;ascii-numeric" ["x-priority"] ["3"] {}
0320 
0321 # Spamtest RFC5235
0322 if spamtest :value "eq" :comparator "i;ascii-numeric" "0" {}
0323 elsif spamtest :value "ge" :comparator "i;ascii-numeric" "3" {}
0324 elsif spamtest :percent :value "lt" :comparator "i;ascii-numeric" "37" {}
0325 if virustest :value "eq" :comparator "i;ascii-numeric" "4" {}
0326 
0327 # Subaddress RFC5233
0328 if envelope :user "to" "postmaster" {}
0329 if envelope :detail "to" "mta-filters" {}
0330 
0331 # Vacation RFC5230
0332 vacation "I'm out";
0333 vacation :subject "Automatic response to: ${1}"
0334                   "I'm away -- send mail to foo in my absence";
0335 vacation :handle "ran-away" "I'm out";
0336 vacation :mime text:
0337    Content-Type: multipart/alternative; boundary=foo
0338 
0339    --foo
0340 
0341    Hello ${sender}, I'm at the beach relaxing.
0342 
0343    --foo
0344    Content-Type: text/html; charset=us-ascii
0345 
0346    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
0347     "http://www.w3.org/TR/REC-html40/strict.dtd">
0348    <HTML><HEAD><TITLE>How to relax</TITLE>
0349    <BASE HREF="http://home.example.com/pictures/"></HEAD>
0350    <BODY><P>I'm at the <A HREF="beach.gif">beach</A> relaxing.
0351    </BODY></HTML>
0352 
0353    --foo--
0354 .
0355 ;
0356 vacation :days 23 :addresses ["kde@example.edu"] "I'm away until October 19.";
0357 
0358 # Vacation Seconds RFC6131
0359 vacation :addresses ["kde@example.edu"] :seconds 1800
0360     "I am in a meeting, and do not have access to email.";
0361 
0362 # Variables RFC5229
0363 "&%${}!" # invalid
0364 "${doh!}" #invalid
0365 "${company}"
0366 "bla ${var42} blub"
0367 "${1}"
0368 "${BAD${Company}" # second one is the variable
0369 "${President, ${Company} Inc.}" # inner one is the variable
0370 set "var" "value";
0371 set "var2" "${var}";
0372 
0373 set "a" "juMBlEd lETteRS";
0374 set :length "b" "${a}";
0375 set :lower "b" "${a}";
0376 set :upperfirst "b" "${a}";
0377 set :upperfirst :lower "b" "${a}";
0378 set :quotewildcard "b" "Rock*";
0379 set :lowerfirst "b" "${a}";
0380 
0381 if string :matches " ${state} " "* pending *" {}
0382 
0383 # Dovecot debug extension
0384 require "vnd.dovecot.debug";
0385 if header :contains "subject" "hello" {
0386     debug_log "Subject header contains hello!";
0387 }