Skip to content

Commit

Permalink
Support multipart mail.
Browse files Browse the repository at this point in the history
Prefer HTML part, then text part. If both cannot be found, use the raw
content.
  • Loading branch information
doitian committed Jan 5, 2013
1 parent fcae38b commit 92d3af9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/capybara/email/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ def source
#
# @return String
def raw
email.body.encoded
if email.mime_type == 'multipart/alternative'
if email.html_part
return email.html_part.body.encoded
elsif email.text_part
return email.text_part.body.encoded
end
end

return email.body.encoded
end

private
Expand Down
28 changes: 28 additions & 0 deletions spec/email/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ def self.call(env)
all_emails.should be_empty
end

# should read html_part
scenario 'multipart email' do
email = deliver(multipart_email)

open_email('test@example.com')
current_email.click_link 'example'
page.should have_content 'Hello world!'
current_email.should have_content 'This is only a html test'

all_emails.first.should eq email

clear_emails
all_emails.should be_empty
end

scenario 'via ActionMailer' do
email = deliver(plain_email)

Expand Down Expand Up @@ -102,3 +117,16 @@ def plain_email
http://example.com
PLAIN
end

def multipart_email
Mail::Message.new do
to 'test@example.com'
text_part do
body plain_email.body.encoded
end
html_part do
content_type 'text/html; charset=UTF-8'
body html_email.body.encoded
end
end
end

0 comments on commit 92d3af9

Please sign in to comment.