Skip to content

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

Closed
rafbm wants to merge 1 commit into
mikel:masterfrom
missive:overwrite-message-sort-order
Closed

rafbm wants to merge 1 commit into
mikel:masterfrom
missive:overwrite-message-sort-order

Conversation

@rafbm

@rafbm rafbm commented Feb 6, 2015

Copy link
Copy Markdown
Contributor

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

mpapis commented Apr 28, 2015

Copy link
Copy Markdown

most likely related to: #706 #675 #655

@jeremy

jeremy commented May 10, 2016

Copy link
Copy Markdown
Collaborator

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