mail-iso-2022-jp 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +10 -3
- data/lib/mail-iso-2022-jp/patches.rb +25 -4
- metadata +3 -3
data/README.md
CHANGED
@@ -40,7 +40,7 @@ Requirements
|
|
40
40
|
|
41
41
|
### Ruby ###
|
42
42
|
|
43
|
-
* 1.8.7
|
43
|
+
* 1.8.7, 1.9.x
|
44
44
|
|
45
45
|
### Gems ###
|
46
46
|
|
@@ -106,15 +106,22 @@ or run this command:
|
|
106
106
|
Remarks
|
107
107
|
-------
|
108
108
|
|
109
|
-
* Does not work with Ruby 1.9.x, currently.
|
110
109
|
* Wave dashes (U+301C) are replaced with fullwidth tildes (U+FF5E) before converted to iso-2022-jp.
|
111
110
|
* Special characters such as `髙` or `﨑` can't be handled correctly when they are found in the mail headers. This is a TODO.
|
112
111
|
|
113
|
-
* 現在のところ、Ruby 1.9.x では動作しません。
|
114
112
|
* 波ダッシュ(U+301C)は、iso-2022-jpへの変換前に全角チルダ(U+FF5E)で置き換えられます。
|
115
113
|
* `髙` や `﨑` といった特殊文字がメールヘッダにある場合は、正しく扱えません。これはTODO項目です。
|
116
114
|
|
117
115
|
|
116
|
+
References
|
117
|
+
----------
|
118
|
+
|
119
|
+
* http://d.hatena.ne.jp/fujisan3776/20110628/1309255427
|
120
|
+
* http://d.hatena.ne.jp/rudeboyjet/20100605/p1
|
121
|
+
* http://d.hatena.ne.jp/hichiriki/20101026#1288107706
|
122
|
+
* http://d.hatena.ne.jp/deeeki/20111003/rails3_mailer_iso2022jp
|
123
|
+
|
124
|
+
|
118
125
|
License
|
119
126
|
-------
|
120
127
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding:utf-8
|
2
|
+
|
2
3
|
module Mail
|
3
4
|
WAVE_DASH = "〜" # U+301C
|
4
5
|
FULLWIDTH_TILDE = "~" # U+FF5E
|
@@ -15,6 +16,17 @@ module Mail
|
|
15
16
|
alias_method :process_body_raw, :process_body_raw_with_iso_2022_jp_encoding
|
16
17
|
end
|
17
18
|
|
19
|
+
class Body
|
20
|
+
def initialize_with_iso_2022_jp_encoding(string = '')
|
21
|
+
if string.respond_to?(:encoding) && string.encoding.to_s == 'ISO-2022-JP'
|
22
|
+
string.force_encoding('US-ASCII')
|
23
|
+
end
|
24
|
+
initialize_without_iso_2022_jp_encoding(string)
|
25
|
+
end
|
26
|
+
alias_method :initialize_without_iso_2022_jp_encoding, :initialize
|
27
|
+
alias_method :initialize, :initialize_with_iso_2022_jp_encoding
|
28
|
+
end
|
29
|
+
|
18
30
|
module FieldWithIso2022JpEncoding
|
19
31
|
def self.included(base)
|
20
32
|
base.send :alias_method, :initialize_without_iso_2022_jp_encoding, :initialize
|
@@ -22,15 +34,15 @@ module Mail
|
|
22
34
|
base.send :alias_method, :do_decode_without_iso_2022_jp_encoding, :do_decode
|
23
35
|
base.send :alias_method, :do_decode, :do_decode_with_iso_2022_jp_encoding
|
24
36
|
end
|
25
|
-
|
37
|
+
|
26
38
|
def initialize_with_iso_2022_jp_encoding(value = nil, charset = 'utf-8')
|
27
39
|
if charset.to_s.downcase == 'iso-2022-jp'
|
28
40
|
value.gsub!(/#{WAVE_DASH}/, FULLWIDTH_TILDE)
|
29
|
-
value = NKF.nkf('--cp932 -
|
41
|
+
value = NKF.nkf('--cp932 -Mj', NKF.nkf('--cp932 -j', value)).gsub("\n", '').strip
|
30
42
|
end
|
31
43
|
initialize_without_iso_2022_jp_encoding(value, charset)
|
32
44
|
end
|
33
|
-
|
45
|
+
|
34
46
|
private
|
35
47
|
def do_decode_with_iso_2022_jp_encoding
|
36
48
|
if charset.to_s.downcase == 'iso-2022-jp'
|
@@ -40,9 +52,18 @@ module Mail
|
|
40
52
|
end
|
41
53
|
end
|
42
54
|
end
|
43
|
-
|
55
|
+
|
44
56
|
class SubjectField < UnstructuredField
|
45
57
|
include FieldWithIso2022JpEncoding
|
58
|
+
|
59
|
+
private
|
60
|
+
def encode(value)
|
61
|
+
if charset.to_s.downcase == 'iso-2022-jp'
|
62
|
+
value
|
63
|
+
else
|
64
|
+
super(value)
|
65
|
+
end
|
66
|
+
end
|
46
67
|
end
|
47
68
|
|
48
69
|
class FromField < StructuredField
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail-iso-2022-jp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kohei MATSUSHITA
|