procmail
[Top] [All Lists]

How to guard against `2 out of 38 messages in my infolder hit the bit-bucket'

1996-01-20 17:12:28

Thanks Soren Dayton <csdayton(_at_)midway(_dot_)uchicago(_dot_)edu> for the tip 
Jan 16 to
use

:0 
* LASTFOLDER ?? . 
/dev/null

I have refined and given more examples below of the usage of LASTFOLDER,
as well as how to make the logfile more readable when delivering carbon
copies to /dev/null after they have been successfully delivered elsewhere.

###########################################################################
##  EXPERIENCED USERS: Skip down to label:      ###     Interesting     ###
###########################################################################

On Fri, 19 Jan 1996, David W. Tamkin wrote:

Leif Erlingsson wondered,

| 2 out of 38 messages in my infolder hit the bit-bucket

the first suggestion is that you define a logfile and turn on verbose
logging.  That way procmail will tell you everything it thinks, and
you'll see exactly what is happening.
 
Then you'll probably be able to pinpoint the problem and figure out its
solution on your own.
 
And so I did. Both msg's missed all rules, and should have ended up in my
INBOX (though one of them now ends up in the intended mailing-list folder
after a rule-enhancement).

Trouble was, I had been careless when adding a new mailinglist-folder:

I often add folders with the c flag - 
:0 c:
* rule
folder

 - so mail can go to more than one folder. (Especially important when one
deliveres mail to more than one user using procmail.)

In order to `sink' mails that should already have been delivered, I later
repeat the `rule', but with the action being /dev/null.

Well, one such repeated rule was a little damaged in the copying - any 
mail with a Sender: field that came this far in my .procmailrc - and that
meant any mail that should end up in my INBOX - got ZAPPED!

(Possibly I've lost up to 4 or 5 personal mails this way, unknowingly.
This number is just speculation, based on the very few personal mails I
have logged from before adding the offensive rule that contained the 
Sender: header.)

###########################################################################
###                             Interesting                             ###
###########################################################################

I got irritated by all the /dev/null showing up in my procmail.log
because I often `sink' previously delivered mail (using the `c' flag)
at the end of my recepie. I would prefer it if the last non - /dev/null
folder showed up instead.

Also, I wanted a way to make sure that mail _never_ was delivered to /dev/null
if it hadn't been delivered to at least one of the folders, my `CHICKEN' -
folder not counted. (The CHICKEN folder is a copy of _all_ incoming mail,
that is deleted by another program the next time I fetch mail using the 
POP-3 protocol --- By the way - anybody have a suggestion on how to get rid 
of the `From POPmail...' line in the logfile and replace it with the next 
line in the mail, starting `>From the real sender...'?)


This following solution solves these two problems:


PATH=/bin:/usr/bin:/usr/local/bin
MAILDIR=$HOME/mail
LOGFILE=$MAILDIR/procmail.log

# LOGABSTRACT=all is turned on and off (for /dev/null) several times below:
LOGABSTRACT=no

:0 c:
CHICKEN

LASTFOLDER=
SAVELASTFOLDER=

# Logging on
LOGABSTRACT=all

:0 c:
* ^From.*(Leif.Erlingsson|leierl|leif)
sent-mail

:0 c:
* ^From.*(Christina.Isaksson|chrisa)
keypeople

#                                                                       #
# Really to Ylva section                                                #
#                                                                       #

:0 c
* ^TOm-17076.*mailbox.swipnet.se
! -oi ylva(_at_)elijah(_dot_)swipnet(_dot_)se

# Hereby Ylva is made an unofficial member of the epfriend mailinglist:
:0 c
* (^From.*owner-|^Sender: owner-)epfriend(_at_)eua(_dot_)ericsson(_dot_)se
! -oi ylva(_at_)elijah(_dot_)swipnet(_dot_)se

SAVELASTFOLDER=$LASTFOLDER
# Logging turned off so we will not catch the /dev/null below
LOGABSTRACT=no

:0
* ^TOm-17076.*mailbox.swipnet.se
* 
!(^TO|^From).*(leif(_at_)localhost|leif(_at_)elijah|leif$|Leif.Erlingsson.*mailbox)
* !^FROM_MAILER
* !(^From.*owner-|^Sender: owner-)epfriend(_at_)eua(_dot_)ericsson(_dot_)se
* LASTFOLDER ?? .
/dev/null

# Above the `* LASTFOLDER ?? .' rule becomes true if $LASTFOLDER contains
# at least one character - that character being the last folder delivered to.

# Logging turned on again
LOGABSTRACT=all
LASTFOLDER=$SAVELASTFOLDER

#                                                                       #
# Mailing List section                                                  #
#                                                                       #

:0 c:
* 
(^From(_dot_)*procmail-request(_at_)Informatik(_dot_)RWTH-Aachen(_dot_)DE|^X-Loop:(_dot_)*procmail(_at_)informatik(_dot_)rwth-aachen(_dot_)de)
procmail

:0:
* 
(^From(_dot_)*procmail-announce-request(_at_)Informatik(_dot_)RWTH-Aachen(_dot_)DE|^X-Loop:(_dot_)*procmail-announce(_at_)informatik(_dot_)rwth-aachen(_dot_)de)
procmail-announce

:0 c:
* (^From.*owner-|^Sender: owner-)epfriend(_at_)eua(_dot_)ericsson(_dot_)se
epfriend

#                                                                       #
# Time to sink already delivered mail, but keep the old $LASTFOLDER !   #
#                                                                       #

SAVELASTFOLDER=$LASTFOLDER
# Logging turned off so we will not catch the /dev/null's below
LOGABSTRACT=no

#                                                                       #
# People section - already delivered, so delete some of it...           #
#                                                                       #

:0
* ^From.*(Leif.Erlingsson|leierl|leif)
* LASTFOLDER ?? .
/dev/null

# Above the `* LASTFOLDER ?? .' rule becomes true if $LASTFOLDER contains
# at least one character - that character being the last folder delivered to.

#                                                                       #
# Mailing List section - already delivered, so delete some of it...     #
#                                                                       #

:0
* (^From.*owner-|^Sender: owner-)epfriend(_at_)eua(_dot_)ericsson(_dot_)se
* LASTFOLDER ?? .
/dev/null

# Above the `* LASTFOLDER ?? .' rule becomes true if $LASTFOLDER contains
# at least one character - that character being the last folder delivered to.

:0
* 
(^From(_dot_)*procmail-request(_at_)Informatik(_dot_)RWTH-Aachen(_dot_)DE|^X-Loop:(_dot_)*procmail(_at_)informatik(_dot_)rwth-aachen(_dot_)de)
* LASTFOLDER ?? .
/dev/null

# Above the `* LASTFOLDER ?? .' rule becomes true if $LASTFOLDER contains
# at least one character - that character being the last folder delivered to.

# And this will only happen if the mail has already been send to some 
# folder - and not /dev/null, because we have saved away $LASTFOLDER
# in $SAVEDLASTFOLDER whenever a carbon-copy of the mail could have ended
# up in /dev/null. (Not that I think this matters much - as long as one
# makes sure $LASTFOLDER is non-empty before delivering to /dev/null,
# one has a guarantee that the mail is delivered in at least one folder. 
# (And by setting LASTFOLDER to nothing _after_ delivering to folder
# CHICKEN, this folder doesn't get counted!))

#                                                                       #
# Not funny to read in logfile that most mail was sent to /dev/null...  #
#                                                                       #

# Logging turned on again, so we can catch delivery to $DEFAULT (`INBOX')
LOGABSTRACT=all
LASTFOLDER=$SAVELASTFOLDER
# The LASTFOLDER=$SAVELASTFOLDER line above doesn't make any difference
# for the logfile, it could be deleted! But I keep it to keep things tidy.

#                                                                       #
# INBOX                                                                 #
#                                                                       #

# Remaining people section mail will have copy deposited to system mailbox

###########################################################################
###             Elsewhere in my recepie I have this:                    ###
###########################################################################

:0
* 
(^TO|^From|^Sender:).*(grass.*list.*cecer|grass.*request.*cecer|grass.*owner.*cecer|grass-lists-owner)
{

# The above rule guarantee that the mail should either go to folder
# grassu or grassp, or to both the folders. But not to any other folder.
# (This rule must be placed after any rule delivering to other users.)

        :0 c:
        * 
(^TO|^From).*(grassu-list.*cecer|grassu-request.*cecer|grassu-owner.*cecer)
        grassu

        :0:
        * 
(^TO|^From).*(grassp-list.*cecer|grassp-request.*cecer|grassp-owner.*cecer)
        grassp

        :0:
        * !LASTFOLDER ?? .
        grassu

# Here's the interesting line - what it says is:
# `If still undelivered to any folder, anywhere, deliver to grassu'.
# It does this by checking that $LASTFOLDER does _not_ contain anything at all.

# The reason I did it this complicated is that the sender of both lists
# is identical, and often the lists cannot be told apart. In those cases,
# the mails are delivered using the `!LASTFOLDER ?? .' - rule to `grassu'.
# (I haven't yet actually seen the addresses `grassu-request'. `grassu-owner',
# etc, but I keep them in the rules just in case.)

        SAVELASTFOLDER=$LASTFOLDER
        LOGABSTRACT=no

        :0
        /dev/null

        LOGABSTRACT=all
        LASTFOLDER=$SAVELASTFOLDER

        # Pseudo code:  Decide that the mail should either or both go to grassu 
and grassp
        #               Possibly deliver a copy to grassu
        #               Possibly deliver to grassp
        #               If still undelivered to any folder, anywhere, deliver 
to grassu
        #               kill copy (this happens if delivered only to grassu but 
not to grassp)
}
 

-- Leif Erlingsson, http://www.geocities.com/RodeoDrive/1998, +46 8 604 0995
                        Use the Internet Address Finder, http://www.iaf.net

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