line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
913
|
use 5.014; |
|
1
|
|
|
|
|
4
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Mail::Qmail::Filter::ValidateFrom; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Mo qw(coerce default); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
9
|
|
|
|
|
|
|
extends 'Mail::Qmail::Filter'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has params => {}; |
12
|
|
|
|
|
|
|
has reject_text => sub { |
13
|
|
|
|
|
|
|
sub { "Invalid e-mail address <$_[0]> in From header line" } |
14
|
|
|
|
|
|
|
}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub filter { |
17
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
18
|
0
|
0
|
|
|
|
|
my $header_from = $self->message->header_from or return; |
19
|
0
|
|
|
|
|
|
my $header_from_address = $header_from->address; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
require Email::Valid; |
22
|
|
|
|
|
|
|
$self->reject( $self->reject_text, $header_from_address ) |
23
|
0
|
0
|
|
|
|
|
unless Email::Valid->new( %{ $self->params } ) |
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
->address($header_from_address); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
__END__ |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Mail::Qmail::Filter::ValidateFrom - |
34
|
|
|
|
|
|
|
check syntax of RFC5322.From address |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 SYNOPSIS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use Mail::Qmail::Filter; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Mail::Qmail::Filter->new->add_filters( |
41
|
|
|
|
|
|
|
'::ValidateFrom' => { |
42
|
|
|
|
|
|
|
skip_for_rcpt => [ 'postmaster', 'postmaster@' . $mydomain ], |
43
|
|
|
|
|
|
|
params => { '-mxcheck' => 1 }, |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
'::Queue', |
46
|
|
|
|
|
|
|
)->run; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 DESCRIPTION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This L<Mail::Qmail::Filter> plugin checks if the C<From> header line of the |
51
|
|
|
|
|
|
|
message contains a valid e-mail address (as far as L<Email::Valid> can tell). |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 OPTIONAL PARAMETERS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 params |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
reference to a hash of parameters to pass to L<Email::Valid> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 reject_text |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Text to use when rejecting the message because it has an invalid address |
62
|
|
|
|
|
|
|
in its C<From> header line. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
May be a string or a subroutine which returns the text. |
65
|
|
|
|
|
|
|
The subroutine may access the problematic address as its first argument. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Default: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub { "Invalid e-mail address <$_[0]> in From header line" }; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SEE ALSO |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
L<Mail::Qmail::Filter/COMMON PARAMETERS FOR ALL FILTERS>, L<Email::Valid> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Copyright 2019 Martin Sluka. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
80
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
81
|
|
|
|
|
|
|
copy of the full license at: |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L<http://www.perlfoundation.org/artistic_license_2_0> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
86
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
87
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
88
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
91
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
92
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
95
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
98
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
99
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
100
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
101
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
102
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
103
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
104
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
107
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
108
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
109
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
110
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
111
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
112
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
113
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |