<<< Date Index >>>     <<< Thread Index >>>

Re: Macro -> procmail recipe



On Sat, Jun 03, 2006 at 07:26:00PM -0400, Dave Waxman wrote:
> I find myself ignoring the same threads in mailings lists constantly.
> While I can of course use the ultimate in subject filtering devices; the
> human brain, I'd prefer something that lets my low capacity system have
> some relief and does the work for me.  What I've been doing is adding
> the specific subject lines to procmail recipes to ignore the threads,
> which works very well.  But when you've got good enough you have to of
> course as a unix user make it better.  I want to make a macro that from
> the index and pager (yes I know two macros) can take the subject of the
> message and add it to a procmail recipe.  
> 
> I am sure it's going to take a bit of a shell script to work with the
> macro and the procmail file.  Now, I know this much and I've an idea ...
> why am I coming to the list?  Quite simple.  I am a salesman by nature
> and trade, I can think of great ideas and sell them; but I couldn't
> implement if my life depended on it.  

The following will accomplish what you want, or at least get you 
started.  Note that in procmail, the ^Subject match is an expression 
that gets evaluated, so I'll leave it as an exercise to figure out how 
to address the issue of a typical subject line being overlong and/or 
containing extraneous characters that would be interpreted incorrectly 
by procmail.

Note also that if you're going to get into the habit of kill-filing 
messages, maintenance will become an issue over time.  I'd suggest 
starting off with a line in your .procmailrc that reads

        INCLUDERC=$PMDIR/path/to/my/subject-filters.rc

and instead of sending the emails to /dev/null, start off by using a 
temporary alternative mbox or location.

You can, of course, make the script interactive, but I've kept it 
rudimentary to illustrate the concept.

#!/usr/bin/perl

# Extract a subject line from an email while in mutt and append 
# it to a procmailrc file as part of a recipe for subsequent 
# processing by procmail.
#
# Usage:  While in mutt's index or pager, pipe the message to this 
# script, or write yourself a macro to accomplish the same.

use strict;
use warnings;

# your procmail rc file (be sure it first exists)
my $procmailrc = "$ENV{HOME}/.procmail/subject-filters.rc";

# prefix a comment to each filter
my $comment = '# Too Boring to Read filter - added';

# add a date for maintainability
my $date = `date`;

# the subject line
my $boringthread;

while (<>) {
        if ( /^\s*Subject:\s*(.*)/ ) {
                $boringthread = $1;
        }
}

open (FILE, ">>$procmailrc") or die "Flaming death! $!\n";
print FILE "$comment $date";
print FILE ":0\n";
print FILE "* ^Subject: $boringthread\n";
print FILE "/dev/null\n\n";

__END__