jpmobile 3.0.9 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +19 -0
- data/Gemfile +3 -11
- data/MIT-LICENSE +1 -1
- data/README.rdoc +7 -8
- data/Rakefile +1 -43
- data/VERSION.yml +1 -1
- data/jpmobile.gemspec +22 -38
- data/lib/jpmobile.rb +3 -1
- data/lib/jpmobile/configuration.rb +19 -0
- data/lib/jpmobile/emoticon/z_combine.rb +0 -4
- data/lib/jpmobile/hook_action_controller.rb +27 -0
- data/lib/jpmobile/mail.rb +56 -77
- data/lib/jpmobile/mailer.rb +1 -0
- data/lib/jpmobile/rack.rb +0 -16
- data/lib/jpmobile/resolver.rb +1 -1
- data/lib/jpmobile/util.rb +35 -128
- data/lib/jpmobile/version.rb +3 -0
- data/lib/tasks/jpmobile_tasks.rake +2 -2
- data/spec/unit/receive_mail_spec.rb +3 -28
- data/spec/unit/util_spec.rb +12 -23
- data/test/rails/overrides/Gemfile +46 -5
- data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +3 -0
- data/test/rails/overrides/app/models/user.rb +0 -1
- data/test/rails/overrides/app/views/layouts/application.html.erb +12 -0
- data/test/rails/overrides/app/views/layouts/application_mobile.html.erb +1 -1
- data/test/rails/overrides/app/views/mobile_mailer/default_to_mail.text.erb +1 -0
- data/test/rails/overrides/app/views/mobile_spec/_partial_view_sample.html.erb +1 -0
- data/test/rails/overrides/app/views/mobile_spec/no_mobile.html.erb +3 -0
- data/test/rails/overrides/config/routes.rb +2 -2
- data/test/rails/overrides/spec/controllers/mobile_spec_controller_spec.rb +36 -2
- data/test/rails/overrides/spec/mailers/mobile_mailer_spec.rb +4 -5
- metadata +194 -142
- data/spec/unit/email-fixtures/iphone-jis.eml +0 -15
- data/spec/unit/email-fixtures/pc-mail-attached-without-subject.eml +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86c3a91d387a147b06a1e8698b4ddcbba1e62c52
|
4
|
+
data.tar.gz: 51c89371e9075628a87c5cdf03cff1922da39466
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5897e0d386accbb2ba9aee29161317c44e550974cf021775badcd932ab77c58475feff381e6da9cff37f0cfb57fb7246cd224916fa0dcbc0255dee34bf430f83
|
7
|
+
data.tar.gz: 78e415d4aea5194564eaaf04dd6a1c5b06cc4c862868bd644555a82433bd127dfd9f8f2c02bd7f6ef7d5f5d6ae1f3ad1118ed9ab1d75d4707c6a8cd831c95096
|
data/.gitignore
ADDED
data/Gemfile
CHANGED
@@ -1,12 +1,4 @@
|
|
1
|
-
source '
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
gem 'rails', '~> 3.2.8'
|
6
|
-
gem 'rspec'
|
7
|
-
gem 'rspec-rails'
|
8
|
-
gem 'webrat'
|
9
|
-
gem 'geokit'
|
10
|
-
gem 'sqlite3-ruby'
|
11
|
-
gem 'hpricot'
|
12
|
-
end
|
3
|
+
# Specify your gem's dependencies in jpmobile.gemspec
|
4
|
+
gemspec
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2006 Yoji Shidara
|
1
|
+
Copyright (c) 2006-2012 Yoji Shidara
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
4
|
|
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= jpmobile: A Rails plugin for Japanese mobile-phones
|
2
2
|
|
3
3
|
== jpmobileとは
|
4
|
-
携帯電話特有の機能を Rails
|
4
|
+
携帯電話特有の機能を Rails 4.0 や Rack middleware で利用するためのプラグイン。
|
5
5
|
以下の機能を備える。
|
6
6
|
|
7
7
|
* 携帯電話のキャリア判別
|
@@ -18,7 +18,7 @@
|
|
18
18
|
* メールの受信(experimental)
|
19
19
|
* 絵文字と漢字コードの変換
|
20
20
|
|
21
|
-
また Rails
|
21
|
+
また Rails 4.0 に以下の機能を追加する
|
22
22
|
* ビューへの自動振分け
|
23
23
|
* 位置情報取得などのリンクヘルパーの追加
|
24
24
|
* セッションIDをフォーム/リンクに付与(Trans SID)
|
@@ -247,8 +247,9 @@ Androidの場合はindex_smart_phone_android.html.erb、Windows Phoneの場合
|
|
247
247
|
trans_sid :always
|
248
248
|
end
|
249
249
|
|
250
|
-
trans_sid
|
251
|
-
|
250
|
+
trans_sid 機能を使う場合には、cookie session store を使用することができず、
|
251
|
+
active_record_storeのgemパッケージが必要です。
|
252
|
+
また Rails 4.0 では Cookie が使える場合にはそちらが優先されてしまうため、:always を指定した場合に問題になる場合があります。
|
252
253
|
trans_sid を使用する際には、例えば config/initializers/session_store.rb で
|
253
254
|
Rails.application.config.session_store :active_record_store
|
254
255
|
Rails.application.config.session_options = {:cookie_only => false}
|
@@ -305,8 +306,6 @@ trans_sid を使用する際には、例えば config/initializers/session_store
|
|
305
306
|
|
306
307
|
== 作者
|
307
308
|
|
308
|
-
Copyright 2006-
|
309
|
+
Copyright 2006-2012 (c) Yoji Shidara, under MIT License.
|
309
310
|
|
310
|
-
Yoji Shidara <dara@shidara.net>
|
311
|
-
|
312
|
-
http://d.hatena.ne.jp/darashi
|
311
|
+
Shin-ichiro OGAWA <rust.stnard@gmail.com>, Yoji Shidara <dara@shidara.net>
|
data/Rakefile
CHANGED
@@ -1,55 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/clean'
|
1
|
+
require "bundler/gem_tasks"
|
4
2
|
require 'rake/testtask'
|
5
|
-
require 'rdoc/task'
|
6
3
|
require 'fileutils'
|
7
4
|
require 'pathname'
|
8
5
|
require 'git'
|
9
6
|
include FileUtils
|
10
7
|
|
11
|
-
begin
|
12
|
-
require 'jeweler'
|
13
|
-
Jeweler::Tasks.new do |gem|
|
14
|
-
gem.name = "jpmobile"
|
15
|
-
gem.summary = "A Rails plugin for Japanese mobile-phones"
|
16
|
-
gem.description = "A Rails plugin for Japanese mobile-phones"
|
17
|
-
gem.email = "dara@shidara.net"
|
18
|
-
gem.homepage = "http://jpmobile-rails.org"
|
19
|
-
gem.authors = ["Yoji Shidara", "Shin-ichiro OGAWA"]
|
20
|
-
|
21
|
-
gem.files.exclude 'test'
|
22
|
-
gem.files.exclude 'spec'
|
23
|
-
gem.files.exclude 'vendor'
|
24
|
-
|
25
|
-
gem.add_development_dependency('rails', '>=3.2.0')
|
26
|
-
gem.add_development_dependency('jeweler', '>=1.5.1')
|
27
|
-
gem.add_development_dependency('rspec', '>=2.6.0')
|
28
|
-
gem.add_development_dependency('rspec-rails', '>=2.6.0')
|
29
|
-
gem.add_development_dependency('webrat', '>=0.7.2')
|
30
|
-
gem.add_development_dependency('geokit', '>=1.5.0')
|
31
|
-
gem.add_development_dependency('sqlite3-ruby', '>=1.3.2')
|
32
|
-
gem.add_development_dependency('hpricot', '>=0.8.3')
|
33
|
-
gem.add_development_dependency('git', '>=1.2.5')
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
37
|
-
end
|
38
|
-
Jeweler::GemcutterTasks.new
|
39
|
-
|
40
8
|
desc 'Default: run unit tests.'
|
41
9
|
task :default => :test
|
42
10
|
|
43
|
-
desc 'Generate documentation for the jpmobile plugin.'
|
44
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
45
|
-
rdoc.rdoc_dir = 'doc'
|
46
|
-
rdoc.title = 'Jpmobile'
|
47
|
-
rdoc.options << '--line-numbers' << '--inline-source' << '-c UTF-8'
|
48
|
-
rdoc.rdoc_files.include('README.rdoc')
|
49
|
-
rdoc.rdoc_files.include('CHANGELOG')
|
50
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
-
end
|
52
|
-
|
53
11
|
desc "Update misc tables"
|
54
12
|
task :update do
|
55
13
|
Dir.glob("tools/update_*.rb").each do |path|
|
data/VERSION.yml
CHANGED
data/jpmobile.gemspec
CHANGED
@@ -1,43 +1,27 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jpmobile/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "jpmobile"
|
8
|
+
gem.version = Jpmobile::VERSION
|
9
|
+
gem.authors = ["Shin-ichiro OGAWA", "Yoji Shidara"]
|
10
|
+
gem.email = ["rust.stnard@gmail.com"]
|
11
|
+
gem.description = %q{A Rails plugin for mobile devices in Japan}
|
12
|
+
gem.summary = %q{A Rails plugin for mobile devices in Japan}
|
13
|
+
gem.homepage = 'http://jpmobile-rails.org'
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
s.description = %q{A Rails plugin for Japanese mobile-phones}
|
14
|
-
s.email = %q{dara@shidara.net}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README', 'README.rdoc', 'init.rb', 'install.rb', 'lib/**/*.*', 'tools/**/*.*']
|
20
|
-
s.homepage = %q{http://jpmobile-rails.org}
|
21
|
-
s.require_paths = ["lib"]
|
22
|
-
s.rubygems_version = %q{1.3.7}
|
23
|
-
s.summary = %q{A Rails plugin for Japanese mobile-phones}
|
24
|
-
s.test_files = Dir['spec/**/*.*', 'test/**/"."' 'tmp/**/*.*']
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
s.add_development_dependency(%q<jeweler>, [">= 1.5.1"])
|
35
|
-
s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
|
36
|
-
s.add_development_dependency(%q<rspec-rails>, [">= 2.3.0"])
|
37
|
-
s.add_development_dependency(%q<webrat>, [">= 0.7.2"])
|
38
|
-
s.add_development_dependency(%q<geokit>, [">= 1.5.0"])
|
39
|
-
s.add_development_dependency(%q<sqlite3-ruby>, [">= 1.3.2"])
|
40
|
-
s.add_development_dependency(%q<hpricot>, [">= 0.8.3"])
|
41
|
-
s.add_development_dependency(%q<git>, [">= 1.2.5"])
|
42
|
-
s.add_development_dependency(%q<rails>, [">= 3.0.3"])
|
19
|
+
gem.add_development_dependency 'rails'
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'rspec-rails'
|
22
|
+
gem.add_development_dependency 'webrat'
|
23
|
+
gem.add_development_dependency 'geokit'
|
24
|
+
gem.add_development_dependency 'sqlite3-ruby'
|
25
|
+
gem.add_development_dependency 'hpricot'
|
26
|
+
gem.add_development_dependency 'git'
|
43
27
|
end
|
data/lib/jpmobile.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) ||
|
3
3
|
$:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
|
+
require "jpmobile/version"
|
4
5
|
|
5
6
|
module Jpmobile
|
6
7
|
autoload :Email, 'jpmobile/email'
|
@@ -52,12 +53,13 @@ module Jpmobile
|
|
52
53
|
end
|
53
54
|
|
54
55
|
# autoload Rack middlewares
|
56
|
+
autoload :Rack, 'jpmobile/rack'
|
55
57
|
module Rack
|
56
58
|
autoload :MobileCarrier, 'jpmobile/rack/mobile_carrier'
|
57
59
|
autoload :ParamsFilter, 'jpmobile/rack/params_filter'
|
58
60
|
autoload :Filter, 'jpmobile/rack/filter'
|
59
61
|
end
|
60
|
-
autoload :Configuration, 'jpmobile/
|
62
|
+
autoload :Configuration, 'jpmobile/configuration'
|
61
63
|
|
62
64
|
autoload :Mailer, 'jpmobile/mailer'
|
63
65
|
autoload :Resolver, 'jpmobile/resolver'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Jpmobile
|
2
|
+
class Configuration
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
attr_accessor :form_accept_charset_conversion
|
6
|
+
attr_accessor :smart_phone_emoticon_compatibility
|
7
|
+
attr_accessor :fallback_view_selector
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@form_accept_charset_conversion = false
|
11
|
+
@smart_phone_emoticon_compatibility = false
|
12
|
+
@fallback_view_selector = false
|
13
|
+
end
|
14
|
+
|
15
|
+
def mobile_filter
|
16
|
+
::Jpmobile::Rack.mount_middlewares
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -16,3 +16,30 @@ module ActionController
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
module AbstractController
|
21
|
+
module Rendering
|
22
|
+
def render_to_body_with_jpmobile(options)
|
23
|
+
if Jpmobile.config.fallback_view_selector and
|
24
|
+
lookup_context.mobile.present? and !lookup_context.mobile.empty?
|
25
|
+
begin
|
26
|
+
expected_view_file = lookup_context.find_template(options[:template], options[:prefixes])
|
27
|
+
|
28
|
+
_candidates = lookup_context.mobile.map { |variant|
|
29
|
+
target_templat = options[:template] + '_' + variant
|
30
|
+
expected_view_file.virtual_path.match(target_templat)
|
31
|
+
}.compact
|
32
|
+
|
33
|
+
if _candidates.empty?
|
34
|
+
lookup_context.mobile = []
|
35
|
+
end
|
36
|
+
rescue ActionView::MissingTemplate
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
render_to_body_without_jpmobile(options)
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method_chain :render_to_body, :jpmobile
|
44
|
+
end
|
45
|
+
end
|
data/lib/jpmobile/mail.rb
CHANGED
@@ -3,41 +3,23 @@ require 'mail'
|
|
3
3
|
|
4
4
|
module Mail
|
5
5
|
# encoding patch
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
str.force_encoding(respond_to?(:pick_encoding) ? pick_encoding(encoding) : fix_encoding(encoding))
|
14
|
-
end
|
15
|
-
# if str contains some emoticon, the following line raises Encoding error
|
16
|
-
str.encode("utf-8", :invalid => :replace, :replace => "") rescue Jpmobile::Util.ascii_8bit(str)
|
17
|
-
end
|
18
|
-
|
19
|
-
# change encoding
|
20
|
-
def self.b_value_encode(str, encoding)
|
21
|
-
str = Jpmobile::Util.encode(str, encoding.to_s)
|
22
|
-
[Ruby19.encode_base64(str), encoding]
|
6
|
+
Ruby19.class_eval do
|
7
|
+
def self.b_value_decode(str)
|
8
|
+
match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
|
9
|
+
if match
|
10
|
+
encoding = match[1]
|
11
|
+
str = self.decode_base64(match[2])
|
12
|
+
str.force_encoding(pick_encoding(encoding))
|
23
13
|
end
|
14
|
+
# if str contains some emoticon, the following line raises Encoding error
|
15
|
+
str.encode("utf-8", :invalid => :replace, :replace => "") rescue Jpmobile::Util.ascii_8bit(str)
|
16
|
+
# decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
|
24
17
|
end
|
25
|
-
elsif self.const_defined?(:Ruby18)
|
26
|
-
Ruby18.class_eval do
|
27
|
-
def self.b_value_decode(str)
|
28
|
-
match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
|
29
|
-
if match
|
30
|
-
encoding = match[1]
|
31
|
-
str = Ruby18.decode_base64(match[2])
|
32
|
-
end
|
33
|
-
str
|
34
|
-
end
|
35
18
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
19
|
+
# change encoding
|
20
|
+
def self.b_value_encode(str, encoding)
|
21
|
+
str = Jpmobile::Util.encode(str, encoding.to_s)
|
22
|
+
[Ruby19.encode_base64(str), encoding]
|
41
23
|
end
|
42
24
|
end
|
43
25
|
|
@@ -47,6 +29,12 @@ module Mail
|
|
47
29
|
def mobile=(m)
|
48
30
|
if @mobile = m
|
49
31
|
@charset = m.mail_charset(@charset)
|
32
|
+
|
33
|
+
if self.body
|
34
|
+
self.body.content_type_with_jpmobile = self.content_type
|
35
|
+
self.body.charset = @charset
|
36
|
+
self.body.mobile = m
|
37
|
+
end
|
50
38
|
end
|
51
39
|
end
|
52
40
|
|
@@ -59,6 +47,7 @@ module Mail
|
|
59
47
|
|
60
48
|
ready_to_send!
|
61
49
|
|
50
|
+
self.body.charset = @charset
|
62
51
|
self.body.mobile = @mobile
|
63
52
|
self.header['Content-Transfer-Encoding'].value = @mobile.content_transfer_encoding(self.header)
|
64
53
|
if @mobile.decorated?
|
@@ -95,18 +84,6 @@ module Mail
|
|
95
84
|
self.body = body_part
|
96
85
|
end
|
97
86
|
|
98
|
-
def init_with_hash_with_jpmobile(hash)
|
99
|
-
if hash[:body_raw]
|
100
|
-
@mobile = hash[:mobile]
|
101
|
-
init_with_string(hash[:body_raw])
|
102
|
-
else
|
103
|
-
init_with_hash_without_jpmobile(hash)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
alias_method :init_with_hash_without_jpmobile, :init_with_hash
|
108
|
-
alias_method :init_with_hash, :init_with_hash_with_jpmobile
|
109
|
-
|
110
87
|
def init_with_string(string)
|
111
88
|
# convert to ASCII-8BIT for ascii incompatible encodings
|
112
89
|
s = Jpmobile::Util.ascii_8bit(string)
|
@@ -120,6 +97,7 @@ module Mail
|
|
120
97
|
process_body_raw_without_jpmobile
|
121
98
|
|
122
99
|
if @mobile
|
100
|
+
@body.charset = @charset
|
123
101
|
@body.mobile = @mobile
|
124
102
|
@body.content_type_with_jpmobile = self.content_type
|
125
103
|
|
@@ -143,11 +121,6 @@ module Mail
|
|
143
121
|
@raw_source = value.to_crlf
|
144
122
|
end
|
145
123
|
|
146
|
-
def separate_parts_with_jpmobile
|
147
|
-
@body.mobile = @mobile
|
148
|
-
separate_parts_without_jpmobile
|
149
|
-
end
|
150
|
-
|
151
124
|
alias_method :encoded_without_jpmobile, :encoded
|
152
125
|
alias_method :encoded, :encoded_with_jpmobile
|
153
126
|
|
@@ -157,9 +130,6 @@ module Mail
|
|
157
130
|
alias_method :process_body_raw_without_jpmobile, :process_body_raw
|
158
131
|
alias_method :process_body_raw, :process_body_raw_with_jpmobile
|
159
132
|
|
160
|
-
alias_method :separate_parts_without_jpmobile, :separate_parts
|
161
|
-
alias_method :separate_parts, :separate_parts_with_jpmobile
|
162
|
-
|
163
133
|
# -- docomo
|
164
134
|
# multipart/mixed
|
165
135
|
# |- multipart/related
|
@@ -260,23 +230,34 @@ module Mail
|
|
260
230
|
# override charset
|
261
231
|
if self.header[:content_type]
|
262
232
|
content_type_charset = Jpmobile::Util.extract_charset(self.header[:content_type].value)
|
263
|
-
@charset = content_type_charset
|
264
233
|
unless content_type_charset.blank?
|
234
|
+
@charset = content_type_charset
|
265
235
|
self.header[:content_type].parameters[:charset] = @charset
|
266
236
|
@mobile_main_type = self.header[:content_type].main_type
|
267
237
|
end
|
238
|
+
|
239
|
+
if !Jpmobile::Email.convertable?(self.header[:content_type].value) and content_type_charset.blank?
|
240
|
+
@charset = ''
|
241
|
+
end
|
268
242
|
end
|
269
243
|
|
270
244
|
# convert header(s)
|
271
245
|
if self.header[:subject]
|
272
246
|
subject_charset = Jpmobile::Util.extract_charset(self.header[:subject].value)
|
247
|
+
|
248
|
+
# override subject encoding if @charset is blank
|
249
|
+
@charset = subject_charset if !subject_charset.blank? # and @charset.blank?
|
273
250
|
self.header[:subject].charset = subject_charset unless subject_charset.blank?
|
274
251
|
|
275
252
|
if @mobile
|
276
253
|
subject_value = Encodings.value_decode(self.header[:subject].value)
|
277
254
|
subject_converting_encoding = Jpmobile::Util.detect_encoding(subject_value)
|
278
255
|
v = @mobile.to_mail_internal(subject_value, subject_converting_encoding)
|
279
|
-
|
256
|
+
if @charset == subject_charset and @mobile.mail_charset != @charset
|
257
|
+
self.header[:subject].value = Jpmobile::Util.force_encode(v, @charset, Jpmobile::Util::UTF8)
|
258
|
+
else
|
259
|
+
self.header[:subject].value = Jpmobile::Util.force_encode(v, @mobile.mail_charset(@charset), Jpmobile::Util::UTF8)
|
260
|
+
end
|
280
261
|
end
|
281
262
|
end
|
282
263
|
|
@@ -341,18 +322,25 @@ module Mail
|
|
341
322
|
# convert encoding
|
342
323
|
def encoded_with_jpmobile(transfer_encoding = '8bit')
|
343
324
|
if @mobile and !multipart?
|
344
|
-
|
345
|
-
|
325
|
+
if @mobile.to_mail_body_encoded?(@raw_source)
|
326
|
+
@raw_source
|
327
|
+
elsif Jpmobile::Util.ascii_8bit?(@raw_source)
|
346
328
|
_raw_source = if transfer_encoding == encoding
|
347
|
-
@raw_source
|
329
|
+
@raw_source
|
348
330
|
else
|
349
|
-
get_best_encoding(transfer_encoding)
|
331
|
+
enc = Mail::Encodings::get_encoding(get_best_encoding(transfer_encoding))
|
332
|
+
enc.encode(@raw_source)
|
350
333
|
end
|
351
|
-
Jpmobile::Util.
|
352
|
-
when /quoted-printable/
|
353
|
-
Jpmobile::Util.set_encoding([@mobile.to_mail_body(@raw_source)].pack("M").gsub(/\n/, "\r\n"), @mobile.mail_charset(@charset))
|
334
|
+
Jpmobile::Util.force_encode(_raw_source, nil, @charset)
|
354
335
|
else
|
355
|
-
|
336
|
+
case transfer_encoding
|
337
|
+
when /quoted-printable/
|
338
|
+
# [str].pack("M").gsub(/\n/, "\r\n")
|
339
|
+
Jpmobile::Util.force_encode([@mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))].pack("M").gsub(/\n/, "\r\n"), Jpmobile::Util::BINARY, @charset)
|
340
|
+
# @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
|
341
|
+
else
|
342
|
+
@mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
|
343
|
+
end
|
356
344
|
end
|
357
345
|
else
|
358
346
|
encoded_without_jpmobile(transfer_encoding)
|
@@ -378,7 +366,9 @@ module Mail
|
|
378
366
|
|
379
367
|
if self.multipart? and @mobile
|
380
368
|
self.parts.each do |part|
|
369
|
+
part.charset = @mobile.mail_charset(part.charset)
|
381
370
|
part.mobile = @mobile
|
371
|
+
part.body.charset = part.charset
|
382
372
|
part.body.mobile = @mobile
|
383
373
|
end
|
384
374
|
end
|
@@ -392,7 +382,7 @@ module Mail
|
|
392
382
|
|
393
383
|
def preamble_with_jpmobile
|
394
384
|
if @mobile
|
395
|
-
Jpmobile::Util.encode(@preamble, @
|
385
|
+
Jpmobile::Util.encode(@preamble, @charset)
|
396
386
|
else
|
397
387
|
preamble_without_jpmobile
|
398
388
|
end
|
@@ -400,7 +390,7 @@ module Mail
|
|
400
390
|
|
401
391
|
def epilogue_with_jpmobile
|
402
392
|
if @mobile
|
403
|
-
Jpmobile::Util.encode(@epilogue, @
|
393
|
+
Jpmobile::Util.encode(@epilogue, @charset)
|
404
394
|
else
|
405
395
|
epilogue_without_jpmobile
|
406
396
|
end
|
@@ -408,7 +398,7 @@ module Mail
|
|
408
398
|
|
409
399
|
def crlf_boundary_with_jpmobile
|
410
400
|
if @mobile
|
411
|
-
Jpmobile::Util.encode(crlf_boundary_without_jpmobile, @
|
401
|
+
Jpmobile::Util.encode(crlf_boundary_without_jpmobile, @charset)
|
412
402
|
else
|
413
403
|
crlf_boundary_without_jpmobile
|
414
404
|
end
|
@@ -416,7 +406,7 @@ module Mail
|
|
416
406
|
|
417
407
|
def end_boundary_with_jpmobile
|
418
408
|
if @mobile
|
419
|
-
Jpmobile::Util.encode(end_boundary_without_jpmobile, @
|
409
|
+
Jpmobile::Util.encode(end_boundary_without_jpmobile, @charset)
|
420
410
|
else
|
421
411
|
end_boundary_without_jpmobile
|
422
412
|
end
|
@@ -445,17 +435,6 @@ module Mail
|
|
445
435
|
|
446
436
|
alias_method :epilogue_without_jpmobile, :epilogue
|
447
437
|
alias_method :epilogue, :epilogue_with_jpmobile
|
448
|
-
|
449
|
-
def split!(boundary)
|
450
|
-
self.boundary = boundary
|
451
|
-
parts = raw_source.split(/(?:\A|\r\n)--#{Regexp.escape(boundary)}(?=(?:--)?\s*$)/)
|
452
|
-
# Make the preamble equal to the preamble (if any)
|
453
|
-
self.preamble = parts[0].to_s.strip
|
454
|
-
# Make the epilogue equal to the epilogue (if any)
|
455
|
-
self.epilogue = parts[-1].to_s.sub('--', '').strip
|
456
|
-
parts[1...-1].to_a.each { |part| @parts << Mail::Part.new(:body_raw => part, :mobile => @mobile) }
|
457
|
-
self
|
458
|
-
end
|
459
438
|
end
|
460
439
|
|
461
440
|
class UnstructuredField
|