File Coverage

blib/lib/Mail/Message/TransferEnc/SevenBit.pm
Criterion Covered Total %
statement 25 32 78.1
branch 5 8 62.5
condition 2 3 66.6
subroutine 5 7 71.4
pod 3 3 100.0
total 40 53 75.4


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::TransferEnc::SevenBit;{
13             our $VERSION = '4.04';
14             }
15              
16 3     3   1975 use parent 'Mail::Message::TransferEnc';
  3         9  
  3         24  
17              
18 3     3   244 use strict;
  3         7  
  3         82  
19 3     3   20 use warnings;
  3         6  
  3         225  
20              
21 3     3   21 use Log::Report 'mail-message', import => [ qw// ];
  3         7  
  3         21  
22              
23             #--------------------
24              
25             sub name() { '7bit' }
26              
27             sub check($@)
28 0     0 1 0 { my ($self, $body, %args) = @_;
29 0         0 $body;
30             }
31              
32             sub decode($@)
33 0     0 1 0 { my ($self, $body, %args) = @_;
34 0         0 $body->transferEncoding('none');
35 0         0 $body;
36             }
37              
38             sub encode($@)
39 2     2 1 15 { my ($self, $body, %args) = @_;
40              
41 2         4 my @lines;
42 2         5 my $changes = 0;
43              
44 2         10 foreach ($body->lines)
45 4 50       24 { $changes++ if s/([^\000-\127])/chr(ord($1) & 0x7f)/ge;
  107         300  
46 4 100       41 $changes++ if s/[\000\013]//g;
47              
48 4 50       15 $changes++ if length > 997;
49 4         16 push @lines, substr($_, 0, 996, '')."\n"
50             while length > 997;
51              
52 4         12 push @lines, $_;
53             }
54              
55 2 50       45 unless($changes)
56 0         0 { $body->transferEncoding('7bit');
57 0         0 return $body;
58             }
59              
60 2   66     17 my $bodytype = $args{result_type} || ref $body;
61 2         20 $bodytype->new(based_on => $body, transfer_encoding => '7bit', data => \@lines);
62             }
63              
64             1;