stalwartlabs / mail-parser

Fast and robust e-mail parsing library for Rust
https://docs.rs/mail-parser/
Apache License 2.0
298 stars 40 forks source link

Comparing addresses #49

Closed soywod closed 1 year ago

soywod commented 1 year ago

The Addr struct derives Eq and PartialEq, which means that two addresses are equal if the name AND the email are equal. Would it make sense to compare addresses only on their email instead? Because technically, John Doe <john.doe@localhost> is the same as John D. <john.doe@localhost> or <john.doe@localhost> or john.doe@localhost.

For the context: my use case right now is to transform a message into a reply template, which implies to reorder addresses, and I need to avoid duplicates (for example, having Cc: john.doe@localhost, John Doe <john.doe@localhost>).

mdecimus commented 1 year ago

It makes sense to compare just the address but that would involve adding a breaking change as current library users expect Eq to compare both address and name. For your use case you could use a custom compare function or create your own Address struct.

soywod commented 1 year ago

It makes sense to compare just the address but that would involve adding a breaking change as current library users expect Eq to compare both address and name.

Then let's wait for your next breaking changes (in order to group them), it is not an important one.

For your use case you could use a custom compare function or create your own Address struct.

I used a custom compare function, but I need to destructure everything before applying it, which makes the code not so clear (instead of just using ==).