Skip to content

Commit

Permalink
fix(GODT-1729): Fix SEARCH string arguments
Browse files Browse the repository at this point in the history
All string argument searches need to be case-insensitive. Optimizations
will be handled in GODT-1733.
  • Loading branch information
LBeernaertProton committed Jul 14, 2022
1 parent 3bbbc71 commit 08e67c9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/backend/mailbox_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

Expand Down Expand Up @@ -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
})
}

Expand All @@ -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
})
}

Expand Down Expand Up @@ -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
})
}

Expand All @@ -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
})
}

Expand Down Expand Up @@ -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
})
}

Expand All @@ -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
})
}

Expand All @@ -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
})
}

Expand Down
33 changes: 33 additions & 0 deletions tests/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func TestSearchBcc(t *testing.T) {
c.C(`A001 search bcc "[email protected]"`)
c.S("* SEARCH 49 50")
c.OK("A001")

// Search is also case-insensitive.
c.C(`A001 search bcc "[email protected]"`)
c.S("* SEARCH 49 50")
c.OK("A001")
})
}

Expand All @@ -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")
})
}

Expand All @@ -69,6 +79,11 @@ func TestSearchCc(t *testing.T) {
c.C(`A001 search cc "Dovecot Mailinglist <[email protected]>"`)
c.S("* SEARCH 53 55 60")
c.OK("A001")

// Search is also case-insensitive.
c.C(`A001 search cc "DoVeCot Mailinglist <[email protected]>"`)
c.S("* SEARCH 53 55 60")
c.OK("A001")
})
}

Expand Down Expand Up @@ -117,6 +132,10 @@ func TestSearchFrom(t *testing.T) {
c.C(`A001 search from "[email protected]"`)
c.S("* SEARCH 5")
c.OK("A001")

c.C(`A001 search from "[email protected]"`)
c.S("* SEARCH 5")
c.OK("A001")
})
}

Expand Down Expand Up @@ -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")
})
}

Expand All @@ -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")
})
}

Expand All @@ -395,6 +424,10 @@ func TestSearchTo(t *testing.T) {
c.C(`A001 search to "Timo Sirainen <[email protected]>"`)
c.S("* SEARCH 49")
c.OK("A001")

c.C(`A001 search to "Timo SirAINEN <[email protected]>"`)
c.S("* SEARCH 49")
c.OK("A001")
})
}

Expand Down

0 comments on commit 08e67c9

Please sign in to comment.