From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 5/6] Modify our local copy of message-do-fcc
Date: Sat, 11 Jun 2016 00:02:51 +0100 [thread overview]
Message-ID: <1465599772-10297-6-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1465599772-10297-1-git-send-email-markwalters1009@gmail.com>
Since we also need to use this code for the draft handling we split
message-do-fcc into convenient sub-chunks (functions or macros as
appropriate).
---
emacs/notmuch-maildir-fcc.el | 71 ++++++++++++++++++++++++++------------------
1 file changed, 42 insertions(+), 29 deletions(-)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 7b3f232..fc645c5 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -124,43 +124,56 @@ by notmuch-mua-mail"
;; Functions for saving a message either using notmuch insert or file
;; fcc. First functions common to the two cases.
+(defmacro with-temporary-notmuch-message-buffer (&rest body)
+ "Set-up a temporary copy of the current message-mode buffer."
+ `(let ((case-fold-search t)
+ (buf (current-buffer))
+ (mml-externalize-attachments message-fcc-externalize-attachments))
+ (with-current-buffer (get-buffer-create " *message temp*")
+ (erase-buffer)
+ (insert-buffer-substring buf)
+ ,@body)))
+
+(defun notmuch-maildir-setup-message-for-saving ()
+ "Setup message for saving. Should be called on a temporary copy.
+
+This is taken from the function message-do-fcc."
+ (message-encode-message-body)
+ (save-restriction
+ (message-narrow-to-headers)
+ (let ((mail-parse-charset message-default-charset)
+ (rfc2047-header-encoding-alist
+ (cons '("Newsgroups" . default)
+ rfc2047-header-encoding-alist)))
+ (mail-encode-encoded-word-buffer)))
+ (goto-char (point-min))
+ (when (re-search-forward
+ (concat "^" (regexp-quote mail-header-separator) "$")
+ nil t)
+ (replace-match "" t t )))
+
(defun notmuch-maildir-message-do-fcc ()
"Process Fcc headers in the current buffer.
-This is a direct copy from message-mode's message-do-fcc."
- (let ((case-fold-search t)
- (buf (current-buffer))
- list file
- (mml-externalize-attachments message-fcc-externalize-attachments))
+This is a rearranged version of message mode's message-do-fcc."
+ (let (list file)
(save-excursion
(save-restriction
(message-narrow-to-headers)
(setq file (message-fetch-field "fcc" t)))
(when file
- (set-buffer (get-buffer-create " *message temp*"))
- (erase-buffer)
- (insert-buffer-substring buf)
- (message-encode-message-body)
- (save-restriction
- (message-narrow-to-headers)
- (while (setq file (message-fetch-field "fcc" t))
- (push file list)
- (message-remove-header "fcc" nil t))
- (let ((mail-parse-charset message-default-charset)
- (rfc2047-header-encoding-alist
- (cons '("Newsgroups" . default)
- rfc2047-header-encoding-alist)))
- (mail-encode-encoded-word-buffer)))
- (goto-char (point-min))
- (when (re-search-forward
- (concat "^" (regexp-quote mail-header-separator) "$")
- nil t)
- (replace-match "" t t ))
- ;; Process FCC operations.
- (while list
- (setq file (pop list))
- (notmuch-fcc-handler file))
- (kill-buffer (current-buffer))))))
+ (with-temporary-notmuch-message-buffer
+ (save-restriction
+ (message-narrow-to-headers)
+ (while (setq file (message-fetch-field "fcc" t))
+ (push file list)
+ (message-remove-header "fcc" nil t)))
+ (notmuch-maildir-setup-message-for-saving)
+ ;; Process FCC operations.
+ (while list
+ (setq file (pop list))
+ (notmuch-fcc-handler file))
+ (kill-buffer (current-buffer)))))))
(defun notmuch-fcc-handler (fcc-header)
"Store message with file fcc."
--
2.1.4
next prev parent reply other threads:[~2016-06-10 23:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-10 23:02 [PATCH 0/6] Use notmuch insert for fcc Mark Walters
2016-06-10 23:02 ` [PATCH 1/6] emacs: notmuch-check-exit-status bugfix Mark Walters
2016-06-10 23:02 ` [PATCH 2/6] emacs: maildir-fcc: prepare for use of notmuch insert Mark Walters
2016-06-10 23:02 ` [PATCH 3/6] emacs: maildir import message-do-fcc Mark Walters
2016-06-10 23:02 ` [PATCH 4/6] emacs: simplify our local copy of message-do-fcc Mark Walters
2016-09-03 20:20 ` David Bremner
2016-09-03 21:42 ` Mark Walters
2016-09-03 22:36 ` David Bremner
2016-06-10 23:02 ` Mark Walters [this message]
2016-09-03 20:33 ` [PATCH 5/6] Modify " David Bremner
2016-09-03 21:39 ` Mark Walters
2016-09-03 22:37 ` David Bremner
2016-06-10 23:02 ` [PATCH 6/6] emacs: maildir: add the actual insert code Mark Walters
2016-09-03 20:43 ` [PATCH 0/6] Use notmuch insert for fcc David Bremner
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=1465599772-10297-6-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).