Skip to content

Commit 884d690

Browse files
committed
Don't fail if there is no html part
1 parent eafdb45 commit 884d690

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

app/models/email.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,18 @@ def html_part
7575

7676
def html_part_images_inlined
7777
# TODO: Find a better home for this bit of code
78-
t = TransformHtml.new(html_part)
79-
doc = t.nokogiri
80-
doc.search("img").each do |img|
81-
if img["src"][0..3] == "cid:"
82-
a = mail.attachments.find { |a| a.url == img["src"] }
83-
# Construct the data url
84-
img["src"] = "data:#{a.mime_type};base64,#{Base64.encode64(a.body.decoded)}" if a
78+
if html_part
79+
t = TransformHtml.new(html_part)
80+
doc = t.nokogiri
81+
doc.search("img").each do |img|
82+
if img["src"][0..3] == "cid:"
83+
a = mail.attachments.find { |a| a.url == img["src"] }
84+
# Construct the data url
85+
img["src"] = "data:#{a.mime_type};base64,#{Base64.encode64(a.body.decoded)}" if a
86+
end
8587
end
88+
doc.to_s
8689
end
87-
doc.to_s
8890
end
8991

9092
# First part with a particular mime type

0 commit comments

Comments
 (0)