procmail
[Top] [All Lists]

Re: strip Received and write to mailbox

1998-08-27 09:02:39
Excerpts from mail: (26-Aug-98) strip Received and write to mailbox by lewst 
As I receive messages from a certain list, I'd like to remove the
Received header from the message and then write it to a mailbox file
based on month in one shot.  Is the following recipe safe, or is there
a better way?

:0:
* ^TOsage-l
|formail -I Received: >> /archives/sage-l/sage-l.`date +%y%m`

It's pretty safe and should work under most circumstances. However, it could
be safer. First off, if you want to keep the recipe simple like this[1], I
would give procmail an explicit lockfile name. You can probably get away
without one, but it wouldn't look pretty. Secondly, you have a Y2K problem.
:-) Change the "%y" to "%Y" to fix that. The other potential problem and the
most serious can occur when the filesystem that contains /archives/sage-l/
becomes full. I had a recipe similar to this, and I lost some important
e-mail a couple days ago when the volume got full. For some reason, procmail
did not fail back to delivering to $ORGMAIL. I assume this is because the
delivering action is a pipe and because a shell was exec'ed. Does anyone know
how to handle such a situation? Would a ":0e" recipe following the above
recipe prevent such e-mail lossage? I would really like to know.

Anyway, I think this would be *safer* (but it's no longer one step and it's
more complex...):

:0
* ^TOsage-l
{
   :0fhW
   |formail -I Received:

   YYYYMM=`date +%Y%m`

   :0:
   /archives/sage-l/sage-l.$YYYYMM
}

Later,
Ed


[1] This recipe could be "optimized" even more, but it would make it even
more complex. It's possible to parse the year and the month from the date in
the "From " header. That would allow you to avoid executing the `date'
command with the delivery of each e-mail. Here's how to do that:

# Get current month and day from From_ header.
:0
* ^From [^ ]+ +... \/...
{ MONTH = $MATCH }

:0
* ^From [^ ]+ +... ...  ?[0-9]+ [0-9]+:[0-9]+:[0-9]+ \/[0-9]+
{ YEAR = $MATCH }

# Convert three-letter month abbreviation to a number.
MONTHS = "01Jan02Feb03Mar04Apr05May06Jun07Jul08Aug09Sep10Oct11Nov12Dec"
:0
* MONTHS ?? $ ^^.*\/([0-9][0-9])($MONTH)
* MATCH ?? ^^\/[0-9][0-9]
{ MM = $MATCH }

YYYYMM = "$YEAR$MM"

(Warning: I don't think all "From " headers look exactly the same, so you
should test this first.)

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