attachments 0.0.5 → 0.0.6
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 +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
data/README.rdoc
CHANGED
@@ -13,9 +13,12 @@ are saved in the /tmp directory.
|
|
13
13
|
Is the /tmp directory and the 'file' shell command on your OS? If not
|
14
14
|
some porting work is needed.
|
15
15
|
|
16
|
+
It is built on top of the mail gem, which in my experience is about 10
|
17
|
+
times faster at decoding large attachments if you us ruby 1.9 instead of 1.8.
|
18
|
+
|
16
19
|
== REQUIREMENTS:
|
17
20
|
|
18
|
-
|
21
|
+
Attachments is presently using the mail and uuidtools ruby gems.
|
19
22
|
It uses the 'file' shell command from filemagic to decide mime types
|
20
23
|
when they are uncertain.
|
21
24
|
|
@@ -38,6 +41,12 @@ when they are uncertain.
|
|
38
41
|
mailfiles.each do |m|
|
39
42
|
# Open mail stored in filename
|
40
43
|
extract.parse m
|
44
|
+
|
45
|
+
# Some info about the mail
|
46
|
+
puts extract.to
|
47
|
+
puts extract.from
|
48
|
+
puts extract.subject
|
49
|
+
|
41
50
|
# Traverse through the extracted attachments
|
42
51
|
extract.files.each do |f|
|
43
52
|
# Do something with the attachments
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/attachments/extract.rb
CHANGED
@@ -31,16 +31,22 @@ module Attachments
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def parse filename
|
34
|
+
parse_file filename
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_file filename
|
34
38
|
@last_parsed = filename
|
35
39
|
|
36
|
-
# Load the email
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
# Load the email as binary to avoid encoding exceptions
|
41
|
+
file = File.new(filename, "rb")
|
42
|
+
raw_mail_data = file.read()
|
43
|
+
file.close()
|
44
|
+
|
45
|
+
parse_data raw_mail_data
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_data raw_mail_data
|
49
|
+
@mail = Mail.new(raw_mail_data)
|
44
50
|
|
45
51
|
# Parse parts recursively until it is not multipart
|
46
52
|
# Ignore types that are not suited for forwarding
|
@@ -59,6 +65,18 @@ module Attachments
|
|
59
65
|
(@mail && @mail.subject) || nil
|
60
66
|
end
|
61
67
|
|
68
|
+
def text_body
|
69
|
+
(@mail && @mail.text_part.body.decoded) || nil
|
70
|
+
end
|
71
|
+
|
72
|
+
def html_body
|
73
|
+
(@mail && @mail.html_part.body.decoded) || nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def mail
|
77
|
+
@mail
|
78
|
+
end
|
79
|
+
|
62
80
|
def name
|
63
81
|
@name
|
64
82
|
end
|