Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/inline attachments #137

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jarrodmoldrich
Copy link

@jarrodmoldrich jarrodmoldrich commented Oct 22, 2021

Changes proposed in this pull request

For parts with content-dispostion: inline its important to reorganize the multipart arrangement in the adapter. In particular it needs to be arrange liked this:

start multipart/mixed
  start multipart/related
    start multipart/alternative
      <text and html parts>
    end multipart/alternative
    <inline parts>
  end multipart/related
  <attachment parts>
end multipart/mixed

My changes reorganize the parts as shown above, while maintaining backwards compatibility. It also adds matching functions for querying for inline attachments as for regular attachments. This change was required for inline images and .ics files to work properly, particularly in Outlook webmail.

I've stopped short of adding tests to the test suite, and I'll wait for you to validate my approach first. I duplicated this code for kalys/bamboo_ses, where it currently functions well for my use cases: kalys/bamboo_ses#43

Note: This PR also deprecates #133 as the original order of text parts should be maintained

- provide functions for detecting inline attachments
- implement a fast concatenation of a list of parts to a message
- add helper method to separate parts into text/inline/attachment
- wrap body and inline attachments in `multipart/related`
@michelson
Copy link

Hi there,

First, thanks for this library. I'm trying this branch, and it works ok; I'm testing it with a set of .eml files, and it is parsed correctly.

the only thing that is missing in this PR is the get_attachments function to be able to get both inline and attachments:

it is a little change though:

  def get_attachments(%Mail.Message{} = message) do
    walk_parts([message], {:cont, []}, fn message, acc ->
      case Mail.Message.is_any_attachment?(message) do
        true ->
          ##### THIS
          case Mail.Message.get_header(message, :content_disposition) do
            ["inline", {"filename", filename}] ->
              {:cont, List.insert_at(acc, -1, {filename, message.body})}
            ["attachment", {"filename", filename}] ->
              {:cont, List.insert_at(acc, -1, {filename, message.body})}
          end
          ###### 
        false ->
          {:cont, acc}
      end
    end)
    |> elem(1)
  end

@bcardarella
Copy link
Member

@jarrodmoldrich thank you very much apoligies this went stale. I know it's a bit rediculous to ask after years but if you could just add regression tests for the additional behavior added I can merge this in.

@Hermanverschooten
Copy link

+1

@jarrodmoldrich
Copy link
Author

Sorry, I've been off the radar, but I'm back! I'll have a look at this in the coming weeks.

@gernotkogler
Copy link

+1

@jarrodmoldrich
Copy link
Author

@bcardarella Sorry for the delay. Added some tests. Let me know if you think this needs anything else.

@princemaple
Copy link
Contributor

Hi @bcardarella do you think this one can go in now?

@bcardarella
Copy link
Member

that'lll be @andrewtimberlake's call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants