procmail
[Top] [All Lists]

Re: Extracting text from a message

1997-03-11 06:10:38
On Tue, 11 Mar 1997 05:58:29 -0500 (EST),
Brock Rozen <brozen(_at_)webdreams(_dot_)com> wrote:
I'm interested in extracting the e-mail address (only the address, no
name or list name) from the message below automatically.
<...>
Once extracted, I want to run a program and pipe the e-mail address as a
variable to it.

I'm wondering whether it would not in fact be easier / more
maintainer-friendly to change the program so +it+ can figure out the
address. 

    #!/usr/local/bin/perl -n

    m/add (regexp1) <(regexp2)> (regexp3) (regexp4)/
        and $user=$3;   # Pick out match on regexp3

    (eof and !$user) and die "Could not find 'add' line\n";

    $user && exec "/your/program/here -parameter $user";


This of course won't work as-is if you want to feed the body of the
mail message to the script you want to run (this Perl script will eat
everything up to and including the 'add' line), but I take it in this
case that you don't. (So in fact you don't want to "pipe" anything
anywhere, strictly speaking -- just execute a program with the user's
address as a parameter.)

Obviously all of the regular expressions as well as the pathname of
the program you want to execute will have to be changed here. 

Yes, it could be done in Procmail, but it seems like a bit of an
unnecessary hassle to me. 
  In particular, it could be easy to change the Perl script so it
already knows the list names and thus you could change regexp2 to
something interesting which already knows which lists to approve.

.obProcmailism:

I assume you really didn't want a simple answer along the lines of

    :0B
    * add regexp1 <regexp2> \/[^ ]*
    | /your/program/here -parameter $MATCH

/* era */

(Of course, the choice of the "add" line is purely arbitrary. 
You could match on "^User xxx has requested subscription ..." 
just as well, but the add line certainly seems preferrable if 
you wish to do it purely within Procmail.)

---------- Forwarded message ----------
Date: Tue, 11 Mar 1997 01:41:49 -0500
From: Shamash ListProcessor <listproc(_at_)shamash(_dot_)org>
To: Brock Rozen <brozen(_at_)torah(_dot_)org>
Subject: Subscription approval request

User nachmanl(_at_)juno(_dot_)com has requested subscription to list 
RAVFRAND.
If you approve, send either of the following requests to
listproc(_at_)shamash(_dot_)org:

add RAVFRAND <password> nachmanl(_at_)juno(_dot_)com Nachman Levine

or

system RAVFRAND <password> nachmanl(_at_)juno(_dot_)com #SUBSCRIBE RAVFRAND 
Nachman
Levine

where 'password' is the list's password, as given to you by the manager of
this system.

-- 
Defin-i-t-e-ly. Sep-a-r-a-te. Gram-m-a-r.  <http://www.iki.fi/~era/>
 * Enjoy receiving spam? Register at <http://www.iki.fi/~era/spam.html>

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