procmail
[Top] [All Lists]

Re: Can procmail be use to forward contents of an INBOX?

1997-03-31 14:44:20
Simeon ben Nevel wrote,

| I'm using procmail to foward mail between my work and home accounts.
| I've got things set-up so that I can use an e-mail message to turn the
| forwarding mechanism on and off.

My personal favorite way of turning recipes on and off at given times --
though no one else seems to use it -- is to write a condition based on
matching the date of receipt information in the From_ line.  If you can do
that, you can have the whole thing automated.  A lot depends on how regular
your hours of switching the forwarding direction are.  If they're different
every day and especially if they're not the same on a given day of the week
from that same day in other weeks, that will be hard to maintain.

Other people put in cron jobs to cp one file or another to the name specified
in an INCLUDERC assignment, but I prefer using the From_ line's timestamp
because it will function properly if the cron job fails or isn't run (or
if you don't have cron access).

| Sometimes however, a buncho mail has already arrived before I have a
| chance to turn the forwarding on at a particular location.
|
| Is there a what to get procmail to process the contents of my in-box
| (which is /var/spool/mail/$LOGNAME) and forward the messages individually
| to a specified address?

Generally one feeds the mailbox as stdin to formail -s procmail (plus the
name of an rcfile as an argument to procmail if you aren't using .procmailrc
for this); be sure that there is something (such as giving a -number option
to formail, or moving the input to a filename not used in the rcfile, or a
simple loop detector) to keep from appending to the input, or you could get
yourself seriously stuck!

| Would I somehow invoke procmail itself from within my .procmailrc?

Not if I understand your situation properly.  You've just logged into a
system and a bunch of mail there was stored in a folder without being
properly handled by procmail because the wrong set of recipes for its
time of day was in effect, right?  So you let formail -s split them up
and refeed them to procmail.

| At work I have the following:
|
| :0
| * ^Subject: sendmailhome
| | touch $HOME/.sendmailhome
|
| :0
| * ^Subject: dontsendmailhome
| | rm -f $HOME/.sendmailhome

Put some ^From: tests or something on there as well so that no one else can
mess with your forwarding!

| :0
| ? test -f $HOME/.sendmailhome
| ! snevel(_at_)my(_dot_)isp(_dot_)com

You need either an asterisk on that condition or :1 (or : with no zero) at
the start of the recipe.

| At my ISP I have something similar to forward mail to work.
|
| I *do* realize that I should have some mail-loop detection here, but I'm
| unsure how to insert the X-Loop: header as part of the last recipe.  I do
| know how to test for it.

You can insert it this way:

 :0
 * ? test -f $HOME/.sendmailhome
 | formail -A"X-Loop: yourname(_at_)your(_dot_)work(_dot_)address" | \
   $SENDMAIL snevel(_at_)your(_dot_)isp(_dot_)com

$SENDMAIL is a variable defined by procmail and does not need to be (and
generally should not be) assigned in your rcfile.

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