File Coverage

blib/lib/Mail/Qmail/Filter/ValidateSender.pm
Criterion Covered Total %
statement 8 13 61.5
branch 0 4 0.0
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 12 22 54.5


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