File Coverage

blib/lib/MailX/Qmail/Queue/Message.pm
Criterion Covered Total %
statement 14 44 31.8
branch 0 14 0.0
condition 0 6 0.0
subroutine 5 11 45.4
pod 5 5 100.0
total 24 80 30.0


line stmt bran cond sub pod time code
1 1     1   14 use 5.014;
  1         3  
2 1     1   4 use warnings;
  1         2  
  1         51  
3              
4              
5             our $VERSION = '1.0';
6              
7             use base 'Mail::Qmail::Queue::Message';
8 1     1   11  
  1         2  
  1         405  
9             use Mail::Address;
10 1     1   13094 use Mail::Header;
  1         1978  
  1         29  
11 1     1   388  
  1         3580  
  1         322  
12             # Use inside-out attributes to avoid interference with base class:
13             my ( %header, %body );
14              
15             my $self = shift;
16             return $header{$self} if exists $header{$self};
17 0     0 1   open my $fh, '<', $self->body_ref or die 'Cannot read message';
18 0 0         $header{$self} = Mail::Header->new($fh);
19 0 0         local $/;
20 0           $body{$self} = <$fh>;
21 0           $header{$self};
22 0           }
23 0            
24             my $self = shift;
25             my $from = $self->header->get('From') or return;
26             ($from) = Mail::Address->parse($from);
27 0     0 1   $from;
28 0 0         }
29 0            
30 0           my $header = shift->header;
31             my $received = $header->get('Received') or return;
32             $received =~ /^from .*? \(HELO (.*?)\) /
33             or $received =~ /^from (\S+) \(/
34 0     0 1   or return;
35 0 0         $1;
36 0 0 0       }
37              
38             my $self = shift;
39 0           ${ $self->body_ref } = join "\n", @_, $self->body;
40             delete $header{$self};
41             $self;
42             }
43 0     0 1    
44 0           my ( $self, $header ) = @_;
  0            
45 0           $self->header unless exists $body{$self}; # force parsing
46 0           $header = $header->as_string if ref $header && $header->can('as_string');
47             ${ $self->body_ref } = join "\n", $header, $body{$self};
48             delete $header{$self};
49             $self;
50 0     0 1   }
51 0 0          
52 0 0 0       my $self = shift;
53 0           delete $header{$self};
  0            
54 0           delete $body{$self};
55 0           }
56              
57             1;
58              
59 0     0      
60 0           =head1 NAME
61 0            
62             MailX::Qmail::Queue::Message - extensions to Mail::Qmail::Queue::Message
63              
64             =head1 DESCRIPTION
65              
66             This class extends L<Mail::Qmail::Queue::Message>.
67              
68             =head1 METHODS
69              
70             =over 4
71              
72             =item ->header
73              
74             get the header of the incoming message as L<Mail::Header> object
75              
76             =item ->header_from
77              
78             get the C<From:> header field of the incoming message as L<Mail::Address> object
79              
80             =item ->helo
81              
82             get the C<HELO>/C<EHLO> string used by the client
83              
84             =item ->add_header
85              
86             Add header fields to the message.
87             Expects C<Field: Value> as argument, without newlines at the end.
88              
89             =item ->replace_header($header)
90              
91             Replace the whole header of the message.
92             C<$header> should either be a properly formatted e-mail header
93             or an object with an C<as_string> method which produces such a string,
94             e.g. a L<Mail::Header> object.
95              
96             =back
97              
98             =head1 BUGS
99              
100             Please report any bugs or feature requests to
101             C<bug-mail-qmail-filter at rt.cpan.org>, or through the web interface at
102             L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mail-Qmail-Filter>.
103             I will be notified, and then you'll automatically be notified of progress on
104             your bug as I make changes.
105              
106             =head1 SUPPORT
107              
108             You can find documentation for this module with the perldoc command.
109              
110             perldoc Mail::Qmail::Filter
111              
112             You can also look for information at:
113              
114             =over 4
115              
116             =item * RT: CPAN's request tracker (report bugs here)
117              
118             L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Mail-Qmail-Filter>
119              
120             =item * AnnoCPAN: Annotated CPAN documentation
121              
122             L<https://annocpan.org/dist/Mail-Qmail-Filter>
123              
124             =item * CPAN Ratings
125              
126             L<https://cpanratings.perl.org/dist/Mail-Qmail-Filter>
127              
128             =item * Search CPAN
129              
130             L<https://metacpan.org/release/Mail-Qmail-Filter>
131              
132             =back
133              
134             =head1 ACKNOWLEDGEMENTS
135             =head1 LICENSE AND COPYRIGHT
136              
137             Copyright 2019 Martin Sluka.
138              
139             This program is free software; you can redistribute it and/or modify it
140             under the terms of the the Artistic License (2.0). You may obtain a
141             copy of the full license at:
142              
143             L<http://www.perlfoundation.org/artistic_license_2_0>
144              
145             Any use, modification, and distribution of the Standard or Modified
146             Versions is governed by this Artistic License. By using, modifying or
147             distributing the Package, you accept this license. Do not use, modify,
148             or distribute the Package, if you do not accept this license.
149              
150             If your Modified Version has been derived from a Modified Version made
151             by someone other than you, you are nevertheless required to ensure that
152             your Modified Version complies with the requirements of this license.
153              
154             This license does not grant you the right to use any trademark, service
155             mark, tradename, or logo of the Copyright Holder.
156              
157             This license includes the non-exclusive, worldwide, free-of-charge
158             patent license to make, have made, use, offer to sell, sell, import and
159             otherwise transfer the Package with respect to any patent claims
160             licensable by the Copyright Holder that are necessarily infringed by the
161             Package. If you institute patent litigation (including a cross-claim or
162             counterclaim) against any party alleging that the Package constitutes
163             direct or contributory patent infringement, then this Artistic License
164             to you shall terminate on the date that such litigation is filed.
165              
166             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
167             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
168             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
169             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
170             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
171             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
172             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
173             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
174              
175             =cut