From: Mark Walters Date: Mon, 11 Jul 2016 07:49:19 +0000 (+0100) Subject: [PATCH v2] emacs: show: let the user override the mime-type of an attachment X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=407a0e8ebe2d43076bc20fdd59b9f421d7972711;p=notmuch-archives.git [PATCH v2] emacs: show: let the user override the mime-type of an attachment --- diff --git a/84/271ec84bf02c83f06bc153f4bff4bca0ffc468 b/84/271ec84bf02c83f06bc153f4bff4bca0ffc468 new file mode 100644 index 000000000..3d346cb4f --- /dev/null +++ b/84/271ec84bf02c83f06bc153f4bff4bca0ffc468 @@ -0,0 +1,177 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 82B946DE02AC + for ; Mon, 11 Jul 2016 00:49:37 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.155 +X-Spam-Level: +X-Spam-Status: No, score=0.155 tagged_above=-999 required=5 tests=[AWL=-0.275, + DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, + RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, + SPF_PASS=-0.001] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id kCP5OyYF-XIc for ; + Mon, 11 Jul 2016 00:49:29 -0700 (PDT) +Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com + [74.125.82.67]) by arlo.cworth.org (Postfix) with ESMTPS id DE3C36DE014D for + ; Mon, 11 Jul 2016 00:49:28 -0700 (PDT) +Received: by mail-wm0-f67.google.com with SMTP id o80so3337933wme.0 + for ; Mon, 11 Jul 2016 00:49:28 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id; + bh=TJTAoj7fv9RZunm5kRybJ2cb/1jKMhHsqDPtuatqut8=; + b=QTnothJM04P8Gikvna77kl9NqpcfhDifPrUhmFDFoNRF9oJz/ZyUIBNYcMjwO7zKoy + JxQZfclilj8BahN2OBhCSlCVGs5BiHTE353LUbrtTx2bOqH9CQnbi2jdZeSmgKkSj0nn + /n9QSMOEb5F7bStIk7GCarQDk/cSSWn2vLNcY55MxBKviRbMHhnJCYGqJ8Zo2DqqxH0M + iQyLDejKDyRLq5piCiGbSsfL5vL5JJj28VB7pgzpQD4MuunvcJ2Nz2ICVZOCMVef/lFz + 2tJQ5mjPr7VnBiEFyitn0Ry4ZJ14k2E3FSp3qHlmmO3N7k78S/hgTrR8uQ33SfZPOLhS + bFQA== +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id; + bh=TJTAoj7fv9RZunm5kRybJ2cb/1jKMhHsqDPtuatqut8=; + b=U79rJI4jsrBwK4A1ei/aD2xIAEn6T7PzVyD3wvJNoEANmgdTs1JwE7IYhgSWYx78We + +pOG0sGd9f4uTRGsqygEn0pLwKOhwJXPF0lzS/h+r3cW8ucOtuqqLhct4db8n5qW5x+i + AVdc35xb8iBXIYnoeE2aYpC30HdAYROCCadevyhQbHPFXX5gqhREmlVuJxwUrA2uzc9g + IEJgcwVzbVOLqdLE4EAFd95EsjEtMJ6gQuTIFtI5YCTwx0DUuV4TS+/8RqXEFB6ZKjEy + Ag0pcakiWcGtK1bSIO/say7Sn3mOc1j6Ye6llPZRc5uHWWiPfQP3oAfY1aZvhFkf38/Y + nlBg== +X-Gm-Message-State: + ALyK8tIJbzKc5KsBDu+QPxzZpaL6d61xqSPG//sWdNQX8YUCXGzSActE5EWAJHNl1HloHw== +X-Received: by 10.28.142.194 with SMTP id q185mr12554670wmd.6.1468223363883; + Mon, 11 Jul 2016 00:49:23 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by smtp.gmail.com with ESMTPSA id 12sm14352548wmj.19.2016.07.11.00.49.22 + (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Mon, 11 Jul 2016 00:49:23 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH v2] emacs: show: let the user override the mime-type of an + attachment +Date: Mon, 11 Jul 2016 08:49:19 +0100 +Message-Id: <1468223359-16736-1-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 2.1.4 +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 11 Jul 2016 07:49:37 -0000 + +This allows the user to override the mime-type of a part in the show +buffer. This takes the simple option of displaying the part with the +specified mime-type in its own buffer (in view mode). This avoids +further complicating the part handling code. + +Bound to ". m" (i.e., m in the part map). Then the user can either +enter a mime-type (with completion to all mime types that mailcap (and +thus notmuch) knows about, or press return for the default choice of +text/plain. +--- + +Hi + +This is (a rather delayed) version 2 of the patch +id:1435702585-27363-1-git-send-email-markwalters1009@gmail.com + +I have fixed bremner's review comment on the naming of the function, +and since it was easy I have added completion for mime-types. + +It is not heavily tested but seems to work. + +Best wishes + +Mark + +emacs/notmuch-show.el | 36 ++++++++++++++++++++++++++++++------ + 1 file changed, 30 insertions(+), 6 deletions(-) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index 6d3149b..06ba549 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -1403,6 +1403,7 @@ reset based on the original query." + (define-key map "v" 'notmuch-show-view-part) + (define-key map "o" 'notmuch-show-interactively-view-part) + (define-key map "|" 'notmuch-show-pipe-part) ++ (define-key map "m" 'notmuch-show-choose-mime-of-part) + (define-key map "?" 'notmuch-subkeymap-help) + map) + "Submap for part commands") +@@ -2337,25 +2338,27 @@ omit --in-reply-to=." + (insert (notmuch-get-bodypart-binary msg part process-crypto))) + buf)) + +-(defun notmuch-show-current-part-handle () ++(defun notmuch-show-current-part-handle (&optional mime-type) + "Return an mm-handle for the part containing point. + + This creates a temporary buffer for the part's content; the +-caller is responsible for killing this buffer as appropriate." ++caller is responsible for killing this buffer as appropriate. If ++MIME-TYPE is given then set the handle's mime-type to MIME-TYPE." + (let* ((msg (notmuch-show-get-message-properties)) + (part (notmuch-show-get-part-properties)) + (buf (notmuch-show-generate-part-buffer msg part)) +- (computed-type (plist-get part :computed-type)) ++ (computed-type (or mime-type (plist-get part :computed-type))) + (filename (plist-get part :filename)) + (disposition (if filename `(attachment (filename . ,filename))))) + (mm-make-handle buf (list computed-type) nil nil disposition))) + +-(defun notmuch-show-apply-to-current-part-handle (fn) ++(defun notmuch-show-apply-to-current-part-handle (fn &optional mime-type) + "Apply FN to an mm-handle for the part containing point. + + This ensures that the temporary buffer created for the mm-handle +-is destroyed when FN returns." +- (let ((handle (notmuch-show-current-part-handle))) ++is destroyed when FN returns. If MIME-TYPE is given then force ++part to be treated as if it had that mime-type." ++ (let ((handle (notmuch-show-current-part-handle mime-type))) + ;; emacs 24.3+ puts stdout/stderr into the calling buffer so we + ;; call it from a temp-buffer, unless + ;; notmuch-show-attachment-debug is non-nil in which case we put +@@ -2400,6 +2403,27 @@ is destroyed when FN returns." + (notmuch-show-apply-to-current-part-handle #'mm-pipe-part)) + + ++(defun notmuch-show--mm-display-part (handle) ++ "Use mm-display-part to display HANDLE in a new buffer. ++ ++If the part is displayed in an external application then close ++the new buffer." ++ (let ((buf (get-buffer-create (generate-new-buffer-name ++ (concat " *notmuch-internal-part*"))))) ++ (switch-to-buffer buf) ++ (if (eq (mm-display-part handle) 'external) ++ (kill-buffer buf) ++ (goto-char (point-min)) ++ (set-buffer-modified-p nil) ++ (view-buffer buf 'kill-buffer-if-not-modified)))) ++ ++(defun notmuch-show-choose-mime-of-part (mime-type) ++ "Choose the mime type to use for displaying part" ++ (interactive ++ (list (completing-read "Mime type to use (default text/plain): " ++ (mailcap-mime-types) nil nil nil nil "text/plain"))) ++ (notmuch-show-apply-to-current-part-handle #'notmuch-show--mm-display-part mime-type)) ++ + (provide 'notmuch-show) + + ;;; notmuch-show.el ends here +-- +2.1.4 +