letter_opener-iso-2022-jp 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -5
- data/letter_opener-iso-2022-jp.gemspec +2 -2
- data/lib/letter_opener/mail_with_iso_2022_jp.rb +19 -15
- data/lib/letter_opener-iso-2022-jp.rb +1 -1
- data/spec/mail_spec.rb +102 -52
- data/spec/spec_helper.rb +3 -0
- data/spec/support/launchy_mock.rb +29 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e8c3d9bb75446b0e397d703921c4c6c1362db23
|
4
|
+
data.tar.gz: 0562da1afc83a54ddab58461b08cfbed2b50cd33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54796e81b98f1207261139220d259d71eb262f5933070e26c096303fc273118ec1dff70ae6e24f7549844907474f7961e424635fe686f1885c52257e67938736
|
7
|
+
data.tar.gz: 206940ca0dc6853fdef7437493c096a2f97834f70b1f9436ebbf799fa1be30d937e343322f38083d4c04e949143e37177fe26b0cf0b2e4595b2d805e5590e8ef
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# letter_opener-iso-2022-jp
|
2
2
|
|
3
|
-
|
3
|
+
This patch provides 'letter_opener' gem with iso-2022-jp conversion capability.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,10 +16,6 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install letter_opener-iso-2022-jp
|
18
18
|
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
19
|
## Contributing
|
24
20
|
|
25
21
|
1. Fork it
|
@@ -27,3 +23,4 @@ TODO: Write usage instructions here
|
|
27
23
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
24
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
25
|
5. Create new Pull Request
|
26
|
+
|
@@ -4,10 +4,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "letter_opener-iso-2022-jp"
|
7
|
-
spec.version = "0.0
|
7
|
+
spec.version = "0.1.0"
|
8
8
|
spec.authors = ["hamajyotan"]
|
9
9
|
spec.email = ["takashi.sakaguchi@ummm.info"]
|
10
|
-
spec.description = "
|
10
|
+
spec.description = "This patch provides 'letter_opener' gem with iso-2022-jp conversion capability."
|
11
11
|
spec.summary = "letter_opener with iso-2022-jp encoding."
|
12
12
|
spec.homepage = "http://github.com/ummm/letter_opener-iso-2022-jp"
|
13
13
|
spec.license = "MIT"
|
@@ -1,35 +1,39 @@
|
|
1
1
|
|
2
2
|
module LetterOpener
|
3
|
-
class MailWithIso2022Jp
|
4
|
-
extend Forwardable
|
5
|
-
|
6
|
-
def initialize mail
|
7
|
-
@mail = mail
|
8
|
-
end
|
9
|
-
|
10
|
-
def_delegators :@mail, :attachments, :multipart?, :content_type
|
3
|
+
class MailWithIso2022Jp < SimpleDelegator
|
11
4
|
|
12
5
|
def subject
|
13
|
-
|
6
|
+
Iso2022JpToUtf8.decode(super)
|
14
7
|
end
|
15
8
|
|
16
9
|
def body
|
17
|
-
|
10
|
+
Mail::Body.new(super.raw_source.encode("UTF-8", "ISO-2022-JP"))
|
18
11
|
end
|
19
12
|
|
20
13
|
def html_part &block
|
21
|
-
part =
|
22
|
-
|
14
|
+
if part = super
|
15
|
+
MailWithIso2022Jp.new(part)
|
16
|
+
end
|
23
17
|
end
|
24
18
|
|
25
19
|
def text_part &block
|
26
|
-
part =
|
27
|
-
|
20
|
+
if part = super
|
21
|
+
MailWithIso2022Jp.new(part)
|
22
|
+
end
|
28
23
|
end
|
29
24
|
|
30
25
|
def [] key
|
31
|
-
Array(
|
26
|
+
Array(super).map { |f| PlainField.new(f.name, Iso2022JpToUtf8.decode(f.value), f.charset) }
|
32
27
|
end
|
33
28
|
end
|
29
|
+
|
30
|
+
class PlainField
|
31
|
+
def initialize name, value, charset
|
32
|
+
@name, @value, @charset = name, value, charset
|
33
|
+
end
|
34
|
+
attr_reader :name, :value, :charset
|
35
|
+
|
36
|
+
def to_str; @value; end
|
37
|
+
end
|
34
38
|
end
|
35
39
|
|
data/spec/mail_spec.rb
CHANGED
@@ -2,90 +2,140 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe
|
6
|
-
let(:location) { Mail.delivery_method.settings[:location] }
|
5
|
+
describe LetterOpener, launchy_mock: true do
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
describe "text mail" do
|
8
|
+
context "given utf-8 encoded mail" do
|
9
|
+
before do
|
10
|
+
Mail.new(charset: "UTF-8") {
|
11
|
+
from "差出人 <foo@example.com>"
|
12
|
+
to "宛先 <bar@example.com>"
|
13
|
+
subject "日本語のタイトル"
|
14
|
+
content_type "text/plain; charset=UTF-8"
|
15
|
+
body "日本語の本文 (UTF-8)"
|
16
|
+
}.deliver
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
+
describe "messages" do
|
20
|
+
subject { messages }
|
21
|
+
its(:size) { should == 1 }
|
22
|
+
end
|
23
|
+
describe "messages[#{0}]" do
|
24
|
+
subject { messages[0] }
|
25
|
+
its(:type) { should == :text }
|
26
|
+
its(:raw) { should match "<dd>"差出人" <foo@example.com></dd>" }
|
27
|
+
its(:raw) { should match "<dd>"宛先" <bar@example.com></dd>" }
|
28
|
+
its(:raw) { should match "<dd><strong>日本語のタイトル</strong></dd>" }
|
29
|
+
its(:raw) { should match '<pre id=\"message_body\">日本語の本文 \(UTF-8\)</pre>' }
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
subject "日本語のタイトル"
|
31
|
-
content_type "text/plain; charset=ISO-2022-JP"
|
32
|
-
body "日本語の本文 (ISO-2022-JP)"
|
33
|
+
context "given iso-2022-jp encoded mail" do
|
34
|
+
before do
|
35
|
+
Mail.new(charset: "ISO-2022-JP") {
|
36
|
+
from "差出人 <foo@example.com>"
|
37
|
+
to "宛先 <bar@example.com>"
|
38
|
+
subject "とてもとてもとてもとてもとてもとても very とてもとてもとてもとてもとてもとても長い日本語のタイトル"
|
39
|
+
content_type "text/plain; charset=ISO-2022-JP"
|
40
|
+
body "日本語の本文 ISO-2022-JP バージョン"
|
41
|
+
}.deliver
|
33
42
|
end
|
34
43
|
|
35
|
-
|
44
|
+
describe "messages" do
|
45
|
+
subject { messages }
|
46
|
+
its(:size) { should == 1 }
|
47
|
+
end
|
48
|
+
describe "messages[#{0}]" do
|
49
|
+
subject { messages[0] }
|
50
|
+
its(:type) { should == :text }
|
51
|
+
its(:raw) { should match "<dd>差出人 <foo@example.com></dd>" }
|
52
|
+
its(:raw) { should match "<dd>宛先 <bar@example.com></dd>" }
|
53
|
+
its(:raw) { should match "<dd><strong>とてもとてもとてもとてもとてもとても very とてもとてもとてもとてもとてもとても長い日本語のタイトル</strong></dd>" }
|
54
|
+
its(:raw) { should match '<pre id=\"message_body\">日本語の本文 ISO-2022-JP バージョン</pre>' }
|
55
|
+
end
|
36
56
|
end
|
37
|
-
|
38
|
-
subject { 1 + 2 }
|
39
|
-
it { expect(subject).to be 3 }
|
40
57
|
end
|
41
58
|
|
42
59
|
context "given multipart mail" do
|
43
60
|
context "given utf-8 encoded mail" do
|
44
61
|
before do
|
45
|
-
|
62
|
+
Mail.new(charset: "UTF-8") {
|
46
63
|
from "差出人 <foo@example.com>"
|
47
64
|
to "宛先 <bar@example.com>"
|
48
65
|
subject "日本語のタイトル"
|
49
66
|
|
50
|
-
text_part
|
67
|
+
text_part {
|
51
68
|
content_type "text/plain; charset=UTF-8"
|
52
69
|
body "日本語の本文 (UTF-8)"
|
53
|
-
|
54
|
-
html_part do
|
55
|
-
content_type "text/html; charset=UTF-8"
|
56
|
-
body "日本語の本文 (UTF-8)"
|
57
|
-
end.charset = "UTF-8"
|
58
|
-
end
|
70
|
+
}.charset = "UTF-8"
|
59
71
|
|
60
|
-
|
72
|
+
html_part {
|
73
|
+
content_type "text/html; charset=UTF-8"
|
74
|
+
body "<h1>日本語の本文 (UTF-8)</h1>"
|
75
|
+
}.charset = "UTF-8"
|
76
|
+
}.deliver
|
61
77
|
end
|
62
78
|
|
63
|
-
|
64
|
-
|
79
|
+
describe "messages" do
|
80
|
+
subject { messages }
|
81
|
+
its(:size) { should == 2 }
|
82
|
+
end
|
83
|
+
describe "messages[#{0}]" do
|
84
|
+
subject { messages[0] }
|
85
|
+
its(:type) { should == :text }
|
86
|
+
its(:raw) { should match "<dd>"差出人" <foo@example.com></dd>" }
|
87
|
+
its(:raw) { should match "<dd>"宛先" <bar@example.com></dd>" }
|
88
|
+
its(:raw) { should match "<dd><strong>日本語のタイトル</strong></dd>" }
|
89
|
+
its(:raw) { should match '<pre id=\"message_body\">日本語の本文 \(UTF-8\)</pre>' }
|
90
|
+
end
|
91
|
+
describe "messages[#{1}]" do
|
92
|
+
subject { messages[1] }
|
93
|
+
its(:type) { should == :html }
|
94
|
+
its(:raw) { should match "<dd>"差出人" <foo@example.com></dd>" }
|
95
|
+
its(:raw) { should match "<dd>"宛先" <bar@example.com></dd>" }
|
96
|
+
its(:raw) { should match "<dd><strong>日本語のタイトル</strong></dd>" }
|
97
|
+
its(:raw) { should match "<h1>日本語の本文 \\(UTF-8\\)</h1>" }
|
98
|
+
end
|
65
99
|
end
|
66
100
|
|
67
|
-
|
101
|
+
context "given iso-2022-jp encoded mail" do
|
68
102
|
before do
|
69
|
-
|
103
|
+
Mail.new(charset: "ISO-2022-JP") {
|
70
104
|
from "差出人 <foo@example.com>"
|
71
105
|
to "宛先 <bar@example.com>"
|
72
|
-
subject "
|
106
|
+
subject "とてもとてもとてもとてもとてもとても very とてもとてもとてもとてもとてもとても長い日本語のタイトル"
|
73
107
|
|
74
|
-
text_part
|
108
|
+
text_part {
|
75
109
|
content_type "text/plain; charset=ISO-2022-JP"
|
76
|
-
body "日本語の本文
|
77
|
-
|
78
|
-
html_part
|
110
|
+
body "日本語の本文 ISO-2022-JP バージョン"
|
111
|
+
}.charset = "ISO-2022-JP"
|
112
|
+
html_part {
|
79
113
|
content_type "text/html; charset=ISO-2022-JP"
|
80
|
-
body "
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
mail.deliver
|
114
|
+
body "<h1>日本語の本文 ISO-2022-JP バージョン</h1>"
|
115
|
+
}.charset = "ISO-2022-JP"
|
116
|
+
}.deliver
|
85
117
|
end
|
86
118
|
|
87
|
-
|
88
|
-
|
119
|
+
describe "messages" do
|
120
|
+
subject { messages }
|
121
|
+
its(:size) { should == 2 }
|
122
|
+
end
|
123
|
+
describe "messages[#{0}]" do
|
124
|
+
subject { messages[0] }
|
125
|
+
its(:type) { should == :text }
|
126
|
+
its(:raw) { should match "<dd>差出人 <foo@example.com></dd>" }
|
127
|
+
its(:raw) { should match "<dd>宛先 <bar@example.com></dd>" }
|
128
|
+
its(:raw) { should match "<dd><strong>とてもとてもとてもとてもとてもとても very とてもとてもとてもとてもとてもとても長い日本語のタイトル</strong></dd>" }
|
129
|
+
its(:raw) { should match '<pre id=\"message_body\">日本語の本文 ISO-2022-JP バージョン</pre>' }
|
130
|
+
end
|
131
|
+
describe "messages[#{1}]" do
|
132
|
+
subject { messages[1] }
|
133
|
+
its(:type) { should == :html }
|
134
|
+
its(:raw) { should match "<dd>差出人 <foo@example.com></dd>" }
|
135
|
+
its(:raw) { should match "<dd>宛先 <bar@example.com></dd>" }
|
136
|
+
its(:raw) { should match "<dd><strong>とてもとてもとてもとてもとてもとても very とてもとてもとてもとてもとてもとても長い日本語のタイトル</strong></dd>" }
|
137
|
+
its(:raw) { should match "<h1>日本語の本文 ISO-2022-JP バージョン</h1>" }
|
138
|
+
end
|
89
139
|
end
|
90
140
|
end
|
91
141
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
|
2
|
+
require "letter_opener"
|
2
3
|
require "mail-iso-2022-jp"
|
3
4
|
require "pry-debugger"
|
4
5
|
|
5
6
|
require "letter_opener-iso-2022-jp"
|
6
7
|
|
8
|
+
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
|
9
|
+
|
7
10
|
RSpec.configure do |config|
|
8
11
|
config.filter_run focus: true
|
9
12
|
config.run_all_when_everything_filtered = true
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
class MockMessage
|
3
|
+
def initialize filename
|
4
|
+
@filename = filename
|
5
|
+
@raw = File.read(filename)
|
6
|
+
end
|
7
|
+
|
8
|
+
def type
|
9
|
+
case File.basename(@filename)
|
10
|
+
when "plain.html"; :text
|
11
|
+
when "rich.html" ; :html
|
12
|
+
end
|
13
|
+
end
|
14
|
+
attr_reader :raw
|
15
|
+
end
|
16
|
+
|
17
|
+
shared_context 'mimiced to receive mail', launchy_mock: true do
|
18
|
+
before do
|
19
|
+
Launchy.stub!(:open).and_return do |uri|
|
20
|
+
path = URI.parse(uri).path
|
21
|
+
dir = File.dirname(path)
|
22
|
+
|
23
|
+
messages.clear
|
24
|
+
Dir[File.join(dir, "**")].sort.each { |msg| messages << MockMessage.new(msg) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
let(:messages) { @messages ||= [] }
|
28
|
+
end
|
29
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: letter_opener-iso-2022-jp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hamajyotan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,8 +94,7 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
98
|
-
email. This gem will eliminate the problem.
|
97
|
+
description: This patch provides 'letter_opener' gem with iso-2022-jp conversion capability.
|
99
98
|
email:
|
100
99
|
- takashi.sakaguchi@ummm.info
|
101
100
|
executables: []
|
@@ -114,6 +113,7 @@ files:
|
|
114
113
|
- lib/letter_opener/message_with_iso_2022_jp.rb
|
115
114
|
- spec/mail_spec.rb
|
116
115
|
- spec/spec_helper.rb
|
116
|
+
- spec/support/launchy_mock.rb
|
117
117
|
homepage: http://github.com/ummm/letter_opener-iso-2022-jp
|
118
118
|
licenses:
|
119
119
|
- MIT
|
@@ -141,3 +141,4 @@ summary: letter_opener with iso-2022-jp encoding.
|
|
141
141
|
test_files:
|
142
142
|
- spec/mail_spec.rb
|
143
143
|
- spec/spec_helper.rb
|
144
|
+
- spec/support/launchy_mock.rb
|