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 8     8   74 use strict;
  8         22  
  8         442  
3 8     8   41 use warnings;
  8         17  
  8         572  
4             our $VERSION = '1.20240923'; # 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 8     8   106 use base 'Mail::DKIM::Canonicalization::DkCommon';
  8         17  
  8         4614  
14 8     8   65 use Carp;
  8         15  
  8         2864  
15              
16             sub init {
17 21     21 0 84 my $self = shift;
18 21         115 $self->SUPER::init;
19              
20 21         81 $self->{canonicalize_body_empty_lines} = 0;
21             }
22              
23             sub canonicalize_header {
24 123     123 0 310 my $self = shift;
25 123 50       426 croak 'wrong number of parameters' unless ( @_ == 1 );
26 123         249 my ($line) = @_;
27              
28 123         483 return $line;
29             }
30              
31             sub canonicalize_body {
32 42     42 0 86 my $self = shift;
33 42         134 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         93 my $empty_lines = $self->{canonicalize_body_empty_lines};
41              
42 42 100       207 if ( $multiline =~ s/^((?:\015\012)+)// )
43             { # count & strip leading empty lines
44 21         101 $empty_lines += length($1) / 2;
45             }
46              
47 42 100 66     233 if ( $empty_lines > 0 && length($multiline) > 0 )
48             { # re-insert leading white if any nonempty lines exist
49 21         118 $multiline = ( "\015\012" x $empty_lines ) . $multiline;
50 21         35 $empty_lines = 0;
51             }
52              
53 42         160 while ( $multiline =~ /\015\012\015\012\z/ )
54             { # count & strip trailing empty lines
55 27         68 chop $multiline;
56 27         45 chop $multiline;
57 27         85 $empty_lines++;
58             }
59              
60 42         92 $self->{canonicalize_body_empty_lines} = $empty_lines;
61 42         195 return $multiline;
62             }
63              
64             1;
65              
66             __END__