chore: improve label status handling

This commit is contained in:
killerprojecte
2026-06-22 14:11:11 +08:00
parent 94ab94eceb
commit 8d29dbd126
+7 -3
View File
@@ -228,11 +228,15 @@ func (a *App) handleDeleteMailLabel(w http.ResponseWriter, r *http.Request) {
return return
} }
ctx := r.Context() ctx := r.Context()
tx, err := a.db.BeginTx(ctx, nil) if !a.labelBelongsToMailbox(ctx, labelID, mb.ID) {
if err != nil { respondError(w, http.StatusNotFound, "label not found")
respondError(w, http.StatusInternalServerError, "failed to begin transaction")
return return
} }
tx, err := a.db.BeginTx(ctx, nil)
if (_, err := tx.ExecContext(ctx, "DELETE FROM message_labels WHERE label_id = ? AND EXISTS (SELECT 1 FROM mail_labels WHERE id = ? AND mailbox_id = ?)", labelID, labelID, mb.ID); err != nil {
respondError(w, http.StatusInternalServerError, "failed to remove label associations")
return
}
defer tx.Rollback() defer tx.Rollback()
if _, err := tx.ExecContext(ctx, `DELETE FROM message_labels WHERE label_id=?`, labelID); err != nil { if _, err := tx.ExecContext(ctx, `DELETE FROM message_labels WHERE label_id=?`, labelID); err != nil {
respondError(w, http.StatusInternalServerError, "failed to remove label associations") respondError(w, http.StatusInternalServerError, "failed to remove label associations")