Пример #1
0
    def test_global(self):
        sieve = '''
            require ["include", "variables"];

            global "test";
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #2
0
    def test_global_no_args(self):
        sieve = '''
            require ["include", "variables"];

            global;
        '''
        self.assertTrue(checksieve.parse_string(sieve, True))
Пример #3
0
    def test_multiline_strings(self):
        sieve = """
            require "vacation";
            vacation :mime
            "Content-Type: multipart/alternative; boundary=foo

            --foo

            I'm at the beach relaxing.  Mmmm, surf...

            --foo
            Content-Type: text/html; charset=us-ascii

            <!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.0//EN\\"
            \\"http://www.w3.org/TR/REC-html40/strict.dtd\\">
            <HTML><HEAD><TITLE>How to relax</TITLE>
            <BASE HREF=\\"http://home.example.com/pictures/\\"></HEAD>
            <BODY><P>I'm at the <A HREF=\\"beach.gif\\">beach</A> relaxing.
            Mmmm, <A HREF=\\"ocean.gif\\">surf</A>...
            </BODY></HTML>

            --foo--
            ";
        """
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #4
0
    def test_global_no_variables_require(self):
        sieve = '''
            require ["include"];

            global "test";
        '''
        self.assertTrue(checksieve.parse_string(sieve, True))
Пример #5
0
    def test_enclose_no_require(self):
        sieve = '''
require [ "foreverypart", "mime" ];

foreverypart
{
 if header :mime :param "filename"
    :matches ["Content-Type", "Content-Disposition"]
      ["*.com", "*.exe", "*.vbs", "*.scr",
       "*.pif", "*.hta", "*.bat", "*.zip" ]
 {
   # these attachment types are executable
   enclose :subject "Warning" text:
WARNING! The enclosed message contains executable attachments.
These attachment types may contain a computer virus program
that can infect your computer and potentially damage your data.

Before clicking on these message attachments, you should verify
with the sender that this message was sent by them and not a
computer virus.
.
;
   break;
 }
}
        '''
        self.assertTrue(checksieve.parse_string(sieve, True))
Пример #6
0
    def test_global_list(self):
        sieve = '''
            require ["include", "variables"];

            global ["foo", "bar", "baz"];
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #7
0
    def test_global_no_args(self):
        sieve = '''
            require ["include", "variables"];

            global;
        '''
        self.assertTrue(checksieve.parse_string(sieve, True))
Пример #8
0
    def test_empty_block(self):
        sieve = '''
            if header :matches "Subject" "NOT A VIRUS" {

            }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #9
0
    def test_extracttext_no_require(self):
        sieve = '''
           require ["mime", "variables", "foreverypart"];

           if header :contains "from" "*****@*****.**"
           {
             # :matches is used to get the value of the Subject header
             if header :matches "Subject" "*"
             {
               set "subject" "${1}";
             }

             # extract the first 100 characters of the first text/* part
             foreverypart
             {
               if header :mime :type :is "Content-Type" "text"
               {
                 extracttext :first 100 "msgcontent";
                 break;
               }
             }

             # if it's not a 'for your information' message
             if not header :contains "subject" "FYI:"
             {
               # do something using ${subject} and ${msgcontent}
               # such as sending a notification using a
               # notification extension
             }
           }
        '''
        self.assertTrue(checksieve.parse_string(sieve, True))
Пример #10
0
 def test_body_no_require(self):
     sieve = '''
         if body :raw :contains "MAKE MONEY FAST" {
             discard;
         }
     '''
     self.assertTrue(checksieve.parse_string(sieve, True))
Пример #11
0
    def test_example_2(self):
        sieve = '''
            require ["variables", "include"];

            set "global.i_am_on_vacation" "1";
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #12
0
 def test_string_no_require(self):
     sieve = '''
         if string :matches " ${state} " "* pending *" {
           # the above test always succeeds
         }
     '''
     self.assertTrue(checksieve.parse_string(sieve, True))
Пример #13
0
    def test_servermetadata(self):
        sieve = '''
        require ["servermetadata", "variables", "envelope"];

        if servermetadata :matches
            "/private/vendor/vendor.isode/notification-uri" "*" {
            set "notif_uri" "${0}";
        }

        if not string :is "${notif_uri}" "none" {
            # :matches is used to get the MAIL FROM address
            if envelope :all :matches "from" "*" {
                set "env_from" " [really: ${1}]";
            }

            # :matches is used to get the value of the Subject header
            if header :matches "Subject" "*" {
                set "subject" "${1}";
            }
            # :matches is used to get the address from the From header
            if address :matches :all "from" "*" {
                set "from_addr" "${1}";
            }

            # notify :message "${from_addr}${env_from}: ${subject}"
            #         "${notif_uri}";
            stop;
        }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #14
0
    def test_example1(self):
        sieve = '''
        require ["envelope", "subaddress", "fileinto"];

        # In this example the same user account receives mail for both
        # "*****@*****.**" and "*****@*****.**"

        # File all messages to postmaster into a single mailbox,
        # ignoring the :detail part.
        if envelope :user "to" "postmaster" {
            fileinto "inbox.postmaster";
            stop;
        }

        # File mailing list messages (subscribed as "ken+mta-filters").
        if envelope :detail "to" "mta-filters" {
            fileinto "inbox.ietf-mta-filters";
        }

        # Redirect all mail sent to "ken+foo".
        if envelope :detail "to" "foo" {
            redirect "*****@*****.**";
        }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #15
0
    def test_example1(self):
        sieve = '''
        require ["enotify", "fileinto", "variables"];

        if header :contains "from" "*****@*****.**" {
            notify :importance "1"
                :message "This is probably very important"
                            "mailto:[email protected]";
            # Don't send any further notifications
            stop;
        }

        if header :contains "to" "*****@*****.**" {
            # :matches is used to get the value of the Subject header
            if header :matches "Subject" "*" {
                set "subject" "${1}";
            }

            # :matches is used to get the value of the From header
            if header :matches "From" "*" {
                set "from" "${1}";
            }

            notify :importance "3"
                :message "[SIEVE] ${from}: ${subject}"
                "mailto:[email protected]";
            fileinto "INBOX.sieve";
        }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #16
0
    def test_example2(self):
        sieve = '''
        require ["enotify", "fileinto", "variables", "envelope"];

        if header :matches "from" "*@*.example.org" {
            # :matches is used to get the MAIL FROM address
            if envelope :all :matches "from" "*" {
                set "env_from" " [really: ${1}]";
            }

            # :matches is used to get the value of the Subject header
            if header :matches "Subject" "*" {
                set "subject" "${1}";
            }

            # :matches is used to get the address from the From header
            if address :matches :all "from" "*" {
                set "from_addr" "${1}";
            }

            notify :message "${from_addr}${env_from}: ${subject}"
                            "mailto:[email protected]";
        }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #17
0
    def test_example3(self):
        sieve = '''
        require ["enotify", "variables"];

        set "notif_method"
        "xmpp:[email protected]?message;subject=SIEVE;body=You%20got%20mail";

        if header :contains "subject" "Your dog" {
            set "notif_method" "tel:+14085551212";
        }

        if header :contains "to" "*****@*****.**" {
            set "notif_method" "";
        }

        if not string :is "${notif_method}" "" {
            notify "${notif_method}";
        }

        if header :contains "from" "*****@*****.**" {
            # :matches is used to get the value of the Subject header
            if header :matches "Subject" "*" {
                set "subject" "${1}";
            }

            # don't need high importance notification for
            # a 'for your information'
            if not header :contains "subject" "FYI:" {
                notify :importance "1" :message "BOSS: ${subject}"
                                    "tel:+14085551212";
            }
        }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #18
0
    def test_return(self):
        sieve = '''
            require ["include"];

            return;
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #19
0
    def test_foreverypart(self):
        sieve = '''
            require ["foreverypart"];

            foreverypart { }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #20
0
    def test_empty_block(self):
        sieve = '''
            if header :matches "Subject" "NOT A VIRUS" {

            }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #21
0
 def test_body_no_require(self):
     sieve = '''
         if body :raw :contains "MAKE MONEY FAST" {
             discard;
         }
     '''
     self.assertTrue(checksieve.parse_string(sieve, True))
Пример #22
0
 def test_string_no_require(self):
     sieve = '''
         if string :matches " ${state} " "* pending *" {
           # the above test always succeeds
         }
     '''
     self.assertTrue(checksieve.parse_string(sieve, True))
Пример #23
0
    def test_global_list(self):
        sieve = '''
            require ["include", "variables"];

            global ["foo", "bar", "baz"];
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #24
0
    def test_example_2(self):
        sieve = '''
            require ["variables", "include"];

            set "global.i_am_on_vacation" "1";
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #25
0
    def test_return_extra_arg(self):
        sieve = '''
            require ["include"];

            return "foo";
        '''
        self.assertTrue(checksieve.parse_string(sieve, True))
Пример #26
0
 def test_with_count(self):
     sieve = '''
     require ["spamtestplus", "fileinto", "relational",
              "comparator-i;ascii-numeric"];
     if spamtest :percent :count "eq"
                 :comparator "i;ascii-numeric" "0"
     {
         fileinto "INBOX.unclassified";
     }
     elsif spamtest :percent :value "eq"
                     :comparator "i;ascii-numeric" "0"
     {
         fileinto "INBOX.not-spam";
     }
     elsif spamtest :percent :value "lt"
                     :comparator "i;ascii-numeric" "37"
     {
         fileinto "INBOX.spam-trap";
     }
     else
     {
         discard;
     }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #27
0
    def test_multiline_strings(self):
        sieve = '''
            require "vacation";
            vacation :mime
            "Content-Type: multipart/alternative; boundary=foo

            --foo

            I'm at the beach relaxing.  Mmmm, surf...

            --foo
            Content-Type: text/html; charset=us-ascii

            <!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.0//EN\\"
            \\"http://www.w3.org/TR/REC-html40/strict.dtd\\">
            <HTML><HEAD><TITLE>How to relax</TITLE>
            <BASE HREF=\\"http://home.example.com/pictures/\\"></HEAD>
            <BODY><P>I'm at the <A HREF=\\"beach.gif\\">beach</A> relaxing.
            Mmmm, <A HREF=\\"ocean.gif\\">surf</A>...
            </BODY></HTML>

            --foo--
            ";
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #28
0
 def test_multi_line_2(self):
     sieve = '''
     if exists "In-Reply-To" {
         /* Single-line-multi-line-comment */
     }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #29
0
    def test_global_no_variables_require(self):
        sieve = '''
            require ["include"];

            global "test";
        '''
        self.assertTrue(checksieve.parse_string(sieve, True))
Пример #30
0
 def test_date_pass(self):
     sieve = '''
  require ["date", "relational", "fileinto"];
  if anyof(date :is "received" "weekday" "0",
           date :is "received" "weekday" "6")
  { fileinto "weekend"; }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #31
0
 def test_string(self):
     sieve = '''
         require ["variables"];
         if string :matches " ${state} " "* pending *" {
           # the above test always succeeds
         }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #32
0
    def test_multiline_string_with_comment(self):
        sieve = '''
        require "fileinto";
        fileinto text: #inline comment
            Inbox
.
;'''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #33
0
 def test_hasflag_no_require(self):
     sieve = '''
     if hasflag :contains "MyVar" "Junk" {
         discard;
         stop;
     }
     '''
     self.assertTrue(checksieve.parse_string(sieve, True))
Пример #34
0
 def test_multi_line_3(self):
     sieve = '''
     if exists "In-Reply-To" {
         /* Multi-line comment
         with a * in it */
     }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #35
0
 def test_date_pass(self):
     sieve = '''
  require ["date", "relational", "fileinto"];
  if anyof(date :is "received" "weekday" "0",
           date :is "received" "weekday" "6")
  { fileinto "weekend"; }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #36
0
 def test_break_no_require(self):
     sieve = '''
         foreverypart
         {
             break;
         }
     '''
     self.assertTrue(checksieve.parse_string(sieve, True))
Пример #37
0
 def test_string(self):
     sieve = '''
         require ["variables"];
         if string :matches " ${state} " "* pending *" {
           # the above test always succeeds
         }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #38
0
    def test_multiline_string_with_comment(self):
        sieve = '''
        require "fileinto";
        fileinto text: #inline comment
            Inbox
.
;'''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #39
0
 def test_example_2(self):
     sieve = '''
        require ["vacation", "variables"];
        if header :matches "subject" "*" {
            vacation :subject "Automatic response to: ${1}"
                     "I'm away -- send mail to foo in my absence";
        }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #40
0
    def test_body(self):
        sieve = '''
            require ["body"];

            if body :raw :contains "MAKE MONEY FAST" {
                discard;
            }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #41
0
 def test_setflag_with_variable(self):
     sieve = '''
     require ["imap4flags", "fileinto"];
     if header :contains "from" "*****@*****.**" {
         setflag "flagvar" "\\Flagged";
         fileinto :flags "${flagvar}" "INBOX.From Boss";
     }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #42
0
 def test_else(self):
     sieve = '''
     if header :matches "Subject" "MAKE MONEY FAST" {
         discard;
     } else {
         keep;
         stop;
     }'''
     self.assertFalse(checksieve.parse_string(sieve, False));
Пример #43
0
 def test_setflag_with_variable(self):
     sieve = '''
     require ["imap4flags", "fileinto"];
     if header :contains "from" "*****@*****.**" {
         setflag "flagvar" "\\Flagged";
         fileinto :flags "${flagvar}" "INBOX.From Boss";
     }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #44
0
 def test_else(self):
     sieve = '''
     if header :matches "Subject" "MAKE MONEY FAST" {
         discard;
     } else {
         keep;
         stop;
     }'''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #45
0
    def test_body(self):
        sieve = '''
            require ["body"];

            if body :raw :contains "MAKE MONEY FAST" {
                discard;
            }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #46
0
 def test_example_3(self):
     sieve = '''
        require "vacation";
        vacation :days 23 :addresses ["*****@*****.**",
                                      "*****@*****.**"]
        "I'm away until October 19.
        If it's an emergency, call 911, I guess." ;
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #47
0
 def test_date_2(self):
     sieve = '''
          require ["date", "relational", "fileinto"];
  if allof(header :is "from" "*****@*****.**",
           date :value "ge" :originalzone "date" "hour" "09",
           date :value "lt" :originalzone "date" "hour" "17")
  { fileinto "urgent"; }
  '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #48
0
 def test_example_1(self):
     sieve = '''
        require "vacation";
        if header :contains "subject" "cyrus" {
            vacation "I'm out -- send mail to cyrus-bugs";
        } else {
            vacation "I'm out -- call me at +1 304 555 0123";
        }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #49
0
    def test_exists(self):
        sieve = '''
           require ["mime", "fileinto"];

           if exists :mime :anychild "content-md5"
           {
               fileinto "INBOX.md5";
           }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #50
0
    def test_address(self):
        sieve = '''
           require ["mime", "fileinto"];

           if address :mime :is :all "content-from" "*****@*****.**"
           {
               fileinto "INBOX.part-from-tim";
           }
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))
Пример #51
0
 def test_test_string(self):
     sieve = '''
     require "variables";
     set "state" "${state} pending";
     if string :matches " ${state} " "* pending *" {
       # the above test always succeeds
       stop;
     }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #52
0
 def test_value_no_require(self):
     sieve = '''
        require ["fileinto"];
        if address :value "gt" :all :comparator "i;ascii-casemap"
              ["from"] ["M"]
       {
          fileinto "From N-Z";
       }
     '''
     self.assertTrue(checksieve.parse_string(sieve, True))
Пример #53
0
 def test_value(self):
     sieve = '''
        require ["relational", "fileinto", "comparator-i;ascii-casemap"];
        if address :value "gt" :all :comparator "i;ascii-casemap"
              ["from"] ["M"]
       {
          fileinto "From N-Z";
       }
     '''
     self.assertFalse(checksieve.parse_string(sieve, False))
Пример #54
0
    def test_example_1(self):
        sieve = '''
            require ["include"];

            include :personal "always_allow";
            include :global "spam_tests";
            include :personal "spam_tests";
            include :personal "mailing_lists";
        '''
        self.assertFalse(checksieve.parse_string(sieve, False))