File Coverage

blib/lib/Mail/Message/Construct/Bounce.pm
Criterion Covered Total %
statement 28 37 75.6
branch 4 12 33.3
condition 2 6 33.3
subroutine 6 6 100.0
pod 1 1 100.0
total 41 62 66.1


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Mail-Message version 4.04.
2             # The POD got stripped from this file by OODoc version 3.06.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2001-2026 by Mark Overmeer.
6              
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10              
11              
12             package Mail::Message;{
13             our $VERSION = '4.04';
14             }
15              
16              
17 2     2   5611 use strict;
  2         5  
  2         87  
18 2     2   9 use warnings;
  2         5  
  2         159  
19              
20 2     2   10 use Log::Report 'mail-message', import => [ qw/__x error trace/ ];
  2         4  
  2         24  
21              
22 2     2   453 use Mail::Message::Head::Complete ();
  2         6  
  2         60  
23 2     2   11 use Mail::Message::Field ();
  2         4  
  2         641  
24              
25             #--------------------
26              
27             sub bounce(@)
28 1     1 1 2259 { my $self = shift;
29 1         7 my $bounce = $self->clone;
30 1         2 my $head = $bounce->head;
31              
32 1 0 33     4 if(@_==1 && ref $_[0] && $_[0]->isa('Mail::Message::Head::ResentGroup' ))
      33        
33 0         0 { $head->addResentGroup(shift);
34 0         0 return $bounce;
35             }
36              
37 1         7 my @rgs = $head->resentGroups;
38 1         4 my $rg = $rgs[0];
39              
40 1 50       5 if(defined $rg)
    50          
41 0         0 { $rg->delete; # Remove group to re-add it later: otherwise
42 0         0 while(@_) # field order in header would be disturbed.
43 0         0 { my $field = shift;
44 0 0       0 ref $field ? $rg->set($field) : $rg->set($field, shift);
45             }
46             }
47             elsif(@_)
48 1         10 { $rg = Mail::Message::Head::ResentGroup->new(@_);
49             }
50             else
51 0         0 { error __x"method bounce requires To, Cc, or Bcc.";
52             }
53              
54 1 50       4 $rg->set(Date => Mail::Message::Field->toDate) unless defined $rg->date;
55              
56 1 50       4 unless(defined $rg->messageId)
57 0         0 { my $msgid = $head->createMessageId;
58 0         0 $rg->set('Message-ID' => "<$msgid>");
59             }
60              
61 1         14 $head->addResentGroup($rg);
62              
63             # Flag action to original message
64 1         7 $self->label(passed => 1); # used by some maildir clients
65              
66 1         7 $bounce;
67             }
68              
69             1;