decoration_mail 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +14 -6
- data/VERSION +1 -1
- data/decoration_mail.gemspec +1 -1
- data/lib/decoration_mail/base.rb +3 -2
- data/lib/decoration_mail/image.rb +1 -1
- data/spec/unit/base_spec.rb +4 -8
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,14 +1,22 @@
|
|
1
|
-
= DecorationMail
|
2
|
-
|
3
1
|
== DecorationMailとは
|
4
2
|
携帯電話で作成されたデコレーションメール(デコメール)をRubyで扱いやすくするためのライブラリです。
|
5
|
-
|
6
3
|
今のところ受信したメールをパースするのみでデコメールの新規作成は出来ません。そのうち実装するかもしれません。。。
|
7
4
|
|
5
|
+
=== 特徴
|
6
|
+
* Rails3から採用されたActionMailerのバックエンド、Mailライブラリを少し拡張して利用します。
|
7
|
+
* デコメールのHTMLをXHTMLとインラインCSSに変換します。
|
8
|
+
* デコメールのHTMLからHTMLタグ、HEADタグ、BODYタグが削除されて本文のみ取得出来ます。
|
9
|
+
* デコメール画像のURLをContent-IDから自動でファイル名に置き換えます(変更可能)。
|
10
|
+
|
8
11
|
== インストール
|
12
|
+
通常
|
9
13
|
|
10
14
|
gem install decoration_mail
|
11
15
|
|
16
|
+
Rails3 ( bundler )
|
17
|
+
|
18
|
+
gem 'decoration_mail'
|
19
|
+
|
12
20
|
|
13
21
|
== 使用例
|
14
22
|
Rails3でも採用されているMailライブラリのMail::Messageを拡張しています。
|
@@ -20,11 +28,11 @@ decorationメソッドで本ライブラリの機能を呼び出す事が出来
|
|
20
28
|
require 'mail
|
21
29
|
require 'decoration_mail'
|
22
30
|
|
23
|
-
@mail = Mail.read('/path/to')
|
31
|
+
@mail = Mail.read('/path/to/foobar.eml')
|
24
32
|
@deco = @mail.decoration
|
25
33
|
|
26
34
|
@html = @deco.save do |image|
|
27
|
-
File.open("/path/to/#{image.filename}", "wb") {|f| f.write(image.
|
35
|
+
File.open("/path/to/#{image.filename}", "wb") {|f| f.write(image.read)}
|
28
36
|
end
|
29
37
|
|
30
38
|
puts @html # => "<div ...."
|
@@ -35,7 +43,7 @@ image.pathにURIを代入することで、出力されるHTMLの<img src="">を
|
|
35
43
|
MogileFSなどのストレージを利用する場合に使用すると便利でしょう。
|
36
44
|
|
37
45
|
@html = @deco.save do |image|
|
38
|
-
File.open("/path/to/#{image.filename}", "wb") {|f| f.write(image.
|
46
|
+
File.open("/path/to/#{image.filename}", "wb") {|f| f.write(image.read)}
|
39
47
|
image.path = "http://xxxxxx/#{image.filename}"
|
40
48
|
end
|
41
49
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/decoration_mail.gemspec
CHANGED
data/lib/decoration_mail/base.rb
CHANGED
@@ -18,7 +18,8 @@ module DecorationMail
|
|
18
18
|
|
19
19
|
@attachments.each do |attachment|
|
20
20
|
content_type = attachment.header['content-type'].to_s
|
21
|
-
content_id =
|
21
|
+
content_id = attachment.header['content-id'].to_s.sub(/^</, '').sub(/>$/, '')
|
22
|
+
content_id = attachment.filename unless content_id
|
22
23
|
file_name = attachment.filename
|
23
24
|
|
24
25
|
next unless check_content_type(content_type)
|
@@ -32,7 +33,7 @@ module DecorationMail
|
|
32
33
|
images.each do |image|
|
33
34
|
image.instance_eval(&block)
|
34
35
|
|
35
|
-
if image.content_id
|
36
|
+
if @body_html.inner_html =~ /#{image.content_id}/
|
36
37
|
@body_html.search("img").each do |element|
|
37
38
|
if element[:src] == image.content_id
|
38
39
|
element[:src] = (image.path ? image.path : image.filename)
|
@@ -6,7 +6,7 @@ module DecorationMail
|
|
6
6
|
attr_reader :content_id, :filename
|
7
7
|
|
8
8
|
def initialize(content_id, content_type, filename, attachment)
|
9
|
-
@content_id =
|
9
|
+
@content_id = "cid:#{content_id}"
|
10
10
|
@content_type = content_type
|
11
11
|
@filename = filename
|
12
12
|
@attachment = attachment
|
data/spec/unit/base_spec.rb
CHANGED
@@ -57,17 +57,13 @@ describe DecorationMail::Base do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "other_imagesオプションで:topを指定すると添付画像をデコメ上部に貼り付ける" do
|
60
|
-
html = subject.save(:other_images => :top)
|
61
|
-
|
62
|
-
end
|
63
|
-
html.should match /other_image\.jpg/
|
60
|
+
html = subject.save(:other_images => :top) {}
|
61
|
+
html.should match /20110205153513\.jpg/
|
64
62
|
end
|
65
63
|
|
66
64
|
it "other_imagesオプションで:bottomを指定すると添付画像をデコメ上部に貼り付ける" do
|
67
|
-
html = subject.save(:other_images => :bottom)
|
68
|
-
|
69
|
-
end
|
70
|
-
html.should match /other_image\.jpg/
|
65
|
+
html = subject.save(:other_images => :bottom) {}
|
66
|
+
html.should match /20110205153513\.jpg/
|
71
67
|
end
|
72
68
|
end
|
73
69
|
end
|