Skip to content
Closed
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
13 changes: 13 additions & 0 deletions lib/bamboo/plug/sent_email_viewer/email_preview_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@

get "/:id/html" do
if email = SentEmail.get(id) do
email = rewrite_html_body_cids(email)

conn
|> Plug.Conn.put_resp_content_type("text/html")
|> send_resp(:ok, email.html_body || "")

Check warning on line 70 in lib/bamboo/plug/sent_email_viewer/email_preview_plug.ex

View workflow job for this annotation

GitHub Actions / Dialyzer

guard_fail

The guard clause can never succeed.
else
render_not_found(conn)
end
Expand Down Expand Up @@ -126,4 +128,15 @@
defp base_path(%{script_name: script_name}) do
"/" <> Enum.join(script_name, "/")
end

defp rewrite_html_body_cids(email) do
%{ email | html_body: email.html_body
|> String.replace(~r/cid:[^'"]+/, fn "cid:" <> id = cid ->
case Enum.find_index(email.attachments, &(&1.content_id == id)) do
nil -> cid
i -> "/sent_emails/#{email.private.local_adapter_id}/attachments/#{i}"
end
end)
}
end
end
Loading