relational.at 3.47 KB
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.

m4_pushdef([MUT_SIEVE_MAILBOX],[relational.mbox])
m4_pushdef([MUT_SIEVE_OPTIONS],[--set ":mailbox:folder=`pwd`" dnl
 --set ":mailbox:mailbox-pattern=`pwd`/"'${user}'])

MUT_TESTCASE([relational address],[test relational address comparator i-ascii-numeric],
[
require [["relational", "comparator-i;ascii-numeric"]];

if address :count "ge" :comparator "i;ascii-numeric" [["to", "cc"] ["3"]]
  {
    discard;
  }
],[],[0],[],
[DISCARD on msg uid 1: marking as deleted
IMPLICIT KEEP on msg uid 2
IMPLICIT KEEP on msg uid 3
IMPLICIT KEEP on msg uid 4
IMPLICIT KEEP on msg uid 5
IMPLICIT KEEP on msg uid 6
IMPLICIT KEEP on msg uid 7
IMPLICIT KEEP on msg uid 8
DISCARD on msg uid 9: marking as deleted
])

MUT_TESTCASE([relational header],[test relational header comparator i-ascii-numeric],
[
require [["relational", "comparator-i;ascii-numeric"]];

if header :count "gt" [["received"]] [["2"]]
  {
    discard;
  }
],[],[0],[],
[IMPLICIT KEEP on msg uid 1
IMPLICIT KEEP on msg uid 2
IMPLICIT KEEP on msg uid 3
IMPLICIT KEEP on msg uid 4
IMPLICIT KEEP on msg uid 5
IMPLICIT KEEP on msg uid 6
IMPLICIT KEEP on msg uid 7
IMPLICIT KEEP on msg uid 8
DISCARD on msg uid 9: marking as deleted
])

m4_pushdef([FILEEXISTS],[test -f "$1" || echo "$1 missing"])

MUT_TESTCASE([relational big test],[test relational relational-hairy],
[
require [["relational", "comparator-i;ascii-numeric", "fileinto"]];

if header :value "lt" :comparator "i;ascii-numeric" [["x-priority"]] [["3"]]
  {
    fileinto "%Priority";
  }
elsif address :count "gt" :comparator "i;ascii-numeric" [["to"]] [["5"]]
  {
    # everything with more than 5 recipients in the "to" field
    # is considered SPAM
    fileinto "%SPAM";
  }
elsif address :value "gt" :all :comparator "i;ascii-casemap" [["from"]] [["M"]]
  {
    fileinto "%From_N-Z";
  }
else
  {
    fileinto "%From_A-M";
  }

if allof (address :count "eq" :comparator "i;ascii-numeric"
                  [["to", "cc"]] [["1"]] ,
          address :all :comparator "i;ascii-casemap"
                  [["to", "cc"]] [["me@foo.example.com.invalid"]])
  {
    fileinto "%Only_me";
  }
],
[
FILEEXISTS([From_A-M])
FILEEXISTS([From_N-Z])
FILEEXISTS([Priority])
FILEEXISTS([Only_me])
FILEEXISTS([SPAM])
],[0],[],
[FILEINTO on msg uid 1: delivering into %From_A-M
FILEINTO on msg uid 2: delivering into %From_N-Z
FILEINTO on msg uid 3: delivering into %Priority
FILEINTO on msg uid 4: delivering into %Priority
FILEINTO on msg uid 5: delivering into %Priority
FILEINTO on msg uid 6: delivering into %From_A-M
FILEINTO on msg uid 7: delivering into %From_A-M
FILEINTO on msg uid 8: delivering into %From_A-M
FILEINTO on msg uid 8: delivering into %Only_me
FILEINTO on msg uid 9: delivering into %SPAM
])
m4_popdef([FILEEXISTS])
m4_popdef([MUT_SIEVE_MAILBOX])
m4_popdef([MUT_SIEVE_OPTIONS])