From fa22e96af759087f14c77d8844a9ee2326bc4e78 Mon Sep 17 00:00:00 2001 From: Moon Sungjoon Date: Thu, 27 Jul 2023 22:59:50 +0900 Subject: [PATCH] Clean up HWP/HWPX MIME types Use the MIME types actually used by the `file` command, which was recently changed for the detection of the HWPX format [1]. application/hwp+zip -> application/x-hwp+zip But the HWPX format includes a 'mimetype' file, which contains the MIME type string "application/hwp+zip", so that was left so because it may be possible to detect it as "application/hwp+zip". [1]: https://github.com/file/file/commit/ceef7ead3a820998b645c72ed5e3d26b1fecf816 --- dangerzone/conversion/doc_to_pixels.py | 30 +++++++++++++++++++++----- install/pyinstaller/pyinstaller.spec | 11 ++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/dangerzone/conversion/doc_to_pixels.py b/dangerzone/conversion/doc_to_pixels.py index fd50f1c..48f4e92 100644 --- a/dangerzone/conversion/doc_to_pixels.py +++ b/dangerzone/conversion/doc_to_pixels.py @@ -78,15 +78,34 @@ class DocumentToPixels(DangerzoneConverter): "type": "libreoffice", }, # .hwp - "application/haansofthwp": { - "type": "libreoffice", - "libreoffice_ext": "h2orestart.oxt", - }, + # Commented MIMEs are not used in `file` and don't conform to the rules. + # Left them for just in case + # PR: https://github.com/freedomofpress/dangerzone/pull/460 + # "application/haansofthwp": { + # "type": "libreoffice", + # "libreoffice_ext": "h2orestart.oxt", + # }, + # "application/vnd.hancom.hwp": { + # "type": "libreoffice", + # "libreoffice_ext": "h2orestart.oxt", + # }, "application/x-hwp": { "type": "libreoffice", "libreoffice_ext": "h2orestart.oxt", }, # .hwpx + # "application/haansofthwpx": { + # "type": "libreoffice", + # "libreoffice_ext": "h2orestart.oxt", + # }, + # "application/vnd.hancom.hwpx": { + # "type": "libreoffice", + # "libreoffice_ext": "h2orestart.oxt", + # }, + "application/x-hwp+zip": { + "type": "libreoffice", + "libreoffice_ext": "h2orestart.oxt", + }, "application/hwp+zip": { "type": "libreoffice", "libreoffice_ext": "h2orestart.oxt", @@ -126,11 +145,12 @@ class DocumentToPixels(DangerzoneConverter): raise ValueError("The document format is not supported") # Temporary fix for the HWPX format + # Should be removed after new release of `file' (current release 5.44) if mime_type == "application/zip": file_type = magic.from_file("/tmp/input_file") hwpx_file_type = 'Zip data (MIME type "application/hwp+zip"?)' if file_type == hwpx_file_type: - mime_type = "application/hwp+zip" + mime_type = "application/x-hwp+zip" # Get file size (in MiB) size = os.path.getsize("/tmp/input_file") / 1024**2 diff --git a/install/pyinstaller/pyinstaller.spec b/install/pyinstaller/pyinstaller.spec index 186b1d2..cc74d3d 100644 --- a/install/pyinstaller/pyinstaller.spec +++ b/install/pyinstaller/pyinstaller.spec @@ -143,16 +143,19 @@ if p == "Darwin": "CFBundleTypeName": "ODF Graphics Document", "CFBundleTypeRole": "Viewer", }, + # Commented MIMEs are not used in `file` and don't conform to the rules. + # Left them for just in case { "CFBundleTypeExtensions": ["hwp", "hwpx"], "CFBundleTypeIconFile": "../macos/document.icns", "CFBundleTypeMIMETypes": [ - "application/vnd.hancom.hwp", - "application/haansofthwp", + #"application/vnd.hancom.hwp", + #"application/haansofthwp", "application/x-hwp", - "application/vnd.hancom.hwpx", - "application/haansofthwpx", + #"application/vnd.hancom.hwpx", + #"application/haansofthwpx", "application/hwp+zip", + "application/x-hwp+zip", ], "CFBundleTypeName": "Hancom Office Document", "CFBundleTypeRole": "Viewer",