mail: Message#from_yaml results in invalid parts when body is not present

Found this behaviour while testing serialization and deserialization of messages via YAML.

The following spec fails (at least on master and 2.6.4)

context 'when body is not present' do
  it 'should encode after deserializing' do
    message = Mail::Message.new(
      to: 'someone@somewhere.com',
      cc: 'someoneelse@somewhere.com',
      bcc: 'someonesecret@somewhere.com',
      subject: 'subject'
    )
    serialized = message.to_yaml
    deserialized = Mail::Message.from_yaml(serialized)
    expect{ deserialized.encoded }.not_to raise_error
  end
end

The #from_yaml method sets @body directly, which after YAML serialization will contain an Array on parts instead of a PartList instance.

Is this a bug, or it’s the expected behaviour (making the body mandatory) ?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 15

Most upvoted comments

>> Mail::Message.from_yaml(Mail.new.to_yaml).encoded
ArgumentError: wrong number of arguments (given 1, expected 0)
    from /Users/jeremy/source/mail/lib/mail/message.rb:1801:in `sort!'

ಠ_ಠ