Skip to content

Commit

Permalink
set ics calendar attachments as content on the email
Browse files Browse the repository at this point in the history
  • Loading branch information
tarzan committed Sep 12, 2024
1 parent 4101cad commit 36af25d
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions lib/bamboo/adapters/send_grid_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -368,21 +368,35 @@ defmodule Bamboo.SendGridAdapter do

defp put_click_tracking(body, _), do: body

defp put_attachments(%{attachments: current_attachments} = body, %Email{attachments: []}),
do: %{body | attachments: Enum.reverse(current_attachments)}

defp put_attachments(body, %Email{attachments: []}), do: body

defp put_attachments(body, %Email{attachments: attachments}) do
transformed =
attachments
|> Enum.reverse()
|> Enum.map(fn attachment ->
%{
filename: attachment.filename,
type: attachment.content_type,
content: Base.encode64(attachment.data)
}
end)

Map.put(body, :attachments, transformed)
defp put_attachments(body, %Email{
attachments: [%{type: "text/calendar;" <> _} = ical_attachment]
}) do
content = Map.get(body, :content, [])

[%{type: ical_attachment.type, content: ical_attachment.data} | content]
|> Enum.reverse()
|> then(&Map.put(body, :content, &1))

Check failure on line 383 in lib/bamboo/adapters/send_grid_adapter.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.10.x | OTP 21)

** (CompileError) lib/bamboo/adapters/send_grid_adapter.ex:383: undefined function then/2

Check failure on line 383 in lib/bamboo/adapters/send_grid_adapter.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.11.x | OTP 22)

** (CompileError) lib/bamboo/adapters/send_grid_adapter.ex:383: undefined function then/2

Check failure on line 383 in lib/bamboo/adapters/send_grid_adapter.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.11.x | OTP 23)

** (CompileError) lib/bamboo/adapters/send_grid_adapter.ex:383: undefined function then/2
end

defp put_attachments(body, %Email{
attachments: [attachment | rest]
}) do
current_attachments = Map.get(body, :attachments, [])

transformed = %{
filename: attachment.filename,
type: attachment.content_type,
content: Base.encode64(attachment.data)
}

body
|> Map.put(:attachments, [transformed | current_attachments])
|> put_attachments(%Email{attachments: rest})
end

defp put_addresses(body, _, []), do: body
Expand Down

0 comments on commit 36af25d

Please sign in to comment.