line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2011-2013 MURATA Yasuhisa |
2
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
3
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package MIME::EcoEncode::JP_B; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.95'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
16
|
use MIME::Base64; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use constant TAIL => '?='; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
822
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $HEAD; # head string |
17
|
|
|
|
|
|
|
our $HTL; # head + tail length |
18
|
|
|
|
|
|
|
our $LF; # line feed |
19
|
|
|
|
|
|
|
our $BPL; # bytes per line |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# add encoded-word for "B" encoding and 7bit-jis string |
22
|
|
|
|
|
|
|
# parameters: |
23
|
|
|
|
|
|
|
# sp : start position (indentation of the first line) |
24
|
|
|
|
|
|
|
# ep : end position of last line (call by reference) |
25
|
|
|
|
|
|
|
# rll : room of last line (default: 0) |
26
|
|
|
|
|
|
|
# fof : flag to check size-over at the first time |
27
|
|
|
|
|
|
|
sub add_ew_jp_b { |
28
|
30
|
|
|
30
|
0
|
57
|
my ($str, $sp, $ep, $rll, $fof) = @_; |
29
|
|
|
|
|
|
|
|
30
|
30
|
50
|
|
|
|
62
|
return '' if $str eq ''; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# encoded size + sp |
33
|
30
|
|
|
|
|
73
|
my $ep_v = int((length($str) + 2) / 3) * 4 + $HTL + $sp; |
34
|
|
|
|
|
|
|
|
35
|
30
|
100
|
|
|
|
55
|
if ($ep_v + $rll <= $BPL) { |
36
|
13
|
|
|
|
|
14
|
$$ep = $ep_v; |
37
|
13
|
|
|
|
|
67
|
return $HEAD . encode_base64($str, '') . TAIL; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
17
|
100
|
|
|
|
29
|
my $ll_flag = ($ep_v <= $BPL) ? 1 : 0; |
41
|
17
|
|
|
|
|
18
|
my $k_in = 0; # ascii: 0, zen: 1 or 2, han: 9 |
42
|
17
|
|
|
|
|
17
|
my $k_in_bak = -1; |
43
|
17
|
|
|
|
|
18
|
my $k_out; |
44
|
|
|
|
|
|
|
my $ec; |
45
|
0
|
|
|
|
|
0
|
my $w1; |
46
|
17
|
|
|
|
|
22
|
my $w1_bak = ''; |
47
|
17
|
|
|
|
|
18
|
my $w = ''; |
48
|
17
|
|
|
|
|
19
|
my $w_len; |
49
|
17
|
|
|
|
|
17
|
my $w_bak = ''; |
50
|
17
|
|
|
|
|
15
|
my $chunk; |
51
|
|
|
|
|
|
|
my $chunk_len; |
52
|
17
|
|
|
|
|
17
|
my $result = ''; |
53
|
17
|
|
|
|
|
16
|
my $ep_str; |
54
|
17
|
|
|
|
|
36
|
my $max_len = int(($BPL - $HTL - $sp) / 4) * 3; |
55
|
17
|
|
|
|
|
23
|
my $max_len2 = int(($BPL - $HTL - 1) / 4) * 3; |
56
|
17
|
|
|
|
|
32
|
my $max_len3 = int(($BPL - $HTL - 1 - $rll) / 4) * 3; |
57
|
|
|
|
|
|
|
|
58
|
17
|
|
|
|
|
61
|
while ($str =~ /(\e(..)|.)/g) { |
59
|
181
|
|
|
|
|
296
|
($w1, $ec) = ($1, $2); |
60
|
181
|
|
|
|
|
183
|
$w .= $w1; |
61
|
181
|
100
|
|
|
|
247
|
if (defined $ec) { |
62
|
44
|
|
|
|
|
43
|
$w1_bak = $w1; |
63
|
44
|
100
|
|
|
|
91
|
if ($ec eq '(B') { |
|
|
100
|
|
|
|
|
|
64
|
13
|
|
|
|
|
14
|
$k_in = 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
elsif ($ec eq '$B') { |
67
|
27
|
|
|
|
|
38
|
$k_in = 1; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
4
|
|
|
|
|
5
|
$k_in = 9; |
71
|
|
|
|
|
|
|
} |
72
|
44
|
|
|
|
|
108
|
next; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
else { |
75
|
137
|
100
|
|
|
|
265
|
if ($k_in == 1) { |
|
|
100
|
|
|
|
|
|
76
|
54
|
|
|
|
|
50
|
$k_in = 2; |
77
|
54
|
|
|
|
|
224
|
next; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
elsif ($k_in == 2) { |
80
|
54
|
|
|
|
|
62
|
$k_in = 1; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
83
|
100
|
|
|
|
111
|
$k_out = $k_in ? 3 : 0; # 3 is "\e\(B" |
84
|
83
|
100
|
|
|
|
142
|
if (pos($str) + $k_out > $max_len) { |
85
|
15
|
|
|
|
|
17
|
$w_len = length($w); |
86
|
15
|
100
|
|
|
|
25
|
if ($k_in_bak < 0) { # size over at the first time |
87
|
8
|
|
|
|
|
9
|
$result = ' '; |
88
|
8
|
50
|
|
|
|
18
|
return $result if $fof; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
7
|
100
|
|
|
|
12
|
if ($k_in_bak) { |
92
|
5
|
|
|
|
|
19
|
$chunk = $w_bak . |
93
|
|
|
|
|
|
|
substr($str, 0, pos($str) - $w_len, "") . "\e\(B"; |
94
|
5
|
100
|
|
|
|
10
|
if ($k_in) { |
95
|
3
|
100
|
|
|
|
8
|
if ($k_in_bak == $k_in) { |
96
|
2
|
|
|
|
|
4
|
$w = $w1_bak . $w; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
2
|
|
|
|
|
4
|
$w = $w1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
2
|
|
|
|
|
9
|
$chunk = $w_bak . substr($str, 0, pos($str) - $w_len, ""); |
105
|
|
|
|
|
|
|
} |
106
|
7
|
|
|
|
|
45
|
$result .= $HEAD . encode_base64($chunk, '') . TAIL . "$LF "; |
107
|
|
|
|
|
|
|
} |
108
|
15
|
|
|
|
|
31
|
substr($str, 0, $w_len, ""); |
109
|
15
|
|
|
|
|
17
|
$chunk_len = length($str) + length($w); |
110
|
15
|
50
|
|
|
|
30
|
if ($chunk_len <= $max_len3) { |
111
|
15
|
|
|
|
|
18
|
$chunk = $w . $str; |
112
|
15
|
|
|
|
|
17
|
last; |
113
|
|
|
|
|
|
|
} |
114
|
0
|
0
|
|
|
|
0
|
$ll_flag = 1 if $chunk_len <= $max_len2; |
115
|
0
|
|
|
|
|
0
|
$w_bak = $w; |
116
|
0
|
|
|
|
|
0
|
$max_len = $max_len2 - length($w_bak); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
else { |
119
|
68
|
100
|
100
|
|
|
160
|
if ($ll_flag and pos($str) + $k_out == length($str)) { # last char |
120
|
2
|
100
|
|
|
|
6
|
if ($k_in_bak < 0) { # size over at the first time |
121
|
1
|
|
|
|
|
2
|
$result = ' '; |
122
|
1
|
50
|
|
|
|
4
|
return $result if $fof; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
else { |
125
|
1
|
50
|
|
|
|
3
|
if ($k_in_bak) { |
126
|
0
|
|
|
|
|
0
|
$chunk = $w_bak . |
127
|
|
|
|
|
|
|
substr($str, 0, pos($str) - length($w), "") . |
128
|
|
|
|
|
|
|
"\e\(B"; |
129
|
0
|
0
|
|
|
|
0
|
if ($k_in) { |
130
|
0
|
0
|
|
|
|
0
|
if ($k_in_bak == $k_in) { |
131
|
0
|
|
|
|
|
0
|
$w = $w1_bak . $w; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
else { |
135
|
0
|
|
|
|
|
0
|
$w = $w1; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else { |
139
|
1
|
|
|
|
|
5
|
$chunk = $w_bak . |
140
|
|
|
|
|
|
|
substr($str, 0, pos($str) - length($w), ""); |
141
|
|
|
|
|
|
|
} |
142
|
1
|
|
|
|
|
6
|
$result .= $HEAD |
143
|
|
|
|
|
|
|
. encode_base64($chunk, '') . TAIL . "$LF "; |
144
|
|
|
|
|
|
|
} |
145
|
2
|
50
|
|
|
|
6
|
$chunk = $k_out ? $w . "\e\(B" : $w; |
146
|
2
|
|
|
|
|
3
|
last; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
66
|
|
|
|
|
67
|
$k_in_bak = $k_in; |
150
|
66
|
|
|
|
|
203
|
$w = ''; |
151
|
|
|
|
|
|
|
} |
152
|
17
|
|
|
|
|
57
|
$ep_str = $HEAD . encode_base64($chunk, '') . TAIL; |
153
|
17
|
|
|
|
|
33
|
$$ep = length($ep_str) + 1; |
154
|
17
|
|
|
|
|
73
|
return $result . $ep_str; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |