(w http.ResponseWriter, r *http.Request)
| 157 | } |
| 158 | |
| 159 | func (s *Server) handleMessages(w http.ResponseWriter, r *http.Request) { |
| 160 | email := r.URL.Query().Get("email") |
| 161 | msgs := s.smtpServer.Messages() |
| 162 | |
| 163 | var summaries []EmailSummary |
| 164 | for _, msg := range msgs { |
| 165 | recipients := msg.RcpttoRequestResponse() |
| 166 | if !matchesRecipient(recipients, email) { |
| 167 | continue |
| 168 | } |
| 169 | |
| 170 | summary, err := parseEmailSummary(msg.MsgRequest()) |
| 171 | if err != nil { |
| 172 | s.logger.Warn(r.Context(), "failed to parse email summary", slog.Error(err)) |
| 173 | continue |
| 174 | } |
| 175 | summaries = append(summaries, summary) |
| 176 | } |
| 177 | |
| 178 | w.Header().Set("Content-Type", "application/json") |
| 179 | if err := json.NewEncoder(w).Encode(summaries); err != nil { |
| 180 | s.logger.Warn(r.Context(), "failed to encode JSON response", slog.Error(err)) |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | func matchesRecipient(recipients [][]string, email string) bool { |
| 185 | if email == "" { |
nothing calls this directly
no test coverage detected