Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix content-type checker #285

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/premailer/rails/hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def message_contains_html?
# Returns true if the message itself has a content type of text/html, thus
# it does not contain other parts such as alternatives and attachments.
def pure_html_message?
message.content_type && message.content_type.include?('text/html')
message.content_type && message.content_type.start_with?('text/html')
end

def generate_html_part_replacement
Expand Down Expand Up @@ -112,7 +112,7 @@ def replace_html_part(new_part)
# If the new part is a pure text/html part, the body and its content type
# are used for the message. If the new part is
def replace_in_pure_html_message(new_part)
if new_part.content_type.include?('text/html')
if new_part.content_type.start_with?('text/html')
message.body = new_part.decoded
message.content_type = new_part.content_type
else
Expand Down
8 changes: 8 additions & 0 deletions spec/integration/hook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ def html_string
include 'multipart/alternative'
expect(processed_message.parts.last.content_type).to include 'image/png'
end

context 'with content-type "type" set' do
before { message.content_type += '; type="text/html"' }

it 'does not change content-type' do
expect(processed_message.content_type).to include 'multipart/mixed'
end
end
end

context 'when message has a skip premailer header' do
Expand Down