procmail
[Top] [All Lists]

Re: get the subject as a variable for an condition

1997-02-03 10:35:05
How can i get the subject in that variable and how do i use that
variable?

SUBJECT="`formail -zx 'Subject:'`"

Formail is a swiss-army knife sort of tool for mucking about with
message headers.  You'll see it popping up all over in anything but the
most basic procmail recipes.

The "-x" tells formail to extract the contents of the subject header.
The "-z" gets tid of leading spaces.  There's lots of quotes because
I've been shell scripting all morning and I'm paranoid about things that
might expand with whitespace.

You use the variable just like any other variable (i.e., stick a '$'
before it).

For example:

SUBJECT="`formail -zx 'Subject:'`"
:0
| echo "$SUBJECT" >> $HOME/subject.log

(Note that this is only an example recipe and if used in this form in a
procmailrc file would accomplish almost, but not quite, nothing remotely
useful -- other than losing all trace of your messages other than the
subject header).

Short warning: do NOT try anything resembling 'mkdir $SUBJECT'.  What if
the subject has spaces in it?  Or other odd characters?  If you're going
to do that, you'll have to play around with the MATCH variable, or with
sed (or both, or something else like perl), to yield something
reasonably safe.

-- Lars

---
Lars Kellogg-Stedman * lars(_at_)bu(_dot_)edu * (617)353-8277
Office of Information Technology, Boston University