From 1c59d63bc3e53fc16671151a92606d305ba5499e Mon Sep 17 00:00:00 2001 From: Philip Hazel Date: Tue, 30 Aug 2005 10:55:52 +0000 Subject: Applied latest Sieve patches from the maintainer. --- src/src/sieve.c | 291 ++++++++++++++++---------------------------------------- 1 file changed, 83 insertions(+), 208 deletions(-) (limited to 'src') diff --git a/src/src/sieve.c b/src/src/sieve.c index 296a23c2d..32170a337 100644 --- a/src/src/sieve.c +++ b/src/src/sieve.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/sieve.c,v 1.12 2005/06/17 10:47:05 ph10 Exp $ */ +/* $Cambridge: exim/src/src/sieve.c,v 1.13 2005/08/30 10:55:52 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -311,8 +311,7 @@ while (nl>0 && hl>0) if (hc&0x80) return 0; #endif /* tolower depends on the locale and only ASCII case must be insensitive */ - if ((nc&0x80) || (hc&0x80)) { if (nc!=hc) return 0; } - else if ((nc>='A' && nc<='Z' ? nc|0x20 : nc) != (hc>='A' && hc<='Z' ? hc|0x20 : hc)) return 0; + if ((nc>='A' && nc<='Z' ? nc|0x20 : nc) != (hc>='A' && hc<='Z' ? hc|0x20 : hc)) return 0; ++n; ++h; --nl; @@ -323,7 +322,7 @@ return (match_prefix ? nl==0 : nl==0 && hl==0); /************************************************* -* Octet-wise glob pattern search * +* Glob pattern search * *************************************************/ /* @@ -333,231 +332,99 @@ Arguments: Returns: 0 needle not found in haystack 1 needle found + -1 pattern error */ -static int eq_octetglob(const struct String *needle, - const struct String *haystack) +static int eq_glob(const struct String *needle, + const struct String *haystack, int ascii_caseless) { -struct String n,h; +const uschar *n,*h,*nend,*hend; +int may_advance=0; -n=*needle; -h=*haystack; -while (n.length) +n=needle->character; +h=haystack->character; +nend=n+needle->length; +hend=h+haystack->length; +while (n='A' && *npart<='Z' ? *npart|0x20 : *npart) != (*hpart>='A' && *hpart<='Z' ? *hpart|0x20 : *hpart)) + : *hpart!=*npart + ) { - while (h.length && (h.character[0]&0x80)) + if (may_advance) + /* string match after a star failed, advance and try again */ { - ++h.character; - --h.length; + ++h; + goto match_part; } + else return 0; } else { - ++h.character; - --h.length; - } + ++npart; + ++hpart; + }; } - else return 0; - break; } - case '\\': - { - ++n.character; - --n.length; - /* FALLTHROUGH */ - } - default: + /* at this point, a part was matched successfully */ + if (may_advance && npart==nend && hpart='A' && nc<='Z' ? nc|0x20 : nc) != (hc>='A' && hc<='Z' ? hc|0x20 : hc)) return 0; - ++h.character; - --h.length; - ++n.character; - --n.length; + ++h; + goto match_part; } + h=hpart; + n=npart; + may_advance=0; } } -return (h.length==0); +return (h==hend ? 1 : may_advance); } @@ -715,12 +582,20 @@ switch (mt) { case COMP_OCTET: { - if (eq_octetglob(needle,haystack)) r=1; + if ((r=eq_glob(needle,haystack,0))==-1) + { + filter->errmsg=CUS "syntactically invalid pattern"; + return -1; + } break; } case COMP_EN_ASCII_CASEMAP: { - if (eq_asciicaseglob(needle,haystack)) r=1; + if ((r=eq_glob(needle,haystack,1))==-1) + { + filter->errmsg=CUS "syntactically invalid pattern"; + return -1; + } break; } default: @@ -2838,12 +2713,12 @@ if (parse_start(&sieve,1,generated)==1) if (sieve.keep) { add_addr(generated,US"inbox",1,0,0,0); - msg = string_sprintf("Keep"); + msg = string_sprintf("Implicit keep"); r = FF_DELIVERED; } - else + else { - msg = string_sprintf("No keep"); + msg = string_sprintf("No implicit keep"); r = FF_DELIVERED; } } -- cgit v1.2.3