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