Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from tylercollier/master

Inline attachments
  • Loading branch information...
commit ead65b456e064ba7516bf693c190a68c08302374 2 parents 3973b99 + 3f78683
David Cornu authored
View
9 lib/letter_opener/message.rb
@@ -42,7 +42,14 @@ def content_type
end
def body
- @body ||= (@part && @part.body || @mail.body).to_s
+ if !@body_string
+ @body_string = (@part && @part.body || @mail.body).to_s
+ mail.attachments.each do |attachment|
+ @body_string.gsub!(attachment.url, "attachments/#{attachment.filename}")
+ end
+ @body = @body_string
+ end
+ @body
end
def from
View
20 spec/letter_opener/delivery_method_spec.rb
@@ -62,5 +62,25 @@
text = File.read(Dir["#{@location}/*/plain.html"].first)
text.should include(File.basename(__FILE__))
end
+
+ it "replaces inline attachment urls" do
+ mail = Mail.deliver do
+ from 'foo@example.com'
+ to 'bar@example.com'
+ subject 'With attachments'
+ attachments[File.basename(__FILE__)] = File.read(__FILE__)
+ url = attachments[0].url
+ html_part do
+ content_type 'text/html; charset=UTF-8'
+ body "Here's an image: <img src='#{url}' />"
+ end
+ end
+ attachment_path = Dir["#{@location}/*/attachments/#{File.basename(__FILE__)}"].first
+ File.exists?(attachment_path).should == true
+ text = File.read(Dir["#{@location}/*/rich.html"].first)
+ mail.parts[0].body.should include(mail.attachments[0].url)
+ text.should_not include(mail.attachments[0].url)
+ text.should include("attachments/#{File.basename(__FILE__)}")
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.