From bb512d5ecde5d08cd9bb41686e9a448823d2f201 Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Thu, 10 Apr 2025 17:38:15 +0530 Subject: [PATCH] fix: Handle 'contact not found' error when checking if contact is blocked for IMAP email search. --- internal/inbox/channel/email/imap.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/inbox/channel/email/imap.go b/internal/inbox/channel/email/imap.go index e9c39178..85df6da0 100644 --- a/internal/inbox/channel/email/imap.go +++ b/internal/inbox/channel/email/imap.go @@ -10,6 +10,7 @@ import ( "github.com/abhinavxd/libredesk/internal/attachment" "github.com/abhinavxd/libredesk/internal/conversation/models" + "github.com/abhinavxd/libredesk/internal/envelope" umodels "github.com/abhinavxd/libredesk/internal/user/models" "github.com/emersion/go-imap/v2" "github.com/emersion/go-imap/v2/imapclient" @@ -200,8 +201,11 @@ func (e *Email) processEnvelope(ctx context.Context, client *imapclient.Client, // Check if contact with this email is blocked / disabed, if so, ignore the message. if contact, err := e.userStore.GetContact(0, fromAddr); err != nil { - e.lo.Error("error checking if user is blocked", "email", fromAddr, "error", err) - return fmt.Errorf("checking if user is blocked: %w", err) + envErr, ok := err.(envelope.Error) + if !ok || envErr.ErrorType != envelope.NotFoundError { + e.lo.Error("error checking if user is blocked", "email", fromAddr, "error", err) + return fmt.Errorf("checking if user is blocked: %w", err) + } } else if !contact.Enabled { e.lo.Debug("contact is blocked, ignoring message", "email", fromAddr) return nil