Skip to content
Browse files

Fix that Outlook and Windows Phone treat all our MIME parts as inline…

… attachments since they include unused, unreferenced Content-IDs.

Closes #389
  • Loading branch information...
1 parent 66ba02e commit aa394d0e1e389b401f6404344cd8f070248c0f68 @jeremy jeremy committed Jan 27, 2013
Showing with 44 additions and 14 deletions.
  1. +2 −0 CHANGELOG.rdoc
  2. +10 −6 lib/mail/message.rb
  3. +6 −2 lib/mail/part.rb
  4. +1 −1 spec/mail/attachments_list_spec.rb
  5. +2 −0 spec/mail/mime_messages_spec.rb
  6. +23 −5 spec/mail/part_spec.rb
View
2 CHANGELOG.rdoc
@@ -10,6 +10,7 @@ Features:
* Setting the html_ or text_part to nil removes it (jeremy)
* Addresses without a parsable email or display name still format as their raw text (jeremy)
* Close pull request 399 - Accept :ca_path and :ca_file options for SMTP delivery (ndbroadbent)
+* Close pull request 389 - Don't add superfluous message headers to MIME parts (djmaze, jeremy)
Performance:
* Close pull request 488 - Speed up field construction & comparison (bpot)
@@ -36,6 +37,7 @@ Bugs:
Coping with third-party bugs:
* Parse multipart boundary from Content-Type headers containing extra semicolons (jeremy)
+* Close pull request 389 - Only add Content-ID to inline attachments to appease Outlook (djmaze, jeremy)
Housekeeping:
* Add development gem dependency on rdoc (jeremy)
View
16 lib/mail/message.rb
@@ -1587,7 +1587,7 @@ def html_part=(msg)
# If nil, delete the html part and back out of multipart/alternative.
elsif @html_part
- parts.delete @html_part
+ parts.delete_if { |p| p.object_id == @html_part.object_id }
@html_part = nil
if text_part
self.content_type = nil
@@ -1609,7 +1609,7 @@ def text_part=(msg)
# If nil, delete the text part and back out of multipart/alternative.
elsif @text_part
- parts.delete @text_part
+ parts.delete_if { |p| p.object_id == @text_part.object_id }
@text_part = nil
if html_part
self.content_type = nil
@@ -1952,15 +1952,19 @@ def identify_and_set_transfer_encoding
end
def add_required_fields
- add_multipart_mixed_header unless !body.multipart?
- add_message_id unless (has_message_id? || self.class == Mail::Part)
- add_date unless has_date?
- add_mime_version unless has_mime_version?
+ add_required_message_fields
+ add_multipart_mixed_header if body.multipart?
add_content_type unless has_content_type?
add_charset unless has_charset?
add_content_transfer_encoding unless has_content_transfer_encoding?
end
+ def add_required_message_fields
+ add_date unless has_date?
+ add_mime_version unless has_mime_version?
+ add_message_id unless has_message_id?
+ end
+
def add_multipart_alternate_header
header['content-type'] = ContentTypeField.with_boundary('multipart/alternative').value
header['content_type'].parameters[:charset] = @charset
View
8 lib/mail/part.rb
@@ -38,8 +38,12 @@ def inline?
end
def add_required_fields
- add_content_id unless has_content_id?
super
+ add_content_id if !has_content_id? && inline?
+ end
+
+ def add_required_message_fields
+ # Override so we don't add Date, MIME-Version, or Message-ID.
end
def delivery_status_report_part?
@@ -113,4 +117,4 @@ def parse_delivery_status_report
end
-end
+end
View
2 spec/mail/attachments_list_spec.rb
@@ -158,7 +158,7 @@ def check_decoded(actual, expected)
end
end
- describe "getting the content ID from an inline attachment" do
+ describe "getting the content ID from an attachment" do
before(:each) do
@mail = Mail.new
@mail.attachments['test.gif'] = File.open(fixture('attachments', 'test.gif'), 'rb', &:read)
View
2 spec/mail/mime_messages_spec.rb
@@ -205,6 +205,7 @@
mail = Mail.new
mail.text_part = Mail::Part.new
mail.html_part = Mail::Part.new
+ mail.parts.length.should eq 2
mail.html_part = nil
mail.parts.length.should eq 1
@@ -216,6 +217,7 @@
mail = Mail.new
mail.text_part = Mail::Part.new
mail.html_part = Mail::Part.new
+ mail.parts.length.should eq 2
mail.text_part = nil
mail.parts.length.should eq 1
View
28 spec/mail/part_spec.rb
@@ -2,14 +2,32 @@
describe Mail::Part do
- it "should put content-ids into parts" do
- part = Mail::Part.new do
- body "This is Text"
- end
+ it "should not add a default Content-ID" do
+ part = Mail::Part.new
+ part.to_s
+ part.content_id.should be_nil
+ end
+
+ it "should not add a default Content-ID to non-inline attachments" do
+ part = Mail::Part.new(:content_disposition => 'attachment')
+ part.to_s
+ part.content_id.should be_nil
+ end
+
+ it "should add a default Content-ID to inline attachments" do
+ part = Mail::Part.new(:content_disposition => 'inline')
part.to_s
part.content_id.should_not be_nil
end
-
+
+ it "should not add a Date, MIME-Version, or Message-ID" do
+ part = Mail::Part.new
+ part.to_s
+ part.date.should be_nil
+ part.mime_version.should be_nil
+ part.message_id.should be_nil
+ end
+
it "should preserve any content id that you put into it" do
part = Mail::Part.new do
content_id "<thisis@acontentid>"

0 comments on commit aa394d0

Please sign in to comment.
Something went wrong with that request. Please try again.