File Coverage

blib/lib/Mail/DKIM/Canonicalization/dk_simple.pm
Criterion Covered Total %
statement 33 33 100.0
branch 5 6 83.3
condition 2 3 66.6
subroutine 7 7 100.0
pod 0 3 0.0
total 47 52 90.3


line stmt bran cond sub pod time code
1             package Mail::DKIM::Canonicalization::dk_simple;
2 7     7   47 use strict;
  7         15  
  7         204  
3 7     7   41 use warnings;
  7         15  
  7         372  
4             our $VERSION = '1.20230911'; # VERSION
5             # ABSTRACT: dk simple canonicalization
6              
7             # Copyright 2005 Messiah College. All rights reserved.
8             # Jason Long
9              
10             # This program is free software; you can redistribute it and/or
11             # modify it under the same terms as Perl itself.
12              
13 7     7   44 use base 'Mail::DKIM::Canonicalization::DkCommon';
  7         20  
  7         3324  
14 7     7   49 use Carp;
  7         14  
  7         2400  
15              
16             sub init {
17 21     21 0 36 my $self = shift;
18 21         76 $self->SUPER::init;
19              
20 21         49 $self->{canonicalize_body_empty_lines} = 0;
21             }
22              
23             sub canonicalize_header {
24 123     123 0 197 my $self = shift;
25 123 50       253 croak 'wrong number of parameters' unless ( @_ == 1 );
26 123         213 my ($line) = @_;
27              
28 123         340 return $line;
29             }
30              
31             sub canonicalize_body {
32 42     42 0 79 my $self = shift;
33 42         94 my ($multiline) = @_;
34              
35             # ignore empty lines at the end of the message body
36             #
37             # (i.e. do not emit empty lines until a following nonempty line
38             # is found)
39             #
40 42         83 my $empty_lines = $self->{canonicalize_body_empty_lines};
41              
42 42 100       187 if ( $multiline =~ s/^((?:\015\012)+)// )
43             { # count & strip leading empty lines
44 21         79 $empty_lines += length($1) / 2;
45             }
46              
47 42 100 66     185 if ( $empty_lines > 0 && length($multiline) > 0 )
48             { # re-insert leading white if any nonempty lines exist
49 21         86 $multiline = ( "\015\012" x $empty_lines ) . $multiline;
50 21         44 $empty_lines = 0;
51             }
52              
53 42         144 while ( $multiline =~ /\015\012\015\012\z/ )
54             { # count & strip trailing empty lines
55 27         53 chop $multiline;
56 27         34 chop $multiline;
57 27         70 $empty_lines++;
58             }
59              
60 42         69 $self->{canonicalize_body_empty_lines} = $empty_lines;
61 42         146 return $multiline;
62             }
63              
64             1;
65              
66             __END__