--- /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 7C7B06DE02DB\r
+ for <notmuch@notmuchmail.org>; Fri, 10 Jun 2016 16:03:57 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.337\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.337 tagged_above=-999 required=5 tests=[AWL=0.233,\r
+ DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7,\r
+ RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001]\r
+ 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 wtglnB6TC_gw for <notmuch@notmuchmail.org>;\r
+ Fri, 10 Jun 2016 16:03:49 -0700 (PDT)\r
+Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com\r
+ [74.125.82.67]) by arlo.cworth.org (Postfix) with ESMTPS id A4D1D6DE02B0 for\r
+ <notmuch@notmuchmail.org>; Fri, 10 Jun 2016 16:03:11 -0700 (PDT)\r
+Received: by mail-wm0-f67.google.com with SMTP id n184so1714263wmn.1\r
+ for <notmuch@notmuchmail.org>; Fri, 10 Jun 2016 16:03:11 -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:in-reply-to:references;\r
+ bh=pp1RSXCfv2ceqixYzO11izXYsYYj4rhW8xqXg1BdG1E=;\r
+ b=yXqyXhsOkAD+0K9VifqfFu5f3JgvBgwIgBORmpp2Qbo2wdkW3iTXXMOecp7q0hBw4r\r
+ Iv5EO/Xup33CQWSqZtJnyJbsnnx/bHwAqmndFSF9UX1EMuElR9GqtENr1P5fTwSm9o38\r
+ nEIGQyiNXaqZgARNwibRMT0uaE81lcB+yaff8R1ElhLYdwJUGhejE0iSAPtj+jI6mLhD\r
+ DqJVOa/2e8lP8k13SQ6MOb926dv9se7v8E2jCyc8HqwcUEWaUCnZF6pGBBT07sYgrxNw\r
+ +q38Yy/6jhgNNnK9P7L/m8Z/0yOKftknDIDKROsX7t/RnhyEMZix7CMo+Y9PDiZcfOUU\r
+ 8UUw==\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references;\r
+ bh=pp1RSXCfv2ceqixYzO11izXYsYYj4rhW8xqXg1BdG1E=;\r
+ b=Dqs/E7dLSJP71jQQr1hQxzG442NmovKPkUwbK4mA33ZO90Wzc1PaYci2sbVhMlkXbH\r
+ XxqgXV9pbXP29xuWs5GEirmN/EUbbgBuQ8X5V85WIvBC71/F18lVKFwg9nMCtE6YK1DW\r
+ hwgaih/1Vo6Tt5raCAdUsion/YLffa+WsY850UQ4OsdvetwzzGS+sU8E+/23f7dt3ytO\r
+ a/e+64037s7wpm5Lhe0bJP0JBC4yzMMDCHIW/GmorSfwgZEwMxyJJq43tJ+eb2xrlU/q\r
+ Yo9nUxNgcTCoOyHdn2+TLqQESbrnhOSzhPAFb35saD8wjV/eid+TwOEUao+ZippgYk9o\r
+ aeiQ==\r
+X-Gm-Message-State:\r
+ ALyK8tL0V4OAHdR+BpaEZPMWT6x0uIJYYcYO3DDcDb0orvHkjt9ZavLDMTmuHhWJKsvW5A==\r
+X-Received: by 10.28.4.7 with SMTP id 7mr1093599wme.77.1465599790321;\r
+ Fri, 10 Jun 2016 16:03:10 -0700 (PDT)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by smtp.gmail.com with ESMTPSA id s10sm14487020wjt.29.2016.06.10.16.03.09\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Fri, 10 Jun 2016 16:03:09 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 5/6] Modify our local copy of message-do-fcc\r
+Date: Sat, 11 Jun 2016 00:02:51 +0100\r
+Message-Id: <1465599772-10297-6-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1465599772-10297-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1465599772-10297-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 10 Jun 2016 23:03:57 -0000\r
+\r
+Since we also need to use this code for the draft handling we split\r
+message-do-fcc into convenient sub-chunks (functions or macros as\r
+appropriate).\r
+---\r
+ emacs/notmuch-maildir-fcc.el | 71 ++++++++++++++++++++++++++------------------\r
+ 1 file changed, 42 insertions(+), 29 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el\r
+index 7b3f232..fc645c5 100644\r
+--- a/emacs/notmuch-maildir-fcc.el\r
++++ b/emacs/notmuch-maildir-fcc.el\r
+@@ -124,43 +124,56 @@ by notmuch-mua-mail"\r
+ ;; Functions for saving a message either using notmuch insert or file\r
+ ;; fcc. First functions common to the two cases.\r
+ \r
++(defmacro with-temporary-notmuch-message-buffer (&rest body)\r
++ "Set-up a temporary copy of the current message-mode buffer."\r
++ `(let ((case-fold-search t)\r
++ (buf (current-buffer))\r
++ (mml-externalize-attachments message-fcc-externalize-attachments))\r
++ (with-current-buffer (get-buffer-create " *message temp*")\r
++ (erase-buffer)\r
++ (insert-buffer-substring buf)\r
++ ,@body)))\r
++\r
++(defun notmuch-maildir-setup-message-for-saving ()\r
++ "Setup message for saving. Should be called on a temporary copy.\r
++\r
++This is taken from the function message-do-fcc."\r
++ (message-encode-message-body)\r
++ (save-restriction\r
++ (message-narrow-to-headers)\r
++ (let ((mail-parse-charset message-default-charset)\r
++ (rfc2047-header-encoding-alist\r
++ (cons '("Newsgroups" . default)\r
++ rfc2047-header-encoding-alist)))\r
++ (mail-encode-encoded-word-buffer)))\r
++ (goto-char (point-min))\r
++ (when (re-search-forward\r
++ (concat "^" (regexp-quote mail-header-separator) "$")\r
++ nil t)\r
++ (replace-match "" t t )))\r
++\r
+ (defun notmuch-maildir-message-do-fcc ()\r
+ "Process Fcc headers in the current buffer.\r
+ \r
+-This is a direct copy from message-mode's message-do-fcc."\r
+- (let ((case-fold-search t)\r
+- (buf (current-buffer))\r
+- list file\r
+- (mml-externalize-attachments message-fcc-externalize-attachments))\r
++This is a rearranged version of message mode's message-do-fcc."\r
++ (let (list file)\r
+ (save-excursion\r
+ (save-restriction\r
+ (message-narrow-to-headers)\r
+ (setq file (message-fetch-field "fcc" t)))\r
+ (when file\r
+- (set-buffer (get-buffer-create " *message temp*"))\r
+- (erase-buffer)\r
+- (insert-buffer-substring buf)\r
+- (message-encode-message-body)\r
+- (save-restriction\r
+- (message-narrow-to-headers)\r
+- (while (setq file (message-fetch-field "fcc" t))\r
+- (push file list)\r
+- (message-remove-header "fcc" nil t))\r
+- (let ((mail-parse-charset message-default-charset)\r
+- (rfc2047-header-encoding-alist\r
+- (cons '("Newsgroups" . default)\r
+- rfc2047-header-encoding-alist)))\r
+- (mail-encode-encoded-word-buffer)))\r
+- (goto-char (point-min))\r
+- (when (re-search-forward\r
+- (concat "^" (regexp-quote mail-header-separator) "$")\r
+- nil t)\r
+- (replace-match "" t t ))\r
+- ;; Process FCC operations.\r
+- (while list\r
+- (setq file (pop list))\r
+- (notmuch-fcc-handler file))\r
+- (kill-buffer (current-buffer))))))\r
++ (with-temporary-notmuch-message-buffer\r
++ (save-restriction\r
++ (message-narrow-to-headers)\r
++ (while (setq file (message-fetch-field "fcc" t))\r
++ (push file list)\r
++ (message-remove-header "fcc" nil t)))\r
++ (notmuch-maildir-setup-message-for-saving)\r
++ ;; Process FCC operations.\r
++ (while list\r
++ (setq file (pop list))\r
++ (notmuch-fcc-handler file))\r
++ (kill-buffer (current-buffer)))))))\r
+ \r
+ (defun notmuch-fcc-handler (fcc-header)\r
+ "Store message with file fcc."\r
+-- \r
+2.1.4\r
+\r