Make email attachments' names simpler (#208)

This commit is contained in:
Kerem Yilmaz
2024-04-18 03:42:10 -07:00
committed by GitHub
parent 7042592bf6
commit d059619e5e

View File

@@ -9,7 +9,6 @@ from enum import StrEnum
from pathlib import Path from pathlib import Path
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from typing import Annotated, Any, Literal, Union from typing import Annotated, Any, Literal, Union
from urllib.parse import urlparse
import filetype import filetype
import structlog import structlog
@@ -822,10 +821,11 @@ class SendEmailBlock(Block):
extension = None extension = None
maintype, subtype = ctype.split("/", 1) maintype, subtype = ctype.split("/", 1)
attachment_filename = urlparse(filename).path.replace("/", "_") attachment_path = Path(path)
attachment_filename = attachment_path.name
# Check if the filename has an extension # Check if the filename has an extension
if not Path(attachment_filename).suffix: if not attachment_path.suffix:
# If no extension, guess it based on the MIME type # If no extension, guess it based on the MIME type
if extension: if extension:
attachment_filename += f".{extension}" attachment_filename += f".{extension}"