mikel / mail

A Really Ruby Mail Library
MIT License
3.62k stars 936 forks source link

Message#== - comparison strategy #1529

Open sebbASF opened 1 year ago

sebbASF commented 1 year ago

The == method has to generate dummy message-ids if none exist.

As it stands, if either message does not have an id, then both are set to the same fixed value.

This seems fine for the case where neither message has an id, but is it the best strategy when one already has an id and the other does not?

Similarly for Dates (see #1527)

sebbASF commented 1 year ago

If both messages have ids, the == method invokes encoded without first creating a copy.

This changes the original instance, which does not seem right.

It would be better to always create a duplicate. The duplicate could then have Date and Message-Id added if not present.

sebbASF commented 1 year ago

There are currently two tests which check that a provided message-id compares equal with nil. These would need to be changed: https://github.com/mikel/mail/blob/bf02b6772e4df20e165c008f595f4eadb8c595a7/spec/mail/message_spec.rb#L1719 and https://github.com/mikel/mail/blob/bf02b6772e4df20e165c008f595f4eadb8c595a7/spec/mail/message_spec.rb#L1730

sebbASF commented 1 year ago

Allowing Message-Id to match against nil causes unexpected behaviour for the == operator

See https://github.com/mikel/mail/pull/1540

At present, Message equality (==) is not transitive.