File Coverage

blib/lib/Mail/Qmail/Filter/ValidateFrom.pm
Criterion Covered Total %
statement 8 14 57.1
branch 0 4 0.0
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 12 23 52.1


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