mail icon indicating copy to clipboard operation
mail copied to clipboard

Message#== - comparison strategy

Open sebbASF opened this issue 2 years ago • 3 comments

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 avatar Dec 09 '22 22:12 sebbASF

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 avatar Dec 10 '22 09:12 sebbASF

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 avatar Dec 10 '22 22:12 sebbASF

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.

sebbASF avatar Dec 14 '22 00:12 sebbASF