procmail
[Top] [All Lists]

Re: counting msgs in mbox

2003-10-10 17:07:48
Dallman Ross wrote:
Baron Fujimoto wrote:
Dallman Ross wrote:
Robert A. Hayden wrote:

grep "^From: " /var/spool/mail/rhayden | wc -l

COUNT = `grep -c '^From:' $MAIL`

If you're trying to count messages in a file in mbox format,
the regex for the message delimiter should be "^From ".  [...]
Note that this may also subject to error if your LDA does not
do "^From " escaping in message bodies.

Yes, certainly, you're right.  I wasn't touting that line.  [...]
The "formail -s echo < $MAIL | wc -l" is what got my vote.

Lars Hecking also suggested grep -c "^From ".  In the Elm package is a
small script called "messages" that does the same.

Formail's technique is safer, but I generally disarm its safeties with
-em1, as my foo-DA does do the needed escapes.  So I'd do the grep -c.

On a related note, here's my concoction for a quick-and-dirty summary:

  formail -X From: -X Subject: -s frum.awk < $MAIL

where frum.awk is a small script:

  #!/usr/bin/awk -f
  BEGIN       { w = 36 }
  /^$/        { exit }
  /^From:/    { sub(/^From: */,    ""); from = substr($0, 1, w) }
  /^Subject:/ { sub(/^Subject: */, ""); subj = substr($0, 1, w) }
  END         { printf "%-*s\t%s\n", w, from, subj }

Mike


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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