mail-iso-2022-jp 2.0.0.pre2 → 2.0.0.pre3

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 CHANGED
@@ -118,8 +118,10 @@ Remarks
118
118
  * (en)
119
119
  * NEC special characters like `①` and IBM extended characters like `髙`, `﨑`
120
120
  are allowed in the subject, recipient names and mail body.
121
- * Fullwidth tilde (U+FF5E) and wave dashe (U+301C) are converted to the fullwidth tilde (2141).
122
- * Fullwidth hyphen minus (U+FF0D) and minus sign (U+2212) are converted to the fullwidth minus (215D).
121
+ * FULLWIDTH TILDE (U+FF5E) and WAVE DASH (U+301C) are converted to the fullwidth tilde `〜` (0x2141).
122
+ * FULLWIDTH HYPHEN MINUS (U+FF0D) and MINUS SIGN (U+2212) are converted to the fullwidth minus `−` (0x215d).
123
+ * EM DASH (U+2014) and HORIZONTAL BAR (U+2015) are converted to the dash sign `—` (0x213d).
124
+ * DOUBLE VERTICAL LINE (U+2016, '‖') and PARALLEL TO (U+2225, `∥`) to `‖` (0x2142).
123
125
  * Halfwidth (Hankaku) katakanas are maintained intact.
124
126
  * Characters that cannot be translated into iso-2022-jp encoding are substituted with question marks (`?`).
125
127
 
@@ -127,6 +129,8 @@ Remarks
127
129
  * `①` などのNEC特殊文字や `髙` や `﨑` といったIBM拡張文字を件名、宛先、本文などに含めることができます。
128
130
  * 全角チルダ(U+FF5E)と波ダッシュ(U+301C)は、全角チルダ(2141)に変換されます。
129
131
  * 全角ハイフンマイナス(U+ff0D)とマイナス記号(U+2212)は、全角マイナス(215D)に変換されます。
132
+ * 長い(em)ダッシュ(U+2014)と水平線(U+2015)は、ダッシュ(213D)に変換されます。
133
+ * 二重縦線(U+2016, '‖')と平行記号(U+2225, `∥`)は、`‖` (0x2142)に変換されます。
130
134
  * 半角カタカナはそのまま維持されます。
131
135
  * 変換できない文字は疑問符(`?`)で置換されます。
132
136
 
@@ -1,3 +1,7 @@
1
+ require 'mail-iso-2022-jp/character_names'
2
+ require 'mail-iso-2022-jp/invalid_encoding_error'
3
+ require 'mail-iso-2022-jp/common_methods_for_field'
4
+
1
5
  if RUBY_VERSION >= '1.9'
2
6
  require 'mail-iso-2022-jp/mail'
3
7
  require 'mail-iso-2022-jp/message'
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+
3
+ module Mail
4
+ WAVE_DASH = [0x301c].pack("U")
5
+ FULLWIDTH_TILDE = [0xff5e].pack("U")
6
+ MINUS_SIGN = [0x2212].pack("U")
7
+ FULLWIDTH_HYPHEN_MINUS = [0xff0d].pack("U")
8
+ EM_DASH = [0x2014].pack("U")
9
+ HORIZONTAL_BAR = [0x2015].pack("U")
10
+ DOUBLE_VERTICAL_LINE = [0x2016].pack("U")
11
+ PARALLEL_TO = [0x2225].pack("U")
12
+ end
@@ -0,0 +1,42 @@
1
+ module Mail
2
+ module CommonMethodsForField
3
+ private
4
+ def do_decode_with_iso_2022_jp_encoding
5
+ if charset.to_s.downcase == 'iso-2022-jp'
6
+ value
7
+ else
8
+ do_decode_without_iso_2022_jp_encoding
9
+ end
10
+ end
11
+
12
+ def b_value_encode(string)
13
+ string.split(' ').map do |s|
14
+ if s =~ /\e/
15
+ encode64(s)
16
+ else
17
+ s
18
+ end
19
+ end.join(" ")
20
+ end
21
+
22
+ def encode(value)
23
+ if charset.to_s.downcase == 'iso-2022-jp'
24
+ value
25
+ else
26
+ super(value)
27
+ end
28
+ end
29
+
30
+ def encode64(string)
31
+ "=?ISO-2022-JP?B?#{Base64.encode64(string).gsub("\n", "")}?="
32
+ end
33
+
34
+ def preprocess(value)
35
+ value = value.to_s.gsub(/#{WAVE_DASH}/, FULLWIDTH_TILDE)
36
+ value = value.to_s.gsub(/#{MINUS_SIGN}/, FULLWIDTH_HYPHEN_MINUS)
37
+ value = value.to_s.gsub(/#{EM_DASH}/, HORIZONTAL_BAR)
38
+ value = value.to_s.gsub(/#{DOUBLE_VERTICAL_LINE}/, PARALLEL_TO)
39
+ value
40
+ end
41
+ end
42
+ end
@@ -1,4 +1,4 @@
1
- # coding:utf-8
1
+ # coding: utf-8
2
2
 
3
3
  require 'mail'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding:utf-8
1
+ # coding: utf-8
2
2
 
3
3
  require 'mail'
4
4
  require 'base64'
@@ -6,6 +6,7 @@ require 'base64'
6
6
  module Mail
7
7
  module FieldWithIso2022JpEncoding
8
8
  def self.included(base)
9
+ base.send :include, Mail::CommonMethodsForField
9
10
  base.send :alias_method, :initialize_without_iso_2022_jp_encoding, :initialize
10
11
  base.send :alias_method, :initialize, :initialize_with_iso_2022_jp_encoding
11
12
  base.send :alias_method, :do_decode_without_iso_2022_jp_encoding, :do_decode
@@ -24,51 +25,19 @@ module Mail
24
25
  end
25
26
 
26
27
  private
27
- def do_decode_with_iso_2022_jp_encoding
28
- if charset.to_s.downcase == 'iso-2022-jp'
29
- value
30
- else
31
- do_decode_without_iso_2022_jp_encoding
32
- end
33
- end
34
-
35
28
  def encode_with_iso_2022_jp(value, charset)
36
- value = value.to_s.gsub(/#{WAVE_DASH}/, FULLWIDTH_TILDE)
37
- value = value.to_s.gsub(/#{MINUS_SIGN}/, FULLWIDTH_HYPHEN_MINUS)
29
+ value = preprocess(value)
38
30
  value = Mail.encoding_to_charset(value, charset)
39
31
  value.force_encoding('ascii-8bit')
40
32
  value = b_value_encode(value)
41
33
  value.force_encoding('ascii-8bit')
42
34
  end
43
35
 
44
- def b_value_encode(string)
45
- string.split(' ').map do |s|
46
- if s =~ /\e/
47
- encode64(s)
48
- else
49
- s
50
- end
51
- end.join(" ")
52
- end
53
-
54
- private
55
- def encode(value)
56
- if charset.to_s.downcase == 'iso-2022-jp'
57
- value
58
- else
59
- super(value)
60
- end
61
- end
62
-
63
36
  def encode_crlf(value)
64
37
  if charset.to_s.downcase == 'iso-2022-jp'
65
38
  value.force_encoding('ascii-8bit')
66
39
  end
67
40
  super(value)
68
41
  end
69
-
70
- def encode64(string)
71
- "=?ISO-2022-JP?B?#{Base64.encode64(string).gsub("\n", "")}?="
72
- end
73
42
  end
74
43
  end
@@ -1,4 +1,4 @@
1
- # coding:utf-8
1
+ # coding: utf-8
2
2
 
3
3
  module Mail
4
4
  class Header
@@ -0,0 +1,3 @@
1
+ module Mail
2
+ class InvalidEncodingError < StandardError; end
3
+ end
@@ -2,15 +2,9 @@
2
2
 
3
3
  # Patches for Mail on Ruby 1.9.3 or above
4
4
  module Mail
5
- WAVE_DASH = "〜" # U+301C
6
- FULLWIDTH_TILDE = "~" # U+FF5E
7
- MINUS_SIGN = [0x2212].pack("U")
8
- FULLWIDTH_HYPHEN_MINUS = [0xff0d].pack("U")
9
5
  ENCODE = { 'iso-2022-jp' => Encoding::CP50221 }
10
6
 
11
7
  def self.encoding_to_charset(str, charset)
12
8
  str.encode(ENCODE[charset.to_s.downcase] || charset, :undef => :replace).force_encoding(charset)
13
9
  end
14
-
15
- class InvalidEncodingError < StandardError; end
16
10
  end
@@ -12,6 +12,8 @@ module Mail
12
12
  "The mail body is not encoded in UTF-8 but in #{value.encoding}")
13
13
  end
14
14
  value = value.gsub(/#{MINUS_SIGN}/, FULLWIDTH_HYPHEN_MINUS)
15
+ value = value.gsub(/#{EM_DASH}/, HORIZONTAL_BAR)
16
+ value = value.gsub(/#{DOUBLE_VERTICAL_LINE}/, PARALLEL_TO)
15
17
  end
16
18
  self.body_without_iso_2022_jp_encoding = value
17
19
  end
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  require 'mail'
4
2
  require 'base64'
5
3
  require 'nkf'
@@ -7,6 +5,7 @@ require 'nkf'
7
5
  module Mail
8
6
  module FieldWithIso2022JpEncoding
9
7
  def self.included(base)
8
+ base.send :include, Mail::CommonMethodsForField
10
9
  base.send :alias_method, :initialize_without_iso_2022_jp_encoding, :initialize
11
10
  base.send :alias_method, :initialize, :initialize_with_iso_2022_jp_encoding
12
11
  base.send :alias_method, :do_decode_without_iso_2022_jp_encoding, :do_decode
@@ -34,33 +33,9 @@ module Mail
34
33
  end
35
34
 
36
35
  def encode_with_iso_2022_jp(value)
37
- value = value.to_s.gsub(/#{WAVE_DASH}/, FULLWIDTH_TILDE)
38
- value = value.to_s.gsub(/#{MINUS_SIGN}/, FULLWIDTH_HYPHEN_MINUS)
36
+ value = preprocess(value)
39
37
  value = NKF.nkf(NKF_OPTIONS, value)
40
38
  b_value_encode(value)
41
39
  end
42
-
43
- def b_value_encode(string)
44
- string.split(' ').map do |s|
45
- if s =~ /\e/
46
- encode64(s)
47
- else
48
- s
49
- end
50
- end.join(" ")
51
- end
52
-
53
- private
54
- def encode(value)
55
- if charset.to_s.downcase == 'iso-2022-jp'
56
- value
57
- else
58
- super(value)
59
- end
60
- end
61
-
62
- def encode64(string)
63
- "=?ISO-2022-JP?B?#{Base64.encode64(string).gsub("\n", "")}?="
64
- end
65
40
  end
66
41
  end
@@ -1,12 +1,4 @@
1
- # coding: utf-8
2
-
3
1
  # Patches for Mail on Ruby 1.8.7
4
2
  module Mail
5
- WAVE_DASH = "〜" # U+301C
6
- FULLWIDTH_TILDE = "~" # U+FF5E
7
- MINUS_SIGN = [0x2212].pack("U")
8
- FULLWIDTH_HYPHEN_MINUS = [0xff0d].pack("U")
9
3
  NKF_OPTIONS = "--oc=CP50220 -xjW --fb-subchar"
10
-
11
- class InvalidEncodingError < StandardError; end
12
4
  end
@@ -1,5 +1,3 @@
1
- # coding:utf-8
2
-
3
1
  require 'mail'
4
2
  require 'nkf'
5
3
 
@@ -16,6 +14,8 @@ module Mail
16
14
  if @charset.to_s.downcase == 'iso-2022-jp'
17
15
  @body_raw = @body_raw.to_s.gsub(/#{WAVE_DASH}/, FULLWIDTH_TILDE)
18
16
  @body_raw = @body_raw.to_s.gsub(/#{MINUS_SIGN}/, FULLWIDTH_HYPHEN_MINUS)
17
+ @body_raw = @body_raw.to_s.gsub(/#{EM_DASH}/, HORIZONTAL_BAR)
18
+ @body_raw = @body_raw.to_s.gsub(/#{DOUBLE_VERTICAL_LINE}/, PARALLEL_TO)
19
19
  @body_raw = NKF.nkf(NKF_OPTIONS, @body_raw)
20
20
  end
21
21
  process_body_raw_without_iso_2022_jp_encoding
@@ -1,4 +1,4 @@
1
- # coding:utf-8
1
+ # coding: utf-8
2
2
 
3
3
  require 'mail'
4
4
 
@@ -1,4 +1,4 @@
1
- # coding:utf-8
1
+ # coding: utf-8
2
2
 
3
3
  require 'mail'
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail-iso-2022-jp
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre2
4
+ version: 2.0.0.pre3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -82,10 +82,13 @@ files:
82
82
  - lib/mail-iso-2022-jp/ruby18/message.rb
83
83
  - lib/mail-iso-2022-jp/ruby18/field_with_iso_2022_jp_encoding.rb
84
84
  - lib/mail-iso-2022-jp/ruby18/mail.rb
85
+ - lib/mail-iso-2022-jp/common_methods_for_field.rb
85
86
  - lib/mail-iso-2022-jp/field_with_iso_2022_jp_encoding.rb
86
87
  - lib/mail-iso-2022-jp/subject_field.rb
87
88
  - lib/mail-iso-2022-jp/structured_fields.rb
89
+ - lib/mail-iso-2022-jp/character_names.rb
88
90
  - lib/mail-iso-2022-jp/header.rb
91
+ - lib/mail-iso-2022-jp/invalid_encoding_error.rb
89
92
  - lib/mail-iso-2022-jp/mail.rb
90
93
  - lib/mail-iso-2022-jp.rb
91
94
  homepage: https://github.com/kuroda/mail-iso-2022-jp