--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id F044A6DE0B44\r
+ for <notmuch@notmuchmail.org>; Tue, 30 Jun 2015 15:17:07 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.57\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.57 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
+ RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 1mi7kF5JRyST for <notmuch@notmuchmail.org>;\r
+ Tue, 30 Jun 2015 15:17:06 -0700 (PDT)\r
+Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com\r
+ [209.85.212.177])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id AF8B06DE0948\r
+ for <notmuch@notmuchmail.org>; Tue, 30 Jun 2015 15:17:05 -0700 (PDT)\r
+Received: by wicgi11 with SMTP id gi11so29392380wic.0\r
+ for <notmuch@notmuchmail.org>; Tue, 30 Jun 2015 15:17:03 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id;\r
+ bh=v2lE64GRA2/7MEmcMxXlftVLMSo3V0NLETjr6vldIXI=;\r
+ b=HSGJIFGFKbuEV0HsRB9VwwCcjlg8mFl4IWfzZo3ze+oimT4oFewTKOJXLEopBT7bi8\r
+ imQ53vY1ocv4RihqmUMFkSVeZreAamcsC1eDncI1lko1TrnxCs5vdmRpQPIixXiLW6JI\r
+ aO9/u8XvnVZgxZzT77GfkiJFE2ut+LKXkbi167n3d1N/u3mp57u0YxP0qN86QE6QrRXG\r
+ ZwGdYPBe8M5kKyibsRAaLrDWgfASkDjaR0fHXKkbN0qJqsFmYiYBU2agPyqaOXGhwBQg\r
+ XPVEvPWjRqaT766isAJICZ/8RASEij61HAGSqJnmNf362AjD7YK2ruvEEbQFEeCtTBQO\r
+ 5lcQ==\r
+X-Received: by 10.194.82.38 with SMTP id f6mr40203477wjy.16.1435702623246;\r
+ Tue, 30 Jun 2015 15:17:03 -0700 (PDT)\r
+Received: from localhost ([92.54.140.178])\r
+ by mx.google.com with ESMTPSA id jy6sm65857417wjc.4.2015.06.30.15.17.02\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Tue, 30 Jun 2015 15:17:02 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: show: let the user override the mime-type of an\r
+ attachment\r
+Date: Tue, 30 Jun 2015 23:16:25 +0100\r
+Message-Id: <1435702585-27363-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 2.1.4\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 30 Jun 2015 22:17:08 -0000\r
+\r
+This allows the user to override the mime-type of a part in the show\r
+buffer. This takes the simple option of displaying the part with the\r
+specified mime-type in its own buffer (in view mode). This avoids\r
+further complicating the part handling code.\r
+\r
+Bound to ". m" (i.e., m in the part map). Then the user can either\r
+enter a mime-type or press return for the default choice of\r
+text/plain.\r
+---\r
+\r
+Jani and dkg suggested something like this on irc. \r
+\r
+As mentioned in the commit message I have taken the simpler option of\r
+displaying the part in its own buffer: the part handling with lazy\r
+parts and hidden parts etc is really very complicated and fragile so I\r
+do not think it sensible to complicate it further for a relatively\r
+uncommon use case.\r
+\r
+It would be nice to have some completions for the mime-type but that\r
+could always be added later.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+ emacs/notmuch-show.el | 35 +++++++++++++++++++++++++++++------\r
+ 1 file changed, 29 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 2a53461..c674e9c 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -1354,6 +1354,7 @@ reset based on the original query."\r
+ (define-key map "v" 'notmuch-show-view-part)\r
+ (define-key map "o" 'notmuch-show-interactively-view-part)\r
+ (define-key map "|" 'notmuch-show-pipe-part)\r
++ (define-key map "m" 'notmuch-show-choose-mime-of-part)\r
+ (define-key map "?" 'notmuch-subkeymap-help)\r
+ map)\r
+ "Submap for part commands")\r
+@@ -2243,25 +2244,27 @@ omit --in-reply-to=<Message-Id>."\r
+ (insert (notmuch-get-bodypart-binary msg part process-crypto)))\r
+ buf))\r
+ \r
+-(defun notmuch-show-current-part-handle ()\r
++(defun notmuch-show-current-part-handle (&optional mime-type)\r
+ "Return an mm-handle for the part containing point.\r
+ \r
+ This creates a temporary buffer for the part's content; the\r
+-caller is responsible for killing this buffer as appropriate."\r
++caller is responsible for killing this buffer as appropriate. If\r
++MIME-TYPE is given then set the handle's mime-type to MIME-TYPE."\r
+ (let* ((msg (notmuch-show-get-message-properties))\r
+ (part (notmuch-show-get-part-properties))\r
+ (buf (notmuch-show-generate-part-buffer msg part))\r
+- (computed-type (plist-get part :computed-type))\r
++ (computed-type (or mime-type (plist-get part :computed-type)))\r
+ (filename (plist-get part :filename))\r
+ (disposition (if filename `(attachment (filename . ,filename)))))\r
+ (mm-make-handle buf (list computed-type) nil nil disposition)))\r
+ \r
+-(defun notmuch-show-apply-to-current-part-handle (fn)\r
++(defun notmuch-show-apply-to-current-part-handle (fn &optional mime-type)\r
+ "Apply FN to an mm-handle for the part containing point.\r
+ \r
+ This ensures that the temporary buffer created for the mm-handle\r
+-is destroyed when FN returns."\r
+- (let ((handle (notmuch-show-current-part-handle)))\r
++is destroyed when FN returns. If MIME-TYPE is given then force\r
++part to be treated as if it had that mime-type."\r
++ (let ((handle (notmuch-show-current-part-handle mime-type)))\r
+ ;; emacs 24.3+ puts stdout/stderr into the calling buffer so we\r
+ ;; call it from a temp-buffer, unless\r
+ ;; notmuch-show-attachment-debug is non-nil in which case we put\r
+@@ -2306,4 +2309,24 @@ is destroyed when FN returns."\r
+ (notmuch-show-apply-to-current-part-handle #'mm-pipe-part))\r
+ \r
+ \r
++(defun notmuch-show-internal-mm-display-part (handle)\r
++ "Use mm-display-part to display HANDLE in a new buffer.\r
++\r
++If the part is displayed in an external application then close\r
++the new buffer."\r
++ (let ((buf (get-buffer-create (generate-new-buffer-name\r
++ (concat " *notmuch-internal-part*")))))\r
++ (switch-to-buffer buf)\r
++ (if (eq (mm-display-part handle) 'external)\r
++ (kill-buffer buf)\r
++ (goto-char (point-min))\r
++ (set-buffer-modified-p nil)\r
++ (view-buffer buf 'kill-buffer-if-not-modified))))\r
++\r
++(defun notmuch-show-choose-mime-of-part (mime-type)\r
++ "Choose the mime type to use for displaying part"\r
++ (interactive\r
++ (list (read-string "Mime type to use (default text/plain): " nil nil "text/plain")))\r
++ (notmuch-show-apply-to-current-part-handle #'notmuch-show-internal-mm-display-part mime-type))\r
++\r
+ (provide 'notmuch-show)\r
+-- \r
+2.1.4\r
+\r