[wellylug] Procmail recipes on days of the week
Chris Hodgetts
chris at archnetnz.com
Thu May 5 12:09:45 NZST 2005
Found it :)
Q: How do I do different actions depending on the time of day, day of
week, etc?
A: The "brute force" answer is to run date(1) each time you receive a
message, and compare the results against some regular expression, but a
simple and efficient shortcut is to use the date stamp which is already
in the From_ line -- it will be in your (machine's) local time zone and
reasonably close to (usually within seconds or even split-seconds of)
the message's arrival.
Here's an example which forwards messages elsewhere, but only on
weekdays between 9 and 5. (Actually, until 16:59:59.)
:0
* ^From [^ ]+[ ]+(Mon|Tue|Wed|Thu|Fri) ... ... .. \
([ 0]9|1[1-6]):[0-5][0-9]:[0-5][0-9]
! frankz at golden.net
If you want to save to a folder with today's date, you can similarly
extract the time out of this time stamp and use that as part of the
folder name:
:0 # Wed Aug 14 15:59:59 +0300 1994
* ^From [^ ]+[ ]+... \/... .. ..:..:.. [+-]?.... ....
{
FROM_=$MATCH
:0
* FROM_ ?? ^^\/[a-z][a-z][a-z]
{ MONTH=$MATCH }
# Exercise: Make sure month name is always properly capitalized,
# and/or convert it to a month number
:0
* FROM_ ?? ^^... \/([ 0][0-9]|1[0-2])
{ DAY=$MATCH }
:0 # Y10K problem! :-)
* FROM_ ?? ()\/[1-9][0-9][0-9][0-9]$$
{ YEAR=$MATCH }
# Should probably bail out here if any of MONTH DAY YEAR unset
:0: # save to daily-yyyy-mmm-dd
daily-$YEAR-$MONTH-$DAY
}
The mailing list archives have numerous variations on this theme.
Chris Hodgetts wrote:
> I am looking at getting procmail to execute a script for when mail comes
> in but it only needs to execute to the script on Tuesday and Thursday.
> (but not on the mail header date, on the system date)
>
> Can procmail do this?
>
> Could anyone give me ideas on what I would need to do?
>
> Thanks
>
> Cheers
>
>
More information about the wellylug
mailing list