From 62c6f561a6105375d940dcdc1048a9b26454931d Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Mon, 14 Dec 2020 12:23:26 +0200 Subject: [PATCH] Fix missing PDF attachment MIME type on opening --- chrome/content/zotero/zoteroPane.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 431f5e214a..655e21ae7d 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -4075,9 +4075,21 @@ var ZoteroPane = new function() } var launchFile = async (path, contentType, itemID) => { + // Fix blank PDF attachment MIME type + if (!contentType) { + let item = await Zotero.Items.getAsync(itemID); + let path = await item.getFilePathAsync(); + let type = 'application/pdf'; + if (Zotero.MIME.sniffForMIMEType(await Zotero.File.getSample(path)) == type) { + contentType = type; + item.attachmentContentType = type; + await item.saveTx(); + } + } // Custom PDF handler if (contentType === 'application/pdf') { this.viewPDF(itemID, event.shiftKey); + // TODO: Still leave an option to use an external PDF viewer return; let pdfHandler = Zotero.Prefs.get("fileHandler.pdf"); if (pdfHandler) {