Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SearchCriteria.Not a pointer #505

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions imapclient/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,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 @@ -311,10 +311,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 @@ -325,10 +325,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 @@ -285,7 +285,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: 6 additions & 2 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type SearchCriteria struct {
Larger int64
Smaller int64

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

Expand Down Expand Up @@ -65,7 +65,11 @@ func (criteria *SearchCriteria) And(other *SearchCriteria) {
criteria.Smaller = other.Smaller
}

criteria.Not = append(criteria.Not, other.Not...)
if criteria.Not != nil && other.Not != nil {
criteria.Not.And(other.Not)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. Should be Or.

} else if other.Not != nil {
criteria.Not = other.Not
}
criteria.Or = append(criteria.Or, other.Or...)
}

Expand Down