procmail
[Top] [All Lists]

Re: Reversing text?

2002-05-09 14:29:10
I would like, however, to be able to put the list messages into a
heirarcial structure ... similar to java packages ... so that lists would
be stored as such ...
list1.domain1.com goes in com/domain1/list1
list2.domain1.com goes in com/domain1/list2
lista.domain2.com goes in com/domain2/lista
listx.domain3.org goes in org/domain3/listx

Anyone know if there is a way to get procmail to do that kind of string
manipulation, or am I asking for too much?

I would go with Sean's suggestion of using sed or awk or perl or
somesuch.  However, you can do it with procmail.  And since we don't get
many recursive includerc examples here these days, here's one way of
doing it....

Create a file somewhere - in my example it is in
/home/marty/mail/reverserc:
---start reverserc--

  :0
  * $ LISTID ?? ()\/[^.]+$\DONE$
  {
    :0
    * MATCH ?? ^\/[^.]+
    { 
      DONE=.$MATCH$DONE
      MBOX=$MBOX/$MATCH
      INCLUDERC=$REVERSERC
    }
  }

---end reverserc----

and put this in your .procmailrc:


  REVERSERC=/home/marty/mail/reverserc

  :0
  * ^List-Id:.*\/[^   ]+\.[^         ]+
  {
    LISTID=$MATCH
    DONE=
    MBOX=lists
    INCLUDERC=$REVERSERC

    :0:
    $MBOX
  }

So this grabs the interesting part of the List-ID: header and puts it
into the LISTID variable.  It empties the DONE variable, points MBOX to
a directory where your hierarchy of mailboxes will be kept and then
includes the reverserc file.  The mail is then delivered to whatever
$MBOX is set to.

And reverserc....it looks for the last part of the list-id that does not
contain a dot and which it has not already matched.  It adds this to the
DONE variable (which keeps track of what has been matched so far) and to
the MBOX variable (which builds the directory path).  And it includse
reverserc again to catch any more of the list-id which might be left.

To make that a bit clearer with an example, consider a mail with the
header:

  List-ID: some.example.com

The .procmailrc recipe sets
    LISTID = some.example.com
    DONE = 
    MBOX = lists
then it includes reverserc.  This does

  * $ LISTID ?? ()\/[^.]+$\DONE$

which expands to

  * LISTID ?? ()\/[^.]+$

which matches "com".  The inner recipe then also matches "com", DONE is
set to ".com", MBOX is set to "lists/com" and reverserc is included
again.

This time, the first condition expands to

  * LISTID ?? ()\/[^.]+\.com$

which matches "example.com".  The inner recipe then matches "example",
DONE is set to ".example.com", MBOX is set to "lists/com/example" and
reverserc is included again.

This time, the first condition exands to

  * LISTID ?? ()\/[^.]+\.example\.com$
which matches "some.example.com".  The inner recipe matches "some", DONE
is ".some.example.com", MBOX is "lists/com/example/some" and reverserc
is included again.

This time, the first condition expands to

  * LISTID ?? ()\/[^.]+\.some\.example\.com$

which does NOT match.  So the includes wind back out, MBOX is
"lists/com/example/some" and that is where the mail gets delivered.

Hope that was at least interesting, if not useful.
Martin
-- 
Martin McCarthy                 /</    http://procmail.non-prophet.org
    `Procmail Companion'        \>\
     Addison Wesley             /</                  PGP key available
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>