?

Log in

No account? Create an account

procmail recipe for enhanced lj-notify

« previous entry | next entry »
Dec. 7th, 2004 | 10:14 pm
mood: geekygeeky
music: Hampton The Hamster - The Hamster Dance (DJ Supastar Remix)

MYADDRESS="junk@example.com"
MYOTHERADDRESS="other@example.net"

:0
# Anything with lj's notifier service address anywhere in the headers
* lj_notify@livejournal.com
# Mail loops are evil. Don't be evil.
* !^X-Loop: $MYADDRESS
{
        #
        # Comments made in my journal or as replies to my comments
        #
        :0
        # first we'll grab the username if it's in the From: header
        # in the format "(brad - LJ Comment)"
        LJUSER=| formail -x"From: " \
                | sed "s/.*[(]\([a-z0-9_]*\) - LJ Comment)/\1/" \
                | tee --append ~/tmp/ljusers.log

        #if you wanted to test the above line, you might add something like
        #| tee --append ~/tmp/ljusers.log

        #
        # Comments I make in any journal, including mine
        #
        # I wish the notifier email would say who I'm replying to; that's how
        # I'd prefer to store it. Instead, we grab the owner of the journal
        # we posted in and use that.
        :0 B
        * You left a comment
        LJUSER=| formail -x"X-Lj-Journal: " \
        | tee --append ~/tmp/ljjournals.log

        #if you wanted to test the above line, you might add something like
        #| tee --append ~/tmp/ljjournals.log


        # change the headers so the message appears to be coming from the writer
        # we'll also throw their name in a new header X-LJ-User
        #
        # we'll use @livejournal.com, even though might not exist for user
        :0 fw
        | formail -i "From: $LJUSER@livejournal.com" \
                -I "X-Loop: $MYADDRESS" \
                -i "X-LJ-User: $LJUSER"

        # forward a copy to another account just in case
        #:0 c
        #! $MYOTHERADDRESS
}


EDIT: Here's an improved version.

MYADDRESS="junk@example.com"
MYOTHERADDRESS="other@example.net"

:0
# Anything with lj's notifier service address anywhere in the headers
* lj_notify@livejournal.com
# Mail loops are evil
* !^X-Loop: $MYADDRESS
{
        #
        # Comments I make in any journal, including mine
        #
        # I wish the notifier email would say who I'm replying to; that's how
        # I'd prefer to store it. Instead, we grab the owner of the journal
        # we posted in and use that.
        #
        :0 B
        * ^You left a comment
        LJUSER=| formail -x"X-Lj-Journal: " \
        | tee --append ~/tmp/ljjournals.log

        #if you wanted to test the above line, you might add something like
        #| tee --append ~/tmp/ljjournals.log


        #
        # Comments made in my journal or as replies to my comments
        #
        :0
        # we'll grab the username if it's in the From: header
        # in the format "(brad - LJ Comment)"
        LJUSER=| formail -x"From: " \
                | sed "s/.*[(]\([a-z0-9_]*\) - LJ Comment)/\1/" \
                | tee --append ~/tmp/ljusers.log

        #if you wanted to test the above line, you might add something like
        #| tee --append ~/tmp/ljusers.log


        # change the headers so the message appears to be coming from the writer
        # we'll also throw their name in a new header X-LJ-User
        #
        # we'll use @livejournal.com, even though might not really exist for user
        :0 fw
        | formail -i "From: $LJUSER@livejournal.com" \
                -I "X-Loop: $MYADDRESS" \
                -i "X-LJ-User: $LJUSER"

        # forward a copy to another account just in case
        #:0 c
        #! $MYOTHERADDRESS
}

Link | Leave a comment | Share

Comments {2}

Ratha

(no subject)

from: papertygre
date: Dec. 7th, 2004 09:17 pm (UTC)
Link

Wow. Oo. Thanks for posting this, it might just be the example I need to finally get off my butt and learn Procmail.

Reply | Thread

Triple Entendre

Thanks! And you found a bug!

from: triple_entendre
date: Dec. 8th, 2004 04:08 am (UTC)
Link

Ahaahaahaaa! You found a bug! My recipe fails in the special case that, when someone replies to a post which contains the procmail recipe itself, it will identify the message as coming from me instead of them! Why this happens is left as an exercise for the reader.

I have fixed the offending recipe, now it won't trigger unless "You left a comment" appears at the beginning of a line. (It's wearing a hat: ^)

I've also reversed the order of the recipes (from more general to more specific), so if you were to, say, reply to this very comment with the words "You left a comment" at the beginning of a line, the same darn thing won't happen.

Reply | Parent | Thread