diff --git a/internal/backend/mailbox_search.go b/internal/backend/mailbox_search.go index 4e6dc165..6c7907ff 100644 --- a/internal/backend/mailbox_search.go +++ b/internal/backend/mailbox_search.go @@ -181,7 +181,7 @@ func (m *Mailbox) matchSearchKeyBcc(ctx context.Context, candidates []*snapMsg, return false, err } - return strings.Contains(value, key.GetText()), nil + return strings.Contains(strings.ToLower(value), strings.ToLower(key.GetText())), nil }) } @@ -213,7 +213,7 @@ func (m *Mailbox) matchSearchKeyBody(ctx context.Context, candidates []*snapMsg, return false, err } - return bytes.Contains(section.Body(), []byte(key.GetText())), nil + return bytes.Contains([]byte(strings.ToLower(string(section.Body()))), []byte(strings.ToLower(key.GetText()))), nil }) } @@ -229,7 +229,7 @@ func (m *Mailbox) matchSearchKeyCc(ctx context.Context, candidates []*snapMsg, k return false, err } - return strings.Contains(value, key.GetText()), nil + return strings.Contains(strings.ToLower(value), strings.ToLower(key.GetText())), nil }) } @@ -263,7 +263,7 @@ func (m *Mailbox) matchSearchKeyFrom(ctx context.Context, candidates []*snapMsg, return false, err } - return strings.Contains(value, key.GetText()), nil + return strings.Contains(strings.ToLower(value), strings.ToLower(key.GetText())), nil }) } @@ -279,7 +279,7 @@ func (m *Mailbox) matchSearchKeyHeader(ctx context.Context, candidates []*snapMs return false, err } - return strings.Contains(value, key.GetText()), nil + return strings.Contains(strings.ToLower(value), strings.ToLower(key.GetText())), nil }) } @@ -496,7 +496,7 @@ func (m *Mailbox) matchSearchKeySubject(ctx context.Context, candidates []*snapM return false, err } - return strings.Contains(value, key.GetText()), nil + return strings.Contains(strings.ToLower(value), strings.ToLower(key.GetText())), nil }) } @@ -507,7 +507,7 @@ func (m *Mailbox) matchSearchKeyText(ctx context.Context, candidates []*snapMsg, return false, err } - return bytes.Contains(literal, []byte(key.GetText())), nil + return bytes.Contains([]byte(strings.ToLower(string(literal))), []byte(strings.ToLower(key.GetText()))), nil }) } @@ -523,7 +523,7 @@ func (m *Mailbox) matchSearchKeyTo(ctx context.Context, candidates []*snapMsg, k return false, err } - return strings.Contains(value, key.GetText()), nil + return strings.Contains(strings.ToLower(value), strings.ToLower(key.GetText())), nil }) } diff --git a/tests/search_test.go b/tests/search_test.go index 7242aea9..abe827e8 100644 --- a/tests/search_test.go +++ b/tests/search_test.go @@ -47,6 +47,11 @@ func TestSearchBcc(t *testing.T) { c.C(`A001 search bcc "dovecot@procontrol.fi"`) c.S("* SEARCH 49 50") c.OK("A001") + + // Search is also case-insensitive. + c.C(`A001 search bcc "dovecot@PROcontrol.FI"`) + c.S("* SEARCH 49 50") + c.OK("A001") }) } @@ -61,6 +66,11 @@ func TestSearchBody(t *testing.T) { c.C(`A001 search body "Content-Length saves just the size of mail body"`) c.S("* SEARCH 50") c.OK("A001") + + // Search is also case-insensitive. + c.C(`A001 search body "Content-LenGTH sAvEs just the size of MaiL body"`) + c.S("* SEARCH 50") + c.OK("A001") }) } @@ -69,6 +79,11 @@ func TestSearchCc(t *testing.T) { c.C(`A001 search cc "Dovecot Mailinglist "`) c.S("* SEARCH 53 55 60") c.OK("A001") + + // Search is also case-insensitive. + c.C(`A001 search cc "DoVeCot Mailinglist "`) + c.S("* SEARCH 53 55 60") + c.OK("A001") }) } @@ -117,6 +132,10 @@ func TestSearchFrom(t *testing.T) { c.C(`A001 search from "reply@seekercenter.net"`) c.S("* SEARCH 5") c.OK("A001") + + c.C(`A001 search from "reply@seeKERcenTER.net"`) + c.S("* SEARCH 5") + c.OK("A001") }) } @@ -373,6 +392,11 @@ func TestSearchSubject(t *testing.T) { c.C(`A003 search subject "mbox problems"`) c.S("* SEARCH 100") c.OK("A003") + + // Subject search is case-insensitive. + c.C(`A003 search subject "MBOX PROBLEMS"`) + c.S("* SEARCH 100") + c.OK("A003") }) } @@ -387,6 +411,11 @@ func TestSearchText(t *testing.T) { c.C(`A002 search text "Content-Length saves just the size of mail body"`) c.S("* SEARCH 50") c.OK("A002") + + // Text search is case-insensitive. + c.C(`A002 search text "ContenT-LeNgTh saveS jUst the Size of mail body"`) + c.S("* SEARCH 50") + c.OK("A002") }) } @@ -395,6 +424,10 @@ func TestSearchTo(t *testing.T) { c.C(`A001 search to "Timo Sirainen "`) c.S("* SEARCH 49") c.OK("A001") + + c.C(`A001 search to "Timo SirAINEN "`) + c.S("* SEARCH 49") + c.OK("A001") }) }