File Coverage

blib/lib/Mail/Qmail/Filter/RewriteFrom.pm
Criterion Covered Total %
statement 8 21 38.1
branch 0 4 0.0
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 12 30 40.0


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