bodyparts 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
data/bodyparts.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bodyparts}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Max Ogden"]
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "bodyparts.gemspec",
27
27
  "lib/bodyparts.rb",
28
28
  "spec/bodyparts_spec.rb",
29
+ "spec/email_with_attachment.eml",
29
30
  "spec/emails.yml",
30
31
  "spec/spec_helper.rb"
31
32
  ]
data/lib/bodyparts.rb CHANGED
@@ -23,11 +23,10 @@ class BodyParts
23
23
  def self.extract_mail_attributes(mail_object)
24
24
  message_id = mail_object['message_id']
25
25
  x_mailer = mail_object['x-mailer']
26
-
27
- if mail_object.multipart?
28
- body = mail_object.parts.first.body.raw_source
26
+ if mail_object.find_first_mime_type('text/html')
27
+ body = mail_object.html_part.body.raw_source
29
28
  else
30
- body = mail_object.body.raw_source
29
+ body = mail_object.text_part.body.raw_source
31
30
  end
32
31
  {:message_id => message_id, :x_mailer => x_mailer, :body => body}
33
32
  end
@@ -40,6 +39,7 @@ class BodyParts
40
39
  else raise "You must pass in either a TMail or Mail object or raw email source text"
41
40
  end
42
41
  body = mail_attributes[:body]
42
+
43
43
  matches = rules.map {|rule| body.match(rule[:reply_delimiter])}.compact!
44
44
  unless matches.empty?
45
45
  match = matches.sort_by {|m| m.begin(0)}.first
@@ -35,4 +35,10 @@ describe "BodyParts" do
35
35
  message = FakeMessage.new_mail(Mail, no_reply[:headers])
36
36
  BodyParts.find_reply_in(message.to_s)[:new_message].should == no_reply[:reply_text]
37
37
  end
38
+
39
+ it "should correctly parse the body from messages that contain attachments" do
40
+ with_attachment = FakeMessage.fake_emails[:with_attachment]
41
+ message = FakeMessage.load_mail(with_attachment[:filename])
42
+ BodyParts.find_reply_in(message)[:new_message].should == with_attachment[:reply_text]
43
+ end
38
44
  end
@@ -0,0 +1,34 @@
1
+ MIME-Version: 1.0
2
+ Received: by 10.100.134.4 with HTTP; Fri, 11 Jun 2010 13:57:35 -0700 (PDT)
3
+ Date: Fri, 11 Jun 2010 13:57:35 -0700
4
+ Delivered-To: support_development@revelationglobal.com
5
+ Message-ID: <AANLkTinQeQ6gTJa4myYGttnWMHiZUuMVGReSDFgieKFd@mail.gmail.com>
6
+ Subject: test
7
+ From: Support Development <support_development@revelationglobal.com>
8
+ To: Support Development <support_development@revelationglobal.com>
9
+ Content-Type: multipart/mixed; boundary=0016e640d06a7d23c60488c7635f
10
+
11
+ --0016e640d06a7d23c60488c7635f
12
+ Content-Type: multipart/alternative; boundary=0016e640d06a7d23c00488c7635d
13
+
14
+ --0016e640d06a7d23c00488c7635d
15
+ Content-Type: text/plain; charset=ISO-8859-1
16
+
17
+ HELLO
18
+
19
+ --0016e640d06a7d23c00488c7635d
20
+ Content-Type: text/html; charset=ISO-8859-1
21
+
22
+ HELLO
23
+
24
+ --0016e640d06a7d23c00488c7635d--
25
+ --0016e640d06a7d23c60488c7635f
26
+ Content-Type: image/png; name="Screen shot 2010-05-13 at 11.49.10 AM.png"
27
+ Content-Disposition: attachment;
28
+ filename="Screen shot 2010-05-13 at 11.49.10 AM.png"
29
+ Content-Transfer-Encoding: base64
30
+ X-Attachment-Id: f_gabi0qqa0
31
+
32
+ iVBORw0KGgoAAAANSUhEUgAAAwQAAAE9CAIAAAA6czL5AAAWZGlDQ1BJQ0MgUHJvZmlsZQAAeAHV
33
+ aMqRrNYEzQAAAABJRU5ErkJggg==
34
+ --0016e640d06a7d23c60488c7635f--
data/spec/emails.yml CHANGED
@@ -134,4 +134,9 @@
134
134
  hay guys
135
135
  :headers:
136
136
  body:
137
- hay guys
137
+ hay guys
138
+ :with_attachment:
139
+ :filename:
140
+ "email_with_attachment"
141
+ :reply_text:
142
+ HELLO
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,10 @@ class FakeMessage
15
15
  "date" => "Wed, 23 Sep 2009 09:11:23 -0700"
16
16
  }
17
17
  end
18
+
19
+ def self.load_mail(name)
20
+ Mail::Message.new(File.read(File.expand_path(File.dirname(__FILE__) + "/#{name}.eml")))
21
+ end
18
22
 
19
23
  def self.new_mail(mail_class, custom_headers={})
20
24
  headers = default_mail_headers.merge(custom_headers)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Max Ogden
@@ -74,6 +74,7 @@ files:
74
74
  - bodyparts.gemspec
75
75
  - lib/bodyparts.rb
76
76
  - spec/bodyparts_spec.rb
77
+ - spec/email_with_attachment.eml
77
78
  - spec/emails.yml
78
79
  - spec/spec_helper.rb
79
80
  has_rdoc: true