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 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
- Typedown is presently using the mail and uuidtools ruby gems.
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.5
1
+ 0.0.6
@@ -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
- m = File.read(filename)
38
- begin
39
- m.force_encoding("UTF-8")
40
- rescue
41
- # force_encoding not supported in ruby 1.8
42
- end
43
- @mail = Mail.new(m)
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