line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Encode::compat::MIME::Header::ISO_2022_JP; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
85688
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
120
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
1
|
|
|
1
|
|
9
|
local $@; |
10
|
1
|
|
|
|
|
7
|
eval { |
11
|
1
|
|
|
|
|
1736
|
require "Encode/MIME/Header/ISO_2022_JP.pm"; |
12
|
|
|
|
|
|
|
}; |
13
|
1
|
50
|
|
|
|
11089
|
if ($@) { |
14
|
|
|
|
|
|
|
# eval the module taken from Encode 2.29 |
15
|
0
|
|
|
|
|
|
eval << '__EOC__'; |
16
|
|
|
|
|
|
|
package Encode::MIME::Header::ISO_2022_JP; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use strict; |
19
|
|
|
|
|
|
|
use warnings; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use base qw(Encode::MIME::Header); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$Encode::Encoding{'MIME-Header-ISO_2022_JP'} = |
24
|
|
|
|
|
|
|
bless { encode => 'B', bpl => 76, Name => 'MIME-Header-ISO_2022_JP' } => |
25
|
|
|
|
|
|
|
__PACKAGE__; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use constant HEAD => '=?ISO-2022-JP?B?'; |
28
|
|
|
|
|
|
|
use constant TAIL => '?='; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Encode::CJKConstants qw(%RE); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = do { my @r = ( q$Revision: 1.3 $ =~ /\d+/g ); sprintf "%d." . "%02d" x $#r, @r }; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# I owe the below codes totally to |
35
|
|
|
|
|
|
|
# Jcode by Dan Kogai & http://www.din.or.jp/~ohzaki/perl.htm#JP_Base64 |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub encode { |
38
|
|
|
|
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
my $str = shift; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
utf8::encode($str) if ( Encode::is_utf8($str) ); |
42
|
|
|
|
|
|
|
Encode::from_to( $str, 'utf8', 'euc-jp' ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my ($trailing_crlf) = ( $str =~ /(\n|\r|\x0d\x0a)$/o ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$str = _mime_unstructured_header( $str, $self->{bpl} ); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
not $trailing_crlf and $str =~ s/(\n|\r|\x0d\x0a)$//o; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return $str; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _mime_unstructured_header { |
54
|
|
|
|
|
|
|
my ( $oldheader, $bpl ) = @_; |
55
|
|
|
|
|
|
|
my $crlf = $oldheader =~ /\n$/; |
56
|
|
|
|
|
|
|
my ( $header, @words, @wordstmp, $i ) = (''); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$oldheader =~ s/\s+$//; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
@wordstmp = split /\s+/, $oldheader; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
for ( $i = 0 ; $i < $#wordstmp ; $i++ ) { |
63
|
|
|
|
|
|
|
if ( $wordstmp[$i] !~ /^[\x21-\x7E]+$/ |
64
|
|
|
|
|
|
|
and $wordstmp[ $i + 1 ] !~ /^[\x21-\x7E]+$/ ) |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
$wordstmp[ $i + 1 ] = "$wordstmp[$i] $wordstmp[$i + 1]"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
|
|
|
|
|
|
push( @words, $wordstmp[$i] ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
push( @words, $wordstmp[-1] ); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
for my $word (@words) { |
76
|
|
|
|
|
|
|
if ( $word =~ /^[\x21-\x7E]+$/ ) { |
77
|
|
|
|
|
|
|
$header =~ /(?:.*\n)*(.*)/; |
78
|
|
|
|
|
|
|
if ( length($1) + length($word) > $bpl ) { |
79
|
|
|
|
|
|
|
$header .= "\n $word"; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
|
|
|
|
|
|
$header .= $word; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
|
|
|
|
|
|
$header = _add_encoded_word( $word, $header, $bpl ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$header =~ /(?:.*\n)*(.*)/; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
if ( length($1) == $bpl ) { |
92
|
|
|
|
|
|
|
$header .= "\n "; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
|
|
|
|
|
|
$header .= ' '; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$header =~ s/\n? $//mg; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$crlf ? "$header\n" : $header; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _add_encoded_word { |
105
|
|
|
|
|
|
|
my ( $str, $line, $bpl ) = @_; |
106
|
|
|
|
|
|
|
my $result = ''; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
while ( length($str) ) { |
109
|
|
|
|
|
|
|
my $target = $str; |
110
|
|
|
|
|
|
|
$str = ''; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
if ( |
113
|
|
|
|
|
|
|
length($line) + 22 + |
114
|
|
|
|
|
|
|
( $target =~ /^(?:$RE{EUC_0212}|$RE{EUC_C})/o ) * 8 > $bpl ) |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
$line =~ s/[ \t\n\r]*$/\n/; |
117
|
|
|
|
|
|
|
$result .= $line; |
118
|
|
|
|
|
|
|
$line = ' '; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
while (1) { |
122
|
|
|
|
|
|
|
my $iso_2022_jp = $target; |
123
|
|
|
|
|
|
|
Encode::from_to( $iso_2022_jp, 'euc-jp', 'iso-2022-jp' ); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $encoded = |
126
|
|
|
|
|
|
|
HEAD . MIME::Base64::encode_base64( $iso_2022_jp, '' ) . TAIL; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
if ( length($encoded) + length($line) > $bpl ) { |
129
|
|
|
|
|
|
|
$target =~ |
130
|
|
|
|
|
|
|
s/($RE{EUC_0212}|$RE{EUC_KANA}|$RE{EUC_C}|$RE{ASCII})$//o; |
131
|
|
|
|
|
|
|
$str = $1 . $str; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
else { |
134
|
|
|
|
|
|
|
$line .= $encoded; |
135
|
|
|
|
|
|
|
last; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$result . $line; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
__EOC__ |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
}; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
__END__ |