File Coverage

blib/lib/Mail/ListDetector/Detector/Mailman.pm
Criterion Covered Total %
statement 61 65 93.8
branch 25 48 52.0
condition 3 6 50.0
subroutine 8 8 100.0
pod 1 2 50.0
total 98 129 75.9


line stmt bran cond sub pod time code
1             package Mail::ListDetector::Detector::Mailman;
2              
3 39     39   219 use strict;
  39         77  
  39         1668  
4 39     39   212 use warnings;
  39         64  
  39         1755  
5              
6 39     39   218 use base qw(Mail::ListDetector::Detector::Base);
  39         80  
  39         25638  
7 39     39   22972 use Mail::ListDetector::List;
  39         108  
  39         1145  
8 39     39   238 use Carp;
  39         77  
  39         13389  
9              
10 114     114 0 422 sub DEBUG { 0 }
11              
12             sub match {
13 46     46 1 107 my $self = shift;
14 46         113 my $message = shift;
15 46 50       193 print "Got message $message\n" if DEBUG;
16 46 50       188 carp ("Mail::ListDetector::Detector::Mailman - no message supplied") unless defined($message);
17 39     39   35825 use Email::Abstract;
  39         15301212  
  39         35175  
18 46         506 my $version = Email::Abstract->get_header($message, 'X-Mailman-Version');
19 46 100       5071 chomp $version if defined $version;
20 46 100 66     285 if ((!defined $version) or $version =~ /^\s*$/) {
21 42 50       163 print "Returning undef - couldn't find mailman version - $version\n" if DEBUG;
22 42         600 return undef;
23             }
24 4 50       14 print "Mailman version $version\n" if DEBUG
25             my $list;
26 4         31 $list = new Mail::ListDetector::List;
27 4         25 $list->listsoftware("GNU Mailman version $version");
28              
29 4         19 my $sender = Email::Abstract->get_header($message, 'Sender');
30 4 50 33     276 print "Sender is $sender\n" if DEBUG && defined $sender;
31             # return undef unless defined $sender;
32 4         7 my $poss_posting_address;
33              
34 4 100       23 if (defined $sender) {
35 2         5 chomp $sender;
36 2 50       21 if ($sender =~ /^(([^@]+)-(admin|owner|bounces)(?:\+[^@]+)?\@(\S+))$/) {
    0          
37 2 50       6 print "sender matches pattern\n" if DEBUG;
38 2         12 $list->listname($2);
39 2 50       7 print "Listname is $2\n" if DEBUG;
40 2         12 $poss_posting_address = $2 . '@' . $4;
41 2 50       15 print "Possible posting address is $poss_posting_address\n" if DEBUG;
42             } elsif ($sender =~ /^((admin|owner)-([^@]+)\@(\S+))$/) {
43 0         0 $list->listname($3);
44 0         0 $poss_posting_address = $3 . '@' . $4;
45 0 0       0 print "Listname is $3\n" if DEBUG;
46 0 0       0 print "Possible posting address is $poss_posting_address\n" if DEBUG;
47             }
48             } else {
49             # fallback way to guess posting address and list name.
50 2         11 my $beenthere = Email::Abstract->get_header($message, 'X-BeenThere');
51 2 50       156 return undef unless defined $beenthere;
52 2 50       6 print "X-BeenThere is $beenthere\n" if DEBUG;
53 2         5 $poss_posting_address = $beenthere;
54 2         5 chomp $poss_posting_address;
55 2 50       15 if ($beenthere =~ /^([^@]+)\@/) {
56 2         9 $list->listname($1);
57             }
58             }
59              
60 4         10 my $posting_address;
61 4         16 my $list_post = Email::Abstract->get_header($message, 'List-Post');
62 4 100       301 if (defined $list_post) {
63 2 50       4 print "Got list post $list_post\n" if DEBUG;
64 2 50       11 if ($list_post =~ /^\]*)\>$/) {
65 2         5 $posting_address = $1;
66 2 50       4 print "Got posting address $posting_address\n" if DEBUG;
67 2         8 $list->posting_address($posting_address);
68             }
69             } else {
70 2 50       5 print "Got posting address $poss_posting_address\n" if DEBUG;
71 2         10 $list->posting_address($poss_posting_address);
72             }
73              
74 4 50       9 print "Returning object $list\n" if DEBUG;
75 4         26 return $list;
76             }
77              
78             1;
79              
80             __END__