maildirfilter match multiple header fields in boolean and?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

maildirfilter match multiple header fields in boolean and?

Chris St Denis-4
This is a little off topic since it's postfix VDA based, but that mailing list is pretty dead so I'm trying here too.


I am trying to setup filters that match multiple header fields in an and
notation such as

subject is test and from is [hidden email]

I can do either of these separately
/^From: [hidden email]/
/^Subject: test/

and I think I can do an 'OR' easily enough with

/^From: [hidden email]|^Subject: test/

But how can I make this work with an AND to match emails with both headers?

Also, how would I negate a match such as "subject DOES NOT contain test"?

Reply | Threaded
Open this post in threaded view
|

Re: maildirfilter match multiple header fields in boolean and?

mouss-2
Chris St Denis wrote:

> This is a little off topic since it's postfix VDA based, but that
> mailing list is pretty dead so I'm trying here too.
>
> I am trying to setup filters that match multiple header fields in an
> and notation such as
>
> subject is test and from is [hidden email]
>
> I can do either of these separately
> /^From: [hidden email]/
> /^Subject: test/
>
> and I think I can do an 'OR' easily enough with
>
> /^From: [hidden email]|^Subject: test/

you can't do it like that, but OR is implicit, so you can do
/^From: [hidden email]/
/^Subject: test/


>
> But how can I make this work with an AND to match emails with both
> headers?
>

you can't. you can use a content filter and implement whatever
header_checks you want.

if you are using spamassassin, you can create a META rule.

> Also, how would I negate a match such as "subject DOES NOT contain test"?
>
if /^Subject:/
!/^Subject: test/   some action
endif

or simply:

/^Subject: test/    DUNNO
/^Subject:/         some action


Reply | Threaded
Open this post in threaded view
|

Re: maildirfilter match multiple header fields in boolean and?

Chris St Denis-4
mouss wrote:
Chris St Denis wrote:
This is a little off topic since it's postfix VDA based, but that mailing list is pretty dead so I'm trying here too.

I am trying to setup filters that match multiple header fields in an and notation such as

subject is test and from is [hidden email]

I can do either of these separately
/^From: [hidden email]
/^Subject: test/

and I think I can do an 'OR' easily enough with

/^From: [hidden email]|^Subject: test/

you can't do it like that, but OR is implicit, so you can do
/^From: [hidden email]
/^Subject: test/



But how can I make this work with an AND to match emails with both headers?


you can't. you can use a content filter and implement whatever header_checks you want.

if you are using spamassassin, you can create a META rule.

Also, how would I negate a match such as "subject DOES NOT contain test"?

if /^Subject:/
!/^Subject: test/   some action
endif

or simply:

/^Subject: test/    DUNNO
/^Subject:/         some action


I was asking in the context of maildirfilter not header checks, their syntax is not quite the same and there isn't really any documentation on maildirfilter beyond
#### Maildirfilter file - vfilter
# ATTENTION: the syntax for maildirfilter values is the following:
# the # sign, followed by a space, followed by a M (uppercase), then a modification time value
# (you need to change this when you change the regexps) made of a maximum of 10 digits, then a
# space again and an arbitrary number of regexps (a regexp always starts with /^ and ends with
# a space) and their corresponding actions
[hidden email]  # M<timestamp> regexp1 action1 regexp2 action2 ...
[hidden email] # M2007022701 /^subject:.*BAD.*/m DISCARD /^from:.*[hidden email]*/m MOVE Trash
[hidden email] # M2007022617 /^subject:.*Viagra.*/m REJECT /^subject:.*trash.*/m MOVE SpamFolder /^subject:.*pharmacy.*/m DISCARD


Header/body checks would be great, but they definitely can't do a boolean AND, and I don't think they can deliver to a specific mailbox like these can.


The functionality I need is filters similar to what Thunderbird (and other mail clients) have for sorting messages. Also, it should be database backed because it needs to be customizable on a per-user basis. Is there anything out there that can do this that is suitable as a content filter or milter?
Reply | Threaded
Open this post in threaded view
|

Re: maildirfilter match multiple header fields in boolean and?

mouss-2
Chris St Denis wrote:

> I was asking in the context of maildirfilter not header checks, their
> syntax is not quite the same and there isn't really any documentation
> on maildirfilter beyond
>
>    [snip]
>
> Header/body checks would be great, but they definitely can't do a
> boolean AND, and I don't think they can deliver to a specific mailbox
> like these can.
>
>
> The functionality I need is filters similar to what Thunderbird (and
> other mail clients) have for sorting messages. Also, it should be
> database backed because it needs to be customizable on a per-user
> basis. Is there anything out there that can do this that is suitable
> as a content filter or milter?
>

It is good practice to use maintained software and to avoid unsupported
patches.

you can use maildrop. maildrop (since version 2) uses pcre syntax and
you can do whatever you want. for example:

if (/^Subject: foo/)
{
     if (/From: bar@example\.com$/)
     {
          exception {
              to "$DEFAULT/.foo.bar/"
          }
    }
    else
    {
          exception {
              to "$DEFAULT/.foo.notbar/"
          }
    }

}


alternatives include:
- procmail: if you are not used to its syntax, you'll find it cryptic...
- dovecot-sieve (if delivering with dovecot LDA): it implements (a
subset of) SIEVE. less flexible than the general maildrop grammar, but
may be enough depending on your needs.