| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Mail::AddressSort |
|
2
|
|
|
|
|
|
|
# Sorts an array of email addresses |
|
3
|
|
|
|
|
|
|
# for the purpose of expediting delivery of multiple recipients |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# Package Definition |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Mail::AddressSort; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
# Compiler Directives |
|
13
|
|
|
|
|
|
|
# |
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
726
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
40
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
# Global Variables |
|
19
|
|
|
|
|
|
|
# |
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
6
|
use vars qw/$VERSION/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1229
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$VERSION=1.0; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# |
|
26
|
|
|
|
|
|
|
# Subroutines |
|
27
|
|
|
|
|
|
|
# |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Constructor method |
|
30
|
|
|
|
|
|
|
sub new |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
0
|
|
|
0
|
1
|
|
my ($class)=shift; |
|
33
|
0
|
|
|
|
|
|
my ($object); |
|
34
|
0
|
|
|
|
|
|
$object={}; |
|
35
|
0
|
|
|
|
|
|
bless ($object); |
|
36
|
0
|
|
|
|
|
|
return($object); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Add addresses to the list |
|
40
|
|
|
|
|
|
|
sub input |
|
41
|
|
|
|
|
|
|
{ |
|
42
|
0
|
|
|
0
|
1
|
|
my ($self)=shift; |
|
43
|
0
|
|
|
|
|
|
my ($addr,$parsed); |
|
44
|
0
|
|
|
|
|
|
while (@_) |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
0
|
|
|
|
|
|
($addr)=shift; |
|
47
|
0
|
|
|
|
|
|
$parsed=_sortFmt($addr); |
|
48
|
0
|
|
|
|
|
|
$self->{list}->{$parsed}=$addr; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
0
|
|
|
|
|
|
return(); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Return all addresses in one sorted array |
|
54
|
|
|
|
|
|
|
sub sorted |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
0
|
|
|
0
|
1
|
|
my ($self)=shift; |
|
57
|
0
|
|
|
|
|
|
my ($key,@array); |
|
58
|
0
|
|
|
|
|
|
foreach $key (sort(keys(%{$self->{list}}))) |
|
|
0
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
{ |
|
60
|
0
|
|
|
|
|
|
push(@array,$self->{list}->{$key}); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
|
return(@array); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Return a count of the number of addresses in the list |
|
66
|
|
|
|
|
|
|
sub count |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
0
|
|
|
0
|
1
|
|
my ($self)=shift; |
|
69
|
0
|
|
|
|
|
|
return scalar(keys(%{$self->{list}})); |
|
|
0
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Return all addresses in an array of arrays limited by a |
|
73
|
|
|
|
|
|
|
# maximun number of addresses per array and also by domain if necessary |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub batches |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
0
|
|
|
0
|
1
|
|
my ($self)=shift; |
|
78
|
0
|
|
|
|
|
|
my ($arg,$max,$hostSplit,$count,$batchNum,$host,$lastHost,$address |
|
79
|
|
|
|
|
|
|
,$out,@list,$batches); |
|
80
|
0
|
|
|
|
|
|
while (@_) |
|
81
|
|
|
|
|
|
|
{ |
|
82
|
0
|
|
|
|
|
|
($arg)=shift; |
|
83
|
0
|
0
|
|
|
|
|
if ($arg eq "-maxRecipients") |
|
|
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
{ |
|
85
|
0
|
|
|
|
|
|
$max=shift; |
|
86
|
0
|
|
|
|
|
|
print("MaxRecp passed as $max\n"); |
|
87
|
|
|
|
|
|
|
} elsif ($arg eq "-byHost") |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
0
|
|
|
|
|
|
$hostSplit=1; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
} |
|
92
|
0
|
0
|
|
|
|
|
if ($max <=0) |
|
93
|
|
|
|
|
|
|
{ |
|
94
|
0
|
|
|
|
|
|
my ($num)=$self->count(); |
|
95
|
0
|
0
|
|
|
|
|
if ($num < 100) |
|
96
|
|
|
|
|
|
|
{ |
|
97
|
0
|
|
|
|
|
|
$max=int($num/5); |
|
98
|
0
|
0
|
|
|
|
|
$max++ if ($max ==0); |
|
99
|
|
|
|
|
|
|
} else { |
|
100
|
0
|
|
|
|
|
|
$max=100; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
0
|
|
|
|
|
|
print("MaxRecp set to $max\n"); |
|
104
|
0
|
|
|
|
|
|
$max++; |
|
105
|
0
|
|
|
|
|
|
$batches=[]; |
|
106
|
0
|
|
|
|
|
|
$count=1; |
|
107
|
0
|
|
|
|
|
|
$batchNum=1; |
|
108
|
0
|
|
|
|
|
|
foreach $address (sort(keys(%{$self->{list}}))) |
|
|
0
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
{ |
|
110
|
0
|
|
|
|
|
|
$out=$self->{list}->{$address}; |
|
111
|
0
|
|
|
|
|
|
($host)=split(/\@/,$address); |
|
112
|
0
|
0
|
|
|
|
|
$lastHost=$host unless ($lastHost); |
|
113
|
0
|
0
|
0
|
|
|
|
if ($count == $max || ($host ne $lastHost && $hostSplit)) |
|
|
|
|
0
|
|
|
|
|
|
114
|
|
|
|
|
|
|
{ |
|
115
|
0
|
|
|
|
|
|
push(@{$batches},[ @list ]); |
|
|
0
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
(@list)=(); |
|
117
|
0
|
|
|
|
|
|
$batchNum++; |
|
118
|
0
|
|
|
|
|
|
$count=1; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
0
|
|
|
|
|
|
push(@list,$out); |
|
121
|
0
|
|
|
|
|
|
$count++; |
|
122
|
0
|
|
|
|
|
|
$lastHost=$host; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
0
|
0
|
|
|
|
|
if (@list) |
|
125
|
|
|
|
|
|
|
{ |
|
126
|
0
|
|
|
|
|
|
push(@{$batches},[ @list ]); |
|
|
0
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
} |
|
128
|
0
|
|
|
|
|
|
return($batches); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub printBatches |
|
132
|
|
|
|
|
|
|
{ |
|
133
|
0
|
|
|
0
|
1
|
|
my ($self,$batch,$number)=@_; |
|
134
|
0
|
|
|
|
|
|
my ($sub,$count,$size,$addr); |
|
135
|
0
|
0
|
|
|
|
|
if ($number) |
|
136
|
|
|
|
|
|
|
{ |
|
137
|
0
|
|
|
|
|
|
_printBatch($batch,$number); |
|
138
|
|
|
|
|
|
|
} else { |
|
139
|
0
|
|
|
|
|
|
$count=scalar(@{$batch}); |
|
|
0
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
for ($sub=1;$sub<=$count;$sub++) |
|
141
|
|
|
|
|
|
|
{ |
|
142
|
0
|
|
|
|
|
|
_printBatch($batch,$sub); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
} |
|
145
|
0
|
|
|
|
|
|
return; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub printHostCount |
|
149
|
|
|
|
|
|
|
{ |
|
150
|
0
|
|
|
0
|
1
|
|
my ($self)=shift; |
|
151
|
0
|
|
|
|
|
|
my (%report,$host,$domain); |
|
152
|
0
|
|
|
|
|
|
(%report)=$self->_hostCount(); |
|
153
|
0
|
|
|
|
|
|
foreach $host (sort(keys(%report))) |
|
154
|
|
|
|
|
|
|
{ |
|
155
|
0
|
|
|
|
|
|
$domain=join(".",reverse(split(/\./,$host))); |
|
156
|
0
|
|
|
|
|
|
printf("%5d %-40s\n",$report{$host},$domain); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
0
|
|
|
|
|
|
return; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# |
|
162
|
|
|
|
|
|
|
# Hidden Subroutines |
|
163
|
|
|
|
|
|
|
# |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _sortFmt |
|
166
|
|
|
|
|
|
|
{ |
|
167
|
0
|
|
|
0
|
|
|
my ($addr)=shift; |
|
168
|
0
|
|
|
|
|
|
my ($parsed,$user,$domain,@dp,@rdp); |
|
169
|
0
|
|
|
|
|
|
($user,$domain)=split(/\@/,$addr); |
|
170
|
0
|
|
|
|
|
|
($domain)=lc($domain); |
|
171
|
0
|
|
|
|
|
|
(@dp)=split(/\./,$domain); |
|
172
|
0
|
|
|
|
|
|
$parsed=join(".",reverse(@dp))."\@".$user; |
|
173
|
0
|
|
|
|
|
|
return($parsed); |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub _printBatch |
|
177
|
|
|
|
|
|
|
{ |
|
178
|
0
|
|
|
0
|
|
|
my ($batch,$number)=@_; |
|
179
|
0
|
|
|
|
|
|
my ($count,$size,$address); |
|
180
|
0
|
|
|
|
|
|
$count=$#$batch; |
|
181
|
0
|
0
|
0
|
|
|
|
return undef if ($number < 1 || $ number > $count); |
|
182
|
0
|
|
|
|
|
|
$size=scalar(@{$batch->[$number-1]}); |
|
|
0
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
print("Batch $number of $count ($size entries)\n"); |
|
184
|
0
|
|
|
|
|
|
foreach $address (@{$batch->[$number-1]}) |
|
|
0
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
{ |
|
186
|
0
|
|
|
|
|
|
print("\t$address\n"); |
|
187
|
|
|
|
|
|
|
} |
|
188
|
0
|
|
|
|
|
|
return; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub _hostCount |
|
192
|
|
|
|
|
|
|
{ |
|
193
|
0
|
|
|
0
|
|
|
my ($self)=shift; |
|
194
|
0
|
|
|
|
|
|
my ($entry,$domain,%count); |
|
195
|
0
|
|
|
|
|
|
foreach $entry (keys(%{$self->{list}})) |
|
|
0
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
{ |
|
197
|
0
|
|
|
|
|
|
($domain)=split(/\@/,$entry); |
|
198
|
0
|
|
|
|
|
|
$count{$domain}++; |
|
199
|
|
|
|
|
|
|
} |
|
200
|
0
|
|
|
|
|
|
return(%count); |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# |
|
204
|
|
|
|
|
|
|
# Exit Area |
|
205
|
|
|
|
|
|
|
# |
|
206
|
|
|
|
|
|
|
1; |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
__END__ |