]> git.deb.at Git - pkg/t-prot.git/blobdiff - t-prot
Merge branch 'upstream'
[pkg/t-prot.git] / t-prot
diff --git a/t-prot b/t-prot
index 936928c9a38720acaada34f0db0069d8317bc933..ee846679214fb2c073f421d2579e3e529888f584 100755 (executable)
--- 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.236 2005/04/25 16:35:56 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            => '1.101';
 use constant REV            => '';
-use constant REL            => q$Revision: 1.230 $=~m/(\d+(?:\.\d+)+)/;
+use constant REL            => q$Revision: 1.236 $=~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
@@ -90,6 +90,8 @@ sub help {
   -A=DIRECTORY    ad footer directory, treat ad footers as signature
   --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
@@ -425,17 +427,24 @@ sub process_msg {
 
     # First, remove and store lines we might need later...
     # Remove headers:
-    for ($x=0; $x<$#$lines; $x++) { if (@$lines[$x] =~ /^$/) { last; }; }
-    @hdr = @$lines[0..$x];
-    splice(@$lines, 0, $x+1);
+    if (!$nohdr) {
+        for ($x=0; $x<$#$lines; $x++) { if (@$lines[$x] =~ /^$/) { last; }; }
+        @hdr = @$lines[0..$x];
+        splice(@$lines, 0, $x+1);
+    }
     # remember the original body lines count
     my $linecount = scalar(@$lines);
 
+    # Remove ML footers:
+    remove_footers($lines, \@ftr, $footers, undef, $ftr_ml);
+
+    # Remove ad footers:
+    remove_footers($lines, \@ads, $ads, undef, $ftr_ad);
 
     # See if we have a multipart content type. If yes, see if it is already
-    # ripped (e.g. by mutt(1)), otherwise only leave the first part if it
-    # is plain text (if not, we are done - non-text messages are not our
-    # business).
+    # ripped (e.g. by you MUA, assuming it does not get special treatment with
+    # --mua=foo), otherwise only leave the first part if it is plain text (if
+    # not, we are done - non-text messages are not our business).
     if ($mua ne 'mutt') { 
         for ($x=0; $x<scalar(@hdr); $x++) {
             if ($hdr[$x] =~ /^Content-Type:\s+(.*)$/i) {
@@ -483,6 +492,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 { 
@@ -525,12 +540,6 @@ sub process_msg {
         }
     }
 
-    # Remove ML footers:
-    remove_footers($lines, \@ftr, $footers, undef, $ftr_ml);
-
-    # Remove ad footers:
-    remove_footers($lines, \@ads, $ads, undef, $ftr_ad);
-
     if ($mua eq 'mutt') {
         # See if we find pgp output generated by mutt before we scramble
         # the thing. If yes, see if we can beautify it.
@@ -848,16 +857,16 @@ my $locale = $ENV{'LC_ALL'}?$ENV{'LC_ALL'}:($ENV{'LC_MESSAGES'}?$ENV{'LC_MESSAGE
 
 # command line switches
 ($ad, $ads, $bigqn, $bigqx, $check, $cr, $sysl, $diff, $elli, $footers, $lax,
-    $ml, $ms, $ms_smart, $mda, $mua, $hdrs, $kamm, $lsig, $sig, $sigint,
+    $ml, $ms, $ms_smart, $mda, $mua, $hdrs, $kamm, $lsig, $nohdr, $sig, $sigint,
     $spass, $trad, $trsp) =
-    (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+    (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
 my $ifile   = '-';    # use STDIN if nothing specified
 
 # get command line params:
 Getopt::Mixed::init('a A=s c d e h i=s k L=s l m M=s o=s P=s p:s r S:i'.
-    ' s t v w bigq:s 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');
+    ' 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 +876,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 +931,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(); }