X-Git-Url: https://git.deb.at/w?p=pkg%2Ft-prot.git;a=blobdiff_plain;f=t-prot;h=20f3119f5b4e607e4af69bb62321b66258aaac26;hp=936928c9a38720acaada34f0db0069d8317bc933;hb=refs%2Fheads%2Fsarge-backports;hpb=1011125442839e1dcca4fd04c64c4d0810f281c7 diff --git a/t-prot b/t-prot index 936928c..20f3119 100755 --- a/t-prot +++ b/t-prot @@ -1,13 +1,13 @@ #!/usr/bin/perl -w -# $Id: t-prot,v 1.230 2005/03/24 22:24:29 jochen Exp $ +# $Id: t-prot,v 1.250 2006/12/19 13:13:57 jochen Exp $ require 5.006; use strict; use Fcntl qw(O_EXCL O_WRONLY O_CREAT); use Getopt::Mixed qw(nextOption); -use constant VER => '1.99'; +use constant VER => '2.3'; use constant REV => ''; -use constant REL => q$Revision: 1.230 $=~m/(\d+(?:\.\d+)+)/; +use constant REL => q$Revision: 1.250 $=~m/(\d+(?:\.\d+)+)/; # MTA expecting mail on STDIN # (you might have to adjust this if using a different MTA) use constant SENDMAIL => '/usr/sbin/sendmail -oi'; @@ -24,8 +24,8 @@ use vars qw( $ad $ads $bigqn $bigqx $boun $check $check_ratio $cr $diff $elli $footers $ftr_ad $ftr_ml $hdrs $indent $kamm $kdiff $kminl $kmaxl $lax $lsig $maxsig $mda $ml $ms $ms_smart $msg_quote $msg_ratio - $mua $ofile $pgpshort $pgpmove $pgpmovevrf $sig $sigint $sign - $spass $spass_prefix $sysl $trad $trsp + $mua $nohdr $ofile $pgpshort $pgpmove $pgpmovevrf $sig $sigint + $sign $spass $spass_prefix $sysl $trad $trsp $gpg_WARNING $gpg_Warning $gpg_Cantcheck $gpg_aka $gpg_bad $gpg_expired $gpg_good $gpg_bug @@ -86,10 +86,12 @@ $gpg_bug = '... this is a bug ('; # help(): print help text and exit with appropriate exit code sub help { print "Usage: $0 [options] - -a remove ad footers; requires -A -A=DIRECTORY ad footer directory, treat ad footers as signature + -a remove ad footers; requires -A --bigq[=n[,x]] remove all but x lines of quotes with more than n lines; default is n=30 and x=10 + --body input has no headers; does not work with --pgp-short; + multipart messages will not be detected -c merge multiple blank lines --check[=FLAGS] check various criteria, print error message and quit; see man page for details @@ -250,7 +252,7 @@ sub decomb { ($$L[$x+1] !~ /^[\s^]/) && ($$L[$x] !~ /-$/) && ($$L[$x+1] !~ /^\Q[...]\E\s*$/) && - ($mua ne 'mutt' || $$L[$x+1] !~ /^(?:\e.+?\a)?\[-- .* --]/) && + ($mua ne 'mutt' || $$L[$x+1] !~ /^(?:\e[^\a]+\a)?\[-- /) && (length($$L[$x])+index($$L[$x+1], ' ')>$max || (index($$L[$x+1], ' ')<0 && length($$L[$x])+length($$L[$x+1])>$max)) && (length($$L[$x])+length($$L[$x+1])<$kmaxl) && @@ -309,11 +311,14 @@ sub pgp { my $ok = 0; while ($X<$Z) { - if ($$L[$X] =~ /^gpg:\s(?:\Q$gpg_WARNING\E|\Q$gpg_Warning\E|\Q$gpg_bad\E|\Q$gpg_Cantcheck\E|\Q$gpg_expired\E)/o) + if (index($$L[$X], "gpg: $gpg_WARNING")==0 || + index($$L[$X], "gpg: $gpg_Warning")==0 || + index($$L[$X], "gpg: $gpg_bad")==0 || + index($$L[$X], "gpg: $gpg_Cantcheck")==0 || + index($$L[$X], "gpg: $gpg_expired")==0 || + index($$L[$X], "gpg: $gpg_bug")==0) { return 0; } - if ($$L[$X] =~ /^gpg:\s\Q$gpg_bug/o) - { return 0; } - if ($$L[$X] =~ /^gpg:\s\Q$gpg_good/o) + if (index($$L[$X], "gpg: $gpg_good")==0) { $ok = 1; } $X++; } @@ -331,32 +336,34 @@ sub pgp { for (my $x=0; $x1 && - $$L[$i] =~ /^gpg:\s\Q$gpg_aka/o && $$L[$i] !~ /\Q$from/) + index($$L[$i], "gpg: $gpg_aka")==0 && + index($$L[$i], $from)<0) { splice(@$L, $i, 1); splice(@$V, $i, 1); $i--; } - elsif ($$L[$i]=~/^(?:\e.+?\a)?(?:\Q$mutt_pgpoutend\E)/o) + elsif ($$L[$i]=~/^(?:\e[^\a]+\a)?(?:\Q$mutt_pgpoutend\E)/o) { if ($pgpmove || ($pgpmovevrf && (!$sigint) && verified($L, $x+1, $i))) @@ -372,7 +379,12 @@ sub pgp { } } elsif ($tmp && - $$L[$x]=~/^(?:\e.+?\a)?(?:\Q$mutt_pgpencrypted\E|\Q$mutt_pgpclearsigned\E|\Q$mutt_pgpsigned\E)/o) + $$L[$x] =~ /^ + (?:\e[^\a]+\a)? + (?:\Q$mutt_pgpencrypted\E | + \Q$mutt_pgpclearsigned\E| + \Q$mutt_pgpsigned\E) + /ox) { splice(@$L, $x+1, 0, @{$tmp[$tmp]}); for (my $i=$x; $i=scalar(@$lines)) { exit(EX_DATAERR); } - if ($bar =~ /^text\/plain/i) { + if ($bar =~ m!^text/plain!) { my $z; for ($z=1; $x+$z<@$lines; $z++) { if (index($$lines[$x+$z], '--'.$foo)==0) { @@ -483,6 +502,12 @@ sub process_msg { } @bo1 = @$lines[0..$x]; splice(@$lines, 0, $x+1); + + # remove mailing list and ad footers within this + # attachment: + remove_footers($lines, \@ftr, $footers, undef, $ftr_ml); + remove_footers($lines, \@ads, $ads, undef, $ftr_ad); + last; } else { @@ -514,7 +539,7 @@ sub process_msg { for ($x=0; $x=0; $x--) { - if ((!$vrb[$x]) && $$lines[$x] =~ /^-- $/) { - if ($diff) { - for (my $i=1; $x+$i+1$lsig))) { - if ($lsig && !$sig) { - unshift(@sig, "[---=| Overlong signature removed by $0: " . - (scalar(@$lines)-$x) . " lines snipped |=---]\n"); + if ($sig || ($lsig && ($#$lines-$x-$empty>$lsig))) { + if ($lsig && !$sig) { + unshift(@sig, "[---=| Overlong signature removed by $0: " . + (scalar(@$lines)-$x) . " lines snipped |=---]\n"); + } + splice(@$lines, $x); } - splice(@$lines, $x); - } - else { - unshift(@sig, @$lines[$x..$#$lines]); - splice(@$lines, $x); + else { + unshift(@sig, @$lines[$x..$#$lines]); + splice(@$lines, $x); + } + if (defined($sign) && ++$sn==$sign) { last; } else { next; } } - if (defined($sign) && ++$sn==$sign) { last; } else { next; } + # any trailing newlines? + elsif ($chk_empty && $$lines[$x] =~ /^\s*$/) { $empty++; } + elsif ($chk_empty) { $chk_empty = 0; } } } } @@ -642,6 +684,7 @@ sub process_msg { if ($ms) { # bloat this array if you want more internationalization: my @tofu = ('Original Message', + 'Original-Nachricht', 'Ursprüngliche Nachricht', 'Ursprungliche Nachricht', 'Mensagem original', @@ -667,16 +710,21 @@ sub process_msg { if ((!$k) && $$lines[$x] !~ /^\s*$/o && ((!$mua) || ($mua eq 'mutt' && - $$lines[$x] !~ /^(?:\e.+?\a)?(?:\Q$mutt_attachment\E)/o && - $$lines[$x] !~ /^(?:\e.+?\a)?(?:\Q$mutt_contenttype\E)/o)) && - ((!$spass) || $$lines[$x]!~/^\Q$spass_prefix/o)) + $$lines[$x] !~ + /^(?:\e[^\a]+\a)?(?:\Q$mutt_attachment\E)/o && + $$lines[$x] !~ + /^(?:\e[^\a]+\a)?(?:\Q$mutt_contenttype\E)/o)) && + ((!$spass) || index($$lines[$x], $spass_prefix)!=0)) { if ($mua eq 'mutt' && (!$tmp) && - $$lines[$x] =~ /^(?:\e.+?\a)?(?:\Q$mutt_pgpoutstart\E)/o) { + $$lines[$x] =~ + /^(?:\e[^\a]+\a)?(?:\Q$mutt_pgpoutstart\E)/o) { $tmp = 1; } elsif ($mua eq 'mutt' && $tmp && - ($$lines[$x] =~ /^(?:\e.+?\a)?(?:\Q$mutt_beginsigned\E)/o || - $$lines[$x] =~ /^(?:\e.+?\a)?(?:\Q$mutt_pgpclearsigstart\E)/o)) { + ($$lines[$x] =~ + /^(?:\e[^\a]+\a)?(?:\Q$mutt_beginsigned\E)/o || + $$lines[$x] =~ + /^(?:\e[^\a]+\a)?(?:\Q$mutt_pgpclearsigstart\E)/o)) { $tmp = 0; } elsif (!$tmp) { $k = 1; @@ -694,17 +742,19 @@ sub process_msg { my $p = 0; # levels of pgp signed parts for (my $i=$x+1; $id diff ftr-ad ftr-ml help>h kminl=i'. - ' kmaxl=i kdiff=i lax-security locale=s ms-smart mua>M pgp-short'. - ' pgp-move pgp-move-vrf sigsmax:i spass version>v'); + ' s t v w bigq:s body check:s debug>d diff ftr-ad ftr-ml help>h'. + ' kminl=i kmaxl=i kdiff=i lax-security locale=s ms-smart mua>M'. + ' pgp-short pgp-move pgp-move-vrf sigsmax:i spass version>v'); while (my ($opt, $val, $pretty) = nextOption()) { if ($opt eq 'a') { $ad = 1; } elsif ($opt eq 'A') { $ads = $val; } @@ -867,6 +917,7 @@ while (my ($opt, $val, $pretty) = nextOption()) { $bigqx = $2?$2:10; if ($bigqn<=0 || $bigqx<=0 || $bigqn<=$bigqx) { help(); } } + elsif ($opt eq 'body') { $nohdr = 1; $hdrs = 1; } elsif ($opt eq 'c') { $cr = 1; } elsif ($opt eq 'check') { $check = 1; @@ -921,6 +972,7 @@ while (my ($opt, $val, $pretty) = nextOption()) { Getopt::Mixed::cleanup(); if (($ml && $footers eq '')|| # no -l without -L ($ad && $ads eq '')|| # no -a without -A + ($nohdr && $pgpshort)|| # --body and --pgp-short are like oil and water ($ifile eq '')|| # no empty -i ($ofile eq '')) # no empty -o { help(); } @@ -933,57 +985,57 @@ if ($mua eq 'mutt') { Locale::gettext::textdomain('mutt'); ($mutt_attachment) = Locale::gettext::gettext("[-- Attachment #%d") =~ - m/^([^%]*)/o; + m/^([^%]*)/; ($mutt_contenttype) = Locale::gettext::gettext("[-- Type: %s/%s, Encoding: %s, Size: %s --]\n") =~ - m/^([^%]*)/o; + m/^([^%]*)/; ($mutt_pgpsigned) = Locale::gettext::gettext("[-- End of signed data --]\n") =~ - m/^(.*?)\n/mo; + m/^(.*)\n/m; ($mutt_beginsigned) = Locale::gettext::gettext("[-- The following data is signed --]\n\n") =~ - m/^(.*?)\n/mo; + m/^(.*)\n/m; ($mutt_pgpclearsigned) = Locale::gettext::gettext("[-- END PGP SIGNED MESSAGE --]\n") =~ - m/^(.*?)\n/mo; + m/^(.*)\n/m; ($mutt_pgpclearsigstart) = Locale::gettext::gettext("[-- BEGIN PGP SIGNED MESSAGE --]\n") =~ - m/^(.*?)\n/mo; + m/^(.*)\n/m; ($mutt_pgpencrypted) = Locale::gettext::gettext("[-- End of PGP/MIME encrypted data --]\n") =~ - m/^(.*?)\n/mo; + m/^(.*)\n/m; ($mutt_pgpoutstart) = Locale::gettext::gettext("[-- PGP output follows (current time: %c) --]\n") =~ - m/^([^%]*)/o; + m/^([^%]*)/; ($mutt_pgpoutend) = Locale::gettext::gettext("[-- End of PGP output --]\n") =~ - m/^(.*?)\n/mo; + m/^(.*)\n/m; Locale::gettext::textdomain('gnupg'); ($gpg_WARNING) = Locale::gettext::gettext("WARNING: using insecure random number generator!!\n") =~ - m/^(.*?: )/o; + m/^([^:]*: )/; ($gpg_Warning) = Locale::gettext::gettext("WARNING: message was encrypted with a weak key in the symmetric cipher.\n") =~ - m/^(.*?: )/o; + m/^([^:]*: )/; ($gpg_Cantcheck) = Locale::gettext::gettext("Can't check signature: %s\n") =~ - m/^([^%]*)/o; + m/^([^%]*)/; ($gpg_aka) = Locale::gettext::gettext((' 'x16).'aka "%s"') =~ - m/^(.*?)["«%]/o; + m/^([^"«%]*)["«%]/; ($gpg_bad) = Locale::gettext::gettext('BAD signature from "%s"') =~ - m/^(.*?)["«%]/o; + m/^([^"«%]*)["«%]/; ($gpg_expired) = Locale::gettext::gettext("Note: This key has expired!\n") =~ - m/^(.*?)\n/mo; + m/^(.*)\n/m; ($gpg_good) = Locale::gettext::gettext('Good signature from "%s"') =~ - m/^(.*?)["«%]/o; + m/^(([^"«%]*))["«%]/; ($gpg_bug) = Locale::gettext::gettext("... this is a bug (%s:%d:%s)\n") =~ - m/^([^%]*)/o; + m/^([^%]*)/; } }