thread_killer



For anyone using procmail and has as little patience as I, I am
including a script to make mailing list threads disappear at the press
of a button (including future submissions). Instructions are included
for making a mutt macro.

The inspiration are all those threads that seem to go on forever, go way
off topic and/or feed trolls. This is not to criticize those that
participate in such discussions. Partially, at least, it helps me
resist the temptation to get involved.

The script could probably stand improvement, and I'd appreciate to be
back fed any such efforts. Apologies in advance to anyone who really
knows perl. I haven't used this in a while but it seems to be working
OK.

#!/usr/bin/perl
#
# thread_killer.pl v1.2 06/18/03
#
# Description: This script adds a procmail recipe to delete mail that
# matches the Subject line of the current mail (ie in the mutt index). It is
# meant to be used as a mutt macro. The idea is to delete the current mail,
# the entire thread that may be started by this mail, *and* any future mail
# for this thread. One stop shopping.
#
# Assumptions
#
# .procmailrc is the name of the procmail config file to diddle with, and it
# exists in the users $HOME. This script will be looking for a line containing
# the keywords: BEGIN _THREAD_KILLER, as an indicator of where to create the
# thread killing recipe. Make sure it exists.
#
# .muttrc macro:
#
# macro index A "<pipe-entry>thread_killer.pl\n\
# <delete-thread>\n"
#
#
# ChangeLog:
#
# v1.2a 10/19/08 - A few, better config related comments.
#
# v1.2 06/18/03 - Added LOG entry.
#
# v1.1 05/28/03 - Add rc file support.
#
#
# Inspired by: inane postings on Red Hat mailing lists ;-)
#
# License: Public domain
#
# By: Hal Burgiss <hal@xxxxxxxxxx>
#
#######################################################################

# Typically this will be $HOME/.procmailrc.
$file="$ENV{HOME}/.procmailrc";

# number of spaces (integer only) to pad left margin (just
# for looks):
$offset=0;

# where to send the unwanted mails
#$destination='$test';
#$destination="/dev/null";
$destination="/tmp/ubuntu-list.tmp";

# name of backup file to keep
$backup="$file.bak";

# Uncomment to turn on some verbose output
#$debug=1;

$rc_file="$ENV{HOME}/.thread_killer.rc";

## Probably no editing needed below this point ########################
chomp($moi=`basename $0`);
$tmpfile="/tmp/$moi-$ENV{USER}";
chomp($date=`date`);

&read_rcfile;

# convert num to number of spaces
$offset=pack("A$offset","");

$data_out=0;

# read the mail ...
while (<STDIN>) {
$debug && print "Current Line: $_";

if (/^Subject: (.*)/) {
# Get our subject line, clean it up, and rebuild it.
$subject = "$1";
$subject =~ s/ *$//;
$subject =~ s/R[eE]: //g;
$subject =~ s/(\.|\?|\*|\$|\+|\^|\[|\]|\(|\))/\\$1/g;
$subject = "Subject: (Re:|RE:|Fwd:|SV:)* *$subject";
close STDIN;
}
# print "$_\n";

}

$debug && print "SUB: $subject\nDATE: $date\n";

if ( ! defined($subject) ) {
$debug && print "Error, no data, bugging out now\n";
exit 1;
}

open(FD, "$file") || die "Can't find $file, exiting.";
open(TMP, ">$tmpfile") || die "Can't create tmpfile: $tmpfile, exiting.";
open(BAK, ">$backup") || die "Can't create backup file $backup, exiting.";

# read, then write procmailrc
while (<FD>) {
print BAK "$_";
print TMP "$_";
if (/BEGIN _THREAD_KILLER/) {
$debug && print "Hit THREAD_KILLER keyword now\n";
# if we hit a thread_killer keyword midstream, write our recipe now
# to our tmp_file.
&write_out;
}

}

! $data_out && &write_out;

system "mv -f $tmpfile $file" || print "Error writing new $file\n";

close FD;
close TMP;
close BAK;

sub write_out {
# write our recipe based on current Subject line to disk:
print TMP
"\n$offset# added by $moi at _KILL_DATE_: $date
$offset:0HD
$offset* ^$subject\$
$offset \{ LOG=\"Threadkill: \"\n
$offset :0:
$offset $destination
$offset \}\n";

# set flag after writing our recipe.
$data_out=1;

}

sub read_rcfile {
if (open(RC,$rc_file)) {
while (<RC>) {
# $output=$_;
$_ =~ s/\n$//g;
$_ =~ s/^ *//g;
$_ =~ s/ *$//g;
$_ =~ s/;$//g;
$_ =~ s/ *= */=/;
$_ =~ s/\$HOME/\$ENV{HOME}/;
$_ =~ s/\~\//\$ENV{HOME}\//;
if (m/^#/) {
} elsif (m/^offset=(\d+)/) {
$offset=$1;
} elsif (m/^file=(.*)/) {
$file=eval("$1");
} elsif (m/^backup=(.*)/) {
$backup=eval("$1");
} elsif (m/^destination=(.*)/) {
$destination=eval("$1");
} elsif (m/^debug=(.*)/) {
$debug=1;
}

}
close(RC);
}

}

#--- eof thread_killer.pl


--
Hal


--
ubuntu-users mailing list
ubuntu-users@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users



Relevant Pages

  • UPDATE: mailing list management
    ... I'm using an older version of PINE, there's no filtering. ... I prefer a procmail or script, as I might migrate to a different mail ... > At the present, all mailing lists are dump in INBOX, which is chaotic. ... > Server is standard with solaris, sendmail, procmail and I'm using PINE. ...
    (SunManagers)
  • OT: procmail recipe/bash scripting issue
    ... processes mail to a web page. ... Here's the recipe: ... If I run the script from the command line iwth a message as input ... however, when I use the procmail recipe, I get this: ...
    (Debian-User)
  • Re: procmail copying to folder, not moving
    ... I've pasted my complete current .procmailrc file below, ... there would be so much interest--try searching the xml-dev or rdf-list mailing lists for "Bob DuCharme." ... One way to make sure that procmail does not fall through waiting for the ... lock is to check after every script if that was the case and if so ...
    (comp.mail.misc)
  • Re: procmail recipe for a given message body
    ... Some of you experienced with procmail hopefully can help me out ... to filter these messages out. ... recipe for that. ... filter messages based on regular expression matches on the "body" ...
    (comp.unix.bsd.freebsd.misc)
  • Re: receive mails through php
    ... PHP script). ... the mail to a file *and* the command, so when the first try blows ... SOME distros use procmail as a default. ... and a copy to your normal mailbox ...
    (comp.lang.php)