procmail
[Top] [All Lists]

Re: procmail regex style using Or construct

2009-02-19 12:04:44
At 15:03 2009-02-19 +0000, o(_dot_)nash(_at_)cs(_dot_)ucc(_dot_)ie wrote:

I want to filter message based on Dete: header so that
in any month:
days 1-7 go in one file
days 8-15 go in another etc ...

You've got some odd math there - your second group is more than 7 days. What are we supposed to figure the third group will be?

Surely, you really intend to have:

        1-7
        8-14
        15-21
        22-28
        28+

Otherwise, please be more specific.

This egrep expression does the trick but does not translate to procmail.
egrep ^Date:.*\ \(1\|2\|3\|4\|5\|6\|7\)\ $MNTH\ $YR sent-mail

Without resorting to separatwe rules like:-

However, you'll either need a clever series of rules to extract info, or at least a batch of rules to operate on a series of dates (just as your egrep above).

MNTH=$1
YR=$2
:0 c
* $ ^Date:\ .*\ 1\ $MNTH\ $YR
/mailbackup/$YR/$MNTH/sent-mail

The following is UNTESTED.

Some notes:
        There's no reason to escape spaces, as they posess no special regexp
                meaning (whereas .?* and others do).
        Dates on _received_ emails are suspect - many don't follow proper
                format.  Since you're using this on SENT mail, just ensure
                your MUA is producing valid Date: headers.
        I maintained the 'c'opy flag on the recipe, but have no idea why you
                were using it (even in the context of your multi-check
                series).  It is only valid if there are other recipes that
                follow the current one that need to operate on a copy of the
                message.
        You could use basically the same method to extract the month and
                year from the date - then formail is simply bursting the
                multiple-message file into individual messages for procmail.

:0 c
* $ ^Date:[     ]*\/[0-9]+ $MNTH $YR
* MATCH ?? \/[0-9]+
{
        # now, MATCH should contain just the day of month.
        # File away with abandon.

        :0
        * MATCH ?? ^^(1|2|3|4|5|6|7)^^
        /mailbackup/$YR/$MNTH/sent-mail/week-one

        :0
        * MATCH ?? ^^(8|9|10|11|12|13|14)^^
        /mailbackup/$YR/$MNTH/sent-mail/week-two

        # the remaining recipes are left as an exercise for the reader.
}

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail