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