bodyparts 0.1.8 → 0.1.9

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.8
1
+ 0.1.9
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.8"
8
+ s.version = "0.1.9"
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"]
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "spec/bodyparts_spec.rb",
29
29
  "spec/email_with_attachment.eml",
30
30
  "spec/emails.yml",
31
+ "spec/quoted_printable.eml",
31
32
  "spec/spec_helper.rb"
32
33
  ]
33
34
  s.homepage = %q{http://github.com/maxogden/bodyparts}
data/lib/bodyparts.rb CHANGED
@@ -26,19 +26,19 @@ class BodyParts
26
26
  end
27
27
 
28
28
  def self.extract_mail_attributes(mail_object)
29
- if mail_encoding = mail_object['content_transfer_encoding']
30
- content_encoding = mail_encoding.encoding
29
+ if mail_object.find_first_mime_type('text/plain')
30
+ part = mail_object.text_part
31
31
  else
32
- content_encoding = "not known"
32
+ part = mail_object
33
33
  end
34
34
 
35
- if mail_object.find_first_mime_type('text/plain')
36
- body = mail_object.text_part.body.raw_source
35
+ if mail_encoding = part['content_transfer_encoding'] || mail_encoding = mail_object['content_transfer_encoding']
36
+ content_encoding = mail_encoding.encoding
37
37
  else
38
- body = mail_object.body.raw_source
38
+ content_encoding = "not known"
39
39
  end
40
40
 
41
- {:content_encoding => content_encoding, :body => body}
41
+ {:content_encoding => content_encoding, :body => part.body.raw_source}
42
42
  end
43
43
 
44
44
  def self.find_reply_in(email)
@@ -1,6 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "BodyParts" do
4
+
4
5
  [TMail::Mail, Mail].each do |mail_object|
5
6
  it "should accept and parse #{mail_object} objects as input" do
6
7
  generic = FakeMessage.fake_emails[:generic]
@@ -35,7 +36,7 @@ describe "BodyParts" do
35
36
  BodyParts.find_reply_in(message.to_s)[:new_message].should == no_reply[:reply_text]
36
37
  end
37
38
 
38
- it "should correctly parse the body from messages that contain attachments" do
39
+ it "should parse quoted printable messages" do
39
40
  with_attachment = FakeMessage.fake_emails[:with_attachment]
40
41
  message = FakeMessage.load_mail(with_attachment[:filename])
41
42
  BodyParts.find_reply_in(message)[:new_message].should == with_attachment[:reply_text]
@@ -44,12 +45,18 @@ describe "BodyParts" do
44
45
  describe "encodings" do
45
46
  [TMail::Mail, Mail].each do |mail_type|
46
47
  ["base64", "Quoted-printable"].each do |encoding|
47
- it "should correctly parse #{encoding} encoded #{mail_type} messages" do
48
+ it "should correctly parse #{mail_type} objects where the entire message is encoded as #{encoding}" do
48
49
  encoded_message = FakeMessage.fake_emails[encoding.to_sym]
49
50
  message = FakeMessage.new_mail(mail_type, encoded_message[:headers])
50
51
  BodyParts.find_reply_in(message)[:new_message].strip.should == encoded_message[:reply_text]
51
52
  end
53
+
54
+ it "should correctly parse #{mail_type} objects where only the individual parts are encoded as #{encoding}"do
55
+ quoted_printable = FakeMessage.fake_emails[:individual_parts_quoted_printable]
56
+ message = FakeMessage.load_mail(quoted_printable[:filename])
57
+ BodyParts.find_reply_in(message)[:new_message].should == quoted_printable[:reply_text].gsub("\n", "\r\n").strip
58
+ end
52
59
  end
53
- end
60
+ end
54
61
  end
55
62
  end
data/spec/emails.yml CHANGED
@@ -156,4 +156,13 @@
156
156
  Quoted-printable
157
157
  body: |
158
158
  To make your upload take a significantly less amount of time, you can use W=
159
- indows Movie Maker to shrink your video before uploading it.=20
159
+ indows Movie Maker to shrink your video before uploading it.=20
160
+ :individual_parts_quoted_printable:
161
+ :filename:
162
+ "quoted_printable"
163
+ :reply_text: |
164
+ thou need to doeth passage to instain thy mother. thou need to doeth passage
165
+ to instain thy mother. thou need to doeth passage to instain thy
166
+ mother. thou need to doeth passage to instain thy mother. thou need to doeth
167
+ passage to instain thy mother. thou need to doeth passage to instain thy
168
+ mother.
@@ -0,0 +1,40 @@
1
+
2
+ MIME-Version: 1.0
3
+ Received: by 10.150.12.18 with HTTP; Mon, 21 Jun 2010 16:04:47 -0700 (PDT)
4
+ In-Reply-To: <AANLkTimRQQOmvw4Y_C2pH5Nc9j8YuBnR0hjhabex1PMD@mail.gmail.com>
5
+ References: <AANLkTimRQQOmvw4Y_C2pH5Nc9j8YuBnR0hjhabex1PMD@mail.gmail.com>
6
+ Date: Mon, 21 Jun 2010 16:04:47 -0700
7
+ Delivered-To: max@revelationglobal.com
8
+ Message-ID: <AANLkTikEayrsOYxKILM2gB9ToaemBlbtENxw9s8m_f7J@mail.gmail.com>
9
+ Subject: Re: testing
10
+ From: max <max@revelationglobal.com>
11
+ To: Max Ogden <max@revelationglobal.com>
12
+ Content-Type: multipart/alternative; boundary=000e0cd47c22cfc52104899254f5
13
+
14
+ --000e0cd47c22cfc52104899254f5
15
+ Content-Type: text/plain; charset=ISO-8859-1
16
+ Content-Transfer-Encoding: quoted-printable
17
+
18
+ thou need to doeth passage to instain thy mother. thou need to doeth pass=
19
+ age
20
+ to instain thy mother. thou need to doeth passage to instain thy
21
+ mother. thou need to doeth passage to instain thy mother. thou need to do=
22
+ eth
23
+ passage to instain thy mother. thou need to doeth passage to instain thy
24
+ mother.=
25
+
26
+
27
+ --000e0cd47c22cfc52104899254f5
28
+ Content-Type: text/html; charset=ISO-8859-1
29
+ Content-Transfer-Encoding: quoted-printable
30
+
31
+ thou need to doeth passage to instain thy mother. thou need to doeth pass=
32
+ age
33
+ to instain thy mother. thou need to doeth passage to instain thy
34
+ mother. thou need to doeth passage to instain thy mother. thou need to do=
35
+ eth
36
+ passage to instain thy mother. thou need to doeth passage to instain thy
37
+ mother.=
38
+
39
+
40
+ --000e0cd47c22cfc52104899254f5--
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 8
9
- version: 0.1.8
8
+ - 9
9
+ version: 0.1.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Max Ogden
@@ -76,6 +76,7 @@ files:
76
76
  - spec/bodyparts_spec.rb
77
77
  - spec/email_with_attachment.eml
78
78
  - spec/emails.yml
79
+ - spec/quoted_printable.eml
79
80
  - spec/spec_helper.rb
80
81
  has_rdoc: true
81
82
  homepage: http://github.com/maxogden/bodyparts