jpmobile 0.1.6 → 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/README +0 -0
- data/README.rdoc +58 -29
- data/Rakefile +1 -1
- data/VERSION.yml +4 -4
- data/lib/jpmobile.rb +3 -0
- data/lib/jpmobile/email.rb +17 -2
- data/lib/jpmobile/emoticon.rb +87 -23
- data/lib/jpmobile/emoticon/au.rb +644 -0
- data/lib/jpmobile/emoticon/softbank.rb +488 -0
- data/lib/jpmobile/emoticon/z_combine.rb +16 -13
- data/lib/jpmobile/hook_action_controller.rb +1 -13
- data/lib/jpmobile/hook_action_view.rb +3 -62
- data/lib/jpmobile/mail.rb +316 -0
- data/lib/jpmobile/mailer.rb +31 -0
- data/lib/jpmobile/mobile/abstract_mobile.rb +66 -0
- data/lib/jpmobile/mobile/au.rb +25 -2
- data/lib/jpmobile/mobile/docomo.rb +23 -1
- data/lib/jpmobile/mobile/emobile.rb +1 -1
- data/lib/jpmobile/mobile/softbank.rb +33 -1
- data/lib/jpmobile/mobile/vodafone.rb +1 -1
- data/lib/jpmobile/mobile/willcom.rb +1 -1
- data/lib/jpmobile/path_set.rb +40 -0
- data/lib/jpmobile/rails.rb +24 -0
- data/lib/jpmobile/resolver.rb +38 -0
- data/lib/jpmobile/util.rb +223 -14
- data/lib/tasks/jpmobile_tasks.rake +41 -48
- data/spec/rack/jpmobile/emoticon_spec.rb +3 -8
- data/spec/rack/jpmobile/filter_spec.rb +1 -1
- data/spec/rack/jpmobile/params_filter_spec.rb +4 -4
- data/spec/rack_helper.rb +5 -9
- data/spec/unit/detect_by_email_spec.rb +29 -0
- data/spec/unit/emoticon_spec.rb +90 -0
- data/spec/unit/encoding_spec.rb +102 -0
- data/spec/unit/mail_spec.rb +117 -0
- data/spec/unit/receive_mail_spec.rb +289 -0
- data/spec/unit/spec_helper.rb +8 -0
- data/spec/unit/util_spec.rb +5 -0
- data/test/rails/overrides/app/controllers/application_controller.rb +3 -2
- data/test/rails/overrides/app/controllers/template_path_controller.rb +8 -0
- data/test/rails/overrides/app/models/mobile_mailer.rb +19 -0
- data/test/rails/overrides/app/models/normal_mailer.rb +9 -0
- data/test/rails/overrides/spec/models/mobile_mailer_spec.rb +737 -0
- data/test/rails/overrides/spec/models/normal_mailer_spec.rb +34 -0
- data/test/rails/overrides/spec/requests/template_path_spec.rb +13 -7
- data/test/rails/overrides/spec/spec_helper.rb +6 -0
- data/test/rails/rails_root/app/controllers/application_controller.rb +3 -2
- data/test/rails/rails_root/app/controllers/template_path_controller.rb +8 -0
- data/test/rails/rails_root/app/models/mobile_mailer.rb +2 -1
- data/test/rails/rails_root/app/models/normal_mailer.rb +9 -0
- data/test/rails/rails_root/config/initializers/secret_token.rb +1 -1
- data/test/rails/rails_root/spec/models/mobile_mailer_spec.rb +73 -80
- data/test/rails/rails_root/spec/models/normal_mailer_spec.rb +34 -0
- data/test/rails/rails_root/spec/requests/template_path_spec.rb +13 -7
- data/test/rails/rails_root/spec/spec_helper.rb +1 -1
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile.rb +2 -1
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +7 -5
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_controller.rb +1 -13
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_view.rb +3 -62
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mail.rb +162 -111
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mailer.rb +31 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/abstract_mobile.rb +34 -3
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +2 -5
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/docomo.rb +4 -5
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +7 -8
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/path_set.rb +40 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/params_filter.rb +1 -1
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rails.rb +24 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/resolver.rb +38 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/util.rb +33 -23
- metadata +43 -14
- data/test/legacy/emoticon_test.rb +0 -63
- data/test/legacy/helper.rb +0 -8
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_mailer.rb +0 -22
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe NormalMailer do
|
5
|
+
include Jpmobile::Util
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
ActionMailer::Base.deliveries = []
|
9
|
+
|
10
|
+
@to = ["outer@jp.mobile", "outer1@jp.mobile"]
|
11
|
+
@subject = "日本語題名"
|
12
|
+
@text = "日本語テキスト"
|
13
|
+
end
|
14
|
+
|
15
|
+
context "PC宛メール" do
|
16
|
+
it "正常に送信できること" do
|
17
|
+
email = NormalMailer.msg(@to, "題名", "本文").deliver
|
18
|
+
|
19
|
+
ActionMailer::Base.deliveries.size.should == 1
|
20
|
+
(email.to - @to).should be_empty
|
21
|
+
end
|
22
|
+
|
23
|
+
it "UTF-8のままであること" do
|
24
|
+
email = NormalMailer.msg(@to, @subject, @text).deliver
|
25
|
+
|
26
|
+
ActionMailer::Base.deliveries.size.should == 1
|
27
|
+
|
28
|
+
raw_mail = ascii_8bit(email.to_s)
|
29
|
+
raw_mail.should match(/UTF-8/i)
|
30
|
+
raw_mail.should match(Regexp.escape("=E6=97=A5=E6=9C=AC=E8=AA=9E=E9=A1=8C=E5=90=8D"))
|
31
|
+
raw_mail.should match(Regexp.escape([@text].pack("m").strip))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -13,7 +13,7 @@ describe TemplatePathController, "DoCoMo SH902i からのアクセス" do
|
|
13
13
|
it 'テンプレートの探索順が正しいこと' do
|
14
14
|
get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
|
15
15
|
|
16
|
-
controller.
|
16
|
+
controller.lookup_context.mobile.should == [ 'mobile_docomo', 'mobile' ]
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -24,7 +24,7 @@ describe TemplatePathController, "au CA32 からのアクセス" do
|
|
24
24
|
it 'テンプレートの探索順が正しいこと' do
|
25
25
|
get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
|
26
26
|
|
27
|
-
controller.
|
27
|
+
controller.lookup_context.mobile.should == [ 'mobile_au', 'mobile' ]
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,7 +35,7 @@ describe TemplatePathController, "Vodafone V903T からのアクセス" do
|
|
35
35
|
it 'テンプレートの探索順が正しいこと' do
|
36
36
|
get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
|
37
37
|
|
38
|
-
controller.
|
38
|
+
controller.lookup_context.mobile.should == [ 'mobile_vodafone', 'mobile_softbank', 'mobile' ]
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -46,7 +46,7 @@ describe TemplatePathController, "SoftBank 910T からのアクセス" do
|
|
46
46
|
it 'テンプレートの探索順が正しいこと' do
|
47
47
|
get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
|
48
48
|
|
49
|
-
controller.
|
49
|
+
controller.lookup_context.mobile.should == [ 'mobile_softbank', 'mobile' ]
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -57,7 +57,7 @@ describe TemplatePathController, "iPhone からのアクセス" do
|
|
57
57
|
it 'テンプレートの探索順が正しいこと' do
|
58
58
|
get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
|
59
59
|
|
60
|
-
controller.
|
60
|
+
controller.lookup_context.mobile.should == [ 'smart_phone_iphone', 'smart_phone' ]
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -68,7 +68,7 @@ describe TemplatePathController, "Android からのアクセス" do
|
|
68
68
|
it 'テンプレートの探索順が正しいこと' do
|
69
69
|
get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
|
70
70
|
|
71
|
-
controller.
|
71
|
+
controller.lookup_context.mobile.should == [ 'smart_phone_android', 'smart_phone' ]
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -79,7 +79,7 @@ describe TemplatePathController, "Windows Phone からのアクセス" do
|
|
79
79
|
it 'テンプレートの探索順が正しいこと' do
|
80
80
|
get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
|
81
81
|
|
82
|
-
controller.
|
82
|
+
controller.lookup_context.mobile.should == [ 'smart_phone_windows_phone', 'smart_phone' ]
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -111,6 +111,12 @@ describe TemplatePathController, "integrated_views" do
|
|
111
111
|
|
112
112
|
response.should have_tag("h1", :content => "show_mobile_docomo.html.erb")
|
113
113
|
end
|
114
|
+
|
115
|
+
it 'disable_mobile_view! のときには index.html.erb が使用されること' do
|
116
|
+
get "/template_path/index", {:pc => true}, { "HTTP_USER_AGENT" => @user_agent}
|
117
|
+
|
118
|
+
response.should have_tag("h1", :content => "index.html.erb")
|
119
|
+
end
|
114
120
|
end
|
115
121
|
|
116
122
|
context "SoftBankからのアクセスの場合" do
|
@@ -9,7 +9,7 @@ module Jpmobile
|
|
9
9
|
%w( DOCOMO_SJIS_TO_UNICODE DOCOMO_UNICODE_TO_SJIS ).each do |const|
|
10
10
|
autoload const, 'jpmobile/emoticon/docomo'
|
11
11
|
end
|
12
|
-
%w( AU_SJIS_TO_UNICODE AU_UNICODE_TO_EMAILJIS AU_SJIS_TO_EMAIL_JIS ).each do |const|
|
12
|
+
%w( AU_SJIS_TO_UNICODE AU_UNICODE_TO_EMAILJIS AU_SJIS_TO_EMAIL_JIS AU_EMAILJIS_TO_UNICODE ).each do |const|
|
13
13
|
autoload const, 'jpmobile/emoticon/au'
|
14
14
|
end
|
15
15
|
%w(
|
@@ -51,10 +51,12 @@ module Jpmobile
|
|
51
51
|
# +str+ のなかでau絵文字をUnicode数値文字参照に置換した文字列を返す。(メール専用)
|
52
52
|
def self.external_to_unicodecr_au_mail(in_str)
|
53
53
|
str = Jpmobile::Util.ascii_8bit(in_str)
|
54
|
-
str.gsub(
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
str.gsub(Jpmobile::Util.jis_string_regexp) do |jis_string|
|
55
|
+
jis_string.gsub(/[\x21-\x7e]{2}/) do |match|
|
56
|
+
jis = match.unpack('n').first
|
57
|
+
unicode = AU_EMAILJIS_TO_UNICODE[jis]
|
58
|
+
unicode ? Jpmobile::Util.ascii_8bit("\x1b\x28\x42&#x%04x;\x1b\x24\x42"%unicode) : match
|
59
|
+
end
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
@@ -1,17 +1,4 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
module AbstractController
|
3
|
-
module ViewPaths
|
4
|
-
def lookup_context_with_jpmobile
|
5
|
-
jpmobile_context = lookup_context_without_jpmobile
|
6
|
-
jpmobile_context.view_paths.controller = self
|
7
|
-
|
8
|
-
jpmobile_context
|
9
|
-
end
|
10
|
-
|
11
|
-
alias_method_chain :lookup_context, :jpmobile
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
2
|
module ActionController
|
16
3
|
class Base
|
17
4
|
include Jpmobile::Helpers
|
@@ -29,3 +16,4 @@ module ActionController
|
|
29
16
|
end
|
30
17
|
|
31
18
|
ActionController::Request.send :include, Jpmobile::Encoding
|
19
|
+
ActionView::LookupContext.register_detail(:mobile) {nil}
|
@@ -1,72 +1,12 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
# = viewの自動切り替え
|
3
|
-
#
|
4
2
|
#:stopdoc:
|
5
3
|
# helperを追加
|
6
4
|
ActionView::Base.class_eval { include Jpmobile::Helpers }
|
7
5
|
#:startdoc:
|
8
6
|
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# index_mobile_vodafone.html.erb
|
12
|
-
# index_mobile_softbank.html.erb
|
13
|
-
# index_mobile.html.erb
|
14
|
-
# index.html.erb
|
15
|
-
# の順にテンプレートが検索される。
|
16
|
-
# BUG: 現状、上記の例では index.html.erb が存在しない場合に振り分けが行われない
|
17
|
-
# (ダミーファイルを置くことで回避可能)。
|
7
|
+
# :stopdoc:
|
8
|
+
# accept-charset に charset を変更できるようにする
|
18
9
|
module ActionView
|
19
|
-
class PathSet
|
20
|
-
attr_accessor :controller
|
21
|
-
|
22
|
-
def find_with_jpmobile(path, prefix = nil, partial = false, details = {}, key = nil) #:nodoc:
|
23
|
-
if controller and controller.kind_of?(ActionController::Base) and
|
24
|
-
(controller.request.mobile? or controller.request.smart_phone?)
|
25
|
-
return path if path.respond_to?(:render)
|
26
|
-
template_candidates = mobile_template_candidates
|
27
|
-
|
28
|
-
each do |load_path|
|
29
|
-
template_candidates.each do |template_postfix|
|
30
|
-
templates = load_path.find_all("#{path}_#{template_postfix}", prefix, partial, details, key)
|
31
|
-
return templates.first unless templates.empty?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
find_without_jpmobile(path, prefix, partial, details, key)
|
37
|
-
end
|
38
|
-
|
39
|
-
alias_method_chain :find, :jpmobile #:nodoc:
|
40
|
-
|
41
|
-
def mobile_template_candidates #:nodoc:
|
42
|
-
candidates = []
|
43
|
-
|
44
|
-
view_class, parent_class, template_prefix = case controller.request.mobile
|
45
|
-
when ::Jpmobile::Mobile::SmartPhone
|
46
|
-
[controller.request.mobile.class, ::Jpmobile::Mobile::SmartPhone, "smart_phone"]
|
47
|
-
when ::Jpmobile::Mobile::AbstractMobile
|
48
|
-
[controller.request.mobile.class, ::Jpmobile::Mobile::AbstractMobile, "mobile"]
|
49
|
-
else
|
50
|
-
[nil, nil, nil]
|
51
|
-
end
|
52
|
-
|
53
|
-
if view_class and parent_class
|
54
|
-
find_mobile_template(view_class, parent_class, template_prefix).push(template_prefix)
|
55
|
-
else
|
56
|
-
[]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
def find_mobile_template(klass, parent, prefix)
|
62
|
-
if klass == parent
|
63
|
-
[]
|
64
|
-
else
|
65
|
-
find_mobile_template(klass.superclass, parent, prefix).unshift("#{prefix}_#{klass.to_s.split(/::/).last.underscore}")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
10
|
module Helpers
|
71
11
|
module FormTagHelper
|
72
12
|
private
|
@@ -85,3 +25,4 @@ module ActionView
|
|
85
25
|
end
|
86
26
|
end
|
87
27
|
end
|
28
|
+
#:startdoc:
|
@@ -38,34 +38,27 @@ module Mail
|
|
38
38
|
class Message
|
39
39
|
attr_accessor :mobile
|
40
40
|
|
41
|
+
def mobile=(m)
|
42
|
+
@mobile = m
|
43
|
+
@charset = m.mail_charset(@charset)
|
44
|
+
|
45
|
+
if @body
|
46
|
+
@body.charset = @charset
|
47
|
+
@body.mobile = m
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
41
51
|
def encoded_with_jpmobile
|
42
52
|
if @mobile
|
43
53
|
header['subject'].mobile = @mobile if header['subject']
|
44
|
-
self.charset = @mobile.mail_charset
|
54
|
+
self.charset = @mobile.mail_charset(@charset)
|
45
55
|
|
46
56
|
ready_to_send!
|
47
57
|
|
48
|
-
self.body.
|
58
|
+
self.body.charset = @charset
|
59
|
+
self.body.mobile = @mobile
|
49
60
|
self.header['Content-Transfer-Encoding'] = '8bit'
|
50
61
|
|
51
|
-
if self.header['Content-Type']
|
52
|
-
pp self.body.charset = case self.header['Content-Type'].value
|
53
|
-
when /iso-2022-jp/i
|
54
|
-
"ISO-2022-JP"
|
55
|
-
when /shift_jis/i
|
56
|
-
"Shift_JIS"
|
57
|
-
else
|
58
|
-
"UTF-8"
|
59
|
-
end
|
60
|
-
unless self.header['Content-Type'] == self.body.charset
|
61
|
-
self.header['Content-Type'] = self.body.charset
|
62
|
-
end
|
63
|
-
pp self.header['Content-Type'].charset
|
64
|
-
pp self.header['Content-Type'].value
|
65
|
-
pp self.header['Content-Type']
|
66
|
-
pp self.body.charset
|
67
|
-
end
|
68
|
-
|
69
62
|
buffer = header.encoded
|
70
63
|
buffer << "\r\n"
|
71
64
|
buffer = @mobile.utf8_to_mail_encode(buffer)
|
@@ -77,56 +70,48 @@ pp self.body.charset
|
|
77
70
|
end
|
78
71
|
|
79
72
|
def parse_message_with_jpmobile
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
"UTF-8"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
self.header['subject'].mobile = @mobile if self.header['subject']
|
73
|
+
header_part, body_part = raw_source.split(/#{CRLF}#{WSP}*#{CRLF}/m, 2)
|
74
|
+
|
75
|
+
self.header = header_part
|
76
|
+
|
77
|
+
@body_part_jpmobile = body_part
|
78
|
+
convert_encoding_jpmobile
|
79
|
+
body_part = @body_part_jpmobile
|
80
|
+
|
81
|
+
self.body = body_part
|
93
82
|
end
|
94
83
|
|
95
|
-
def
|
96
|
-
#
|
84
|
+
def init_with_string(string)
|
85
|
+
# convert to ASCII-8BIT for ascii incompatible encodings
|
97
86
|
s = Jpmobile::Util.ascii_8bit(string)
|
87
|
+
self.raw_source = s
|
88
|
+
set_envelope_header
|
89
|
+
parse_message
|
90
|
+
@separate_parts = multipart?
|
91
|
+
end
|
98
92
|
|
99
|
-
|
100
|
-
|
101
|
-
s.split(/\n|\r/).each do |line|
|
102
|
-
if line =~ /^From:/
|
103
|
-
content_has_from = true
|
104
|
-
break if mobile_class = Jpmobile::Email.detect_from_mail_header(line)
|
105
|
-
end
|
106
|
-
end
|
93
|
+
def process_body_raw_with_jpmobile
|
94
|
+
process_body_raw_without_jpmobile
|
107
95
|
|
108
|
-
|
109
|
-
|
96
|
+
@body.charset = @charset
|
97
|
+
@body.mobile = @mobile
|
110
98
|
|
111
|
-
|
99
|
+
if has_content_transfer_encoding? and
|
100
|
+
["base64", "quoted-printable"].include?(content_transfer_encoding) and
|
101
|
+
["text", nil].include?(@mobile_main_type)
|
102
|
+
@body.decode_transfer_encoding
|
103
|
+
end
|
112
104
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
part.body.mobile = @mobile
|
118
|
-
part.body.set_encoding_jpmobile
|
119
|
-
end
|
105
|
+
if @body.multipart?
|
106
|
+
@body.parts.each do |p|
|
107
|
+
p.charset = @charset
|
108
|
+
p.mobile = @mobile
|
120
109
|
end
|
121
|
-
else
|
122
|
-
init_with_string_without_jpmobile(s)
|
123
110
|
end
|
124
111
|
end
|
125
112
|
|
126
|
-
def
|
127
|
-
|
128
|
-
|
129
|
-
self.body.mobile = @mobile
|
113
|
+
def body_lazy_with_jpmobile(value, index)
|
114
|
+
body_lazy_without_jpmobile(value, index)
|
130
115
|
end
|
131
116
|
|
132
117
|
alias_method :encoded_without_jpmobile, :encoded
|
@@ -135,28 +120,71 @@ pp self.body.charset
|
|
135
120
|
alias_method :parse_message_without_jpmobile, :parse_message
|
136
121
|
alias_method :parse_message, :parse_message_with_jpmobile
|
137
122
|
|
138
|
-
alias_method :init_with_string_without_jpmobile, :init_with_string
|
139
|
-
alias_method :init_with_string, :init_with_string_with_jpmobile
|
140
|
-
|
141
123
|
alias_method :process_body_raw_without_jpmobile, :process_body_raw
|
142
124
|
alias_method :process_body_raw, :process_body_raw_with_jpmobile
|
125
|
+
|
126
|
+
alias_method :body_lazy_without_jpmobile, :body_lazy
|
127
|
+
alias_method :body_lazy, :body_lazy_with_jpmobile
|
128
|
+
|
129
|
+
private
|
130
|
+
def convert_encoding_jpmobile
|
131
|
+
# decide mobile carrier
|
132
|
+
if self.header['From']
|
133
|
+
mobile_class = Jpmobile::Email.detect_from_mail_header(self.header['From'].value)
|
134
|
+
@mobile ||= (mobile_class || Jpmobile::Mobile::AbstractMobile ).new(nil, nil)
|
135
|
+
end
|
136
|
+
|
137
|
+
# override charset
|
138
|
+
if self.header['Content-Type']
|
139
|
+
@charset = Jpmobile::Util.extract_charset(self.header['Content-Type'].value)
|
140
|
+
self.header['Content-Type'].parameters[:charset] = @charset
|
141
|
+
@mobile_main_type = self.header['Content-Type'].main_type
|
142
|
+
end
|
143
|
+
|
144
|
+
# convert header(s)
|
145
|
+
if self.header['Subject']
|
146
|
+
subject_charset = Jpmobile::Util.extract_charset(self.header['Subject'].value)
|
147
|
+
|
148
|
+
# override subject encoding if @charset is blank
|
149
|
+
@charset = subject_charset if !subject_charset.blank? and @charset.blank?
|
150
|
+
|
151
|
+
self.header['Subject'].charset = subject_charset
|
152
|
+
|
153
|
+
if @mobile
|
154
|
+
v = @mobile.to_mail_internal(
|
155
|
+
Encodings.value_decode(self.header['Subject'].value), subject_charset)
|
156
|
+
self.header['Subject'].value = Jpmobile::Util.force_encode(v, @mobile.mail_charset(@charset), Jpmobile::Util::UTF8)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
if @body_part_jpmobile and @mobile
|
161
|
+
@body_part_jpmobile = @mobile.decode_transfer_encoding(@body_part_jpmobile, @charset)
|
162
|
+
end
|
163
|
+
end
|
143
164
|
end
|
144
165
|
|
145
166
|
class Part
|
167
|
+
def init_with_string(string)
|
168
|
+
self.raw_source = string
|
169
|
+
set_envelope_header
|
170
|
+
parse_message
|
171
|
+
@separate_parts = multipart?
|
172
|
+
end
|
173
|
+
|
146
174
|
def parse_message_with_jpmobile
|
147
|
-
|
148
|
-
|
149
|
-
if
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
when /shift_jis/i
|
154
|
-
"Shift_JIS"
|
155
|
-
else
|
156
|
-
"UTF-8"
|
157
|
-
end
|
158
|
-
self.body.charset = @charset
|
175
|
+
header_part, body_part = raw_source.split(/#{CRLF}#{WSP}*#{CRLF}/m, 2)
|
176
|
+
|
177
|
+
if header_part =~ HEADER_LINE
|
178
|
+
self.header = header_part
|
179
|
+
else
|
180
|
+
self.header = "Content-Type: text/plain\r\n"
|
159
181
|
end
|
182
|
+
|
183
|
+
@body_part_jpmobile = body_part
|
184
|
+
convert_encoding_jpmobile
|
185
|
+
body_part = @body_part_jpmobile
|
186
|
+
|
187
|
+
self.body = body_part
|
160
188
|
end
|
161
189
|
|
162
190
|
alias_method :parse_message_without_jpmobile, :parse_message
|
@@ -169,25 +197,17 @@ pp self.body.charset
|
|
169
197
|
# convert encoding
|
170
198
|
def encoded_with_jpmobile(transfer_encoding = '8bit')
|
171
199
|
if @mobile and !multipart?
|
172
|
-
if @mobile.to_mail_body_encoded?(raw_source)
|
173
|
-
raw_source
|
200
|
+
if @mobile.to_mail_body_encoded?(@raw_source)
|
201
|
+
@raw_source
|
174
202
|
else
|
175
|
-
@mobile.to_mail_body(Jpmobile::Util.force_encode(raw_source, @charset, Jpmobile::Util::UTF8))
|
203
|
+
@mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
|
176
204
|
end
|
177
205
|
else
|
178
206
|
encoded_without_jpmobile(transfer_encoding)
|
179
207
|
end
|
180
208
|
end
|
181
|
-
def decoded_with_jpmobile
|
182
|
-
if @mobile and !multipart?
|
183
|
-
@raw_source = @mobile.to_mail_internal(@raw_source, nil) unless @jpmobile_decoded
|
184
|
-
@jpmobile_decoded = true
|
185
|
-
end
|
186
|
-
|
187
|
-
if @charset
|
188
|
-
@raw_source = Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8)
|
189
|
-
end
|
190
209
|
|
210
|
+
def decoded_with_jpmobile
|
191
211
|
decoded_without_jpmobile
|
192
212
|
end
|
193
213
|
|
@@ -196,21 +216,56 @@ pp self.body.charset
|
|
196
216
|
@charset ||= only_us_ascii? ? 'US-ASCII' : nil
|
197
217
|
end
|
198
218
|
|
199
|
-
# set encoding to @raw_source in init
|
200
|
-
def set_encoding_jpmobile
|
201
|
-
@raw_source = Jpmobile::Util.set_encoding(@raw_source, @charset)
|
202
|
-
end
|
203
|
-
|
204
219
|
def mobile=(m)
|
220
|
+
@mobile = m
|
221
|
+
|
205
222
|
if self.multipart?
|
206
223
|
self.parts.each do |part|
|
207
|
-
part.
|
208
|
-
part.
|
224
|
+
part.charset = @charset
|
225
|
+
part.mobile = @mobile
|
226
|
+
part.body.charset = @charset
|
227
|
+
part.body.mobile = @mobile
|
209
228
|
end
|
210
229
|
end
|
230
|
+
end
|
211
231
|
|
212
|
-
|
213
|
-
|
232
|
+
def decode_transfer_encoding
|
233
|
+
_raw_source = Encodings.get_encoding(encoding).decode(@raw_source)
|
234
|
+
_raw_source = Jpmobile::Util.set_encoding(_raw_source, @charset)
|
235
|
+
|
236
|
+
@raw_source = @mobile.decode_transfer_encoding(_raw_source, @charset)
|
237
|
+
end
|
238
|
+
|
239
|
+
def preamble_with_jpmobile
|
240
|
+
if @mobile
|
241
|
+
Jpmobile::Util.encode(@preamble, @charset)
|
242
|
+
else
|
243
|
+
preamble_without_jpmobile
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def epilogue_with_jpmobile
|
248
|
+
if @mobile
|
249
|
+
Jpmobile::Util.encode(@epilogue, @charset)
|
250
|
+
else
|
251
|
+
epilogue_without_jpmobile
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def crlf_boundary_with_jpmobile
|
256
|
+
if @mobile
|
257
|
+
Jpmobile::Util.encode(crlf_boundary_without_jpmobile, @charset)
|
258
|
+
else
|
259
|
+
epilogue_without_jpmobile
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def end_boundary_with_jpmobile
|
264
|
+
if @mobile
|
265
|
+
Jpmobile::Util.encode(end_boundary_without_jpmobile, @charset)
|
266
|
+
else
|
267
|
+
epilogue_without_jpmobile
|
268
|
+
end
|
214
269
|
end
|
215
270
|
|
216
271
|
alias_method :encoded_without_jpmobile, :encoded
|
@@ -221,19 +276,22 @@ pp self.body.charset
|
|
221
276
|
|
222
277
|
alias_method :set_charset_without_jpmobile, :set_charset
|
223
278
|
alias_method :set_charset, :set_charset_with_jpmobile
|
224
|
-
end
|
225
279
|
|
226
|
-
|
227
|
-
|
280
|
+
alias_method :preamble_without_jpmobile, :preamble
|
281
|
+
alias_method :preamble, :preamble_with_jpmobile
|
228
282
|
|
229
|
-
|
230
|
-
|
283
|
+
alias_method :crlf_boundary_without_jpmobile, :crlf_boundary
|
284
|
+
alias_method :crlf_boundary, :crlf_boundary_with_jpmobile
|
231
285
|
|
232
|
-
|
286
|
+
alias_method :end_boundary_without_jpmobile, :end_boundary
|
287
|
+
alias_method :end_boundary, :end_boundary_with_jpmobile
|
233
288
|
|
234
|
-
|
235
|
-
|
236
|
-
|
289
|
+
alias_method :epilogue_without_jpmobile, :epilogue
|
290
|
+
alias_method :epilogue, :epilogue_with_jpmobile
|
291
|
+
end
|
292
|
+
|
293
|
+
class UnstructuredField
|
294
|
+
attr_accessor :mobile
|
237
295
|
end
|
238
296
|
|
239
297
|
# for subject
|
@@ -252,14 +310,7 @@ pp self.body.charset
|
|
252
310
|
end
|
253
311
|
end
|
254
312
|
|
255
|
-
# def decoded_with_jpmobile
|
256
|
-
# decoded_without_jpmobile
|
257
|
-
# end
|
258
|
-
|
259
313
|
alias_method :encoded_without_jpmobile, :encoded
|
260
314
|
alias_method :encoded, :encoded_with_jpmobile
|
261
|
-
|
262
|
-
# alias_method :decoded_without_jpmobile, :decoded
|
263
|
-
# alias_method :decoded, :decoded_with_jpmobile
|
264
315
|
end
|
265
316
|
end
|