Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix attachment handling in ActionMailer::InlineCssHook.delivering_ema…
…il(message)
- Loading branch information
1 parent
037a534
commit 43ebf9f
Showing
2 changed files
with
37 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
# encoding: utf-8 | ||
# | ||
# Always inline CSS for HTML emails | ||
# | ||
module ActionMailer | ||
class InlineCssHook | ||
def self.delivering_email(message) | ||
|
||
if html_part = (message.html_part || (message.content_type =~ /text\/html/ && message)) | ||
|
||
# Generate an email with all CSS inlined (access CSS a FS path) | ||
premailer = ::Premailer.new(html_part.body.to_s, | ||
:with_html_string => true) | ||
premailer = ::Premailer.new(html_part.body.to_s, :with_html_string => true) | ||
|
||
# Prepend host to remaning URIs. | ||
# Two-phase conversion to avoid request deadlock from dev. server (Issue #4) | ||
premailer = ::Premailer.new(premailer.to_inline_css, | ||
:with_html_string => true, | ||
:base_url => message.header[:host].to_s) | ||
existing_text_part = message.text_part && message.text_part.body.to_s | ||
# Reset the body | ||
message.body = nil | ||
premailer = ::Premailer.new(premailer.to_inline_css, :with_html_string => true, | ||
:base_url => message.header[:host].to_s) | ||
|
||
# Add an HTML part with CSS inlined. | ||
message.html_part do | ||
content_type "text/html; charset=utf-8" | ||
body premailer.to_inline_css | ||
end | ||
# Add a text part with either the pre-existing text part, or one generated with premailer. | ||
message.text_part do | ||
content_type "text/plain; charset=utf-8" | ||
body existing_text_part || premailer.to_plain_text | ||
end | ||
|
||
end | ||
|
||
# Return the message, ActionMailer doesn't seem to care, but it's useful | ||
# for writing meaningful tests. | ||
message | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters