unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: show: allow user to insert rfc822 parts as messages
@ 2016-05-20 11:38 Mark Walters
  2016-05-23 12:24 ` David Edmondson
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Walters @ 2016-05-20 11:38 UTC (permalink / raw)
  To: notmuch

This adds a part-handler function that uses notmuch-insert to insert
an rfc822 part as a message in its own right. This allows the user to
reply directly to that message.
---

I receive quite a lot of forwarded messages which include the original
message as an rfc822 part, and have used this for quite some time
without any problems.

Best wishes

Mark


emacs/notmuch-show.el | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 5d9b7b4..de41a8f 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -141,6 +141,11 @@ indentation."
 		 (const :tag "View interactively"
 			notmuch-show-interactively-view-part)))
 
+(defcustom notmuch-show-part-insert-folder ""
+  "Default folder to insert rfc822 parts"
+  :group 'notmuch-show
+  :type 'string)
+
 (defcustom notmuch-show-only-matching-messages nil
   "Only matching messages are shown by default."
   :type 'boolean
@@ -1403,6 +1408,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 "i" 'notmuch-show-insert-part)
     (define-key map "?" 'notmuch-subkeymap-help)
     map)
   "Submap for part commands")
@@ -2330,11 +2336,13 @@ caller is responsible for killing this buffer as appropriate."
 	 (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 &rest args)
   "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."
+Any ARGS are passed to the function FN as arguments after the mm-handle.
+
+This function ensures that the temporary buffer created for the
+mm-handle is destroyed when FN returns."
   (let ((handle (notmuch-show-current-part-handle)))
     ;; emacs 24.3+ puts stdout/stderr into the calling buffer so we
     ;; call it from a temp-buffer, unless
@@ -2343,9 +2351,9 @@ is destroyed when FN returns."
     (unwind-protect
 	(if notmuch-show-attachment-debug
 	    (with-current-buffer (generate-new-buffer " *notmuch-part*")
-	      (funcall fn handle))
+	      (apply fn handle args))
 	  (with-temp-buffer
-	    (funcall fn handle)))
+	    (apply fn handle args)))
       (kill-buffer (mm-handle-buffer handle)))))
 
 (defun notmuch-show-part-button-default (&optional button)
@@ -2379,6 +2387,17 @@ is destroyed when FN returns."
   (interactive)
   (notmuch-show-apply-to-current-part-handle #'mm-pipe-part))
 
+(defun notmuch-show-insert-part ()
+  "If the current part is rfc822 then insert into the mailstore"
+  (interactive)
+  (let* ((part (notmuch-show-get-part-properties))
+	 (computed-type (plist-get part :computed-type)))
+    (if (notmuch-match-content-type computed-type "message/rfc822")
+	(let* ((folder (read-from-minibuffer "Folder to save part to: "
+					     notmuch-show-part-insert-folder))
+	       (cmd (concat notmuch-command " insert --folder=" folder)))
+	  (notmuch-show-apply-to-current-part-handle #'mm-pipe-part cmd))
+      (message "Not a message/rfc822 part."))))
 
 (provide 'notmuch-show)
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-23 12:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-20 11:38 [PATCH] emacs: show: allow user to insert rfc822 parts as messages Mark Walters
2016-05-23 12:24 ` David Edmondson

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).