Skip to content

Commit

Permalink
Don't fail if there is no html part
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Jun 27, 2024
1 parent eafdb45 commit 884d690
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions app/models/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ def html_part

def html_part_images_inlined
# TODO: Find a better home for this bit of code
t = TransformHtml.new(html_part)
doc = t.nokogiri
doc.search("img").each do |img|
if img["src"][0..3] == "cid:"
a = mail.attachments.find { |a| a.url == img["src"] }
# Construct the data url
img["src"] = "data:#{a.mime_type};base64,#{Base64.encode64(a.body.decoded)}" if a
if html_part
t = TransformHtml.new(html_part)
doc = t.nokogiri
doc.search("img").each do |img|
if img["src"][0..3] == "cid:"
a = mail.attachments.find { |a| a.url == img["src"] }
# Construct the data url
img["src"] = "data:#{a.mime_type};base64,#{Base64.encode64(a.body.decoded)}" if a
end
end
doc.to_s
end
doc.to_s
end

# First part with a particular mime type
Expand Down

0 comments on commit 884d690

Please sign in to comment.