Skip to content

Commit

Permalink
smtp: Replacing multi-query-param search index with JSON-Unmarshal se…
Browse files Browse the repository at this point in the history
…arch index, by request of Martin
  • Loading branch information
Lucas Hinderberger committed Jul 10, 2024
1 parent 1f98ea0 commit aedd4e4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/smtp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,21 @@ func buildMultipartMeta(part *ReceivedPart) map[string]any {
func extractSearchRegexes(
w http.ResponseWriter, queryParams map[string][]string, paramName string,
) ([]*regexp.Regexp, error) {
searchParams, ok := queryParams[paramName]
filteredParams, ok := queryParams[paramName]
if ok {
if len(filteredParams) != 1 {
return nil, fmt.Errorf(
"expected 1 %q query parameter, got %d (use JSON array for multiple queries)",
paramName, len(filteredParams),
)
}

var searchParams []string
err := json.Unmarshal([]byte(filteredParams[0]), &searchParams)
if err != nil {
searchParams = []string{filteredParams[0]}
}

out := make([]*regexp.Regexp, len(searchParams))

for i, p := range searchParams {
Expand Down

0 comments on commit aedd4e4

Please sign in to comment.