jpmobile 1.0.0.pre.2 → 1.0.0.pre.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -2,4 +2,4 @@
2
2
  :major: 1
3
3
  :minor: 0
4
4
  :patch: 0
5
- :build: pre.2
5
+ :build: pre.3
@@ -94,7 +94,7 @@ module Jpmobile::Mobile
94
94
 
95
95
  # メール送信用
96
96
  def to_mail_subject(str)
97
- "=?#{mail_charset}?B?" + [to_mail_encoding(str)].pack('m').strip + "?="
97
+ [to_mail_encoding(str)].pack('m').strip.split(/\n|\r\n/).map{|subj| "=?#{mail_charset}?B?#{subj}?="}.join("\n ")
98
98
  end
99
99
  def to_mail_body(str)
100
100
  to_mail_encoding(str)
@@ -105,9 +105,6 @@ module Jpmobile::Mobile
105
105
  end
106
106
 
107
107
  # メール送信用
108
- def to_mail_subject(str)
109
- "=?#{mail_charset}?B?" + [to_mail_encoding(str)].pack('m').strip + "?="
110
- end
111
108
  def to_mail_body(str)
112
109
  to_mail_encoding(str)
113
110
  end
@@ -97,13 +97,12 @@ module Jpmobile::Mobile
97
97
  end
98
98
 
99
99
  # メール送信用
100
- def to_mail_subject(str)
101
- str = to_external(str, nil, nil).first
102
- "=?#{mail_charset}?B?" + [str].pack('m').strip + "?="
103
- end
104
100
  def to_mail_body(str)
105
101
  to_external(str, nil, nil).first
106
102
  end
103
+ def to_mail_encoding(str)
104
+ to_external(str, nil, nil).first
105
+ end
107
106
  def to_mail_internal(str, charset)
108
107
  if Jpmobile::Util.shift_jis?(str) or Jpmobile::Util.ascii_8bit?(str) or charset == mail_charset
109
108
  # 絵文字を数値参照に変換
@@ -62,9 +62,6 @@ module Jpmobile::Mobile
62
62
  end
63
63
 
64
64
  # メール送信用
65
- def to_mail_subject(str)
66
- "=?#{mail_charset}?B?" + [to_mail_encoding(str)].pack('m').strip + "?="
67
- end
68
65
  def to_mail_body(str)
69
66
  to_mail_encoding(str)
70
67
  end
data/lib/jpmobile/util.rb CHANGED
@@ -14,6 +14,12 @@ module Jpmobile
14
14
  OVERLINE = [0x203e].pack("U")
15
15
  FULLWIDTH_MACRON = [0xffe3].pack("U")
16
16
 
17
+ EM_DASH = [0x2014].pack("U")
18
+ HORIZONTAL_BAR = [0x2015].pack("U")
19
+
20
+ MINUS_SIGN = [0x2212].pack("U")
21
+ FULLWIDTH_HYPHEN_MINUS = [0xFF0D].pack("U")
22
+
17
23
  module_function
18
24
  def deep_apply(obj, &proc)
19
25
  case obj
@@ -90,6 +96,10 @@ module Jpmobile
90
96
  utf8_str = wavedash_to_fullwidth_tilde(utf8_str)
91
97
  # オーバーライン対策(不可逆的)
92
98
  utf8_str = overline_to_fullwidth_macron(utf8_str)
99
+ # ダッシュ対策(不可逆的)
100
+ utf8_str = emdash_to_horizontal_bar(utf8_str)
101
+ # マイナス対策(不可逆的)
102
+ utf8_str = minus_sign_to_fullwidth_pyphen_minus(utf8_str)
93
103
 
94
104
  if utf8_str.respond_to?(:encode)
95
105
  utf8_str.encode(SJIS, :crlf_newline => true)
@@ -210,6 +220,18 @@ module Jpmobile
210
220
  utf8_str.gsub(FULLWIDTH_MACRON, OVERLINE)
211
221
  end
212
222
 
223
+ def emdash_to_horizontal_bar(utf8_str)
224
+ utf8_str.gsub(EM_DASH, HORIZONTAL_BAR)
225
+ end
226
+
227
+ def minus_sign_to_fullwidth_pyphen_minus(utf8_str)
228
+ utf8_str.gsub(MINUS_SIGN, FULLWIDTH_HYPHEN_MINUS)
229
+ end
230
+
231
+ def fullwidth_pyphen_minus_to_minus_sign(utf8_str)
232
+ utf8_str.gsub(FULLWIDTH_HYPHEN_MINUS, MINUS_SIGN)
233
+ end
234
+
213
235
  def force_encode(str, from, to)
214
236
  s = str.dup
215
237
  return str if detect_encoding(str) == to
@@ -114,4 +114,75 @@ describe "Jpmobile::Mail" do
114
114
  end
115
115
  end
116
116
  end
117
+
118
+ describe "long subject" do
119
+ before(:each) do
120
+ @mail = Mail.new
121
+ @mail.subject = "弊社採用応募へのお申込み誠にありがとうございますと言いたいところだがそうは簡単には物事は運ばないことを心しておいてもらいたいと苦言を呈する故に弊社は維持しているのです"
122
+ @mail.body = "株式会社・・"
123
+ @mail.from = "info@jpmobile-rails.org"
124
+ end
125
+
126
+ describe "Docomo" do
127
+ before(:each) do
128
+ @mobile = Jpmobile::Mobile::Docomo.new(nil, nil)
129
+ @mail.mobile = @mobile
130
+ @mail.to = "info+to@jpmobile-rails.org"
131
+ end
132
+
133
+ it "should contain encoded subject" do
134
+ @mail.to_s.should match(sjis_regexp("=?Shift_JIS?B?lb6O0I3Ml3CJnpXlgtaCzIKokFyNnoLdkL2CyYKgguiCqoLGgqSCsoK0gqKC?="))
135
+ @mail.to_s.should match(sjis_regexp("=?Shift_JIS?B?3IK3gsaMvoKigr2CooLGgrGC64K+gqqCu4Kkgs2KyJJQgsmCzZWojpaCzYle?="))
136
+ @mail.to_s.should match(sjis_regexp("=?Shift_JIS?B?gs6CyIKigrGCxoLwkFOCtYLEgqiCooLEguCC54Kigr2CooLGi+qMvoLwkuaC?="))
137
+ @mail.to_s.should match(sjis_regexp("=?Shift_JIS?B?t4LpjMyCyZW+jtCCzYjbjp2CtYLEgqKC6YLMgsWCtw==?="))
138
+ end
139
+ end
140
+
141
+ describe "Au" do
142
+ before(:each) do
143
+ @mobile = Jpmobile::Mobile::Au.new(nil, nil)
144
+ @mail.mobile = @mobile
145
+ @mail.to = "info+to@jpmobile-rails.org"
146
+ end
147
+
148
+ it "should contain encoded subject" do
149
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?GyRCSkA8UjpOTVExfkpnJFgkTiQqPz05fiRfQD8kSyQiJGokLCRIJCYkNCQ2?=")))
150
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?JCQkXiQ5JEg4QCQkJD8kJCRIJDMkbSRAJCwkPSQmJE80SkMxJEskT0oqO3Yk?=")))
151
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?TzE/JFAkSiQkJDMkSCRyPzQkNyRGJCokJCRGJGIkaSQkJD8kJCRINmw4QCRy?=")))
152
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?RGgkOSRrOE4kS0pAPFIkTzBdO30kNyRGJCQkayROJEckORsoQg==?=")))
153
+ end
154
+ end
155
+
156
+ describe "Softbank" do
157
+ before(:each) do
158
+ @mobile = Jpmobile::Mobile::Softbank.new(nil, nil)
159
+ @mail.mobile = @mobile
160
+ @mail.to = "info+to@jpmobile-rails.org"
161
+ end
162
+
163
+ it "should contain encoded subject" do
164
+ @mail.to_s.should match(sjis_regexp("=?Shift_JIS?B?lb6O0I3Ml3CJnpXlgtaCzIKokFyNnoLdkL2CyYKgguiCqoLGgqSCsoK0gqKC?="))
165
+ @mail.to_s.should match(sjis_regexp("=?Shift_JIS?B?3IK3gsaMvoKigr2CooLGgrGC64K+gqqCu4Kkgs2KyJJQgsmCzZWojpaCzYle?="))
166
+ @mail.to_s.should match(sjis_regexp("=?Shift_JIS?B?gs6CyIKigrGCxoLwkFOCtYLEgqiCooLEguCC54Kigr2CooLGi+qMvoLwkuaC?="))
167
+ @mail.to_s.should match(sjis_regexp("=?Shift_JIS?B?t4LpjMyCyZW+jtCCzYjbjp2CtYLEgqKC6YLMgsWCtw==?="))
168
+ end
169
+ end
170
+
171
+ describe "AbstractMobile" do
172
+ before(:each) do
173
+ @mobile = Jpmobile::Mobile::AbstractMobile.new(nil, nil)
174
+ @mail.mobile = @mobile
175
+ @mail.to = "info+to@jpmobile-rails.org"
176
+ end
177
+
178
+ context "to_s" do
179
+ it "should contain encoded subject" do
180
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?GyRCSkA8UjpOTVExfkpnJFgkTiQqPz05fiRfQD8kSyQiJGokLCRIJCYkNCQ2?=")))
181
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?JCQkXiQ5JEg4QCQkJD8kJCRIJDMkbSRAJCwkPSQmJE80SkMxJEskT0oqO3Yk?=")))
182
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?TzE/JFAkSiQkJDMkSCRyPzQkNyRGJCokJCRGJGIkaSQkJD8kJCRINmw4QCRy?=")))
183
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?RGgkOSRrOE4kS0pAPFIkTzBdO30kNyRGJCQkayROJEckORsoQg==?=")))
184
+ end
185
+ end
186
+ end
187
+ end
117
188
  end
@@ -46,6 +46,14 @@ describe Jpmobile::Util, ".deep_apply" do
46
46
  utf8_to_sjis([0x203e].pack("U")).should == sjis("\x81\x50")
47
47
  end
48
48
 
49
+ it "U+2014が0x815Cに変換されること" do
50
+ utf8_to_sjis([0x2014].pack("U")).should == sjis("\x81\x5C")
51
+ end
52
+
53
+ it "U+2212が0x817Cに変換されること" do
54
+ utf8_to_sjis([0x2212].pack("U")).should == sjis("\x81\x7C")
55
+ end
56
+
49
57
  it "jis_string_regexpでISO-2022-JPの文字列がマッチすること" do
50
58
  jis_string_regexp.match(ascii_8bit(utf8_to_jis("abcしからずんばこじをえずdef"))).should_not be_nil
51
59
  jis_to_utf8(jis("\x1b\x24\x42#{$1}\x1b\x28\x42")).should == "しからずんばこじをえず"
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- RailsRoot::Application.config.secret_token = 'cd4376c24b0c709240272ca3e6e9da688833c2a1a7ca1228bb68f8f7767e9da43b6d309f825fa18cc80c8f0a5e6d009a5cd9d5246ba5277ca64040469a1d2e96'
7
+ RailsRoot::Application.config.secret_token = '30b2e525066442670f0070c3613af392261800e535c709b47d44c9a0a01ed9105a5319f62d6707d6b0f1d6f900f15bf318f517155b3443bf3c2fb16bc025563a'
@@ -94,7 +94,7 @@ module Jpmobile::Mobile
94
94
 
95
95
  # メール送信用
96
96
  def to_mail_subject(str)
97
- "=?#{mail_charset}?B?" + [to_mail_encoding(str)].pack('m').strip + "?="
97
+ [to_mail_encoding(str)].pack('m').strip.split(/\n|\r\n/).map{|subj| "=?#{mail_charset}?B?#{subj}?="}.join("\n ")
98
98
  end
99
99
  def to_mail_body(str)
100
100
  to_mail_encoding(str)
@@ -105,9 +105,6 @@ module Jpmobile::Mobile
105
105
  end
106
106
 
107
107
  # メール送信用
108
- def to_mail_subject(str)
109
- "=?#{mail_charset}?B?" + [to_mail_encoding(str)].pack('m').strip + "?="
110
- end
111
108
  def to_mail_body(str)
112
109
  to_mail_encoding(str)
113
110
  end
@@ -97,13 +97,12 @@ module Jpmobile::Mobile
97
97
  end
98
98
 
99
99
  # メール送信用
100
- def to_mail_subject(str)
101
- str = to_external(str, nil, nil).first
102
- "=?#{mail_charset}?B?" + [str].pack('m').strip + "?="
103
- end
104
100
  def to_mail_body(str)
105
101
  to_external(str, nil, nil).first
106
102
  end
103
+ def to_mail_encoding(str)
104
+ to_external(str, nil, nil).first
105
+ end
107
106
  def to_mail_internal(str, charset)
108
107
  if Jpmobile::Util.shift_jis?(str) or Jpmobile::Util.ascii_8bit?(str) or charset == mail_charset
109
108
  # 絵文字を数値参照に変換
@@ -62,9 +62,6 @@ module Jpmobile::Mobile
62
62
  end
63
63
 
64
64
  # メール送信用
65
- def to_mail_subject(str)
66
- "=?#{mail_charset}?B?" + [to_mail_encoding(str)].pack('m').strip + "?="
67
- end
68
65
  def to_mail_body(str)
69
66
  to_mail_encoding(str)
70
67
  end
@@ -14,6 +14,12 @@ module Jpmobile
14
14
  OVERLINE = [0x203e].pack("U")
15
15
  FULLWIDTH_MACRON = [0xffe3].pack("U")
16
16
 
17
+ EM_DASH = [0x2014].pack("U")
18
+ HORIZONTAL_BAR = [0x2015].pack("U")
19
+
20
+ MINUS_SIGN = [0x2212].pack("U")
21
+ FULLWIDTH_HYPHEN_MINUS = [0xFF0D].pack("U")
22
+
17
23
  module_function
18
24
  def deep_apply(obj, &proc)
19
25
  case obj
@@ -90,6 +96,10 @@ module Jpmobile
90
96
  utf8_str = wavedash_to_fullwidth_tilde(utf8_str)
91
97
  # オーバーライン対策(不可逆的)
92
98
  utf8_str = overline_to_fullwidth_macron(utf8_str)
99
+ # ダッシュ対策(不可逆的)
100
+ utf8_str = emdash_to_horizontal_bar(utf8_str)
101
+ # マイナス対策(不可逆的)
102
+ utf8_str = minus_sign_to_fullwidth_pyphen_minus(utf8_str)
93
103
 
94
104
  if utf8_str.respond_to?(:encode)
95
105
  utf8_str.encode(SJIS, :crlf_newline => true)
@@ -210,6 +220,18 @@ module Jpmobile
210
220
  utf8_str.gsub(FULLWIDTH_MACRON, OVERLINE)
211
221
  end
212
222
 
223
+ def emdash_to_horizontal_bar(utf8_str)
224
+ utf8_str.gsub(EM_DASH, HORIZONTAL_BAR)
225
+ end
226
+
227
+ def minus_sign_to_fullwidth_pyphen_minus(utf8_str)
228
+ utf8_str.gsub(MINUS_SIGN, FULLWIDTH_HYPHEN_MINUS)
229
+ end
230
+
231
+ def fullwidth_pyphen_minus_to_minus_sign(utf8_str)
232
+ utf8_str.gsub(FULLWIDTH_HYPHEN_MINUS, MINUS_SIGN)
233
+ end
234
+
213
235
  def force_encode(str, from, to)
214
236
  s = str.dup
215
237
  return str if detect_encoding(str) == to
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jpmobile
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.0.0.pre.2
5
+ version: 1.0.0.pre.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Yoji Shidara
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-03-03 00:00:00 +09:00
14
+ date: 2011-04-18 00:00:00 +09:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency