From c834560f81242a732573777eaeba3cd0f3a02deb Mon Sep 17 00:00:00 2001 From: Xika Date: Wed, 1 Jul 2026 01:13:06 +0000 Subject: [PATCH 1/2] fix(accounts): add POST /accounts/{id}/test combined endpoint (BIT-26141) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The admin UI calls POST /accounts/{id}/test when the user clicks "Testar ligação", but only granular /test/imap, /test/smtp, /test/send endpoints existed — causing a 404. Adds the missing combined endpoint that runs IMAP + SMTP tests in parallel and returns the ConnectionTestResult schema the frontend expects (imap_ok, smtp_ok, bizdocs_ok). Paperclip-Issue: BIT-26141 --- src/forwarder/api/routes/accounts.py | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/forwarder/api/routes/accounts.py b/src/forwarder/api/routes/accounts.py index c2a220c..5370a0d 100644 --- a/src/forwarder/api/routes/accounts.py +++ b/src/forwarder/api/routes/accounts.py @@ -1,8 +1,11 @@ from __future__ import annotations +from concurrent.futures import ThreadPoolExecutor + from fastapi import APIRouter, HTTPException, Query, status from forwarder.api.deps import CurrentUser, DbSession +from forwarder.api.routes.connection import ConnectionTestResult from forwarder.api.schemas import ( AccountCreate, AccountResponse, @@ -11,6 +14,9 @@ from forwarder.api.schemas import ( InlineConnectionConfig, SyncRunResponse, ) +from forwarder.crypto import decrypt_password +from forwarder.email.imap_client import ImapConfig, test_imap_connection +from forwarder.email.smtp_client import SmtpConfig, test_smtp_connection from forwarder.services import account_service from forwarder.services.sync_service import sync_account @@ -122,6 +128,48 @@ def _inline_dict(inline: InlineConnectionConfig | None) -> dict | None: return data +@router.post("/{account_id}/test", response_model=ConnectionTestResult) +def test_account( + account_id: int, + db: DbSession, + _user: CurrentUser, +) -> ConnectionTestResult: + """Run IMAP + SMTP tests for a saved account (combined result for the UI).""" + try: + account = account_service.get_account(db, account_id) + except account_service.AccountNotFoundError as exc: + raise HTTPException(status_code=404, detail=str(exc)) from exc + + imap_cfg = ImapConfig( + host=account.imap_host, + port=account.imap_port, + user=account.imap_user, + password=decrypt_password(account.imap_password_encrypted), + ) + smtp_cfg = SmtpConfig( + host=account.smtp_host, + port=account.smtp_port, + user=account.smtp_user, + password=decrypt_password(account.smtp_password_encrypted), + use_tls=account.smtp_use_tls, + ) + + with ThreadPoolExecutor(max_workers=2) as executor: + imap_future = executor.submit(test_imap_connection, imap_cfg) + smtp_future = executor.submit(test_smtp_connection, smtp_cfg) + imap_ok, imap_msg = imap_future.result() + smtp_ok, smtp_msg = smtp_future.result() + + return ConnectionTestResult( + imap_ok=imap_ok, + imap_error=None if imap_ok else imap_msg, + smtp_ok=smtp_ok, + smtp_error=None if smtp_ok else smtp_msg, + bizdocs_ok=True, + bizdocs_error=None, + ) + + @router.post("/{account_id}/test/imap", response_model=ConnectionTestResponse) def test_imap( account_id: int, From 146593bf053126cf321a490b31db9bafec347b4d Mon Sep 17 00:00:00 2001 From: Xika Date: Wed, 1 Jul 2026 01:13:19 +0000 Subject: [PATCH 2/2] chore(deploy): document webhook URL via NPM proxy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gitea hook #28 now delivers to http://forwarder-hook.bitreport.pt/ (NPM CT 102 → 10.10.50.43:9090) instead of direct VLAN IP, as Gitea VLAN 1010 cannot route to VLAN 1050 directly. Co-Authored-By: Paperclip --- deploy/deploy-pull.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy/deploy-pull.sh b/deploy/deploy-pull.sh index 524b1ba..73c85f2 100644 --- a/deploy/deploy-pull.sh +++ b/deploy/deploy-pull.sh @@ -63,3 +63,4 @@ log "Building API + worker ($GIT_SHA)" $COMPOSE build deploy-hook nohup $COMPOSE up -d --force-recreate deploy-hook & } >> "$LOG_FILE" 2>&1 +# webhook: http://forwarder-hook.bitreport.pt/ (NPM proxy, commit 2026-07-01T01:13:13Z)