diff --git a/fetcher/fetcher.go b/fetcher/fetcher.go index 89cec4cba3e6ff012a1dd4b576cf61c5928662c2..8e647453a080d210566a6db76bc7902a435bc9e4 100644 --- a/fetcher/fetcher.go +++ b/fetcher/fetcher.go @@ -205,17 +205,28 @@ func FetchMailboxEmails(account *config.Account, mailbox string, limit, offset u fetchEmail = strings.ToLower(strings.TrimSpace(account.Email)) } - // Check if any recipient matches the fetchEmail + // Determine if this is a sent mailbox + isSentMailbox := mailbox == getSentMailbox(account) + + // Apply different filtering logic based on mailbox type matched := false - for _, r := range toAddrList { - if strings.EqualFold(strings.TrimSpace(r), fetchEmail) { + if isSentMailbox { + // For sent mailbox, check if the sender matches the fetchEmail + if strings.EqualFold(strings.TrimSpace(fromAddr), fetchEmail) { matched = true - break + } + } else { + // For inbox and other mailboxes, check if any recipient matches the fetchEmail + for _, r := range toAddrList { + if strings.EqualFold(strings.TrimSpace(r), fetchEmail) { + matched = true + break + } } } if !matched { - // Skip messages not addressed to the configured fetch email + // Skip messages not matching the filter criteria continue }