imc-vibe/backend/internal/api/handlers/queue.go
Christoph Haas 060f88dffe Fix mail queue and logs commands
- Hardcode paths: /usr/sbin/postqueue, /usr/sbin/postsuper, /usr/bin/journalctl
- Fix postqueue: remove -p flag (conflicts with -j)
- Add stderr logging for queue errors
2026-03-22 01:40:06 +01:00

60 lines
1.3 KiB
Go

package handlers
import (
"log"
"net/http"
"github.com/imc-vibe/backend/internal/mail"
)
type QueueHandler struct{}
func NewQueueHandler() *QueueHandler {
return &QueueHandler{}
}
func (h *QueueHandler) List(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
Error(w, http.StatusMethodNotAllowed, "method not allowed")
return
}
entries, err := mail.GetQueue()
if err != nil {
log.Printf("Queue error: %v", err)
Error(w, http.StatusServiceUnavailable, "failed to get queue: "+err.Error())
return
}
Success(w, entries)
}
func (h *QueueHandler) Requeue(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
Error(w, http.StatusMethodNotAllowed, "method not allowed")
return
}
id := extractID(r.URL.Path)
if err := mail.RequeueMail(id); err != nil {
Error(w, http.StatusInternalServerError, "failed to requeue mail")
return
}
Success(w, map[string]string{"message": "mail requeued"})
}
func (h *QueueHandler) Delete(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodDelete {
Error(w, http.StatusMethodNotAllowed, "method not allowed")
return
}
id := extractID(r.URL.Path)
if err := mail.DeleteFromQueue(id); err != nil {
Error(w, http.StatusInternalServerError, "failed to delete from queue")
return
}
NoContent(w)
}