diff --git a/service/integration/proton/handlers.go b/service/integration/proton/handlers.go index ed0c59a..7f77094 100644 --- a/service/integration/proton/handlers.go +++ b/service/integration/proton/handlers.go @@ -188,3 +188,38 @@ func (h *Handlers) HandleArchive(w http.ResponseWriter, r *http.Request) { h.logger.Error("failed to encode response", "error", err) } } + +type deleteRequest struct { + UID string `json:"uid"` +} + +func (h *Handlers) HandleDelete(w http.ResponseWriter, r *http.Request) { + var req deleteRequest + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + util.JSONError(w, "invalid request body", http.StatusBadRequest) + return + } + + if req.UID == "" { + util.JSONError(w, "uid is required", http.StatusBadRequest) + return + } + + if h.monitor == nil { + util.JSONError(w, "Proton integration not enabled", http.StatusBadRequest) + return + } + + if err := h.monitor.Delete(req.UID); err != nil { + h.logger.Error("failed to delete email", "uid", req.UID, "error", err) + util.JSONError(w, "failed to delete", http.StatusInternalServerError) + return + } + + h.logger.Info("deleted email", "uid", req.UID) + + w.Header().Set("Content-Type", "application/json") + if err := json.NewEncoder(w).Encode(map[string]bool{"success": true}); err != nil { + h.logger.Error("failed to encode response", "error", err) + } +} diff --git a/service/integration/proton/messages.go b/service/integration/proton/messages.go index b1e8014..6e0b8ea 100644 --- a/service/integration/proton/messages.go +++ b/service/integration/proton/messages.go @@ -98,6 +98,15 @@ func (m *Monitor) sendNotification(msg *protonmail.Message) { "uid": msg.ID, }, }, + { + ID: "delete", + Label: "Delete", + Endpoint: "/api/v1/proton/delete", + Method: "POST", + Data: map[string]any{ + "uid": msg.ID, + }, + }, }, } diff --git a/service/integration/proton/monitor.go b/service/integration/proton/monitor.go index 4b9dbad..6af389a 100644 --- a/service/integration/proton/monitor.go +++ b/service/integration/proton/monitor.go @@ -165,3 +165,10 @@ func (m *Monitor) Archive(msgID string) error { } return m.client.UnlabelMessages(protonmail.LabelInbox, []string{msgID}) } + +func (m *Monitor) Delete(msgID string) error { + if m.client == nil { + return nil + } + return m.client.DeleteMessages([]string{msgID}) +} diff --git a/service/integration/proton/routes.go b/service/integration/proton/routes.go index bf2e2b4..8b2f1e7 100644 --- a/service/integration/proton/routes.go +++ b/service/integration/proton/routes.go @@ -181,6 +181,7 @@ func RegisterRoutes(router *chi.Mux, handlers *Handlers, auth func(http.Handler) r.Use(auth) r.Post("/mark-read", handlers.HandleMarkRead) r.Post("/archive", handlers.HandleArchive) + r.Post("/delete", handlers.HandleDelete) r.Post("/auth", authH.handleAuth) r.Delete("/auth", authH.handleDelete) })