Skip to content

Commit

Permalink
Merge pull request #2174 from freedomofpress/support-direct-print-images
Browse files Browse the repository at this point in the history
Support printing images directly based on mimetypes cups supports
  • Loading branch information
legoktm committed Aug 23, 2024
2 parents 86eac8b + 50b40cd commit eb5a345
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/securedrop_client/export_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 24 additions & 3 deletions export/securedrop_export/print/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/")


Expand Down Expand Up @@ -300,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}")
Expand All @@ -314,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):
"""
Expand Down
2 changes: 1 addition & 1 deletion export/securedrop_export/print/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eb5a345

Please sign in to comment.