Fixed #165, missing style on html emails with blockquote in outlook.

This commit is contained in:
Martin Edenhofer 2016-02-11 00:09:27 +01:00
parent 8965826a3f
commit 4438cef46a
2 changed files with 99 additions and 47 deletions

View file

@ -7,10 +7,10 @@ module Channel::EmailBuild
=begin
mail = Channel::EmailBuild.build(
:from => 'sender@example.com',
:to => 'recipient@example.com',
:body => 'somebody with some text',
:content_type => 'text/plain',
from: 'sender@example.com',
to: 'recipient@example.com',
body: 'somebody with some text',
content_type: 'text/plain',
)
=end
@ -110,11 +110,17 @@ module Channel::EmailBuild
=begin
Check if string is a complete html document. If not, add head and css styles.
full_html_document_string = Channel::EmailBuild.html_complete_check(html_string)
=end
def self.html_complete_check(html)
# apply mail client fixes
html = Channel::EmailBuild.html_mail_client_fixes(html)
return html if html =~ /<html>/i
css = "font-family:'Helvetica Neue', Helvetica, Arial, Geneva, sans-serif; font-size: 12px;"
@ -166,4 +172,20 @@ HERE
html
end
=begin
Add/change markup to display html in any mail client nice.
html_string_with_fixes = Channel::EmailBuild.html_mail_client_fixes(html_string)
=end
def self.html_mail_client_fixes(html)
# https://github.com/martini/zammad/issues/165
html.gsub('<blockquote type="cite">', '<blockquote type="cite" style="border-left: 2px solid blue; margin: 0px; padding: 8px 12px 8px 12px;">')
end
end

View file

@ -162,4 +162,34 @@ class EmailBuildTest < ActiveSupport::TestCase
end
test 'email - html email client fixes' do
# https://github.com/martini/zammad/issues/165
html_raw = '<blockquote type="cite">some
text
</blockquote>
123
<blockquote type="cite">some
text
</blockquote>'
html_with_fixes = Channel::EmailBuild.html_mail_client_fixes(html_raw)
assert_not_equal(html_with_fixes, html_raw)
html_should = '<blockquote type="cite" style="border-left: 2px solid blue; margin: 0px; padding: 8px 12px 8px 12px;">some
text
</blockquote>
123
<blockquote type="cite" style="border-left: 2px solid blue; margin: 0px; padding: 8px 12px 8px 12px;">some
text
</blockquote>'
assert_equal(html_should, html_with_fixes)
end
end