Subject: Re: Question

From: "Michael J. Corrigan" <[email-masked]>
Date: Thu, 05 Jan 1995 18:27:22 -0800

>      Hi,
>      
>      I want to save mail messages to files when they are from a 
>      certain address.  The file name should be the first word in the 
>      subject line.
>      
>      The steps I think should be done are:
>      
>         1.  Set an environment variable equal to the first word of the 
>      subject.  How do I do this?  I have successfully used Awk from 
>      the command line to do this to a string, but have not been able 
>      to put it into procmailrc successfully.

A line like:

FIRST_WORD=`formail -x Subject: | awk  '{print $1}'`

sets the environment variable FIRST_WORD to the first word
of the Subject: line.

>      
>         2.  cat the body of the mail to the filename saved in the 
>      environment variable.
>      

Now follow the environment variable setting line with:

:0:
*^From:.*certain_address.*
$FIRST_WORD

and that's it.

You don't need to have procmail cat the mail, just giving a word
(or in this case giving a variable whose value is a word)
as the action tells procmail to put the message in a file named
after the word.

If you actually only wanted the body of the message in the file, then make
the recipe action

| formail -I "" >> $FIRST_WORD
or
| sed '/^$/,$p' >> $FIRST_WORD

instead of just $FIRST_WORD

If it could be the case that the mail from certain_address has an empty
or missing Subject: header (in which case this recipe will be such that
procmail will put the mail in your default mailbox - ? /usr/spool/you)
then you might want something like:

FIRST_WORD=`formail -x Subject: | awk  '{print $1}'`
:0
*^From:.*certain_address.*
{
	:0:
	*? test X$FIRST_WORD != X
	$FIRST_WORD

	:0:
	NO_SUBJECT
}

which does what the first recipe does except that it collects
the messages with no Subject: into a file named NO_SUBJECT

> 
>      I've tried to do these things but just can't figure it out.  Any 
>      help would be greatly appreciated.
>      
>      Thanks,
>      
>      Howard Heller
       [email-masked]

---

From: [email-masked] (David W. Tamkin)
Date: Thu, 5 Jan 1995 21:40:23 -0600 (CST)

Howard Heller wrote,

|      I want to save mail messages to files when they are from a
|      certain address.  The file name should be the first word in the
|      subject line.

With procmail 3.10 that's very easy:

 :0:
 * ^From.*that_certain_address
 * ^Subject:.*\/[^ 	]+
 $MATCH

The brackets enclose a caret (for negation), a space, and a tab.  To handle
mail from that address that has an empty subject, a blank subject, or no
subject line at all, do this:

 :0
 * ^From.*that_certain_address
 {
  :0:
  * ^Subject:.*\/[^ 	]+
  $MATCH

  :0:
  no_subject
 }

If, as Michael Corrigan brought up, you want to store only the body, add the
`b' flag (":0b:" instead of ":0:"); there's no need to run extra programs.

David W. Tamkin  Box 3284  Skokie, Illinois  60076-6284
[email-masked]    MCI Mail: 426-1818   +1 312 714 5610