From e2319714cac2ca4e14ba0aaa3563a66757b7ad83 Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Tue, 20 May 2025 00:02:15 +0530 Subject: [PATCH] fix(imap-email): lowercase all envelope email addresses for consistent matching and deduplication --- internal/inbox/channel/email/imap.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/inbox/channel/email/imap.go b/internal/inbox/channel/email/imap.go index 34fe9aa6..9568f667 100644 --- a/internal/inbox/channel/email/imap.go +++ b/internal/inbox/channel/email/imap.go @@ -186,7 +186,7 @@ func (e *Email) processEnvelope(ctx context.Context, client *imapclient.Client, e.lo.Warn("no sender received for email", "message_id", env.MessageID) return nil } - var fromAddress = env.From[0].Addr() + var fromAddress = strings.ToLower(env.From[0].Addr()) // Check if the message already exists in the database. // If it does, ignore it. @@ -225,29 +225,29 @@ func (e *Email) processEnvelope(ctx context.Context, client *imapclient.Client, Type: umodels.UserTypeContact, } - // Set `to`, `cc`, and `bcc` addresses in meta. + // Lowercase and set the `to`, `cc`, `from` and `bcc` addresses in message meta. var ccAddr = make([]string, 0, len(env.Cc)) var toAddr = make([]string, 0, len(env.To)) var bccAddr = make([]string, 0, len(env.Bcc)) var fromAddr = make([]string, 0, len(env.From)) for _, cc := range env.Cc { if cc.Addr() != "" { - ccAddr = append(ccAddr, cc.Addr()) + ccAddr = append(ccAddr, strings.ToLower(cc.Addr())) } } for _, to := range env.To { if to.Addr() != "" { - toAddr = append(toAddr, to.Addr()) + toAddr = append(toAddr, strings.ToLower(to.Addr())) } } for _, bcc := range env.Bcc { if bcc.Addr() != "" { - bccAddr = append(bccAddr, bcc.Addr()) + bccAddr = append(bccAddr, strings.ToLower(bcc.Addr())) } } for _, from := range env.From { if from.Addr() != "" { - fromAddr = append(fromAddr, from.Addr()) + fromAddr = append(fromAddr, strings.ToLower(from.Addr())) } }