#
# An attempt to render, as SIEVE, the advice from RFC 3834 section 2 "When
# (not) to send automatic responses".  Assumes we are a "Personal
# Responder".
#
# This is not valid SIEVE; The following expansions must first be
# performed:
#
#  - %myaddrs%    list of valid recipient addresses
#  - %untrusted%  list of untrusted envelope senders
#
# Example:
#
#  sed -e 's/%myaddrs%/["me1@example.org", "me2@example.org"]/' \
#      -e 's/%untrusted%/["evil@example.org"]/' < rfc3834.sieve.in
#
require ["envelope"];

if anyof ( # Fails to account for syntax defined in section 5.1
           # SHOULD NOT
           not header :is "auto-submitted" "no", 
           
           # SHOULD NOT
           not address :all :is ["to",
                                 "cc",
                                 "bcc",
                                 "resent-to",
                                 "resent-cc",
                                 "resent-bcc"] %myaddrs%,

           # MAY
           envelope :all :is "from" %untrusted%,

           # XXX Not clear if this correctly expresses a null sender
           # MUST NOT
           envelope :all :is "from" "",

           # Strictly speaking localparts are case-sensitive hence the
           # use of :comparator.  In reality the default "i;ascii-casemap"
           # comparator almost certainly make more sense.
           # MAY
           envelope :comparator "i;octet"
                    :localpart :is "from" ["MAILER-DAEMON"],
           envelope :comparator "i;octet"
                    :localpart :matches "from" ["*-request",
                                                "owner-*"],

           # XXX no such recommendation is actually made
           # MAY
           header :is "precedence" "list",

           # Mentions List-* and references RFC2369.  Not possible to
           # express "list-*" as a header match in sieve.  Instead just
           # enumerate the RFC2369 and RFC2919 (List-ID) defined headers.
           # MAY
           exists "list-help",
           exists "list-unsubscribe",
           exists "list-subscribe",
           exists "list-post",
           exists "list-owner",
           exists "list-archive",
           exists "list-id"
) {
  discard;
}
