using GmailCatchallLabeler.Configuration; using GmailCatchallLabeler.Gmail; using GmailCatchallLabeler.Labels; namespace GmailCatchallLabeler.Tests; public sealed class RecipientExtractorTests { private readonly RecipientExtractor extractor = new(new GmailOptions { CatchallDomain = "arnemoerman.be" }); [Fact] public void ExtractLocalParts_ReadsDeliveryAndRecipientHeaders() { GmailHeader[] headers = [ new("Delivered-To", "tomscott@arnemoerman.be"), new("To", "Example , other@example.com"), new("Subject", "Ignored") ]; var result = extractor.ExtractLocalParts(headers); Assert.Equal(2, result.Count); Assert.Contains("tomscott", result); Assert.Contains("every-foods", result); } [Fact] public void ExtractLocalParts_IsCaseInsensitiveAndDeduplicates() { GmailHeader[] headers = [ new("X-Original-To", "News@ArneMoerman.be"), new("Cc", "news@arnemoerman.be") ]; var result = extractor.ExtractLocalParts(headers); Assert.Single(result); Assert.Contains("News", result); } [Fact] public void ExtractLocalParts_IgnoresOtherDomainsAndMalformedHeaders() { GmailHeader[] headers = [ new("To", "other@example.com"), new("Envelope-To", "not an address <") ]; Assert.Empty(extractor.ExtractLocalParts(headers)); } }