line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Qmail::Envelope; |
2
|
8
|
|
|
8
|
|
62802
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
288
|
|
3
|
|
|
|
|
|
|
|
4
|
8
|
|
|
8
|
|
40
|
use vars qw/$VERSION/; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
8532
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.53'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
## constructor |
9
|
|
|
|
|
|
|
sub new { |
10
|
8
|
|
|
8
|
0
|
103
|
my $class = shift; |
11
|
8
|
|
|
|
|
46
|
my $self = { |
12
|
|
|
|
|
|
|
data => '', |
13
|
|
|
|
|
|
|
recips => '', |
14
|
|
|
|
|
|
|
sender => '', |
15
|
|
|
|
|
|
|
@_ |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
8
|
|
|
|
|
30
|
bless($self, $class); |
19
|
|
|
|
|
|
|
|
20
|
8
|
|
|
|
|
47
|
$self->{'sender'} = ''; |
21
|
8
|
|
|
|
|
20
|
$self->{'recips'} = []; |
22
|
8
|
|
|
|
|
22
|
$self->{'rcpt_hosts'} = {}; |
23
|
8
|
|
|
|
|
20
|
$self->{'recips_map'} = {}; |
24
|
|
|
|
|
|
|
|
25
|
8
|
100
|
|
|
|
35
|
if ($self->{'data'}) { |
26
|
7
|
|
|
|
|
40
|
$self->init_envelope_data; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
8
|
|
|
|
|
26
|
return $self; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
## if the constructor is called with the 'data' attribute defined ... |
34
|
|
|
|
|
|
|
sub init_envelope_data { |
35
|
7
|
|
|
7
|
0
|
16
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
## elegant rewrite by Peter Pentchev -- thanks! |
38
|
7
|
50
|
|
|
|
80
|
return 0 unless $self->{'data'} =~ /^F([^\0]+)\0T(.*?)\0\0/; |
39
|
7
|
|
|
|
|
67
|
my ($sender, @recips) = ($1, split(/\0T/, $2)); |
40
|
|
|
|
|
|
|
|
41
|
7
|
|
|
|
|
19
|
$self->{'sender'} = $sender; |
42
|
7
|
|
|
|
|
23
|
$self->{'recips'} = [ @recips ]; |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
|
|
37
|
$self->map_recips; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub add_recip { |
49
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
50
|
0
|
|
|
|
|
0
|
push (@{$self->{'recips'}}, shift()); |
|
0
|
|
|
|
|
0
|
|
51
|
0
|
|
|
|
|
0
|
$self->map_recips; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub remove_recip { |
55
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
56
|
0
|
|
|
|
|
0
|
my $recip = shift; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
my $new_recips = []; |
59
|
0
|
|
|
|
|
0
|
foreach my $r (@{$self->{'recips'}}) { |
|
0
|
|
|
|
|
0
|
|
60
|
0
|
0
|
|
|
|
0
|
next if ($r eq $recip); |
61
|
0
|
|
|
|
|
0
|
push (@$new_recips, $r); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
$self->{'recips'} = $new_recips; |
65
|
0
|
|
|
|
|
0
|
$self->map_recips; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub remove_recips_for_host { |
70
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
71
|
0
|
|
|
|
|
0
|
my $rcpt_host = shift; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
my $new_recips = []; |
74
|
0
|
|
|
|
|
0
|
foreach my $r (@{$self->{'recips'}}) { |
|
0
|
|
|
|
|
0
|
|
75
|
0
|
|
|
|
|
0
|
$r =~ /^.*@(\S+)$/io; |
76
|
0
|
0
|
|
|
|
0
|
next if ($1 eq $rcpt_host); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
0
|
push (@$new_recips, $r); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
0
|
$self->{'recips'} = $new_recips; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
$self->map_recips; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub remove_all_recips { |
89
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
90
|
0
|
|
|
|
|
0
|
$self->{'recips_map'} = {}; |
91
|
0
|
|
|
|
|
0
|
$self->{'recips'} = []; |
92
|
0
|
|
|
|
|
0
|
$self->{'rcpt_hosts'} = {}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub map_recips { |
97
|
7
|
|
|
7
|
0
|
15
|
my $self = shift; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
## maps instances of a recipient within the 'recips' array |
100
|
7
|
|
|
|
|
16
|
$self->{'recips_map'} = {}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
## maps instances of a host in the 'recips' array |
103
|
7
|
|
|
|
|
19
|
$self->{'rcpt_hosts'} = {}; |
104
|
|
|
|
|
|
|
|
105
|
7
|
|
|
|
|
16
|
my $index = 0; |
106
|
|
|
|
|
|
|
|
107
|
7
|
|
|
|
|
11
|
foreach my $r (@{$self->{'recips'}}) { |
|
7
|
|
|
|
|
23
|
|
108
|
|
|
|
|
|
|
|
109
|
16
|
50
|
|
|
|
48
|
if (exists($self->{'recips_map'}->{$r})) { |
110
|
0
|
|
|
|
|
0
|
push(@{$self->{'recips_map'}->{$r}}, $index); |
|
0
|
|
|
|
|
0
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
else { |
114
|
16
|
|
|
|
|
56
|
$self->{'recips_map'}->{$r}->[0] = $index; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
## pull off the host |
118
|
16
|
|
|
|
|
63
|
$r =~ /^.*@(\S+)$/io; |
119
|
|
|
|
|
|
|
|
120
|
16
|
100
|
|
|
|
66
|
unless ($self->{'rcpt_hosts'}->{$1}) { |
121
|
14
|
|
|
|
|
55
|
$self->{'rcpt_hosts'}->{$1} = []; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
16
|
|
|
|
|
26
|
push(@{$self->{'rcpt_hosts'}->{$1}}, $index); |
|
16
|
|
|
|
|
47
|
|
125
|
|
|
|
|
|
|
|
126
|
16
|
|
|
|
|
42
|
$index++; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub gen { |
131
|
|
|
|
|
|
|
|
132
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
133
|
1
|
|
|
|
|
3
|
my $e = 'F' . $self->{'sender'} . "\0"; |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
|
|
3
|
foreach my $r (@{$self->{'recips'}}) { |
|
1
|
|
|
|
|
15
|
|
136
|
2
|
|
|
|
|
6
|
$e .= 'T' . $r . "\0"; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
1
|
|
|
|
|
4
|
$e .= "\0"; |
140
|
|
|
|
|
|
|
|
141
|
1
|
|
|
|
|
6
|
return $e; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub as_string { |
146
|
|
|
|
|
|
|
|
147
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
148
|
1
|
|
|
|
|
4
|
my $e = 'F' . $self->{'sender'}; |
149
|
|
|
|
|
|
|
|
150
|
1
|
|
|
|
|
2
|
foreach my $r (@{$self->{'recips'}}) { |
|
1
|
|
|
|
|
2
|
|
151
|
2
|
|
|
|
|
5
|
$e .= 'T' . $r; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
1
|
|
|
|
|
6
|
return $e; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub rcpt_hosts { |
159
|
1
|
|
|
1
|
0
|
4
|
return [ keys %{ shift()->{'rcpt_hosts'} }]; |
|
1
|
|
|
|
|
5
|
|
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub sender { |
164
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
165
|
1
|
|
50
|
|
|
9
|
my $sender = shift || ''; |
166
|
|
|
|
|
|
|
|
167
|
1
|
50
|
|
|
|
11
|
return $self->{'sender'} unless ($sender); |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
0
|
$self->{'sender'} = $sender; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub total_recips { |
173
|
1
|
|
|
1
|
0
|
4
|
return scalar(@{ shift()->{'recips'} }); |
|
1
|
|
|
|
|
7
|
|
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub total_recips_for_host { |
177
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
178
|
1
|
|
|
|
|
2
|
return scalar(@{ $self->{'rcpt_hosts'}->{shift()} }); |
|
1
|
|
|
|
|
8
|
|
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub remove_duplicate_recips { |
182
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
my $recip_hash = {}; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
foreach my $r (@{$self->{'recips'}}) { |
|
0
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
$recip_hash->{$r} = 1; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
$self->{'recips'} = keys %$recip_hash; |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
$self->map_recips; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
1; |
197
|
|
|
|
|
|
|
__END__ |