Skip to content

Commit

Permalink
imap: make SearchCriteria.Not a pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Apr 7, 2023
1 parent 8bb451c commit 3b75bf4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
10 changes: 4 additions & 6 deletions imapclient/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ func writeSearchKey(enc *imapwire.Encoder, criteria *imap.SearchCriteria) {
encodeItem("SMALLER").SP().Number64(criteria.Smaller)
}

for _, not := range criteria.Not {
if criteria.Not != nil {
encodeItem("NOT").SP()
writeSearchKey(enc, &not)
writeSearchKey(enc, criteria.Not)
}
for _, or := range criteria.Or {
encodeItem("OR").SP()
Expand Down Expand Up @@ -290,10 +290,8 @@ func searchCriteriaIsASCII(criteria *imap.SearchCriteria) bool {
return false
}
}
for _, not := range criteria.Not {
if !searchCriteriaIsASCII(&not) {
return false
}
if criteria.Not != nil && !searchCriteriaIsASCII(criteria.Not) {
return false
}
for _, or := range criteria.Or {
if !searchCriteriaIsASCII(&or[0]) || !searchCriteriaIsASCII(&or[1]) {
Expand Down
6 changes: 2 additions & 4 deletions imapserver/imapmemserver/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,8 @@ func (msg *message) search(seqNum uint32, criteria *imap.SearchCriteria) bool {
}
}

for _, not := range criteria.Not {
if msg.search(seqNum, &not) {
return false
}
if criteria.Not != nil && msg.search(seqNum, criteria.Not) {
return false
}
for _, or := range criteria.Or {
if !msg.search(seqNum, &or[0]) && !msg.search(seqNum, &or[1]) {
Expand Down
2 changes: 1 addition & 1 deletion imapserver/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func readSearchKeyWithAtom(criteria *imap.SearchCriteria, dec *imapwire.Decoder,
if err := readSearchKey(&not, dec); err != nil {
return nil
}
criteria.Not = append(criteria.Not, not)
criteria.And(&imap.SearchCriteria{Not: &not})
case "OR":
if !dec.ExpectSP() {
return dec.Err()
Expand Down
8 changes: 5 additions & 3 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type SearchCriteria struct {
Larger int64
Smaller int64

Not []SearchCriteria
Not *SearchCriteria
Or [][2]SearchCriteria
}

Expand Down Expand Up @@ -90,8 +90,10 @@ func (criteria *SearchCriteria) And(other *SearchCriteria) {
criteria.Smaller = other.Smaller
}

for _, not := range other.Not {
criteria.Not = append(criteria.Not, not)
if criteria.Not != nil && other.Not != nil {
criteria.Not.And(other.Not)
} else if other.Not != nil {
criteria.Not = other.Not
}
for _, or := range other.Or {
criteria.Or = append(criteria.Or, or)
Expand Down

0 comments on commit 3b75bf4

Please sign in to comment.