unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH] emacs: show: allow user to insert rfc822 parts as messages
Date: Fri, 20 May 2016 12:38:15 +0100	[thread overview]
Message-ID: <1463744295-12533-1-git-send-email-markwalters1009@gmail.com> (raw)

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

             reply	other threads:[~2016-05-20 11:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-20 11:38 Mark Walters [this message]
2016-05-23 12:24 ` [PATCH] emacs: show: allow user to insert rfc822 parts as messages David Edmondson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1463744295-12533-1-git-send-email-markwalters1009@gmail.com \
    --to=markwalters1009@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).