vboxes fix

This commit is contained in:
2026-03-19 14:28:09 +01:00
parent b7f7c1f7c0
commit 06dfbfcbc4
30 changed files with 4405 additions and 166 deletions
+33 -3
View File
@@ -29,9 +29,9 @@ from typing import Any
from sqlalchemy import select
from app.database import AsyncSessionLocal
from app.models import Mailbox, Message, SendJob
from app.models import Attachment, Mailbox, Message, SendJob
from app.smtp.sender import SmtpSender
from app.storage.minio_client import upload_outbound_eml
from app.storage.minio_client import download_attachment, upload_outbound_eml
logger = logging.getLogger(__name__)
@@ -105,6 +105,36 @@ async def send_pec(ctx: dict[str, Any], send_job_id: str) -> dict:
f"per job {send_job_id}{msg.to_addresses}"
)
# ── Carica allegati da MinIO (se presenti) ────────────────────────────
attachments_data: list[dict] | None = None
if msg.has_attachments:
att_result = await db.execute(
select(Attachment).where(Attachment.message_id == msg.id)
)
att_records = list(att_result.scalars().all())
if att_records:
attachments_data = []
for att in att_records:
try:
content = await download_attachment(att.storage_path)
attachments_data.append(
{
"filename": att.filename,
"content": content,
"content_type": att.content_type or "application/octet-stream",
}
)
logger.debug(
f"[send_pec] Allegato caricato per invio: "
f"{att.filename} ({len(content)} bytes)"
)
except Exception as att_err:
logger.warning(
f"[send_pec] Impossibile caricare allegato "
f"'{att.filename}' ({att.storage_path}): {att_err}"
)
# Continua senza questo allegato
# ── Tenta invio SMTP ──────────────────────────────────────────────────
try:
sender = SmtpSender(mailbox)
@@ -114,7 +144,7 @@ async def send_pec(ctx: dict[str, Any], send_job_id: str) -> dict:
subject=msg.subject or "",
body_text=msg.body_text or "",
body_html=msg.body_html,
attachments=None, # allegati in fase successiva (Fase 5)
attachments=attachments_data,
)
# ── Successo: aggiorna DB ─────────────────────────────────────────