MCPcopy Create free account
hub / github.com/buggregator/server / handleMessages

Function handleMessages

modules/smtp/api.go:62–107  ·  view source on GitHub ↗

handleMessages returns SMTP messages matching the given filter.

(store event.Store)

Source from the content-addressed store, hash-verified

60
61// handleMessages returns SMTP messages matching the given filter.
62func handleMessages(store event.Store) http.HandlerFunc {
63 return func(w http.ResponseWriter, r *http.Request) {
64 f := parseFilter(r)
65
66 events, err := store.FindAll(r.Context(), event.FindOptions{Type: "smtp", Project: f.Project})
67 if err != nil {
68 smtpError(w, err.Error(), http.StatusInternalServerError)
69 return
70 }
71
72 filtered := applyFilter(events, f)
73
74 if f.Order == "asc" {
75 // Store returns desc; reverse for asc.
76 for i, j := 0, len(filtered)-1; i < j; i, j = i+1, j-1 {
77 filtered[i], filtered[j] = filtered[j], filtered[i]
78 }
79 }
80
81 total := len(filtered)
82
83 // Apply offset/limit after sorting.
84 if f.Offset > 0 {
85 if f.Offset >= len(filtered) {
86 filtered = nil
87 } else {
88 filtered = filtered[f.Offset:]
89 }
90 }
91 if f.Limit > 0 && len(filtered) > f.Limit {
92 filtered = filtered[:f.Limit]
93 }
94 if filtered == nil {
95 filtered = []event.Event{}
96 }
97
98 smtpJSON(w, map[string]any{
99 "data": filtered,
100 "meta": map[string]any{
101 "total": total,
102 "limit": f.Limit,
103 "offset": f.Offset,
104 },
105 })
106 }
107}
108
109// handleMessagesWait long-polls for a matching SMTP message.
110// It holds the connection until a match arrives or the timeout expires.

Callers 1

registerSMTPAPIFunction · 0.85

Calls 5

parseFilterFunction · 0.85
smtpErrorFunction · 0.85
applyFilterFunction · 0.85
smtpJSONFunction · 0.85
FindAllMethod · 0.65

Tested by

no test coverage detected