From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 3/6] emacs: maildir import message-do-fcc
Date: Sat, 3 Sep 2016 23:59:40 +0100 [thread overview]
Message-ID: <1472943583-4547-4-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1472943583-4547-1-git-send-email-markwalters1009@gmail.com>
We will need our own local copy of message-do-fcc so this commit just
copies the code straight from message.el so that it is easier to see
our local changes coming in the next commit.
---
emacs/notmuch-maildir-fcc.el | 64 ++++++++++++++++++++++++++++++++++++++++++++
emacs/notmuch-mua.el | 7 +++--
2 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 835258f..6fed11f 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -120,6 +120,70 @@ by notmuch-mua-mail"
subdir
(concat (notmuch-database-path) "/" subdir))))))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Functions for saving a message either using notmuch insert or file
+;; fcc. First functions common to the two cases.
+
+(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))
+ (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))
+ (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
+ ;; Pipe the article to the program in question.
+ (call-process-region (point-min) (point-max) shell-file-name
+ nil nil nil shell-command-switch
+ (match-string 1 file))
+ ;; Save the article.
+ (setq file (expand-file-name file))
+ (unless (file-exists-p (file-name-directory file))
+ (make-directory (file-name-directory file) t))
+ (if (and message-fcc-handler-function
+ (not (eq message-fcc-handler-function 'rmail-output)))
+ (funcall message-fcc-handler-function file)
+ ;; FIXME this option, rmail-output (also used if
+ ;; message-fcc-handler-function is nil) is not
+ ;; documented anywhere AFAICS. It should work in Emacs
+ ;; 23; I suspect it does not work in Emacs 22.
+ ;; FIXME I don't see the need for the two different cases here.
+ ;; mail-use-rfc822 makes no difference (in Emacs 23),and
+ ;; the third argument just controls \"Wrote file\" message.
+ (if (and (file-readable-p file) (mail-file-babyl-p file))
+ (rmail-output file 1 nil t)
+ (let ((mail-use-rfc822 t))
+ (rmail-output file 1 t t))))))
+ (kill-buffer (current-buffer))))))
+
(defun notmuch-fcc-handler (fcc-header)
"Store message with file fcc."
(notmuch-maildir-fcc-file-fcc fcc-header))
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index f3a4e5a..61b029b 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -33,6 +33,7 @@
(declare-function notmuch-show-insert-body "notmuch-show" (msg body depth))
(declare-function notmuch-fcc-header-setup "notmuch-maildir-fcc" ())
(declare-function notmuch-fcc-handler "notmuch-maildir-fcc" (destdir))
+(declare-function notmuch-maildir-message-do-fcc "notmuch-maildir-fcc" ())
;;
@@ -491,12 +492,14 @@ will be addressed to all recipients of the source message."
(defun notmuch-mua-send-and-exit (&optional arg)
(interactive "P")
(let ((message-fcc-handler-function #'notmuch-fcc-handler))
- (message-send-and-exit arg)))
+ (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
+ (message-send-and-exit arg))))
(defun notmuch-mua-send (&optional arg)
(interactive "P")
(let ((message-fcc-handler-function #'notmuch-fcc-handler))
- (message-send arg)))
+ (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
+ (message-send arg))))
(defun notmuch-mua-kill-buffer ()
(interactive)
--
2.1.4
next prev parent reply other threads:[~2016-09-03 22:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-03 22:59 [PATCH v2 0/6] Use notmuch insert for fcc Mark Walters
2016-09-03 22:59 ` [PATCH v2 1/6] emacs: notmuch-check-exit-status bugfix Mark Walters
2016-09-04 11:31 ` David Bremner
2016-09-03 22:59 ` [PATCH v2 2/6] emacs: maildir-fcc: prepare for use of notmuch insert Mark Walters
2016-09-03 22:59 ` Mark Walters [this message]
2016-09-03 22:59 ` [PATCH v2 4/6] emacs: simplify our local copy of message-do-fcc Mark Walters
2016-09-03 22:59 ` [PATCH v2 5/6] Modify " Mark Walters
2016-09-03 22:59 ` [PATCH v2 6/6] emacs: maildir: add the actual insert code Mark Walters
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=1472943583-4547-4-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).