File Coverage

lib/Sisimai/Order.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition 4 4 100.0
subroutine 6 6 100.0
pod 1 2 50.0
total 38 39 97.4


line stmt bran cond sub pod time code
1             package Sisimai::Order;
2 88     88   122264 use v5.26;
  88         318  
3 88     88   481 use strict;
  88         153  
  88         2133  
4 88     88   365 use warnings;
  88         165  
  88         4928  
5 88     88   41098 use Sisimai::Lhost;
  88         232  
  88         55277  
6              
7             sub make {
8             # Returns an MTA Order decided by the first word of the "Subject": header
9             # @param [String] argv0 Subject header string
10             # @return [Array] Order of MTA modules
11             # @since v4.25.4
12 3524     3524 0 350055 my $class = shift;
13 3524   100     10807 my $argv0 = shift || return []; y/_[] / /s, s/\A[ ]+// for $argv0;
  3507         15248  
14 3507         19637 my @words = split(/[ ]/, lc($argv0), 3);
15 3507         7716 my $first = '';
16              
17             # The following order is decided by the first 2 words of Subject: header
18 3507         12516 state $subject = {
19             'abuse-report' => ['Sisimai::ARF'],
20             'auto' => ['Sisimai::RFC3834'],
21             'auto-reply' => ['Sisimai::RFC3834'],
22             'automatic-reply' => ['Sisimai::RFC3834'],
23             'aws-notification' => ['Sisimai::Lhost::AmazonSES'],
24             'complaint-about' => ['Sisimai::ARF'],
25             'delivery-failure' => ['Sisimai::Lhost::Domino', 'Sisimai::Lhost::X2'],
26             'delivery-notification' => ['Sisimai::Lhost::MessagingServer'],
27             'delivery-status' => [
28             'Sisimai::Lhost::OpenSMTPD',
29             'Sisimai::Lhost::GoogleWorkspace',
30             'Sisimai::Lhost::Gmail',
31             'Sisimai::Lhost::GoogleGroups',
32             'Sisimai::Lhost::AmazonSES',
33             'Sisimai::Lhost::X3',
34             ],
35             'dmarc-ietf-dmarc' => ['Sisimai::ARF'],
36             'email-feedback' => ['Sisimai::ARF'],
37             'failed-delivery' => ['Sisimai::Lhost::X2'],
38             'failure-delivery' => ['Sisimai::Lhost::X2'],
39             'failure-notice' => ['Sisimai::Lhost::qmail', 'Sisimai::Lhost::mFILTER', 'Sisimai::Lhost::Activehunter'],
40             'loop-alert' => ['Sisimai::Lhost::FML'],
41             'mail-could' => ['Sisimai::Lhost::TrendMicro'],
42             'mail-delivery' => [
43             'Sisimai::Lhost::Exim',
44             'Sisimai::Lhost::DragonFly',
45             'Sisimai::Lhost::GMX',
46             'Sisimai::Lhost::Zoho',
47             'Sisimai::Lhost::EinsUndEins',
48             ],
49             'mail-failure' => ['Sisimai::Lhost::Exim'],
50             'mail-system' => ['Sisimai::Lhost::EZweb'],
51             'message-delivery' => ['Sisimai::Lhost::MailFoundry'],
52             'message-frozen' => ['Sisimai::Lhost::Exim'],
53             'non-recapitabile' => ['Sisimai::Lhost::Exchange2007'],
54             'non-remis' => ['Sisimai::Lhost::Exchange2007'],
55             'notice' => ['Sisimai::Lhost::Courier'],
56             'postmaster-email' => ['Sisimai::Lhost::Mimecast'],
57             'postmaster-notify' => ['Sisimai::Lhost::Sendmail'],
58             'returned-mail' => [
59             'Sisimai::Lhost::Sendmail',
60             'Sisimai::Lhost::Biglobe',
61             'Sisimai::Lhost::V5sendmail',
62             'Sisimai::Lhost::X1',
63             ],
64             'there-was' => ['Sisimai::Lhost::X6'],
65             'undeliverable' => ['Sisimai::Lhost::Exchange2007', 'Sisimai::Lhost::Exchange2003'],
66             'undeliverable-mail' => ['Sisimai::Lhost::MailMarshal', 'Sisimai::Lhost::IMailServer'],
67             'undeliverable-message' => ['Sisimai::Lhost::Notes', 'Sisimai::Lhost::Verizon'],
68             'undelivered-mail' => ['Sisimai::Lhost::Postfix', 'Sisimai::Lhost::Zoho'],
69             'warning' => ['Sisimai::Lhost::Sendmail', 'Sisimai::Lhost::Exim'],
70             };
71              
72 3507 100       13200 if( rindex($words[0], ':') > 0 ) {
73             # Undeliverable: ..., notify: ...
74 206         821 $first = lc substr($argv0, 0, index($argv0, ':'));
75              
76             } else {
77             # Postmaster notify, returned mail, ...
78 3301         15602 $first = join('-', splice(@words, 0, 2));
79             }
80 3507         10156 $first =~ y/:",*//d;
81 3507   100     23563 return $subject->{ $first } || [];
82             }
83              
84             sub another {
85             # Make MTA modules list as a spare
86             # @return [Array] Ordered module list
87             # @since v4.13.1
88              
89             # There are another patterns in the value of "Subject:" header of a bounce mail generated by the
90             # following MTA modules
91 86     86 1 662 state $orderE0 = [
92             'Sisimai::Lhost::Exim',
93             'Sisimai::Lhost::Sendmail',
94             'Sisimai::Lhost::Exchange2007',
95             'Sisimai::Lhost::Exchange2003',
96             'Sisimai::Lhost::TrendMicro',
97             'Sisimai::Lhost::KDDI',
98             'Sisimai::Lhost::FML',
99             'Sisimai::Lhost::Verizon',
100             'Sisimai::Lhost::AmazonSES',
101             'Sisimai::Lhost::ApacheJames',
102             'Sisimai::Lhost::X2',
103             ];
104              
105             # Fallback list: The following MTA/ESP modules is not listed orderE0
106 86         836 state $orderE1 = [
107             'Sisimai::Lhost::Postfix',
108             'Sisimai::Lhost::OpenSMTPD',
109             'Sisimai::Lhost::qmail',
110             'Sisimai::Lhost::Courier',
111             'Sisimai::Lhost::MessagingServer',
112             'Sisimai::Lhost::GoogleWorkspace',
113             'Sisimai::Lhost::Gmail',
114             'Sisimai::Lhost::GMX',
115             'Sisimai::Lhost::Zoho',
116             'Sisimai::Lhost::Domino',
117             'Sisimai::Lhost::Notes',
118             'Sisimai::Lhost::IMailServer',
119             'Sisimai::Lhost::mFILTER',
120             'Sisimai::Lhost::Activehunter',
121             'Sisimai::Lhost::MailFoundry',
122             'Sisimai::Lhost::GoogleGroups',
123             'Sisimai::Lhost::MailMarshal',
124             'Sisimai::Lhost::V5sendmail',
125             'Sisimai::Lhost::EZweb',
126             'Sisimai::Lhost::Biglobe',
127             'Sisimai::Lhost::EinsUndEins',
128             'Sisimai::Lhost::DragonFly',
129             'Sisimai::Lhost::X1',
130             'Sisimai::Lhost::X3',
131             'Sisimai::Lhost::X6',
132             ];
133 86         890 return [@$orderE0, @$orderE1];
134             };
135              
136             1;
137             __END__