Procmail Troubles

Discussion in 'Programming/Scripts' started by bobzilla, Jan 26, 2015.

  1. bobzilla

    bobzilla New Member

    Hi,
    I'm trying to configure procmail to manage imap emails running on dovecot. The filtering works, but always leaves a copy of a email in the inbox. What's the cause and how can I avoid this duplication? Thanks.
    .procmailrc and log output are below:

    VERBOSE=on
    PATH=/usr/bin:/usr/local/bin
    MAILDIR=$HOME/boxes/domain.com/fred^/.imap/
    LOGFILE=$HOME/proclog
    SHELL=/bin/sh

    :0:
    * ^Subject:.*test
    Stuff

    ---------------
    procmail: Assigning "SHELL=/bin/sh"
    procmail: Match on "^Subject:.*test"
    procmail: Locking "Stuff.lock"
    procmail: Assigning "LASTFOLDER=Stuff"
    procmail: Opening "Stuff"
    procmail: Acquiring kernel-lock
    procmail: Unlocking "Stuff.lock"
    procmail: Notified comsat: "username@number:/usr/home/username/boxes/domian.com/fred^/.imap//Stuff"
    From person@email.com Sat Jan 24 00:04:42 2015
    Subject: test
    Folder: Stuff 2213
     
    Last edited: Jan 27, 2015
  2. bobzilla

    bobzilla New Member

    Solved.
    Found an ancient post from an extremely helpful Pair Networks user explaining how to write a recipe without letting qmail interfere.
    http://ziggr.com/pairmail/

    "EXITCODE=99 tells qmail that we are going to take care of delivering each message, and that qmail does not need to deliver it to the mailbox. If we did not do this, qmail would see the default return code 0 (OK) and interpret that as "the filter program said the email was acceptable, so now I should deliver it." This results in duplicate copies of all mail landing in your mailbox, as well as filtered spam/ham copies landing in spam/ham mailboxes."

    The final working recipe:

    LOGFILE=$HOME/proclog
    VERBOSE=YES

    # prevent qmail (the program that is calling procmail
    # as a filter) from delivering the original mail.
    EXITCODE=99

    MAILDIR=$HOME/boxes/domain.com
    INBOX=$MAILDIR/fred
    GREY=$MAILDIR/fred^/.imap/grey
    JUNK=$MAILDIR/fred^/.imap/Junk
    TEST=$MAILDIR/fred^/.imap/Test


    # Spam level 5.0 or greater
    :0
    * ^X-Spam-Level: \*\*\*\*\*
    ${JUNK}

    # Spam level 2.0-4.9: hold in grey area
    :0
    * ^X-Spam-Level: \*\*
    ${GREY}

    :0:
    * ^Subject:.*test
    ${TEST}

    # Spam level < 2.0: it's probably real email, deliver as normal
    :0:
    ${INBOX}
     
    till likes this.

Share This Page