Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Inline attachments #1

Merged
merged 2 commits into from

2 participants

tylercollier David Cornu
tylercollier

@davidcornu, thanks for your efforts with attachments.

I have a small addition to work with inline attachments (such as images).

Tyler Collier added some commits
Tyler Collier Regexp replacement of inline attachment urls with relative path, so t…
…hat e.g. images will shown in html body
25d9463
Tyler Collier Added a test 3f78683
David Cornu
Owner

Thanks! I don't have something to test this with so I'll take your word.

David Cornu davidcornu merged commit ead65b4 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 21, 2012
  1. Regexp replacement of inline attachment urls with relative path, so t…

    Tyler Collier authored
    …hat e.g. images will shown in html body
  2. Added a test

    Tyler Collier authored
This page is out of date. Refresh to see the latest.
9 lib/letter_opener/message.rb
View
@@ -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
20 spec/letter_opener/delivery_method_spec.rb
View
@@ -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
Something went wrong with that request. Please try again.