feat: add account toggle, message dedup tracking, SMTP per-user and Gmail OAuth flow plan

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
Agent-Logs-Url: https://github.com/christianlouis/pop_puller_to_gmail/sessions/b77800ca-b452-4427-b0bf-63403e906916
This commit is contained in:
copilot-swe-agent[bot]
2026-03-25 11:20:22 +00:00
parent a1d258de01
commit a15216c630
6 changed files with 245 additions and 48 deletions
+33 -1
View File
@@ -8,7 +8,7 @@ from sqlalchemy import select, desc
from app.core.database import get_db
from app.core.deps import get_current_active_user
from app.core.security import encrypt_credential
from app.models.database_models import User, MailAccount
from app.models.database_models import User, MailAccount, AccountStatus
from app.models.schemas import (
MailAccountCreate,
MailAccountResponse,
@@ -182,6 +182,38 @@ async def delete_mail_account(
await db.commit()
@router.patch("/{account_id}/toggle", response_model=MailAccountResponse)
async def toggle_mail_account(
account_id: int,
current_user: User = Depends(get_current_active_user),
db: AsyncSession = Depends(get_db),
):
"""Toggle the enabled/disabled state of a mail account"""
result = await db.execute(
select(MailAccount).where(
MailAccount.id == account_id, MailAccount.user_id == current_user.id
)
)
account = result.scalar_one_or_none()
if not account:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Mail account not found"
)
account.is_enabled = not account.is_enabled # type: ignore[assignment]
# When re-enabling a previously errored account, reset status to ACTIVE
# so the scheduler picks it up on the next run.
if account.is_enabled and account.status == AccountStatus.ERROR:
account.status = AccountStatus.ACTIVE # type: ignore[assignment]
await db.commit()
await db.refresh(account)
return account
@router.post("/test", response_model=MailAccountTestResponse)
async def test_mail_connection(
test_request: MailAccountTestRequest,