Make sure that we don't duplicate Person instances with the *same-ish* email
Patchwork keeps attribution of patches by assigning them to a Person
model - something that is looked up / created basing on the email.
In find_author()
we look for a Person instance basing on their email:
person = Person.objects.get(email__iexact=email)
Sometimes we get:
Exception Type: MultipleObjectsReturned
Exception Value: get() returned more than one Person -- it returned 2!
Request data not supplied
This may happen if user sent us multiple messages with varying casing of their email-address in the "From" field. Common example would be: Name.Surname@example.com vs name.surname@example.com
Which leaves us with discarded emails...
RFC5321 and RFC2822 just vaguely states that the local-part is up to interpretation by the host and:
However, exploiting the case sensitivity of mailbox local-parts impedes interoperability and is discouraged.
Tough call time: since most email services seem to treat the local-part as case-insensitive we should de-duplicate on our side.
Sadly there seems to be no sane way of having case insensitive fields or adding case insensitive unique constraint via Django.
TODO:
-
figure out where were we save()
-ing Persons with different email capitalization without trying to look for them first -
converge on using lowercase everywhere, e.g. via Model.clean()
-
create a migration that deduplicates users -
write tests for the above