jpmobile 5.0.0 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -3
- data/.rubocop.yml +123 -0
- data/CONTRIBUTING.md +16 -14
- data/Gemfile +6 -0
- data/Gemfile.lock +198 -0
- data/README.md +409 -0
- data/Rakefile +9 -9
- data/circle.yml +14 -0
- data/jpmobile.gemspec +9 -10
- data/lib/jpmobile.rb +6 -5
- data/lib/jpmobile/datum_conv.rb +35 -35
- data/lib/jpmobile/docomo_guid.rb +7 -8
- data/lib/jpmobile/email.rb +12 -12
- data/lib/jpmobile/emoticon.rb +85 -76
- data/lib/jpmobile/emoticon/au.rb +1284 -1284
- data/lib/jpmobile/emoticon/conversion_table.rb +3905 -3906
- data/lib/jpmobile/emoticon/docomo.rb +252 -252
- data/lib/jpmobile/emoticon/google.rb +9 -9
- data/lib/jpmobile/emoticon/softbank.rb +471 -471
- data/lib/jpmobile/emoticon/unicode.rb +9 -9
- data/lib/jpmobile/emoticon/z_combine.rb +20 -23
- data/lib/jpmobile/encoding.rb +1 -1
- data/lib/jpmobile/fallback_view_selector.rb +2 -3
- data/lib/jpmobile/filter.rb +44 -47
- data/lib/jpmobile/helpers.rb +38 -38
- data/lib/jpmobile/hook_action_view.rb +7 -7
- data/lib/jpmobile/hook_test_request.rb +0 -1
- data/lib/jpmobile/lookup_context.rb +1 -2
- data/lib/jpmobile/mail.rb +156 -134
- data/lib/jpmobile/mailer.rb +4 -4
- data/lib/jpmobile/mobile/abstract_mobile.rb +62 -36
- data/lib/jpmobile/mobile/android.rb +0 -1
- data/lib/jpmobile/mobile/android_tablet.rb +0 -1
- data/lib/jpmobile/mobile/au.rb +40 -28
- data/lib/jpmobile/mobile/black_berry.rb +0 -1
- data/lib/jpmobile/mobile/ddipocket.rb +1 -2
- data/lib/jpmobile/mobile/docomo.rb +47 -36
- data/lib/jpmobile/mobile/emobile.rb +1 -2
- data/lib/jpmobile/mobile/google_emoticon.rb +1 -1
- data/lib/jpmobile/mobile/ipad.rb +0 -1
- data/lib/jpmobile/mobile/iphone.rb +0 -1
- data/lib/jpmobile/mobile/smart_phone.rb +0 -1
- data/lib/jpmobile/mobile/softbank.rb +24 -20
- data/lib/jpmobile/mobile/tablet.rb +0 -1
- data/lib/jpmobile/mobile/unicode_emoticon.rb +15 -15
- data/lib/jpmobile/mobile/vodafone.rb +0 -1
- data/lib/jpmobile/mobile/willcom.rb +7 -7
- data/lib/jpmobile/mobile/windows_phone.rb +0 -1
- data/lib/jpmobile/path_set.rb +1 -1
- data/lib/jpmobile/position.rb +30 -14
- data/lib/jpmobile/rack/filter.rb +4 -4
- data/lib/jpmobile/rack/mobile_carrier.rb +0 -1
- data/lib/jpmobile/rack/params_filter.rb +7 -6
- data/lib/jpmobile/rails.rb +3 -4
- data/lib/jpmobile/request_with_mobile.rb +9 -6
- data/lib/jpmobile/resolver.rb +23 -17
- data/lib/jpmobile/session/active_record_store.rb +7 -9
- data/lib/jpmobile/session/mem_cache_store.rb +7 -9
- data/lib/jpmobile/sinatra.rb +1 -1
- data/lib/jpmobile/trans_sid.rb +15 -20
- data/lib/jpmobile/util.rb +61 -77
- data/lib/jpmobile/version.rb +1 -1
- data/lib/tasks/jpmobile_tasks.rake +35 -28
- data/spec/rack/jpmobile/android_spec.rb +5 -5
- data/spec/rack/jpmobile/au_spec.rb +74 -59
- data/spec/rack/jpmobile/black_berry_spec.rb +5 -5
- data/spec/rack/jpmobile/docomo_spec.rb +77 -64
- data/spec/rack/jpmobile/emoticon_spec.rb +137 -121
- data/spec/rack/jpmobile/filter_spec.rb +149 -128
- data/spec/rack/jpmobile/iphone_spec.rb +9 -8
- data/spec/rack/jpmobile/mobile_by_ua_spec.rb +22 -21
- data/spec/rack/jpmobile/params_filter_spec.rb +104 -96
- data/spec/rack/jpmobile/softbank_spec.rb +49 -42
- data/spec/rack/jpmobile/willcom_spec.rb +22 -18
- data/spec/rack/jpmobile/windows_phone.rb +5 -5
- data/spec/rack_helper.rb +9 -8
- data/spec/spec_helper.rb +5 -6
- data/spec/unit/decorated_mail_spec.rb +8 -9
- data/spec/unit/email_spec.rb +44 -44
- data/spec/unit/emoticon_spec.rb +57 -58
- data/spec/unit/encoding_spec.rb +35 -36
- data/spec/unit/is_carrier_spec.rb +49 -49
- data/spec/unit/mail_spec.rb +153 -143
- data/spec/unit/mobile/iphone_spec.rb +6 -7
- data/spec/unit/receive_mail_spec.rb +172 -173
- data/spec/unit/spec_helper.rb +6 -6
- data/spec/unit/util_spec.rb +125 -46
- data/spec/unit/valid_ip_spec.rb +35 -35
- data/spec/unit/variants_spec.rb +18 -19
- data/test/rails/overrides/Gemfile +54 -0
- data/test/rails/overrides/Gemfile.jpmobile +1 -2
- data/test/rails/overrides/app/controllers/admin/top_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/docomo_guid_base_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/filter_controller_base.rb +14 -6
- data/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/template_path_controller.rb +1 -2
- data/test/rails/overrides/app/controllers/trans_sid_base_controller.rb +18 -10
- data/test/rails/overrides/app/controllers/trans_sid_metal_controller.rb +0 -1
- data/test/rails/overrides/app/mailers/decorated_mailer.rb +3 -4
- data/test/rails/overrides/app/mailers/mobile_mailer.rb +5 -6
- data/test/rails/overrides/app/mailers/normal_mailer.rb +2 -3
- data/test/rails/overrides/autotest/discover.rb +2 -2
- data/test/rails/overrides/config/initializers/jpmobile_generator.rb +2 -2
- data/test/rails/overrides/config/routes.rb +95 -2
- data/test/rails/overrides/db/migrate/001_add_sessions_table.rb +2 -2
- data/test/rails/overrides/db/migrate/20100824062306_create_users.rb +1 -1
- data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +24 -25
- data/test/rails/overrides/spec/controllers/helpers_spec.rb +88 -88
- data/test/rails/overrides/spec/controllers/mobile_spec_controller_spec.rb +9 -9
- data/test/rails/overrides/spec/controllers/template_path_spec.rb +19 -19
- data/test/rails/overrides/spec/features/admin/top_spec.rb +7 -7
- data/test/rails/overrides/spec/features/filter_spec.rb +101 -102
- data/test/rails/overrides/spec/helpers/helpers_spec.rb +4 -4
- data/test/rails/overrides/spec/mailers/decorated_mailer_spec.rb +12 -12
- data/test/rails/overrides/spec/mailers/mobile_mailer_spec.rb +209 -194
- data/test/rails/overrides/spec/mailers/normal_mailer_spec.rb +10 -10
- data/test/rails/overrides/spec/rails_helper.rb +1 -1
- data/test/rails/overrides/spec/requests/docomo_spec.rb +13 -13
- data/test/rails/overrides/spec/requests/emobile_spec.rb +19 -19
- data/test/rails/overrides/spec/requests/pc_spec.rb +6 -6
- data/test/rails/overrides/spec/requests/softbank_emulator_spec.rb +6 -6
- data/test/rails/overrides/spec/requests/template_path_spec.rb +60 -60
- data/test/rails/overrides/spec/requests/trans_sid_spec.rb +89 -89
- data/test/sinatra/test/filter_test.rb +10 -11
- data/tools/e4u_conv.rb +0 -1
- metadata +18 -14
- data/README +0 -0
- data/README.rdoc +0 -308
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
#:stopdoc:
|
3
2
|
# helperを追加
|
4
3
|
ActionView::Base.class_eval { include Jpmobile::Helpers }
|
@@ -11,23 +10,24 @@ module ActionView
|
|
11
10
|
module Helpers
|
12
11
|
module FormTagHelper
|
13
12
|
private
|
13
|
+
|
14
14
|
def html_options_for_form(url_for_options, options, *parameters_for_url)
|
15
|
-
accept_charset = (Rails.application.config.jpmobile.form_accept_charset_conversion && request && request.mobile && request.mobile.default_charset) ||
|
15
|
+
accept_charset = (Rails.application.config.jpmobile.form_accept_charset_conversion && request && request.mobile && request.mobile.default_charset) || 'UTF-8'
|
16
16
|
|
17
17
|
options.stringify_keys.tap do |html_options|
|
18
|
-
html_options[
|
18
|
+
html_options['enctype'] = 'multipart/form-data' if html_options.delete('multipart')
|
19
19
|
# The following URL is unescaped, this is just a hash of options, and it is the
|
20
20
|
# responsability of the caller to escape all the values.
|
21
|
-
html_options[
|
22
|
-
html_options[
|
23
|
-
html_options[
|
21
|
+
html_options['action'] = url_for(url_for_options, *parameters_for_url)
|
22
|
+
html_options['accept-charset'] = accept_charset
|
23
|
+
html_options['data-remote'] = true if html_options.delete('remote')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
class Base
|
30
|
-
delegate :default_url_options, :
|
30
|
+
delegate :default_url_options, to: :controller unless respond_to?(:default_url_options)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
#:startdoc:
|
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
ActionView::LookupContext.register_detail(:mobile) {[]}
|
1
|
+
ActionView::LookupContext.register_detail(:mobile) { [] }
|
data/lib/jpmobile/mail.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
require 'mail'
|
3
2
|
|
4
3
|
module Mail
|
@@ -15,7 +14,8 @@ module Mail
|
|
15
14
|
attr_accessor :mobile
|
16
15
|
|
17
16
|
def mobile=(m)
|
18
|
-
|
17
|
+
@mobile = m
|
18
|
+
if @mobile
|
19
19
|
@charset = m.mail_charset(@charset)
|
20
20
|
end
|
21
21
|
end
|
@@ -29,10 +29,10 @@ module Mail
|
|
29
29
|
|
30
30
|
ready_to_send!
|
31
31
|
|
32
|
-
self.body.mobile
|
32
|
+
self.body.mobile = @mobile
|
33
33
|
self.header['Content-Transfer-Encoding'].value = @mobile.content_transfer_encoding(self.header)
|
34
34
|
if @mobile.decorated?
|
35
|
-
unless self.content_type
|
35
|
+
unless self.content_type =~ %r{image/}
|
36
36
|
self.header['Content-ID'] = nil
|
37
37
|
end
|
38
38
|
|
@@ -54,7 +54,8 @@ module Mail
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def parse_message_with_jpmobile
|
57
|
-
|
57
|
+
_crlf_raw_source = raw_source.encode(raw_source.encoding, universal_newline: true).encode!(raw_source.encoding, crlf_newline: true)
|
58
|
+
header_part, body_part = _crlf_raw_source.lstrip.split(/#{CRLF}#{CRLF}|#{CRLF}#{WSP}*#{CRLF}(?!#{WSP})/m, 2)
|
58
59
|
# header_part, body_part = raw_source.lstrip.split(HEADER_SEPARATOR, 2)
|
59
60
|
|
60
61
|
self.header = header_part
|
@@ -63,7 +64,7 @@ module Mail
|
|
63
64
|
convert_encoding_jpmobile
|
64
65
|
body_part = @body_part_jpmobile
|
65
66
|
|
66
|
-
self.body
|
67
|
+
self.body = body_part
|
67
68
|
end
|
68
69
|
|
69
70
|
def init_with_hash_with_jpmobile(hash)
|
@@ -81,6 +82,9 @@ module Mail
|
|
81
82
|
def init_with_string(string)
|
82
83
|
# convert to ASCII-8BIT for ascii incompatible encodings
|
83
84
|
s = Jpmobile::Util.ascii_8bit(string)
|
85
|
+
unless s.ascii_only?
|
86
|
+
s = s.kind_of?(String) ? s.to_str.encode(s.encoding, :universal_newline => true).encode!(s.encoding, :crlf_newline => true) : ''
|
87
|
+
end
|
84
88
|
self.raw_source = s
|
85
89
|
set_envelope_header
|
86
90
|
parse_message
|
@@ -90,20 +94,20 @@ module Mail
|
|
90
94
|
def process_body_raw_with_jpmobile
|
91
95
|
process_body_raw_without_jpmobile
|
92
96
|
|
93
|
-
|
94
|
-
@body.mobile = @mobile
|
95
|
-
@body.content_type_with_jpmobile = self.content_type
|
97
|
+
return unless @mobile
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
-
["text"].include?(@mobile_main_type)
|
100
|
-
@body.decode_transfer_encoding
|
101
|
-
end
|
99
|
+
@body.mobile = @mobile
|
100
|
+
@body.content_type_with_jpmobile = self.content_type
|
102
101
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
102
|
+
if has_content_transfer_encoding? &&
|
103
|
+
['base64', 'quoted-printable'].include?(self.content_transfer_encoding) &&
|
104
|
+
['text'].include?(@mobile_main_type)
|
105
|
+
@body.decode_transfer_encoding
|
106
|
+
end
|
107
|
+
|
108
|
+
if @body.multipart?
|
109
|
+
@body.parts.each do |p|
|
110
|
+
p.mobile = @mobile
|
107
111
|
end
|
108
112
|
end
|
109
113
|
end
|
@@ -137,78 +141,78 @@ module Mail
|
|
137
141
|
alias_method :add_charset_without_jpmobile, :add_charset
|
138
142
|
alias_method :add_charset, :add_charset_with_jpmobile
|
139
143
|
|
140
|
-
# -- docomo
|
141
|
-
# multipart/mixed
|
142
|
-
# |- multipart/related
|
143
|
-
# | |- multipart/alternative
|
144
|
-
# | | |- text/plain
|
145
|
-
# | | |- text/html
|
146
|
-
# | |- image/xxxx (インライン画像)
|
147
|
-
# |- image/xxxx (添付画像)
|
148
|
-
|
149
|
-
# -- au
|
150
|
-
# multipart/mixed
|
151
|
-
# |- multipart/alternative
|
152
|
-
# | |- text/plain
|
153
|
-
# | |- text/html
|
154
|
-
# |- image/xxxx (インライン画像)
|
155
|
-
# |- image/xxxx (添付画像)
|
156
|
-
|
157
|
-
# -- normal
|
158
|
-
# multipart/mixed
|
159
|
-
# |- multipart/alternative
|
160
|
-
# | |- text/plain
|
161
|
-
# | |- text/html
|
162
|
-
# | |- image/xxxx (インライン画像)
|
163
|
-
# |- image/xxxx (添付画像)
|
144
|
+
# -- docomo
|
145
|
+
# multipart/mixed
|
146
|
+
# |- multipart/related
|
147
|
+
# | |- multipart/alternative
|
148
|
+
# | | |- text/plain
|
149
|
+
# | | |- text/html
|
150
|
+
# | |- image/xxxx (インライン画像)
|
151
|
+
# |- image/xxxx (添付画像)
|
152
|
+
|
153
|
+
# -- au
|
154
|
+
# multipart/mixed
|
155
|
+
# |- multipart/alternative
|
156
|
+
# | |- text/plain
|
157
|
+
# | |- text/html
|
158
|
+
# |- image/xxxx (インライン画像)
|
159
|
+
# |- image/xxxx (添付画像)
|
160
|
+
|
161
|
+
# -- normal
|
162
|
+
# multipart/mixed
|
163
|
+
# |- multipart/alternative
|
164
|
+
# | |- text/plain
|
165
|
+
# | |- text/html
|
166
|
+
# | |- image/xxxx (インライン画像)
|
167
|
+
# |- image/xxxx (添付画像)
|
164
168
|
|
165
169
|
def rearrange!
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
inline_images << p
|
179
|
-
elsif p.content_disposition
|
180
|
-
attached_files << p
|
170
|
+
return unless @mobile && @mobile.decoratable?
|
171
|
+
|
172
|
+
@mobile.decorated = true
|
173
|
+
text_body_part = find_part_by_content_type('text/plain').first
|
174
|
+
html_body_part = find_part_by_content_type('text/html').first
|
175
|
+
html_body_part.transport_encoding = 'quoted-printable' if html_body_part
|
176
|
+
inline_images = []
|
177
|
+
attached_files = []
|
178
|
+
attachments.each do |p|
|
179
|
+
if p.content_type.match(%r{^image/}) && p.content_disposition.match(/^inline/)
|
180
|
+
if p.header['Content-Type'].parameters['filename']
|
181
|
+
p.header['Content-Type'].parameters['name'] = p.header['Content-Type'].parameters['filename'].to_s
|
181
182
|
end
|
183
|
+
inline_images << p
|
184
|
+
elsif p.content_disposition
|
185
|
+
attached_files << p
|
182
186
|
end
|
187
|
+
end
|
183
188
|
|
184
|
-
|
185
|
-
|
186
|
-
|
189
|
+
alternative_part = Mail::Part.new { content_type 'multipart/alternative' }
|
190
|
+
alternative_part.add_part(text_body_part) if text_body_part
|
191
|
+
alternative_part.add_part(html_body_part) if html_body_part
|
187
192
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
end
|
194
|
-
inline_images.clear
|
195
|
-
else
|
196
|
-
related_part = alternative_part
|
193
|
+
if @mobile.require_related_part?
|
194
|
+
related_part = Mail::Part.new { content_type 'multipart/related' }
|
195
|
+
related_part.add_part(alternative_part)
|
196
|
+
inline_images.each do |inline_image|
|
197
|
+
related_part.add_part(inline_image)
|
197
198
|
end
|
199
|
+
inline_images.clear
|
200
|
+
else
|
201
|
+
related_part = alternative_part
|
202
|
+
end
|
198
203
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
+
unless self.header['Content-Type'].sub_type == 'mixed'
|
205
|
+
self.header['Content-Type'] = self.content_type.gsub(/#{self.header['Content-Type'].sub_type}/, 'mixed')
|
206
|
+
end
|
207
|
+
self.parts.clear
|
208
|
+
self.body = nil
|
204
209
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
end
|
210
|
+
self.add_part(related_part)
|
211
|
+
inline_images.each do |inline_image|
|
212
|
+
self.add_part(inline_image)
|
213
|
+
end
|
214
|
+
attached_files.each do |attached_file|
|
215
|
+
self.add_part(attached_file)
|
212
216
|
end
|
213
217
|
end
|
214
218
|
|
@@ -218,7 +222,7 @@ module Mail
|
|
218
222
|
self.parts.each do |part|
|
219
223
|
if part.multipart?
|
220
224
|
finded_parts << part.find_part_by_content_type(content_type)
|
221
|
-
elsif part.content_type
|
225
|
+
elsif part.content_type =~ /^#{content_type}/
|
222
226
|
finded_parts << part
|
223
227
|
end
|
224
228
|
end
|
@@ -227,6 +231,7 @@ module Mail
|
|
227
231
|
end
|
228
232
|
|
229
233
|
private
|
234
|
+
|
230
235
|
def convert_encoding_jpmobile
|
231
236
|
# decide mobile carrier
|
232
237
|
if self.header[:from]
|
@@ -248,14 +253,14 @@ module Mail
|
|
248
253
|
header[:subject].value = header[:subject].decoded
|
249
254
|
end
|
250
255
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
@body_part_jpmobile = @mobile.decode_transfer_encoding(@body_part_jpmobile, @charset)
|
256
|
+
return unless @body_part_jpmobile && @mobile && !@charset.empty?
|
257
|
+
|
258
|
+
if ['base64', 'quoted-printable'].include?(self.content_transfer_encoding) &&
|
259
|
+
self.content_type.match(/text/)
|
260
|
+
@body_part_jpmobile = Jpmobile::Util.decode(@body_part_jpmobile, self.content_transfer_encoding, @charset)
|
261
|
+
self.content_transfer_encoding = @mobile.class::MAIL_CONTENT_TRANSFER_ENCODING
|
258
262
|
end
|
263
|
+
@body_part_jpmobile = @mobile.decode_transfer_encoding(@body_part_jpmobile, @charset)
|
259
264
|
end
|
260
265
|
|
261
266
|
def ascii_compatible!(str)
|
@@ -274,22 +279,23 @@ module Mail
|
|
274
279
|
def parse_message_with_jpmobile
|
275
280
|
header_part, body_part = raw_source.split(/#{CRLF}#{WSP}*#{CRLF}/m, 2)
|
276
281
|
|
277
|
-
if header_part
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
+
self.header = if header_part && header_part.match(HEADER_LINE)
|
283
|
+
header_part
|
284
|
+
else
|
285
|
+
"Content-Type: text/plain\r\n"
|
286
|
+
end
|
282
287
|
|
283
288
|
@body_part_jpmobile = body_part
|
284
289
|
convert_encoding_jpmobile
|
285
290
|
body_part = @body_part_jpmobile
|
286
|
-
self.body
|
291
|
+
self.body = body_part
|
287
292
|
end
|
288
293
|
|
289
294
|
alias_method :parse_message_without_jpmobile, :parse_message
|
290
295
|
alias_method :parse_message, :parse_message_with_jpmobile
|
291
296
|
|
292
297
|
private
|
298
|
+
|
293
299
|
def ascii_compatible!(str)
|
294
300
|
str
|
295
301
|
end
|
@@ -304,17 +310,17 @@ module Mail
|
|
304
310
|
|
305
311
|
# convert encoding
|
306
312
|
def encoded_with_jpmobile(transfer_encoding = '8bit')
|
307
|
-
if @mobile
|
313
|
+
if @mobile && !multipart?
|
308
314
|
case transfer_encoding
|
309
315
|
when /base64/
|
310
316
|
_raw_source = if transfer_encoding == encoding
|
311
317
|
@raw_source.dup
|
312
318
|
else
|
313
|
-
|
319
|
+
negotiate_best_encoding(transfer_encoding).encode(@raw_source)
|
314
320
|
end
|
315
321
|
Jpmobile::Util.set_encoding(_raw_source, @mobile.mail_charset(@charset))
|
316
322
|
when /quoted-printable/
|
317
|
-
Jpmobile::Util.set_encoding([@mobile.to_mail_body(@raw_source)].pack(
|
323
|
+
Jpmobile::Util.set_encoding([@mobile.to_mail_body(@raw_source)].pack('M').gsub(/\n/, "\r\n"), @mobile.mail_charset(@charset))
|
318
324
|
else
|
319
325
|
@mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, nil, Jpmobile::Util::UTF8))
|
320
326
|
end
|
@@ -329,18 +335,18 @@ module Mail
|
|
329
335
|
|
330
336
|
# fix charset
|
331
337
|
def set_charset_with_jpmobile
|
332
|
-
@charset ||=
|
338
|
+
@charset ||= ascii_only? ? 'US-ASCII' : nil
|
333
339
|
end
|
334
340
|
|
335
341
|
def mobile=(m)
|
336
342
|
@mobile = m
|
337
343
|
|
338
|
-
if [
|
339
|
-
|
344
|
+
if ['base64', 'quoted-printable'].include?(self.encoding) &&
|
345
|
+
/text/.match(self.content_type_with_jpmobile)
|
340
346
|
self.decode_transfer_encoding
|
341
347
|
end
|
342
348
|
|
343
|
-
if self.multipart?
|
349
|
+
if self.multipart? && @mobile
|
344
350
|
self.parts.each do |part|
|
345
351
|
part.mobile = @mobile
|
346
352
|
part.body.mobile = @mobile
|
@@ -417,7 +423,7 @@ module Mail
|
|
417
423
|
self.preamble = parts[0].to_s.strip
|
418
424
|
# Make the epilogue equal to the epilogue (if any)
|
419
425
|
self.epilogue = parts[-1].to_s.sub('--', '').strip
|
420
|
-
parts[1...-1].to_a.each { |part| @parts << Mail::Part.new(:
|
426
|
+
parts[1...-1].to_a.each { |part| @parts << Mail::Part.new(body_raw: part, mobile: @mobile) }
|
421
427
|
self
|
422
428
|
end
|
423
429
|
end
|
@@ -428,7 +434,7 @@ module Mail
|
|
428
434
|
|
429
435
|
class OptionalField
|
430
436
|
def charset
|
431
|
-
@charset =~ /iso-2022-jp/i ? 'UTF-8' : @charset
|
437
|
+
(@charset =~ /iso-2022-jp/i) ? 'UTF-8' : @charset
|
432
438
|
end
|
433
439
|
end
|
434
440
|
|
@@ -450,15 +456,15 @@ module Mail
|
|
450
456
|
def decoded_with_jpmobile
|
451
457
|
if @mobile
|
452
458
|
return value unless value =~ /\=\?[^?]+\?([QB])\?[^?]*?\?\=/mi
|
453
|
-
Encodings.collapse_adjacent_encodings(value).each
|
459
|
+
Encodings.collapse_adjacent_encodings(value).each { |line|
|
454
460
|
line.gsub!(/\=\?[^?]+\?([QB])\?[^?]*?\?\=/mi) do |string|
|
455
|
-
case
|
456
|
-
when 'B','b' then decode_b_value_for_mobile(string)
|
457
|
-
when 'Q','q' then Encodings.q_value_decode(string)
|
461
|
+
case Regexp.last_match(1)
|
462
|
+
when 'B', 'b' then decode_b_value_for_mobile(string)
|
463
|
+
when 'Q', 'q' then Encodings.q_value_decode(string)
|
458
464
|
else line
|
459
465
|
end
|
460
466
|
end
|
461
|
-
|
467
|
+
}.join('')
|
462
468
|
else
|
463
469
|
decoded_without_jpmobile
|
464
470
|
end
|
@@ -496,7 +502,8 @@ module Mail
|
|
496
502
|
alias_method :initialize, :initialize_with_jpmobile
|
497
503
|
|
498
504
|
def mobile=(m)
|
499
|
-
|
505
|
+
@mobile = m
|
506
|
+
if @mobile
|
500
507
|
self.charset = @mobile.mail_charset
|
501
508
|
self.value = @jpmobile_raw_text
|
502
509
|
self.parse
|
@@ -506,6 +513,15 @@ module Mail
|
|
506
513
|
def encoded_with_jpmobile
|
507
514
|
if @mobile
|
508
515
|
self.charset = @mobile.mail_charset
|
516
|
+
|
517
|
+
_value = address_list.addresses.map { |_a|
|
518
|
+
if Utilities.blank?(_a.display_name) || _a.display_name.ascii_only?
|
519
|
+
_a.to_s
|
520
|
+
else
|
521
|
+
"#{@mobile.to_mail_subject(_a.display_name)} <#{_a.address}>"
|
522
|
+
end
|
523
|
+
}.join(", ")
|
524
|
+
@address_list = AddressList.new(_value)
|
509
525
|
end
|
510
526
|
|
511
527
|
encoded_without_jpmobile
|
@@ -525,7 +541,8 @@ module Mail
|
|
525
541
|
alias_method :initialize, :initialize_with_jpmobile
|
526
542
|
|
527
543
|
def mobile=(m)
|
528
|
-
|
544
|
+
@mobile = m
|
545
|
+
if @mobile
|
529
546
|
self.charset = @mobile.mail_charset
|
530
547
|
self.value = @jpmobile_raw_text
|
531
548
|
self.parse
|
@@ -535,6 +552,15 @@ module Mail
|
|
535
552
|
def encoded_with_jpmobile
|
536
553
|
if @mobile
|
537
554
|
self.charset = @mobile.mail_charset
|
555
|
+
|
556
|
+
_value = address_list.addresses.map { |_a|
|
557
|
+
if Utilities.blank?(_a.display_name) || _a.display_name.ascii_only?
|
558
|
+
_a.to_s
|
559
|
+
else
|
560
|
+
"#{@mobile.to_mail_subject(_a.display_name)} <#{_a.address}>"
|
561
|
+
end
|
562
|
+
}.join(", ")
|
563
|
+
@address_list = AddressList.new(_value)
|
538
564
|
end
|
539
565
|
|
540
566
|
encoded_without_jpmobile
|
@@ -550,16 +576,12 @@ module Mail
|
|
550
576
|
end
|
551
577
|
|
552
578
|
def get_display_name_with_jpmobile
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
else
|
560
|
-
raise ex
|
561
|
-
end
|
562
|
-
end
|
579
|
+
get_display_name_without_jpmobile
|
580
|
+
rescue NoMethodError => ex
|
581
|
+
raise ex unless ex.message =~ /undefined method `gsub' for nil:NilClass/
|
582
|
+
|
583
|
+
name = unquote(tree.display_name.text_value.strip.to_s)
|
584
|
+
strip_all_comments(name.to_s)
|
563
585
|
end
|
564
586
|
|
565
587
|
alias_method :encoded_without_jpmobile, :encoded
|
@@ -571,8 +593,8 @@ module Mail
|
|
571
593
|
|
572
594
|
class ContentTypeElement # :nodoc:
|
573
595
|
def initialize_with_jpmobile(string)
|
574
|
-
if m = string.match(/\A(.*?)(name|filename)=("|')(.+)("|')(.*?)\z/)
|
575
|
-
|
596
|
+
if (m = string.match(/\A(.*?)(name|filename)=("|')(.+)("|')(.*?)\z/)) &&
|
597
|
+
m[4].each_byte.detect { |b| (b == 0 || b > 127) }
|
576
598
|
name = [m[4]].pack('m').strip
|
577
599
|
string = "#{m[1]}#{m[2]}=#{m[3]}#{name}#{m[5]}#{m[6]}"
|
578
600
|
end
|
@@ -585,8 +607,8 @@ module Mail
|
|
585
607
|
|
586
608
|
class ContentDispositionElement # :nodoc:
|
587
609
|
def initialize_with_jpmobile(string)
|
588
|
-
if m = string.match(/\A(.*?)(name|filename)=("|')(.+)("|')(.*?)\z/)
|
589
|
-
|
610
|
+
if (m = string.match(/\A(.*?)(name|filename)=("|')(.+)("|')(.*?)\z/)) &&
|
611
|
+
m[4].each_byte.detect { |b| (b == 0 || b > 127) }
|
590
612
|
name = [m[4]].pack('m').strip
|
591
613
|
string = "#{m[1]}#{m[2]}=#{m[3]}#{name}#{m[5]}#{m[6]}"
|
592
614
|
end
|
@@ -599,8 +621,8 @@ module Mail
|
|
599
621
|
|
600
622
|
class ContentLocationElement # :nodoc:
|
601
623
|
def initialize_with_jpmobile(string)
|
602
|
-
if m = string.match(/\A(.*?)(name|filename)=("|')(.+)("|')(.*?)\z/)
|
603
|
-
|
624
|
+
if (m = string.match(/\A(.*?)(name|filename)=("|')(.+)("|')(.*?)\z/)) &&
|
625
|
+
m[4].each_byte.detect { |b| (b == 0 || b > 127) }
|
604
626
|
name = [m[4]].pack('m').strip
|
605
627
|
string = "#{m[1]}#{m[2]}=#{m[3]}#{name}#{m[5]}#{m[6]}"
|
606
628
|
end
|
@@ -612,17 +634,17 @@ module Mail
|
|
612
634
|
end
|
613
635
|
|
614
636
|
class Sendmail
|
615
|
-
def
|
616
|
-
if mail.respond_to?(:encoded)
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
637
|
+
def self.call(path, arguments, destinations, mail)
|
638
|
+
encoded_mail = if mail.respond_to?(:encoded)
|
639
|
+
mail.encoded
|
640
|
+
else
|
641
|
+
mail
|
642
|
+
end
|
621
643
|
if Jpmobile::Util.jis?(encoded_mail)
|
622
644
|
encoded_mail = Jpmobile::Util.ascii_8bit(encoded_mail)
|
623
645
|
end
|
624
646
|
|
625
|
-
IO.popen("#{path} #{arguments} #{destinations}",
|
647
|
+
IO.popen("#{path} #{arguments} #{destinations}", 'w+') do |io|
|
626
648
|
io.puts encoded_mail.gsub(/\r\r\n/, "\n").to_lf
|
627
649
|
io.flush
|
628
650
|
end
|