Re: Adding a header

[email protected] Fri, 20 Sep 2002 11:44:20 +0300
Newsgroups gmane.mail.ifile.general
Message-ID <[email protected]>
On Wed, 18 Sep 2002 14:22:16 -0500 (CDT), Luke Francl <[email protected]>
wrote:
 > If there was an "X-ifile-category:" header, you could set procmail
 > up to filter "X-ifile-category: spam" messages to /dev/null while
 > "X-ifile-category: ifile-discuss" would go to your ifile folder. I
 > think writing procmail rules of this kind would be a lot easier.
 > And as David notes, more "full featured" mail clients like KMail
 > and Evolution can sort messages into folders based on these sort of
 > simple rules.

Procmail is pretty good for +doing+ these kinds of things to messages,
so that part of the reasoning isn't really valid. But for less capable
filtering systems, the feature might be a good addition.

Off the top of my head,

    # .procmailrc excerpt

    CATEGORY=`ifile -q -c`

    :0hfw
    * CATEGORY ?? .
    | formail -I "X-ifile-category: $CATEGORY"

This could equally well be a shell script, except you need to store
the message in a temporary file then -- you'd pass your message
through this shell script (instad of Procmail, perhaps):

    #!/bin/sh

    # Set up temporary file (TODO: should prolly use mktemp or something)
    umask 077
    tmp=/tmp/.ifiler.$$
    trap 'rm -f $tmp; exit 1' 1 2 3 5 15

    # Store incoming message in a temporary file
    if cat >$tmp ; then : nothing
    else
        echo "$0: error: could not create $tmp -- exiting" >&2
        exit 127
    fi

    # Get ifile's categorization
    CATEGORY=`ifile -q -c <$tmp`

    # Output message with X-ifile-category header added
    formail -I "X-ifile-category: $CATEGORY" <$tmp

    # Clean up and quit
    rm -f $tmp

Again, untested, and off the top of my head; still, hope this helps,

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
Join the civilized world -- ban spam like we did: <http://www.euro.cauce.org/>