#!/usr/bin/perl $|=1; # not 0 - then flush after every print/write $name=$ARGV[0]; # 0 ist hier 1. arg, nicht name! nicht wie in c! # *** USE AT YOUR OWN RISK *** # # Public Domain by Eric Auer 2004 # # Usage: Zapp-stupid-mailheaders.pl FILENAME # where FILENAME is the name of a mbox mailbox # # Purpose: removes superfluous / boring kinds # of mail headers, like spam test results and # mailing list standard hint headers like those # who tell you where to mail to unsubscribe. print STDERR "Datei: $name\n"; if ( $name eq "" ) { print STDERR "Kein Name gegeben\n"; die; } if (! -e $name) { print STDERR "$name nicht gefunden\n"; die; } if (! -w $name) { print STDERR "$name nicht schreibbar\n"; die; } print STDERR "$name wird nun gefiltert\n"; $flag=2; open(REIN,"<$name"); @ding=; close(REIN); open(RAUS,">$name"); foreach $line (@ding) { chop $line; # kill trailing LF # # always -> "" -> 2 (body) # 2 (body) -> "^From " -> 1 (header) # 0,1 (...) -> "^[A-Z]+" -> 1 (header) # 0,1 (...) -> "^Received: " -> 0 (kill) ### unnoetig # 0 (kill) (nicht 1!) -> "^ " -> 0 (kill) # if ( $line eq "" ) { $flag=2; } if (( $flag == 2) && ($line =~ /^From\ / )) { $flag=1; } if (( $flag != 2 ) && ( $line =~ /^[A-Za-z-?]+:\ / )) { $flag=1; } if (( $flag != 2 ) && ( $line =~ /^Received:\ / )) { $flag=0; } ### if (( $flag == 0 ) && ( $line =~ /^\ / )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^X-Keywords:/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^Importance:/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^X-MSMail-Priority:/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^Delivered-To:/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^Approved-By:/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^X-NCC-RegID:/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^Comments:/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^Mail-Followup-To:/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^X-Exmh-Isig/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^X-Spam-Report:/ )) { $flag=0; } ### X-Spam-Report is detailled spamassasin result, added to zaplist 8/2004 if (( $flag != 2 ) && ( $line =~ /^X-AntiVirus:/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^X-Greylist:/ )) { $flag=0; } if (( $flag != 2 ) && ( $line =~ /^List-/ )) { $flag=0; } ## List-Unsubscribe: List-Id: List-Post: List-Help: List-Subscribe: ... ##// if (( $flag == 0 ) && ( $line =~ /^List-Archive:/ )) { $flag=1; } ##// but not: List-Archive: ... for SourceForge / Mailman lists (8/2004) # print STDERR "$flag $line\n"; if ( $flag != 0 ) { print RAUS "$line\n"; } }; close(RAUS); ### Tipps von Arne 3/00: # if ($flag!=2) { # $_=$line; # $flag=0 if /^Received:/ || /^X-Keywords:/ || # /^Importance:/ || /^X-MSMail-Priority:/ || # /^Delivered-To:/ || /^Approved-By:/ || # /^X-NCC-RegID:/ || /^Comments:/ || # /^Mail-Followup-To:/ || /^X-Exmh-Isig/; # } # # An der Formatierung kann man dann noch drehen, oder gar die Header # auslagern: # # my @headers=('Received','X-Keywords','Importance','X-MSMail-Priority', # 'Delivered-To','Approved-By','X-NCC-RegID','Comments','Mail-Followup-To', # 'X-Exmh-Isig'); # [...] # $flag=0 if grep {$line =~ /^$_:/; } (@headers);