From 5f274d58cc27947d50060b4c0dbd37071fd3f1d1 Mon Sep 17 00:00:00 2001 From: Sreenadh TC Date: Thu, 29 Jul 2021 23:14:43 +0530 Subject: [PATCH 1/2] add content-disposition opts --- lib/bamboo/attachment.ex | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/bamboo/attachment.ex b/lib/bamboo/attachment.ex index ab82f2cc..6d618379 100644 --- a/lib/bamboo/attachment.ex +++ b/lib/bamboo/attachment.ex @@ -2,14 +2,20 @@ defmodule Bamboo.Attachment do @moduledoc """ """ - defstruct filename: nil, content_type: nil, path: nil, data: nil, content_id: nil + defstruct filename: nil, + content_type: nil, + path: nil, + data: nil, + content_id: nil, + content_disposition: nil @type t :: %__MODULE__{ path: nil | String.t(), filename: nil | String.t(), content_type: nil | String.t(), data: nil | binary(), - content_id: nil | String.t() + content_id: nil | String.t(), + content_disposition: nil | String.t() } @doc ~S""" @@ -26,12 +32,12 @@ defmodule Bamboo.Attachment do Bamboo.Attachment.new("/path/to/attachment.png") Bamboo.Attachment.new("/path/to/attachment.png", filename: "image.png") - Bamboo.Attachment.new("/path/to/attachment.png", filename: "image.png", content_type: "image/png", content_id: "12387432") + Bamboo.Attachment.new("/path/to/attachment.png", filename: "image.png", content_type: "image/png", content_id: "12387432", content_disposition: "attachment") Bamboo.Attachment.new(params["file"]) # Where params["file"] is a %Plug.Upload email |> put_html_layout({LayoutView, "email.html"}) - |> put_attachment(%Bamboo.Attachment{content_type: "image/png", filename: "logo.png", data: "content", content_id: "2343333333"}) + |> put_attachment(%Bamboo.Attachment{content_type: "image/png", filename: "logo.png", data: "content", content_id: "2343333333", content_disposition: "attachment"}) """ def new(path, opts \\ []) @@ -44,6 +50,7 @@ defmodule Bamboo.Attachment do filename = opts[:filename] || Path.basename(path) content_type = opts[:content_type] || determine_content_type(path) content_id = opts[:content_id] + content_disposition = opts[:content_disposition] data = File.read!(path) %__MODULE__{ @@ -51,7 +58,8 @@ defmodule Bamboo.Attachment do data: data, filename: filename, content_type: content_type, - content_id: content_id + content_id: content_id, + content_disposition: content_disposition } end From 778bbc922195c234c77cd36ee14f6d9d0123bd22 Mon Sep 17 00:00:00 2001 From: Sreenadh TC Date: Thu, 29 Jul 2021 23:23:14 +0530 Subject: [PATCH 2/2] fix failing tests --- test/lib/bamboo/email_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/bamboo/email_test.exs b/test/lib/bamboo/email_test.exs index f60112b1..4b121389 100644 --- a/test/lib/bamboo/email_test.exs +++ b/test/lib/bamboo/email_test.exs @@ -92,7 +92,7 @@ defmodule Bamboo.EmailTest do attachment = %Bamboo.Attachment{filename: nil, data: "content"} msg = - "You must provide a filename for the attachment, instead got: %Bamboo.Attachment{content_id: nil, content_type: nil, data: \"content\", filename: nil, path: nil}" + "You must provide a filename for the attachment, instead got: %Bamboo.Attachment{content_disposition: nil, content_id: nil, content_type: nil, data: \"content\", filename: nil, path: nil}" assert_raise RuntimeError, msg, fn -> new_email() |> put_attachment(attachment) @@ -103,7 +103,7 @@ defmodule Bamboo.EmailTest do attachment = %Bamboo.Attachment{filename: "attachment.docx", data: nil} msg = - "The attachment must contain data, instead got: %Bamboo.Attachment{content_id: nil, content_type: nil, data: nil, filename: \"attachment.docx\", path: nil}" + "The attachment must contain data, instead got: %Bamboo.Attachment{content_disposition: nil, content_id: nil, content_type: nil, data: nil, filename: \"attachment.docx\", path: nil}" assert_raise RuntimeError, msg, fn -> new_email() |> put_attachment(attachment)