| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mail::DKIM::TextWrap; |
|
2
|
2
|
|
|
2
|
|
62088
|
use strict; |
|
|
2
|
|
|
|
|
13
|
|
|
|
2
|
|
|
|
|
116
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
80
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.20230212'; # VERSION |
|
5
|
|
|
|
|
|
|
# ABSTRACT: text wrapping module written for use with DKIM |
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
1755
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
9
|
|
|
9
|
1
|
7376
|
my $class = shift; |
|
12
|
9
|
|
|
|
|
38
|
my %args = @_; |
|
13
|
9
|
|
|
|
|
125
|
my $self = { |
|
14
|
|
|
|
|
|
|
Margin => 72, |
|
15
|
|
|
|
|
|
|
Break => qr/\s/, |
|
16
|
|
|
|
|
|
|
BreakBefore => undef, |
|
17
|
|
|
|
|
|
|
Swallow => qr/\s/, |
|
18
|
|
|
|
|
|
|
Separator => "\n", |
|
19
|
|
|
|
|
|
|
cur => 0, |
|
20
|
|
|
|
|
|
|
may_break => 0, |
|
21
|
|
|
|
|
|
|
soft_space => "", |
|
22
|
|
|
|
|
|
|
word => "", |
|
23
|
|
|
|
|
|
|
%args, |
|
24
|
|
|
|
|
|
|
}; |
|
25
|
9
|
|
100
|
|
|
37
|
$self->{Output} ||= \*STDOUT; |
|
26
|
9
|
|
|
|
|
102
|
return bless $self, $class; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Internal properties: |
|
30
|
|
|
|
|
|
|
# |
|
31
|
|
|
|
|
|
|
# cur - the last known column position |
|
32
|
|
|
|
|
|
|
# |
|
33
|
|
|
|
|
|
|
# may_break - nonzero if the current location allows a linebreak |
|
34
|
|
|
|
|
|
|
# |
|
35
|
|
|
|
|
|
|
# soft_space - contains added text that will not be printed if a linebreak |
|
36
|
|
|
|
|
|
|
# occurs |
|
37
|
|
|
|
|
|
|
# |
|
38
|
|
|
|
|
|
|
# word - contains the current word |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Internal methods: |
|
41
|
|
|
|
|
|
|
# |
|
42
|
|
|
|
|
|
|
# _calculate_new_column() - determine where cur would be after adding some text |
|
43
|
|
|
|
|
|
|
# |
|
44
|
|
|
|
|
|
|
# my $new_cur = _calculate_new_column($cur, "some additional\ntext"); |
|
45
|
|
|
|
|
|
|
# |
|
46
|
|
|
|
|
|
|
sub _calculate_new_column { |
|
47
|
446
|
|
|
446
|
|
720
|
my ( $cur, $text ) = @_; |
|
48
|
446
|
50
|
|
|
|
758
|
confess "invalid argument" unless defined($text); |
|
49
|
|
|
|
|
|
|
|
|
50
|
446
|
|
|
|
|
1367
|
while ( $text =~ /^(.*?)([\n\r\t])(.*)$/s ) { |
|
51
|
76
|
|
|
|
|
129
|
$cur += length($1); |
|
52
|
76
|
100
|
|
|
|
134
|
if ( $2 eq "\t" ) { |
|
53
|
18
|
|
|
|
|
41
|
$cur = ( int( $cur / 8 ) + 1 ) * 8; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
else { |
|
56
|
58
|
|
|
|
|
82
|
$cur = 0; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
76
|
|
|
|
|
266
|
$text = $3; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
446
|
|
|
|
|
648
|
$cur += length($text); |
|
61
|
446
|
|
|
|
|
724
|
return $cur; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub add { |
|
66
|
122
|
|
|
122
|
1
|
6890
|
my ( $self, $text ) = @_; |
|
67
|
122
|
|
|
|
|
172
|
my $break_after = $self->{Break}; |
|
68
|
122
|
|
|
|
|
156
|
my $break_before = $self->{BreakBefore}; |
|
69
|
122
|
|
|
|
|
158
|
my $swallow = $self->{Swallow}; |
|
70
|
122
|
|
|
|
|
184
|
$self->{word} .= $text; |
|
71
|
122
|
|
|
|
|
256
|
while ( length $self->{word} ) { |
|
72
|
471
|
|
|
|
|
604
|
my $word; |
|
73
|
471
|
100
|
100
|
|
|
3096
|
if ( defined($break_before) |
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
and $self->{word} =~ s/^(.+?)($break_before)/$2/s ) |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
|
|
|
|
|
|
# note- $1 should have at least one character |
|
77
|
16
|
|
|
|
|
36
|
$word = $1; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
elsif ( defined($break_after) |
|
80
|
|
|
|
|
|
|
and $self->{word} =~ s/^(.*?)($break_after)//s ) |
|
81
|
|
|
|
|
|
|
{ |
|
82
|
361
|
|
|
|
|
823
|
$word = $1 . $2; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
elsif ( $self->{NoBuffering} ) { |
|
85
|
22
|
|
|
|
|
41
|
$word = $self->{word}; |
|
86
|
22
|
|
|
|
|
82
|
$self->{word} = ""; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
else { |
|
89
|
72
|
|
|
|
|
494
|
last; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
399
|
50
|
|
|
|
798
|
die "assertion failed" unless length($word) >= 1; |
|
93
|
|
|
|
|
|
|
|
|
94
|
399
|
|
|
|
|
543
|
my $next_soft_space; |
|
95
|
399
|
100
|
100
|
|
|
1633
|
if ( defined($swallow) && $word =~ s/($swallow)$//s ) { |
|
96
|
84
|
|
|
|
|
151
|
$next_soft_space = $1; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
else { |
|
99
|
315
|
|
|
|
|
502
|
$next_soft_space = ""; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
399
|
|
|
|
|
669
|
my $to_print = $self->{soft_space} . $word; |
|
103
|
399
|
|
|
|
|
670
|
my $new_pos = _calculate_new_column( $self->{cur}, $to_print ); |
|
104
|
|
|
|
|
|
|
|
|
105
|
399
|
100
|
100
|
|
|
863
|
if ( $new_pos > $self->{Margin} && $self->{may_break} ) { |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# what would happen if we put the separator in? |
|
108
|
|
|
|
|
|
|
my $w_sep = |
|
109
|
47
|
|
|
|
|
92
|
_calculate_new_column( $self->{cur}, $self->{Separator} ); |
|
110
|
47
|
100
|
|
|
|
118
|
if ( $w_sep < $self->{cur} ) { |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# inserting the separator gives us more room, |
|
113
|
|
|
|
|
|
|
# so do it |
|
114
|
46
|
|
|
|
|
112
|
$self->output( $self->{Separator} ); |
|
115
|
46
|
|
|
|
|
72
|
$self->{soft_space} = ""; |
|
116
|
46
|
|
|
|
|
65
|
$self->{cur} = $w_sep; |
|
117
|
46
|
|
|
|
|
111
|
$self->{word} = $word . $next_soft_space . $self->{word}; |
|
118
|
46
|
|
|
|
|
115
|
next; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
353
|
|
|
|
|
784
|
$self->output($to_print); |
|
123
|
353
|
|
|
|
|
630
|
$self->{soft_space} = $next_soft_space; |
|
124
|
353
|
|
|
|
|
466
|
$self->{cur} = $new_pos; |
|
125
|
353
|
|
|
|
|
858
|
$self->{may_break} = 1; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub finish { |
|
131
|
12
|
|
|
12
|
1
|
44
|
my $self = shift; |
|
132
|
12
|
|
|
|
|
27
|
$self->flush; |
|
133
|
12
|
|
|
|
|
30
|
$self->reset; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub flush { |
|
138
|
30
|
|
|
30
|
1
|
51
|
my $self = shift; |
|
139
|
|
|
|
|
|
|
|
|
140
|
30
|
|
|
|
|
59
|
local $self->{NoBuffering} = 1; |
|
141
|
30
|
|
|
|
|
59
|
local $self->{Swallow} = undef; |
|
142
|
30
|
|
|
|
|
54
|
$self->add(""); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub output { |
|
146
|
399
|
|
|
399
|
1
|
528
|
my $self = shift; |
|
147
|
399
|
|
|
|
|
523
|
my $to_print = shift; |
|
148
|
|
|
|
|
|
|
|
|
149
|
399
|
|
|
|
|
530
|
my $out = $self->{Output}; |
|
150
|
399
|
50
|
|
|
|
1074
|
if ( UNIVERSAL::isa( $out, "GLOB" ) ) { |
|
|
|
50
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
0
|
print $out $to_print; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa( $out, "SCALAR" ) ) { |
|
154
|
399
|
|
|
|
|
677
|
$$out .= $to_print; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub reset { |
|
159
|
12
|
|
|
12
|
0
|
19
|
my $self = shift; |
|
160
|
12
|
|
|
|
|
27
|
$self->{cur} = 0; |
|
161
|
12
|
|
|
|
|
20
|
$self->{soft_space} = ""; |
|
162
|
12
|
|
|
|
|
30
|
$self->{word} = ""; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__END__ |