mirror of
https://github.com/idrainformatica/PecFlow.git
synced 2026-06-16 12:45:42 +02:00
fase 4
This commit is contained in:
@@ -134,6 +134,52 @@ def _sanitize_filename(filename: str) -> str:
|
||||
return safe or "attachment"
|
||||
|
||||
|
||||
async def upload_outbound_eml(
|
||||
tenant_id: str,
|
||||
mailbox_id: str,
|
||||
message_id: str,
|
||||
eml_bytes: bytes,
|
||||
) -> str:
|
||||
"""
|
||||
Carica il raw EML di un messaggio outbound su MinIO.
|
||||
|
||||
Percorso: tenants/{tenant_id}/mailboxes/{mailbox_id}/outbound/{message_id}.eml
|
||||
|
||||
Args:
|
||||
tenant_id: UUID del tenant
|
||||
mailbox_id: UUID della casella mittente
|
||||
message_id: UUID del messaggio
|
||||
eml_bytes: byte del raw EML
|
||||
|
||||
Returns:
|
||||
Percorso oggetto su MinIO (senza bucket name)
|
||||
"""
|
||||
client = get_minio_client()
|
||||
bucket = settings.minio_bucket
|
||||
object_path = (
|
||||
f"tenants/{tenant_id}/mailboxes/{mailbox_id}/outbound/{message_id}.eml"
|
||||
)
|
||||
|
||||
try:
|
||||
import io as _io
|
||||
data_stream = _io.BytesIO(eml_bytes)
|
||||
await client.put_object(
|
||||
bucket_name=bucket,
|
||||
object_name=object_path,
|
||||
data=data_stream,
|
||||
length=len(eml_bytes),
|
||||
content_type="message/rfc822",
|
||||
)
|
||||
logger.debug(
|
||||
f"EML outbound caricato: s3://{bucket}/{object_path} "
|
||||
f"({len(eml_bytes)} bytes)"
|
||||
)
|
||||
return object_path
|
||||
except Exception as e:
|
||||
logger.error(f"Errore upload EML outbound {object_path}: {e}")
|
||||
raise
|
||||
|
||||
|
||||
async def ensure_bucket_exists() -> None:
|
||||
"""Verifica che il bucket MinIO esista, altrimenti lo crea."""
|
||||
client = get_minio_client()
|
||||
|
||||
Reference in New Issue
Block a user