how to kill mail threads i dont care about - someone w procmail skill?

Todd Zullinger tmz at pobox.com
Sat Jul 11 04:50:50 UTC 2009


Mail Lists wrote:
>  Every once in a while I want to not read any posts or any followups
> when they are initiated by a certain person - or on a specific topic/
> Topics are easy to killfile coz we only need to match the subject.
>
>  Anyone got any ideas (procmail probably simplest) how to kill an entire
> mail thread if that thread is started by a specific email address ?

I've got one, and it looks quite a bit like what you outlined below in
psuedo-code. ;)

In my procmail config, I have these two recipes:

# drop mail from anyone in the killfile
:0 W
* ? formail -x"From" -x"From:" -x"Sender:" -x"Reply-To:" -x"Return-Path:" \
    | egrep -is -f $HOME/.procmail/killfile
{
    # add it to the killthread cache
    :0 Wic: killthread.lock
    | formail -D 40960 $HOME/.procmail/killthread.cache

    :0
    killfiled/
}

# drop threads started by anyone in the killfile
:0
* ? formail -c -x 'References' -x 'In-Reply-To' | thread-kill
killfiled/

The thread-kill script is a little bit of python:

#!/usr/bin/python

import os
import sys

verbose = False
if len(sys.argv) > 1:
    if sys.argv[1] == '-v':
        verbose = True

cache = os.path.expanduser('~/.procmail/killthread.cache')
if not os.path.exists(cache):
    raise SystemExit(1)

killed = [i for i in open(cache).read().strip('\x00').split('\x00') if i]
if verbose:
    print killed
    print

msgids = [i for l in sys.stdin.readlines() for i in l.split() if i]
if verbose:
    print msgids
    print

for m in msgids:
    if verbose:
        print 'checking if %s matches...' % m,
    if m in killed:
        if verbose:
            print 'yes'
        raise SystemExit(0)
    elif verbose:
        print 'no'

raise SystemExit(1)

My $HOME/.procmail/killfile generally just contains a few email
addresses, though it could contain regular expressions if more
flexibility is desired.

>  I think the logic could be something like ( there may be better
>  ways to do this)
>
>   If (<from> matches <target>)
>          append Message-ID to message_id_list
>          junk message.
>
> Loop (ID from message_id_list)
>     If (any mail has References matching ID
>         junk message;
>
>
>  Of course message_id_list is a growing list and should probably be
>  culled every week (or something).

The beauty of using formail's -D option is that it will do this
culling for you, based on size.

Fortunately, I don't feel the need to use this very often, so I have
not gotten around to improving it much in a long time.  One minor
improvement I intend to make some afternoon is to add a mutt macro to
drop message-ids for threads I want to die directly into the the
killthread cache.

-- 
Todd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The most useful piece of learning for the uses of life is to unlearn
what is untrue.
    -- Antisthenes

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 542 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20090711/78c8d828/attachment-0001.sig>


More information about the fedora-list mailing list