[Mailed and mailed.]
On Tue, 25 Feb 1997 11:08:49 +0000 (GMT),
David Epstein <mareb(_at_)csv(_dot_)warwick(_dot_)ac(_dot_)uk> wrote:
I have a mail folder to which messages have been added in a fairly
random order. I need a procmail/formail recipe for sorting
them into date order.
A date stamp canonicalizer was posted to the list recently. If you
think all the date stamps are in some sort of sortable order already,
how about a Procmail recipe to spew out the messages into files named
by the date stamp? The rest of the task then amounts to writing a
shell script to list the files in the sort order you require.
(Of course, if you have a good date canonicalizer, you can use that
in addition to, or perhaps even instead of, the below sed snippet.
GNU date is pretty good at this. The commented out command in the
below rc snippet is an [untested] example of how you might use GNU
date. I don't think it will adjust time zones for you, though, so you
might want to grab the canonicalizer anyway. It was posted by Gary
Funck on Feb 16th and the archive name is archive/latest/9628. I think
you should have received instructions for using the archive when you
joined the list. If you can't manage, ask me for a copy in private
# If you have messages with no date stamp, tough luck ...
#DATE=`/usr/local/gnu/bin/date -d "\'formail -zxDate:\`" +'%y%m%d%H%M%S'`
DATE=`formail -zxDate: | sed -e 's/[ ]/_/g' # thats a tab and a space`
# $DATE is now the date stamp with whitespace converted to underscores
Could you please explain if I need a special rc file? How do I stop
the contents of the folder spewing into my regular incoming mail
folder? How do I stop procmail reading my default .procmailrc?
For any one-shot task, create a separate rc file (say, rc.temp) and
run it like
procmail rc.temp <file.mbox # handle a single message
or, with formail,
formail -s procmail rc.temp <file.mbox # handle an mbox with many msgs
The file rc.temp should contain something like
at the beginning (in addition to the normal PATH= etcetera) to
redirect any "spillover" messages to the named file, instead of your
regular inbox. (You might also want to make sure it's not writing to
your regular Procmail log file; I leave this as an exercise.)
Hope this helps,
/* era */
Free tip: Rmail or Gnus should be able to handle this too, on the mail
file itself. You wouldn't happen to be a happy GNU Emacs user?
(I'm sure other mail handling programs can do this, too.)
Defin-i-t-e-ly. Sep-a-r-a-te. Gram-m-a-r. <http://www.iki.fi/~era/>
* Enjoy receiving spam? Register at <http://www.iki.fi/~era/spam.html>