procmail
[Top] [All Lists]

Re: help about formail

1999-12-09 03:08:04
On Sun, 5 Dec 1999 22:22:10 +0200 (EET), Claudiu Bosioc
<cbosioc(_at_)uem(_dot_)utt(_dot_)ro> wrote:
$ cat inbox | formail -ds formail -x Subject:
this, the output is only 16 lines long because some emails don't have a
subject.
I need formail to output a blank line instead of nothing, so the output
would be 21 lines, same as above.

You already received excellent responses, but I wanted to fill in a
couple of gaps here.

First, the horrible Useless Use of Cat. I have a web page about this
at <http://www.iki.fi/era/unix/award.html> -- of course it's mostly
just a marginal thing, but it's good to at least be aware of the
issue.

Second, in cases where you want to do something fancier than just
print out headers, you might have to invoke a process per message
anyhow. Here's one thing I've been using recently which is of course
extremely simple in itself, but it scales to larger applications. The
trivial sed script will merely add a line with two dashes after each
message. Obviously, you could want to do more elaborate processing
using the same model.

 $ formail -s sed '$a\
--' < mailbox

When you're extracting a fairly arbitrary set of headers and want to
see the difference between, say, messages which have a Subject,
messages which have an empty Subject, and messages which lack a
Subject, this is a good way to disambiguate them. Or if you're dumping
out the Received: headers from all messages in a mailbox, you probably
want some sort of separator between them. Naturally, you're not
limited to sed (which is sort of tricky because of the quoted wrapped
line in the example above); other programs can do something similar.
For a quick and dirty example, try head(1):

 $ formail -cXReceived: -s head -100 - /dev/null <spam | less
 ==> standard input <==
 Received: from post.it.helsinki.fi (post-ether.it.helsinki.fi [128.214.4.122
])      by kantti.Helsinki.FI (8.9.3/8.9.3-SPAMmers-sod-off) with ESMTP id AA
A26452  for <reriksso(_at_)cc(_dot_)helsinki(_dot_)fi>; Thu, 4 Nov 1999 
00:33:54 +0200 (EET)
 Received: from nets5.rz.rwth-aachen.de (nets5.rz.RWTH-Aachen.DE [137.226.144
.13])   by post.it.helsinki.fi (8.9.3/8.9.3-SPAMmers-sod-off) with ESMTP id A
AA13128         for <reriksso(_at_)cc(_dot_)helsinki(_dot_)fi>; Thu, 4 Nov 1999 
00:33:53 +0200
 (EET)
 Received: from campino.informatik.rwth-aachen.de (campino.Informatik.RWTH-Aa
chen.DE [137.226.116.240])      by nets5.rz.rwth-aachen.de (8.9.1a/8.9.1/8) w
ith ESMTP id XAA20022;  Wed, 3 Nov 1999 23:33:51 +0100 (MET)
 Received: (from lists(_at_)localhost)  by campino.informatik.rwth-aachen.de 
(8.9.1a/8.9.1/3) id XAA04046;   Wed, 3 Nov 1999 23:33:51 +0100 (MET)

 ==> /dev/null <==
 ==> standard input <==
 Received: from post.it.helsinki.fi (post-ether.it.helsinki.fi [128.214.4.122
])      by kantti.Helsinki.FI (8.9.3/8.9.3-SPAMmers-sod-off) with ESMTP id MA
A19353;         Fri, 5 Nov 1999 12:54:39 +0200 (EET)
 Received: from nets5.rz.rwth-aachen.de (nets5.rz.RWTH-Aachen.DE [137.226.144
[--- less prompt ---]

Hope this helps,

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

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