feat(email-service): Per-message contact name storage #438
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds per-message contact name storage to preserve the exact sender and recipient names as they appear in each email.
Changes:
from_namecolumn toemail_messagesto store the sender's name as it appears in the messagenamecolumn toemail_message_recipientsto store recipient names as they appear in the messageemail_contactsnames when unavailableBackground:
Previously, we avoided storing contact names for generic emails in

email_contactsdue to an edge case where personal names could be associated with shared addresses:This led to incorrect name display when multiple people used the same email address.
By storing names on a per-message basis, we now correctly handle this scenario—each message displays the name as it appeared when sent.
Migration & Backfill:
The migration includes a backfill for existing messages where possible. However, as mentioned, generic email names processed before this change were intentionally not stored in
email_contactsand cannot be fully recovered. Rather than re-processing 6.7 million messages across 444 accounts, new messages going forward will have complete name data. Existing messages will show names where available inemail_contacts. There is already logic in the FE to handle the case where no name exists for the contact, so this shouldn't result in any weird behaviour.Screenshots, GIFs, and Videos