Aaron Turner asked,
| I haven't ever seen this mentioned, but maybe someone can help. I work
| part time (M, W, F) and go to school T & TH. I'd like emails from certain
| addresses to be auto-forwarded from my main account (Best) to school on
| Tues, and Thurs, and forwarded to work M, W, F.
|
| Is there a way to check the current date from procmail and forward
| appropriately? Thanks!
Does your mail come in with a From_ line at the top? If so, it includes
the timestamp of the message's arrival, and procmail can find it out just
by looking at the From_ line without running extra programs and shells to
connect them.
:0
* ^^From [^ ]+ +\/(Sun|Mon|Tue|Wed|Thu|Fri|Sat)
{ WEEKDAY=$MATCH }
:0
* WEEKDAY ?? Mon|Wed|Fri
[action for those three days]
:0E
* WEEKDAY ?? ^T
[action for the other two weekdays]
:0E
* WEEKDAY ?? ^S
[action for mail arriving on weekends]
:0E
[action if $WEEKDAY is not set or is messed up]
I regularly use the time and date information in the From_ line to make
recipes turn on and shut off automatically at specific times, and the method
works very well without extra processes. By using a more complicated expres-
sion, you can have the various reactions start and end at another time of the
day instead of midnight. For example, you could have no forwarding at night
or on weekends, or mail that arrives nights or weekends could get the same
treatment as mail that will come on the next day of work or school. You
could even preprogram it to handle major holidays.
In fact, I have an rcfile that extracts all the timestamp information in
the From_ line into variables. You can simply source it with an INCLUDERC
assignment and then do whatever tests you like on the variables that it sets:
:0 # get date variables from From_ line
* ^^From +[^ ]+ +\/(Sun|Mon|Tue|Wed|Thu|Fri|Sat) .*[0-9]
{ WDMTY=$MATCH }
:0
* WDMTY ?? ^^\/...
{ WEEKDAY=$MATCH }
:0
* $ WDMTY ?? ^^$\WEEKDAY \/.*
{ MDTY=$MATCH }
:0
* MDTY ?? ^^\/...
{ MONTH=$MATCH }
:0
* $ MDTY ?? $\MONTH +\/[0-9].*
{ DTY=$MATCH }
:0
* DTY ?? ^^\/[0-9]+
{ DAY=$MATCH }
:0 # get the most common case out of the way
* DAY ?? [1-3].
{ FULLDAY=$DAY }
:0E # otherwise, in case day of month has a leading zero
* DAY ?? 0\/.
{ FULLDAY=$DAY
DAY=$MATCH }
:0E
* DAY ?? ^^.^^
{ FULLDAY=0$DAY }
:0E # Houston, we have a problem.
{ FULLDAY=$DAY }
:0
* DTY ?? ()\/..:..:..
{ TIME=$MATCH }
:0
* $ DTY ?? $\TIME +\/[0-9]+
{ YEAR=$MATCH }
:0
* TIME ?? ^\/..
{ HOUR=$MATCH }
:0
* TIME ?? ^..:\/..
{ MINUTE=$MATCH }
:0
* TIME ?? ()\/..$
{ SECONDCOUNT=$MATCH } # to prevent conflicts with $SECOND or $SECONDS
WMDTY MDTY DTY # no longer useful, clear them out