Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 784C9431FBC for ; Mon, 21 Dec 2009 19:18:24 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gX2SIwQxfNGa for ; Mon, 21 Dec 2009 19:18:23 -0800 (PST) Received: from office.neopsis.com (office.neopsis.com [78.46.209.98]) by olra.theworths.org (Postfix) with ESMTP id 79870431FAE for ; Mon, 21 Dec 2009 19:18:23 -0800 (PST) Received: from calvin.caurea.org ([62.65.141.13]) (authenticated user tom@dbservice.com) by office.neopsis.com (using TLSv1/SSLv3 with cipher AES256-SHA (256 bits)) for notmuch@notmuchmail.org; Tue, 22 Dec 2009 04:18:21 +0100 Message-ID: <4B303A7D.5090803@dbservice.com> Date: Tue, 22 Dec 2009 04:18:21 +0100 From: Tomas Carnecky User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.3a1pre) Gecko/20091216 Lightning/1.1a1pre Shredder/3.1a1pre MIME-Version: 1.0 To: notmuch@notmuchmail.org References: <1261450617-24616-1-git-send-email-tom@dbservice.com> In-Reply-To: <1261450617-24616-1-git-send-email-tom@dbservice.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [notmuch] [PATCH] Add post-add and post-tag hooks X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 03:18:24 -0000 On 12/22/09 3:56 AM, Tomas Carnecky wrote: > The post-add hook is run by 'notmuch new' after each new message is added, > post-tag is run after a tag has been added or removed. The hooks are stored > in the users home directory (~/.notmuch/hooks/). > > Since post-tag is run unconditionally every time a new tag is added or removed, > that means it is also invoked when 'notmuch new' adds the two implicit > tags (inbox, unread). So make sure your scripts don't choke on that and can > be both executed in parallel. What are these good for? I (try to) use these two hooks to automatically tag messages. But not in the usual way, I don't use static scripts, I use a spam filter. I hope to be able to teach it to classify the messages, not only spam/ham but also add tags such as patch (does that message contain a patch?), tag messages based on which mailing lists the messages belong etc. I use dspam as the spam filter. Each tag is actually a virtual user that exists in dspam. When adding new messages dspam classifies the mails and I assign the tags based on the result. If dspam deemed the message Spam then I set the tag. To train dspam I use the post-tag hook: whenever I change a tag (for example add 'spam' to a falsely unrecognized spam), the post-tag hook retrains dspam. Since the post-add hook is running synchronously with 'notmuch new', this adds quite a bit overhead. Depending on how fast the spam filter is, it adds more or less time to do the import of new messages. It also depends on how many tags you want to assign - dspam has to run once for each tag to see if the tag should be assigned or not. tom --- >8 --- post-add #!/bin/bash # This is so that the post-tag doesn't trigger retraining! export NOTMUCH_POST_ADD=1 MESSAGEID=$1 FILENAME=$2 # Array of tags. tags=( spam ) for tag in "${tags[@]}"; do RESULT="$(/opt/dspam/bin/dspam --user $tag --deliver=summary < $FILENAME)" if echo $RESULT | grep -q 'result="Spam";'; then echo $tag fi done # I remove the inbox flag from all new messages and keep only 'unread' echo "-inbox" --- >8 --- --- >8 --- post-tag #!/bin/sh if [ "$NOTMUCH_POST_ADD" ]; then echo "Exiting due to running in post-add" exit fi MESSAGEID=$1 FILENAME=$2 TAG=$3 ADDREMOVE=$4 if [ "x$ADDREMOVE" = "xadded" ]; then CLASS="spam" else CLASS="innocent" fi /opt/dspam/bin/dspam --user $TAG --source=error --class=$CLASS < $FILENAME --- >8 ---