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