procmail
[Top] [All Lists]

Re: LASTFOLDER blues

2007-03-25 13:21:15
On Sun, Mar 25, 2007 at 08:17:12PM +0200, Axel Thimm wrote:

On Sun, Mar 25, 2007 at 07:24:14PM +0200, Dallman Ross wrote:

On Sat, Mar 24, 2007 at 11:34:15PM +0100, Axel Thimm wrote:
And how do I know that the message was not delivered elsewhere? ;)

  :0 e
  * LASTFOLDER ?? .
  $FALLBACK

That's a joke, right? The subject is called "LASTFOLDER blues"
because LASTFOLDER cannot be used for that query ...

Addressing only this one point for now: no, not a joke.  The
LASTFOLDER is used here to make sure we want to exit procmail after
this recipe; that is, the last recipe did attempt to deliver with
one of our optional multi-delivery recipes.  The e-flag causes the
delivery to FALLBACK to happen only if the last recipe errored out.
If there was no error as shown by the e-flag, then the most recent
LASTFOLDER delivery did in fact succeed, so there is at least
one good copy of the message saved.  I have already tested this
algorithm.

Here is an example.  First, the rcfile:


    9:52pm [~/Mail] 753[0]> cat deliverme.rc 
      :0 c:
      #* conditions for delivery to A
      FolderA
   
      :0 c:
      #* conditions for delivery to B
      FolderB
   
      :0:
      #* conditions for delivery to C
      FolderC
   
      :0 e:
      * LASTFOLDER ?? .
      FALLBACK
   

Here are the mail folders, with okay perms:
   
    9:52pm [~/Mail] 754[0]> ls -l Folder*
   -rw-------    1 dman     users        3488 Mar 25 21:51 FolderA
   -rw-------    1 dman     users        3488 Mar 25 21:51 FolderB
   -rw-------    1 dman     users        3488 Mar 25 21:51 FolderC


Here is a successful run that saves to all three folders and then exits:
   
    9:52pm [~/Mail] 755[0]> procmail -m DEFAULT=/dev/null VERBOSE=y 
deliverme.rc < $SPAMPLE
   procmail: [6209] Sun Mar 25 21:53:06 2007
   procmail: Assigning "MAILDIR=."
   procmail: Rcfile: "deliverme.rc"
   procmail: Locking "FolderA.lock"
   procmail: Assigning "LASTFOLDER=FolderA"
   procmail: Opening "FolderA"
   procmail: Acquiring kernel-lock
   procmail: [6209] Sun Mar 25 21:53:07 2007
   procmail: Unlocking "FolderA.lock"
   procmail: Locking "FolderB.lock"
   procmail: Assigning "LASTFOLDER=FolderB"
   procmail: Opening "FolderB"
   procmail: Acquiring kernel-lock
   procmail: [6209] Sun Mar 25 21:53:08 2007
   procmail: Unlocking "FolderB.lock"
   procmail: Locking "FolderC.lock"
   procmail: Assigning "LASTFOLDER=FolderC"
   procmail: Opening "FolderC"
   procmail: Acquiring kernel-lock
   procmail: [6209] Sun Mar 25 21:53:09 2007
   procmail: Unlocking "FolderC.lock"
   From Danielsijie(_at_)wanadoo(_dot_)fr  Sat Aug  6 23:40:41 2005
    Subject: Dating site for sexoholics
     Folder: FolderC                                                          
1744


Now I'll remove write perms from the target folders:
   
    9:53pm [~/Mail] 756[0]> chmod u-w Folder*


Here we go again with a trial run.  This time, FALLBACK was used:
   
    9:53pm [~/Mail] 757[0]> procmail -m DEFAULT=/dev/null VERBOSE=y 
deliverme.rc < $SPAMPLE
   procmail: [2844] Sun Mar 25 21:53:29 2007
   procmail: Assigning "MAILDIR=."
   procmail: Rcfile: "deliverme.rc"
   procmail: Locking "FolderA.lock"
   procmail: Assigning "LASTFOLDER=FolderA"
   procmail: Opening "FolderA"
   procmail: Error while writing to "FolderA"
   procmail: Unlocking "FolderA.lock"
   procmail: Locking "FolderB.lock"
   procmail: Assigning "LASTFOLDER=FolderB"
   procmail: Opening "FolderB"
   procmail: Error while writing to "FolderB"
   procmail: Unlocking "FolderB.lock"
   procmail: Locking "FolderC.lock"
   procmail: Assigning "LASTFOLDER=FolderC"
   procmail: Opening "FolderC"
   procmail: Error while writing to "FolderC"
   procmail: Unlocking "FolderC.lock"
   procmail: Match on "."
   procmail: Locking "FALLBACK.lock"
   procmail: Assigning "LASTFOLDER=FALLBACK"
   procmail: Opening "FALLBACK"
   procmail: Acquiring kernel-lock
   procmail: [2844] Sun Mar 25 21:53:30 2007
   procmail: Unlocking "FALLBACK.lock"
   From Danielsijie(_at_)wanadoo(_dot_)fr  Sat Aug  6 23:40:41 2005
    Subject: Dating site for sexoholics
     Folder: FALLBACK                                                         
1744


Ta-dah!

Of course, we only get FALLBACK if the most recent recipe in the block
was the one that failed to write.  If a previous recipe in the optional
block failed, but the current one doesn't run because, say, of mismatched
conditions, then FALLBACK won't work.  (The e-flag won't run.)  So you
do need to test each instance of delivering recipes.  You could make
it look cleaner by using an INCLUDERC.

---------------------- start fallback.rc ----------------------

  :0:
  $MYDELIVERY

  :0 e:
  ${FALLBACK:-${DEFAULT:-$ORGMAIL}}

  :0 e
  { ERRORCODE = 77 }

----------------------- end fallback.rc -----------------------



The main rcfile then contains:

   :0
   * conditons for FolderA
   { MYDELIVERY = FolderA  INCLUDERC = fallback.rc }

   :0
   * conditons for FolderB
   { MYDELIVERY = FolderB  INCLUDERC = fallback.rc }

   :0
   * conditons for FolderC
   { MYDELIVERY = FolderC  INCLUDERC = fallback.rc }



Dallman

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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