attachments 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -1
- data/VERSION +1 -1
- data/lib/attachments/extract.rb +26 -8
- data/test/data/mail_0002.eml +1255 -0
- data/test/data/mail_0002.jpg +0 -0
- data/test/helper.rb +2 -0
- data/test/test_attachments.rb +74 -27
- metadata +6 -4
Binary file
|
data/test/helper.rb
CHANGED
data/test/test_attachments.rb
CHANGED
@@ -1,44 +1,91 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'helper'
|
2
4
|
require 'iconv'
|
3
5
|
|
4
6
|
class TestAttachments < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
context "Parse test cases without crashes" do
|
8
|
+
setup do
|
9
|
+
@extract = Attachments::Extract.new [ "text/plain", "image/jpeg" ]
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
teardown do
|
13
|
+
@extract.close
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
should "parse text/plain + text/html" do
|
17
|
+
assert_nothing_raised do
|
18
|
+
@extract.parse "./test/data/mail_0001.eml"
|
19
|
+
end
|
20
|
+
end
|
17
21
|
|
18
|
-
|
19
|
-
|
22
|
+
should "parse text/plain with UTF-8 and image/jpeg" do
|
23
|
+
assert_nothing_raised do
|
24
|
+
@extract.parse "./test/data/mail_0002.eml"
|
25
|
+
end
|
26
|
+
end
|
20
27
|
end
|
21
28
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
|
30
|
+
context "Just text text/plain and text/html" do
|
31
|
+
setup do
|
32
|
+
@extract = Attachments::Extract.new [ "text/plain" ]
|
33
|
+
@extract.parse "./test/data/mail_0001.eml"
|
34
|
+
end
|
35
|
+
|
36
|
+
teardown do
|
37
|
+
@extract.close
|
38
|
+
end
|
39
|
+
|
40
|
+
should "extract a part mail_001" do
|
41
|
+
assert_equal(@extract.files.length, 1)
|
26
42
|
end
|
27
|
-
end
|
28
43
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
44
|
+
should "extract part of type text/plain" do
|
45
|
+
assert_equal(@extract.files[0][:mime_type], "text/plain")
|
46
|
+
end
|
47
|
+
|
48
|
+
should "create files from the attachments" do
|
49
|
+
@extract.files.each do |f|
|
50
|
+
assert File::exists?(f[:tmpfile])
|
51
|
+
puts f.inspect
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
should "remove tmp files on close" do
|
56
|
+
tmpfile = @extract.files[0][:tmpfile]
|
57
|
+
@extract.close
|
58
|
+
assert !File::exists?(tmpfile)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
should "save as text/plain as utf-8" do
|
63
|
+
tmpfile = @extract.files[0][:tmpfile]
|
64
|
+
m = File.read(tmpfile)
|
65
|
+
assert_nothing_raised do
|
66
|
+
# Provoke an exception if not valid utf-8
|
67
|
+
Iconv.conv("ISO-8859-1", "utf-8", m)
|
68
|
+
end
|
69
|
+
end
|
33
70
|
end
|
34
71
|
|
72
|
+
context "UTF-8 and text/plain and image attachment" do
|
73
|
+
setup do
|
74
|
+
@extract = Attachments::Extract.new [ "text/plain", "image/jpeg" ]
|
75
|
+
@extract.parse "./test/data/mail_0002.eml"
|
76
|
+
end
|
35
77
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
78
|
+
teardown do
|
79
|
+
@extract.close
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
should "not modify image" do
|
84
|
+
tmpfile = @extract.files[1][:tmpfile]
|
85
|
+
|
86
|
+
isIdentical = FileUtils::compare_file(tmpfile, "test/data/mail_0002.jpg")
|
87
|
+
assert(isIdentical)
|
42
88
|
end
|
43
89
|
end
|
44
90
|
end
|
91
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attachments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rune Myrland
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-16 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -70,6 +70,8 @@ files:
|
|
70
70
|
- lib/attachments/extract.rb
|
71
71
|
- lib/attachments/filemagic.rb
|
72
72
|
- test/data/mail_0001.eml
|
73
|
+
- test/data/mail_0002.eml
|
74
|
+
- test/data/mail_0002.jpg
|
73
75
|
- test/helper.rb
|
74
76
|
- test/test_attachments.rb
|
75
77
|
has_rdoc: true
|