procmail
[Top] [All Lists]

Re: Archiving mail

1997-11-13 16:20:21
Now, my promised response for Andreas Sikkema, who cleared up my questions:

T> 1. Is the folder a plain file, a mail directory, or an MH-style directory?
S> Just a plain text file ...

OK ...

T> 2. Is this for particular items of mail or for your $DEFAULT?
S> For particulary items of mail, which I already filter, so I just need
S> to copy those (because i want to read them in my incoming mail-folder
S> _and_ archive them)

Hmmm.  All right; we'll deal with that.  This makes it more complicated to
implement, but #1 eases the problem somewhat.

T> 3. How will the name of the month be incorporated into the name of the
T> folder?  The first three letters, the entire word, the two-digit decimal
S> The two digit style is sufficient enough.. and

The three-letter form appears in the From_ line, so we'll add one recipe to
convert it to the two-digit form.

T> 4. Should the name of the folder incorporate the year... ?  If so, do you
T> want all four digits of the year or just two?
S> ... I'd like to have a four digit year

All right.

S> What I want is something like this:
S> :c:
S> * ^From: (_dot_)*introspective-digest(_at_)tcp(_dot_)com(_dot_)*
S> 1997_11_introspective_digest

Well, before we continue, that trailing .* is a waste; it doesn't affect
results but does slow procmail down a tiny bit.  Regexps are not like shell
globbing patterns, where you must put "*" on each side if you want to specify
only a substring; they are substrings by nature unless you anchor them with ^
or $ (on, in procmail, with ^^).

Also, don't bet unnecessarily on a space after the colon.

S> What I want to do is the the folder name should be created automatically.

Oh, it will be.  You can count on that.

S> I don't really understand the regexp version though..

Then I'll use a longer but less confusing one in the final answer.  The
earlier one was just enough to make sure that it matched the month and not
the day of the week, but for comprehensibility's sake let's be more explicit.

 :0
 * ^^From +[^ ]+ +[^ ]+ +\/(Jan|Feb|Ma[ry]|Apr|Ju[nl]|Aug|Sep|Oct|Nov|Dec).*
 { monthandrest=$MATCH }

 :0
 * monthandrest ?? ^^\/...
 { monthnym=$MATCH }

 :0
 * monthandrest ?? () \/[0-9]+^^
 { year=$MATCH }

 monthsstring=Jan01Feb02Mar03Apr04May05Jun06Jul07Aug08Sep09Oct10Nov11Dec12
 :0 # technically one should use $\monthnym but here it doesn't matter
 * $ monthsstring ?? $monthnym\/..
 { monthnumber=$MATCH }

 # Braces are needed because underscores are legal in variable names:
 monthprefix=${year}_${monthnumber}_

Now here comes the annoying part because of item #2 up there: for every
folder where you want the name to begin that way, you have to remember
to write

    :0flags:
    * conditions
    ${monthprefix}restofname

in its recipe, such as for your example:

  :0c:
  * ^From:(_dot_)*introspective-digest(_at_)tcp\(_dot_)com
  ${monthprefix}introspective_digest

Procmail will expand the variable in the name of the folder before figuring
out the implicit name for the local lockfile.

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