File Coverage

blib/lib/Mail/Message/Construct/Text.pm
Criterion Covered Total %
statement 40 40 100.0
branch 13 18 72.2
condition 4 7 57.1
subroutine 8 8 100.0
pod 4 4 100.0
total 69 77 89.6


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 5     5   1332 use strict;
  5         13  
  5         218  
18 5     5   24 use warnings;
  5         22  
  5         439  
19              
20 5     5   50 use Log::Report 'mail-message', import => [ qw// ];
  5         10  
  5         42  
21              
22 5     5   1035 use IO::Lines ();
  5         28  
  5         2527  
23              
24             #--------------------
25              
26             sub string()
27 5     5 1 1192 { my $self = shift;
28 5         29 $self->head->string . $self->body->string;
29             }
30              
31              
32             sub lines()
33 8     8 1 15 { my $self = shift;
34 8         12 my @lines;
35 8         134 my $file = IO::Lines->new(\@lines);
36 8         564 $self->print($file);
37 8 50       79 wantarray ? @lines : \@lines;
38             }
39              
40              
41             sub file()
42 2     2 1 4 { my $self = shift;
43 2         23 my $file = IO::Lines->new;
44 2         165 $self->print($file);
45 2         13 $file->seek(0,0);
46 2         76 $file;
47             }
48              
49              
50             sub printStructure(;$$)
51 6     6 1 10 { my $self = shift;
52              
53 6 50 33     35 my $indent
    100          
54             = @_==2 ? pop
55             : defined $_[0] && !ref $_[0] ? shift
56             : '';
57              
58 6 50       13 my $fh = @_ ? shift : select;
59              
60 6         9 my $buffer; # only filled if filehandle==undef
61 6 50       13 open $fh, '>:raw', \$buffer unless defined $fh;
62              
63 6   100     17 my $subject = $self->get('Subject') || '';
64 6 100       17 $subject = ": $subject" if length $subject;
65              
66 6   50     13 my $type = $self->get('Content-Type', 0) || '';
67 6         18 my $size = $self->size;
68 6 50       18 my $deleted = $self->label('deleted') ? ', deleted' : '';
69              
70 6         19 my $text = "$indent$type$subject ($size bytes$deleted)\n";
71 6         27 $fh->print($text);
72              
73 6         101 my $body = $self->body;
74             my @parts
75 6 100       46 = $body->isNested ? ($body->nested)
    100          
76             : $body->isMultipart ? $body->parts
77             : ();
78              
79             $_->printStructure($fh, $indent.' ')
80 6         32 for @parts;
81              
82 6         32 $buffer;
83             }
84              
85             #--------------------
86              
87             1;