1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#!/usr/bin/perl -T
#
# Test stripping signatures
#
use strict;
use warnings;
use lib qw(. .. tests);
use Tools;
use Test::More tests => 37;
use Mail::Message::Body::Construct;
use Mail::Message::Body;
#
# No strip possible
#
my @lines = map { "$_\n" } qw/1 2 3 4 5/;
my $body = Mail::Message::Body::Lines->new(data => \@lines);
my ($stripped, $sig) = $body->stripSignature;
my $equal = $stripped==$body;
ok($equal, 'stripped 1');
ok(!defined $sig);
cmp_ok($stripped->nrLines, "==", @lines);
my $stripped2 = $body->stripSignature;
$equal = $stripped2==$body;
ok($equal, 'stripped 2');
#
# Simple strip
#
@lines = map { "$_\n" } qw(a b -- sig);
$body = Mail::Message::Body::Lines->new(data => \@lines);
($stripped, $sig) = $body->stripSignature;
ok($stripped!=$body);
ok($sig!=$body);
cmp_ok($stripped->nrLines, "==", 2);
my @stripped_lines = $stripped->lines;
cmp_ok(@stripped_lines, "==", 2);
is($stripped_lines[0], $lines[0]);
is($stripped_lines[1], $lines[1]);
cmp_ok($sig->nrLines, "==", 2);
my @sig_lines = $sig->lines;
cmp_ok(@sig_lines, "==", 2);
is($sig_lines[0], $lines[2]);
is($sig_lines[1], $lines[3]);
#
# Try signature too large
#
@lines = map { "$_\n" } qw/1 2 3 -- 4 5 6 7 8 9 10/;
$body = Mail::Message::Body::Lines->new(data => \@lines);
($stripped, $sig) = $body->stripSignature(max_lines => 7);
ok(!defined $sig);
cmp_ok($stripped->nrLines, "==", 11);
($stripped, $sig) = $body->stripSignature(max_lines => 8);
cmp_ok($sig->nrLines, "==", 8);
@sig_lines = $sig->lines;
cmp_ok(@sig_lines, "==", 8);
is($sig_lines[0], $lines[3]);
is($sig_lines[1], $lines[4]);
is($sig_lines[-1], $lines[-1]);
cmp_ok($stripped->nrLines, "==", 3);
@stripped_lines = $stripped->lines;
cmp_ok(@stripped_lines, "==", 3);
is($stripped_lines[0], $lines[0]);
is($stripped_lines[1], $lines[1]);
is($stripped_lines[2], $lines[2]);
#
# Try whole body is signature
#
@lines = map { "$_\n" } qw/-- 1 2 3 4/;
$body = Mail::Message::Body::Lines->new(data => \@lines);
($stripped, $sig) = $body->stripSignature(max_lines => 7);
cmp_ok($sig->nrLines , "==", 5);
ok(defined $stripped);
cmp_ok($stripped->nrLines , "==", 0);
#
# Try string to find sep
#
@lines = map { "$_\n" } qw/1 2 3 abc 4 5 6/;
$body = Mail::Message::Body::Lines->new(data => \@lines);
($stripped, $sig) = $body->stripSignature(pattern => 'b');
ok(!defined $sig);
($stripped, $sig) = $body->stripSignature(pattern => 'a');
cmp_ok($sig->nrLines , "==", 4);
#
# Try regexp to find sep
#
@lines = map { "$_\n" } qw/1 2 3 abba baab 4 5 6/;
$body = Mail::Message::Body::Lines->new(data => \@lines);
($stripped, $sig) = $body->stripSignature(pattern => qr/b{2}/);
ok($sig);
cmp_ok($sig->nrLines , "==", 5);
cmp_ok($stripped->nrLines , "==", 3);
#
# Try code to find sep
#
@lines = map { "$_\n" } qw/1 2 3 ab 4 5 6/;
$body = Mail::Message::Body::Lines->new(data => \@lines);
($stripped, $sig) = $body->stripSignature(pattern => sub {$_[0] eq "ab\n"});
ok($sig);
cmp_ok($sig->nrLines , "==", 4);
cmp_ok($stripped->nrLines , "==", 3);
|