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

Allow overwriting Mail::Message sort order… for real #853

Closed
wants to merge 1 commit into from

Conversation

rafbm
Copy link
Contributor

@rafbm rafbm commented Feb 6, 2015

So I tried to build the following email:

mail = Mail.new do
  # FIXME: This does not work.
  body.set_sort_order []

  part do |p|
    p.text_part { body 'Hello world!' }
    p.html_part { body 'Hello <b>world</b>!' }
  end

  attachments['README.txt'] = 'some text'
end

An alternative part (plain + HTML) followed by a .txt attachment.

The resulting email was structured this way:

multipart/mixed
  text/plain (attachment)
  multipart/alternative
    text/plain
    text/html

Starting with the attachment looked like a bug to me, so I dug a bit. I found about Mail::Body#sort_parts! and the default @part_sort_order, so I tried disabling the sorting altogether by passing Mail::Body#set_sort_order an empty array (see FIXME comment above).

It did not work, because Mail::Message#ready_to_send! does a hard-coded parts.sort! with the default order, effectively making Mail::Body#set_sort_order useless.

This patch contains the fix. The example above now produces the following structure:

multipart/mixed
  multipart/alternative
    text/plain
    text/html
  text/plain (attachment)

@mpapis
Copy link

mpapis commented Apr 28, 2015

most likely related to: #706 #675 #655

@jeremy
Copy link
Collaborator

jeremy commented May 10, 2016

Squashed 7812a77

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.

3 participants