procmail
[Top] [All Lists]

Re: Variable destination Inbox file year and month ?

2001-09-03 09:02:06
On  3 Sep, Emre Bastuz wrote:
| Hi,
| 
| I´m quite new to procmail but somehow think that
| it might be useful for my particular task
| (two tasks actually):
| 
| - I´d like to put incoming mails into Inbox
|    files according to the scheme "yyyy.mm",
|    eg. "2001.09".
| 
|    It´s possible to solve this by using
| 
|    # September 2001:
|    :0 H
|    * ^Date:\ .*\ Sep\ 2001\ .*
|    2001.09
| 
|    in .procmailrc, though this means entering every
|    month manually.
| 
|    I have played around with regular expressions
|    and grouping them in particular - I am able to
|    extract the current month and year as \1 and \2
|    now and convert them from "Sep 2001" to 2001.09".
| 
|    How can I use the values of \1 and \2 in .procmailrc
|    as destination Inbox ? Can I do this directly or do
|    I have to use some kind of wrapper shell script and
|    pipe the mail to it ?

First of all, so there's no confusion, you can't use backreferences
(\1 and \2) directly in procmail. The procmailrc man page documents the
reguar expression tokens procmail knows. Also, you might want to
consider using the envelope "From " rather than the Date: header. The
Date: header, if it exists, will be set to the local time of the
*sending* system and, due to timezone differences amd mis-set clocks
(like mine), comparisions and sorting are difficult at best. The
envelope contains the time your system received it so probably makes a
better benchmark for sorting. Also, you'll run across all kinds of date
formats from different MUAs. The envelope date format will at least be
the same from message to message on your system, making it a much easier
candidate for matching.

Something like (untested):

MONTHS='(J(an|u[ln])|Feb|Ma[ry]|A(pr|ug)|Sep|Oct|Nov|Dec)'
MONTH_LOOKUP='Jan:01:Feb:02:Mar:03:Apr:04:May:05:Jun:06'
MONTH_LOOKUP="$MONTH_LOOKUP:Jul:07:Aug:08:Sep:09:Oct:10:Nov:11:Dec:12"
TIME_RE='[0-5][0-9][0-5][0-9]'
TIME_RE="([0-1][0-9]|2[0-3]):$TIME_RE:$TIME_RE"
YEAR_RE='(19[6-9][0-9|20[0-9][0-9])'

:0
* $ ^^From.*\<\/$MONTHS ([ 0-2][0-9]|3[01]) $TIME_RE $YEAR_RE
{
  THEDATE="$MATCH"
  :0
  * $ THEDATE ?? ()\/$MONTHS
  * $ MONTH_LOOKUP ?? $MATCH:\/[^:]+
  { MM=$MATCH }
  :0
  * $ THEDATE ?? $TIME_RE \/$YEAR_RE
  { YYYY=$MATCH }
  :0:
  $YYYY.$MM
}

| - Secondly I would like to use the technique mentioned
|    above to split already existing very large Inbox files
|    (several months) into the yyyy.mm scheme by cat'ing
|    the content to procmail.
| 
| Is it possible to do what I have come up with ? How ?
| 

Yes, you should find numerous discussions of post processing existing
mail boxes in the archives, and an example in man (1) procmail.

http://www.xray.mpe.mpg.de/mailing-lists/procmail/

For that matter, there must also be examples of similar or other methods
for sorting by YYYY.MM in the archive too. Whatever you do, test
carefully. See Sean Straw's example of setting up a test environment.

http://www.xray.mpe.mpg.de/mailing-lists/procmail/2000-12/msg00078.html

-- 
                   /"\
Don Hammond        \ /     ASCII Ribbon Campaign
Raleigh, NC US      X        Against HTML Mail,
                   / \      and News Too

_______________________________________________
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>