new delete action for proton mail notifications

This commit is contained in:
Egor 2026-02-24 20:43:17 -08:00
parent 2ca579a2d8
commit f9af82edcf
4 changed files with 52 additions and 0 deletions

View file

@ -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)
}
}

View file

@ -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,
},
},
},
}

View file

@ -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})
}

View file

@ -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)
})