From 612a013dc71cf17d889199e8a729d0133c7dd8bd Mon Sep 17 00:00:00 2001 From: Ro Date: Fri, 23 Aug 2024 13:42:02 -0400 Subject: [PATCH 1/2] Support direct printing of image types found in /usr/share/cups/mime/mime.types --- export/securedrop_export/print/service.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/export/securedrop_export/print/service.py b/export/securedrop_export/print/service.py index fec7ff223..656f9a4d2 100644 --- a/export/securedrop_export/print/service.py +++ b/export/securedrop_export/print/service.py @@ -31,7 +31,28 @@ "application/x-7z-compressed", ] -MIMETYPE_PRINT_WITHOUT_CONVERSION = ["application/pdf", "text/plain"] +# These are a subset of mimetypes that cups supports for direct printing: +# see /usr/share/cups/mime/mime.types +MIMETYPE_PRINT_WITHOUT_CONVERSION = [ + "application/pdf", + "text/plain", + "image/gif", + "image/png", + "image/jpeg", + "image/pwg-raster", + "image/tiff", + "image/x-photocd", + "image/x-portable-anymap", + "image/x-portable-bitmap", + "image/x-portable-graymap", + "image/x-portable-pixmap", + "image/x-sgi-rgb", + "image/x-xbitmap", + "image/x-xpixmap", + "image/x-sun-raster", + "image/x-bitmap", + "image/x-icon", +] LIBREOFFICE_DESKTOP_DIR = Path("/usr/share/applications/") From 50b40cdaa976ef1ebccb39f11c30a054703a64c2 Mon Sep 17 00:00:00 2001 From: Ro Date: Fri, 23 Aug 2024 13:46:56 -0400 Subject: [PATCH 2/2] Rename ERROR_MIMETYPE_UNKNOWN to ERROR_MIMETYPE_UNSUPPORTED. This is a more accurate term; an unknown mimetype will raise ERROR_MIMETYPE_DISCOVERY. --- client/securedrop_client/export_status.py | 2 +- export/securedrop_export/print/service.py | 4 ++-- export/securedrop_export/print/status.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/securedrop_client/export_status.py b/client/securedrop_client/export_status.py index dc0b1b3a2..70ecca462 100644 --- a/client/securedrop_client/export_status.py +++ b/client/securedrop_client/export_status.py @@ -48,7 +48,7 @@ class ExportStatus(Enum): # Print error ERROR_PRINT = "ERROR_PRINT" ERROR_UNPRINTABLE_TYPE = "ERROR_UNPRINTABLE_TYPE" - ERROR_MIMETYPE_UNKNOWN = "ERROR_MIMETYPE_UNKNOWN" + ERROR_MIMETYPE_UNSUPPORTED = "ERROR_MIMETYPE_UNSUPPORTED" ERROR_MIMETYPE_DISCOVERY = "ERROR_MIMETYPE_DISCOVERY" # New diff --git a/export/securedrop_export/print/service.py b/export/securedrop_export/print/service.py index 656f9a4d2..195d4be5e 100644 --- a/export/securedrop_export/print/service.py +++ b/export/securedrop_export/print/service.py @@ -321,7 +321,7 @@ def _needs_pdf_conversion(self, filename: Path): ) except subprocess.CalledProcessError: logger.error(f"Could not process mimetype of {filename}") - raise ExportException(sdstatus=Status.ERROR_MIMETYPE_UNKNOWN) + raise ExportException(sdstatus=Status.ERROR_MIMETYPE_DISCOVERY) # Don't print "audio/*", "video/*", or archive mimetypes if mimetype.startswith(MIMETYPE_UNPRINTABLE) or mimetype in MIMETYPE_ARCHIVE: logger.info(f"Unprintable file {filename}") @@ -335,7 +335,7 @@ def _needs_pdf_conversion(self, filename: Path): return True else: logger.error("Mimetype is unknown or unsupported.") - raise ExportException(sdstatus=Status.ERROR_MIMETYPE_UNKNOWN) + raise ExportException(sdstatus=Status.ERROR_MIMETYPE_UNSUPPORTED) def _print_file(self, file_to_print: Path): """ diff --git a/export/securedrop_export/print/status.py b/export/securedrop_export/print/status.py index 589c3afe7..75e136cbf 100644 --- a/export/securedrop_export/print/status.py +++ b/export/securedrop_export/print/status.py @@ -13,7 +13,7 @@ class Status(BaseStatus): # Print error ERROR_PRINT = "ERROR_PRINT" ERROR_UNPRINTABLE_TYPE = "ERROR_UNPRINTABLE_TYPE" - ERROR_MIMETYPE_UNKNOWN = "ERROR_MIMETYPE_UNKNOWN" + ERROR_MIMETYPE_UNSUPPORTED = "ERROR_MIMETYPE_UNSUPPORTED" ERROR_MIMETYPE_DISCOVERY = "ERROR_MIMETYPE_DISCOVERY" # New