File Coverage

blib/lib/Mail/Message/Convert/HtmlFormatText.pm
Criterion Covered Total %
statement 29 29 100.0
branch n/a
condition 2 4 50.0
subroutine 9 9 100.0
pod 1 2 50.0
total 41 44 93.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::Convert::HtmlFormatText;{
13             our $VERSION = '4.04';
14             }
15              
16 2     2   38528 use parent 'Mail::Message::Convert';
  2         7  
  2         19  
17              
18 2     2   223 use strict;
  2         5  
  2         58  
19 2     2   11 use warnings;
  2         4  
  2         122  
20              
21 2     2   12 use Log::Report 'mail-message', import => [ qw// ];
  2         4  
  2         12  
22              
23 2     2   2895 use HTML::TreeBuilder ();
  2         52997  
  2         70  
24 2     2   621 use HTML::FormatText ();
  2         8058  
  2         54  
25              
26 2     2   1206 use Mail::Message::Body::String ();
  2         8  
  2         408  
27              
28             #--------------------
29              
30             sub init($)
31 2     2 0 7 { my ($self, $args) = @_;
32 2         22 $self->SUPER::init($args);
33              
34             $self->{MMCH_formatter} = HTML::FormatText->new(
35             leftmargin => $args->{leftmargin} // 3,,
36 2   50     59 rightmargin => $args->{rightmargin} // 72,
      50        
37             );
38              
39 2         145 $self;
40             }
41              
42             #--------------------
43              
44             sub format($)
45 2     2 1 12 { my ($self, $body) = @_;
46              
47 2         26 my $dec = $body->encode(transfer_encoding => 'none');
48 2         14 my $tree = HTML::TreeBuilder->new_from_file($dec->file);
49              
50             (ref $body)->new(
51             based_on => $body,
52             mime_type => 'text/plain',
53             charset => 'iso-8859-1',
54 2         13570 data => [ $self->{MMCH_formatter}->format($tree) ],
55             );
56             }
57              
58             1;