#!/usr/bin/perl # # premutt is called by a mutt macro and receives the mail message. # It processes the message and pipes the output to 'metamutt -D' to # split a digest message. premutt corrects 'From:' lines on individual # messages by removing unrequired spaces before 'From:' and adding a # copy of the 'To:' line, to facilitate replies to the separate digest # messages. # # Copyright (C), Brian Salter-Duke, 2002. # # This script is free software. # # Useage in muttrc # macro index S "| premutt | metamutt -D\n" # macro pager S "| premutt | metamutt -D\n" $b = ''; $a = 1; $t = '/tmp/pre.$$'; open (TEMP,"> $t") || die "Can not open $t for writing"; while () { chop; $i = $_; # Get To: line from first headers. if (($a) && ($i =~ /^To:/)) { $b = $i; $a = 0; } # Assume that the From: line we are looking for has up to 8 # spaces at the beginning and any From: line in the digest # index has more than 8 spaces at the front. Not all digest # indices have From: Lines in them, but some do. Note that # even when From: line is correct, we still do this to add the # Reply-To: line. if ($i =~ /^ {0,8}From:/) { $i =~ s/^ *//; print TEMP "$i\n"; print TEMP "$b\n" unless $b eq ''; } else { print TEMP "$i\n"; } } close (TEMP); # OK, we might as well clean up the 'Date:' lines that have spaces # before 'Date:'. Someone might find it useful. open (TEMP,"< $t") || die "Can not open $t for reading"; while () { chop; $i = $_; if ($i =~ /^ *Date:/) { $i =~ s/^ *//; } print "$i\n"; } close (TEMP); unlink $t if -e $t;