procmail
[Top] [All Lists]

Re: To and From

1999-06-10 02:25:13
On Wed, 09 Jun 1999 19:15:26 +0200,
Jost Schaper <jost(_at_)schaper(_dot_)org> wrote:
In procmailex(5) I read (1st example):
"Sort out all mail coming from the scuba-diving-list ..."
:0:
* ^TOscuba
scubafile
Why doesn't it read:
:0:
* ^Fromscuba
scubafile
as the mail is coming _from_ the list?

Because customarily, the mail is originally sent To: the list and this
header is not removed when the list forwards it to the subscribers. 

In practice, I find it better to filter lists on their From_ line
because this is usually genuinely unique to the list in question (and
you get it right even if the list was Bcc:ed or whatever; this might
be a case you don't want to get right, though, because it's probably
spam nowadays).

You should notice that ^TO is a special macro in Procmail, whereas
^From is not, so ^Fromscuba would actually only match (the unlikely
literal sequence) "Fromscuba" at beginning of line in the headers.

1st) When I am on holidays, I have to stay subscribed to a busy mailing
list, as the who-command is processed a few times a day.
(|sort -f >>list_file  which works fine)
How can I delete the incoming list-mail?
How can I save just the eMAil-Adress and the text of each mail in a
file?

This isn't entirely clear to me (what is a who-command and what
exactly is the sort supposed to accomplish?) but the actual questions
seem easy enough to answer.

    :0
    * some expression which uniquely identifies mail from the list
    /dev/null

to delete, and to save, try something like

    :0:
    * some expression which uniquely identifies mail from the list
    | formail -X"From " -k >>list-archive

depending on what you mean by "the eMAil-Adress" [sic]. This
particular recipe will keep the From_ line but discard all headers,
and append the results to a file.

An e-mail message often contains more than one "sender" address and
it's a bit tricky to know without more explanations which one you
actually want. If the From_ line (the very first line of the message)
contains the original sender's address, that's probably a good one to
keep (because it doubles as the message separator in Unix mbox files).
If not, you might want to keep the From_ line +in addition+ to e.g.
the From: header (look at some stored mail messages to see the
difference) because the From_ line acts as the message separator in
Unix mbox files.

Conveniently, you can get both "From " (which is conventionally
written From_ with an underscore, because the quotes are a hassle) and
"From:" by just telling formail you want all headers which start with
"From":

    | formail -X"From" -k >>list-archive

There is a bit about the From_ line which you should perhaps read in
the mini-FAQ at <http://www.iki.fi/era/procmail/mini-faq.html>

2nd) I would like to have parts of my outgoing mail beeing sorted into
folders. Sorted by the customer's adresses.
Just the body, as the rest is well known.
How can I do that?

This depends entirely on what sort of control you have over your
outgoing mail. If you can set up your mail client to BCC: yourself all
outgoing mail, that could be one solution. As far as Procmail is
concerned, this is fairly trivial, but we can't help you with the part
of invoking Procmail on your outgong mail without more information.
(For Pine, you can set up outgoing mail to pass through a filter of
your making; other mail clients might provide their own hooks, or you
can persuade your administrator to set something up in your Sendmail
configuration for you.)

So let's say you manage to set up your config so that you will be
piping all outgoing message into "| procmail $HOME/.backward" (i.e.
not directly suitable for the case where you Bcc: yourself; in that
case, you have to put some checks around this and plonk it into your
regular .procmailrc) -- then the contents of .backward could be
something like

    SHELL=/bin/sh
    MAILDIR=$HOME/Mail
    DEFAULT=OUT.oops

    :0:
    * ^TO_client1
    OUT.client1

    :0:
    * ^TO_client2
    OUT.client2

    :
    # etc ad naus. -- one recipe for each client address

or you could create a single recipe which somehow takes the To: line
and transforms it into a folder name. Here, remember that Procmail
basically lets you invoke any piece of shell script to help you out:

    # Many commands in backticks -- this could probably be optimized
    CLIENT`formail -IFrom: -R To: From: | formail -rzxTo: | mapper.pl`
    :0:
    * CLIENT ?? .
    $CLIENT

where mapper.pl could be something like

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

%mapping = (
  'era(_at_)iki(_dot_)fi' => 'OUT.era',
  'jost(_at_)schaper(_dot_)org' => 'OUT.self',       # curious :-)
  'procmail(_at_)informatik(_dot_)rwth-aachen(_dot_)de' => 'OUT.procmail',
  # etc
);

$mapping = $mapping{lc($_)};

print "$mapping" if $mapping;
__END__

The condition line makes Procmail conveniently just bypass this recipe
if mapping.pl doesn't provide a mapping (i.e. if CLIENT remains
empty). (Setting DEFAULT=OUT.oops says any outgoing mail which isn't
saved elsewhere should go to the folder named OUT.oops when Procmail
reaches the end of this rc file.)

The string of formails is because I want to trim down the To: line to
just the actual e-mail address -- this could be done in Perl as well,
or otherwise accomplished without all these calls to formail.

Hope this helps,

/* era */

Uh, this is not very heavily tested :-)

-- 
.obBotBait: It shouldn't even matter whether     <http://www.iki.fi/era/>
I am a resident of the state of Washington. <http://members.xoom.com/procmail/>
 * Sign the European spam petition! <http://www.politik-digital.de/spam/en/> *

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