Allow filtering emails via headers
This commit is contained in:
@ -19,6 +19,7 @@ type InboxSearch struct {
|
||||
From string
|
||||
Body string
|
||||
Subject string
|
||||
Headers map[string]string
|
||||
After time.Time
|
||||
Before time.Time
|
||||
}
|
||||
@ -149,6 +150,38 @@ func HandleGetInbox(ctx context.Context, qry cqrs.Query) (interface{}, error) {
|
||||
match = false
|
||||
}
|
||||
|
||||
if req.Search.Headers != nil {
|
||||
found := false
|
||||
|
||||
for searchKey, searchValue := range req.Search.Headers {
|
||||
for headerKey, headerValues := range eml.Headers {
|
||||
if searchKey != headerKey {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, hv := range headerValues {
|
||||
if strings.Contains(hv, searchValue) {
|
||||
found = true
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
match = false
|
||||
}
|
||||
}
|
||||
|
||||
if match {
|
||||
filtered = append(filtered, eml)
|
||||
}
|
||||
|
Reference in New Issue
Block a user