From 2b6fc073fb6c344cb2d7a0377e9b337f68b563a4 Mon Sep 17 00:00:00 2001 From: William Tan Date: Wed, 12 Jan 2022 01:38:20 -0500 Subject: [PATCH] Better plaintext detection --- test/text.pgp | 3 +++ web/src/decrypt.rs | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 test/text.pgp diff --git a/test/text.pgp b/test/text.pgp new file mode 100644 index 0000000..d41de08 --- /dev/null +++ b/test/text.pgp @@ -0,0 +1,3 @@ +-----BEGIN PGP MESSAGE----- +-----END PGP MESSAGE----- + diff --git a/web/src/decrypt.rs b/web/src/decrypt.rs index aeb9afd..6ed1518 100644 --- a/web/src/decrypt.rs +++ b/web/src/decrypt.rs @@ -141,17 +141,17 @@ impl> ContentTypeExt for T { fn content_type(&self) -> ContentType { let mime_type = self.mime_type(); - if mime_type.starts_with("text/") || mime_type == "application/mbox" { + if mime_type.starts_with("image/") // check image first because svg is image + // application/x-riff is WebP + || mime_type == "application/x-riff" + { + ContentType::Image + } else if tree_magic_mini::match_u8("text/plain", self.as_ref()) { if std::str::from_utf8(self.as_ref()).is_ok() { ContentType::Text } else { ContentType::Unknown } - } else if mime_type.starts_with("image/") - // application/x-riff is WebP - || mime_type == "application/x-riff" - { - ContentType::Image } else if mime_type.starts_with("audio/") { ContentType::Audio } else if mime_type.starts_with("video/") @@ -197,4 +197,5 @@ mod content_type { test_content_type!(zip_is_zip, "archive.zip", ContentType::ZipArchive); test_content_type!(gzip_is_gzip, "image.png.gz", ContentType::GzipArchive); test_content_type!(binary_is_unknown, "omegaupload", ContentType::Unknown); + test_content_type!(pgp_is_text, "text.pgp", ContentType::Text); }