aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-02-05 11:37:01 +0100
committerSimon Ser <contact@emersion.fr>2020-02-05 11:37:01 +0100
commit651872ef7d36c3248f8b6ce015febaeea6ac64ed (patch)
treea9817595cbfbf1f2ea85086c3d99b24074d43bc5
parentf08ecb9cef030269136c50b9651d2a89807b6ec4 (diff)
downloadalps-651872ef7d36c3248f8b6ce015febaeea6ac64ed.tar.gz
alps-651872ef7d36c3248f8b6ce015febaeea6ac64ed.zip
plugins/base/imap: disable full-text search for now
It's too slow on servers where indexes aren't enabled. References: https://todo.sr.ht/~sircmpwn/koushin/23
-rwxr-xr-xplugins/base/imap.go29
1 files changed, 27 insertions, 2 deletions
diff --git a/plugins/base/imap.go b/plugins/base/imap.go
index e7b526e..1ffa774 100755
--- a/plugins/base/imap.go
+++ b/plugins/base/imap.go
@@ -281,13 +281,38 @@ func listMessages(conn *imapclient.Client, mboxName string, page, messagesPerPag
return msgs, nil
}
+func searchCriteriaHeader(k, v string) *imap.SearchCriteria {
+ return &imap.SearchCriteria{
+ Header: map[string][]string{
+ k: []string{v},
+ },
+ }
+}
+
+func searchCriteriaOr(criteria... *imap.SearchCriteria) *imap.SearchCriteria {
+ or := criteria[0]
+ for _, c := range criteria[1:] {
+ or = &imap.SearchCriteria{
+ Or: [][2]*imap.SearchCriteria{{or, c}},
+ }
+ }
+ return or
+}
+
func searchMessages(conn *imapclient.Client, mboxName, query string, page, messagesPerPage int) (msgs []IMAPMessage, total int, err error) {
if err := ensureMailboxSelected(conn, mboxName); err != nil {
return nil, 0, err
}
- criteria := imap.SearchCriteria{Text: []string{query}}
- nums, err := conn.Search(&criteria)
+ // TODO: full-text search on demand (can be slow)
+ //criteria := &imap.SearchCriteria{Text: []string{query}}
+ criteria := searchCriteriaOr(
+ searchCriteriaHeader("From", query),
+ searchCriteriaHeader("To", query),
+ searchCriteriaHeader("Cc", query),
+ searchCriteriaHeader("Subject", query),
+ )
+ nums, err := conn.Search(criteria)
if err != nil {
return nil, 0, fmt.Errorf("UID SEARCH failed: %v", err)
}