diff --git a/src/api/mail_routes.py b/src/api/mail_routes.py index b49ab29..ef83690 100644 --- a/src/api/mail_routes.py +++ b/src/api/mail_routes.py @@ -297,6 +297,25 @@ async def send_mail(body: Dict[str, Any]): return result +@router.delete("") +async def delete_mail(prefix: Optional[str] = Query(None)): + """批量删除邮件(按标题前缀匹配,status→cancelled)""" + if not prefix: + raise HTTPException(400, "`prefix` 查询参数必填") + + bb = _bb() + tasks = bb.list_tasks() + + deleted_ids = [] + for t in tasks: + if t.title and t.title.startswith(prefix): + if t.status not in ("cancelled",): + bb.update_task_status(t.id, "cancelled", agent="mail-cleanup-api") + deleted_ids.append(t.id) + + return {"ok": True, "deleted_count": len(deleted_ids), "deleted_ids": deleted_ids} + + @router.patch("/{mail_id}") async def update_mail(mail_id: str, body: Dict[str, Any]): """更新 Mail(标记已读/已执行)"""