[PATCH] emacs: Re-arrange message sending code
authorDavid Edmondson <dme@dme.org>
Thu, 15 Apr 2010 15:50:27 +0000 (16:50 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:39 +0000 (09:36 -0800)
73/8061a7a98102c00ed3a93e4cfb57786821b0c6 [new file with mode: 0644]

diff --git a/73/8061a7a98102c00ed3a93e4cfb57786821b0c6 b/73/8061a7a98102c00ed3a93e4cfb57786821b0c6
new file mode 100644 (file)
index 0000000..27a62e9
--- /dev/null
@@ -0,0 +1,295 @@
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 5F9C54196F0\r
+       for <notmuch@notmuchmail.org>; Thu, 15 Apr 2010 08:50:39 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.9\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
+       tests=[BAYES_00=-1.9] autolearn=ham\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id kmoQPv+xjIEB for <notmuch@notmuchmail.org>;\r
+       Thu, 15 Apr 2010 08:50:38 -0700 (PDT)\r
+Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com\r
+       [74.125.82.181])\r
+       by olra.theworths.org (Postfix) with ESMTP id A6257431FC1\r
+       for <notmuch@notmuchmail.org>; Thu, 15 Apr 2010 08:50:37 -0700 (PDT)\r
+Received: by wyj26 with SMTP id 26so728920wyj.26\r
+       for <notmuch@notmuchmail.org>; Thu, 15 Apr 2010 08:50:37 -0700 (PDT)\r
+Received: by 10.216.168.8 with SMTP id j8mr214660wel.192.1271346636902;\r
+       Thu, 15 Apr 2010 08:50:36 -0700 (PDT)\r
+Received: from ut.hh.sledj.net (gmp-ea-fw-1b.sun.com [192.18.8.1])\r
+       by mx.google.com with ESMTPS id x14sm12770271wbs.0.2010.04.15.08.50.29\r
+       (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+       Thu, 15 Apr 2010 08:50:30 -0700 (PDT)\r
+Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
+       id 34ECA5941D9; Thu, 15 Apr 2010 16:50:32 +0100 (BST)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: Re-arrange message sending code\r
+Date: Thu, 15 Apr 2010 16:50:27 +0100\r
+Message-Id: <1271346627-25310-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.0\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://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: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 15 Apr 2010 15:50:39 -0000\r
+\r
+Define a new `mail-user-agent' (`notmuch-user-agent') and use it by\r
+default. Re-arrange various routines that send mail to use this\r
+(compose, reply, forward). Insert a `User-Agent:' header by default.\r
+---\r
+ emacs/notmuch-hello.el |    2 +\r
+ emacs/notmuch-mua.el   |   94 ++++++++++++++++++++++++++++++++++++++++++++++++\r
+ emacs/notmuch-show.el  |    5 ++-\r
+ emacs/notmuch.el       |   43 ++++++++++++++++------\r
+ 4 files changed, 130 insertions(+), 14 deletions(-)\r
+ create mode 100644 emacs/notmuch-mua.el\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index c49a35f..83586f2 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -25,6 +25,7 @@\r
\r
+ (require 'notmuch-lib)\r
+ (require 'notmuch)\r
++(require 'notmuch-mua)\r
\r
+ (declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line))\r
+ (declare-function notmuch-folder-count "notmuch" (search))\r
+@@ -314,6 +315,7 @@ diagonal."\r
\r
+   (use-local-map widget-keymap)\r
+   (local-set-key "=" 'notmuch-hello-update)\r
++  (local-set-key "m" 'notmuch-mua-mail)\r
+   (local-set-key "q" '(lambda () (interactive) (kill-buffer (current-buffer))))\r
+   (local-set-key "s" 'notmuch-hello-goto-search)\r
\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+new file mode 100644\r
+index 0000000..c8a8743\r
+--- /dev/null\r
++++ b/emacs/notmuch-mua.el\r
+@@ -0,0 +1,94 @@\r
++;; notmuch-mua.el --- emacs style mail-user-agent\r
++;;\r
++;; Copyright © David Edmondson\r
++;;\r
++;; This file is part of Notmuch.\r
++;;\r
++;; Notmuch is free software: you can redistribute it and/or modify it\r
++;; under the terms of the GNU General Public License as published by\r
++;; the Free Software Foundation, either version 3 of the License, or\r
++;; (at your option) any later version.\r
++;;\r
++;; Notmuch is distributed in the hope that it will be useful, but\r
++;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
++;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
++;; General Public License for more details.\r
++;;\r
++;; You should have received a copy of the GNU General Public License\r
++;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
++;;\r
++;; Authors: David Edmondson <dme@dme.org>\r
++\r
++(require 'message)\r
++\r
++;;\r
++\r
++(defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)\r
++  "Hook run before sending messages."\r
++  :group 'notmuch\r
++  :type 'hook)\r
++\r
++(defcustom notmuch-mua-user-agent-function 'notmuch-mua-user-agent\r
++  "Function used to generate a `User-Agent:' string. If this is\r
++`nil' then no `User-Agent:' will be generated."\r
++  :group 'notmuch\r
++  :type 'function)\r
++\r
++;;\r
++\r
++(defun notmuch-mua-user-agent ()\r
++  "Generate a `User-Agent:' string suitable for notmuch."\r
++  (concat\r
++   ;; Trim off the trailing newline.\r
++   (substring (shell-command-to-string\r
++             (concat notmuch-command " --version"))\r
++            0 -1)\r
++   " (Emacs " emacs-version "/"\r
++   system-configuration ")"))\r
++\r
++(defun notmuch-mua-forward-message ()\r
++  (message-forward)\r
++  (save-excursion\r
++    (when notmuch-mua-user-agent-function\r
++      (let ((user-agent (funcall notmuch-mua-user-agent-function)))\r
++      (when (not (string= "" user-agent))\r
++        (message-add-header (format "User-Agent: %s" user-agent)))))\r
++    (message-sort-headers)\r
++    (message-hide-headers))\r
++  (set-buffer-modified-p nil))\r
++\r
++(defun notmuch-mua-mail (&optional to subject other-headers continue\r
++                                 switch-function yank-action send-actions)\r
++  (interactive)\r
++\r
++  (when notmuch-mua-user-agent-function\r
++    (let ((user-agent (funcall notmuch-mua-user-agent-function)))\r
++      (when (not (string= "" user-agent))\r
++      (push (cons "User-Agent" user-agent) other-headers))))\r
++\r
++  (message-mail to subject other-headers continue\r
++              switch-function yank-action send-actions)\r
++  (message-hide-headers))\r
++\r
++(defun notmuch-mua-send-and-exit (&optional arg)\r
++  (interactive "P")\r
++  (message-send-and-exit arg))\r
++\r
++(defun notmuch-mua-kill-buffer ()\r
++  (interactive)\r
++  (message-kill-buffer))\r
++\r
++(defun notmuch-mua-message-send-hook ()\r
++  "The default function used for `notmuch-mua-send-hook', this\r
++simply runs the corresponding `message-mode' hook functions."\r
++  (run-hooks 'message-send-hook))\r
++\r
++;;\r
++\r
++(define-mail-user-agent 'notmuch-user-agent\r
++  'notmuch-mua-mail 'notmuch-mua-send-and-exit\r
++  'notmuch-mua-kill-buffer 'notmuch-mua-send-hook)\r
++\r
++;;\r
++\r
++(provide 'notmuch-mua)\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 54d1c48..d1b0f1a 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -30,6 +30,7 @@\r
+ (require 'notmuch-lib)\r
+ (require 'notmuch-query)\r
+ (require 'notmuch-wash)\r
++(require 'notmuch-mua)\r
\r
+ (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))\r
+ (declare-function notmuch-reply "notmuch" (query-string))\r
+@@ -519,7 +520,7 @@ function is used. "\r
+       (define-key map (kbd "M-TAB") 'notmuch-show-previous-button)\r
+       (define-key map (kbd "TAB") 'notmuch-show-next-button)\r
+       (define-key map "s" 'notmuch-search)\r
+-      (define-key map "m" 'message-mail)\r
++      (define-key map "m" 'notmuch-mua-mail)\r
+       (define-key map "f" 'notmuch-show-forward-message)\r
+       (define-key map "r" 'notmuch-show-reply)\r
+       (define-key map "|" 'notmuch-show-pipe-message)\r
+@@ -835,7 +836,7 @@ any effects from previous calls to\r
+   "Forward the current message."\r
+   (interactive)\r
+   (with-current-notmuch-show-message\r
+-   (message-forward)))\r
++   (notmuch-mua-forward-message)))\r
\r
+ (defun notmuch-show-next-message ()\r
+   "Show the next message."\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index b9a0a3e..56bb27f 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -53,6 +53,7 @@\r
\r
+ (require 'notmuch-lib)\r
+ (require 'notmuch-show)\r
++(require 'notmuch-mua)\r
\r
+ (defcustom notmuch-search-authors-width 20\r
+   "Number of columns to use to display authors in a notmuch-search buffer."\r
+@@ -117,15 +118,33 @@ For example:\r
+    mm-handle))\r
\r
+ (defun notmuch-reply (query-string)\r
+-  (switch-to-buffer (generate-new-buffer "notmuch-draft"))\r
+-  (call-process notmuch-command nil t nil "reply" query-string)\r
+-  (message-insert-signature)\r
+-  (goto-char (point-min))\r
+-  (if (re-search-forward "^$" nil t)\r
+-      (progn\r
+-      (insert "--text follows this line--")\r
+-      (forward-line)))\r
+-  (message-mode))\r
++  (let (headers body)\r
++    ;; This make assumptions about the output of `notmuch reply', but\r
++    ;; really only that the headers come first followed by a blank\r
++    ;; line and then the body.\r
++    (with-temp-buffer\r
++      (call-process notmuch-command nil t nil "reply" query-string)\r
++      (goto-char (point-min))\r
++      (if (re-search-forward "^$" nil t)\r
++        (save-excursion\r
++          (save-restriction\r
++            (narrow-to-region (point-min) (point))\r
++            (goto-char (point-min))\r
++            (setq headers (mail-header-extract)))))\r
++      (forward-line 1)\r
++      (setq body (buffer-substring (point) (point-max))))\r
++    (notmuch-mua-mail (mail-header 'to headers)\r
++                    (mail-header 'subject headers)\r
++                    (loop for header in headers\r
++                          if (not (or (eq 'to (car header))\r
++                                      (eq 'subject (car header))))\r
++                          collect header))\r
++    (message-sort-headers)\r
++    (message-hide-headers)\r
++    (save-excursion\r
++      (goto-char (point-max))\r
++      (insert body))\r
++    (set-buffer-modified-p nil)))\r
\r
+ (defun notmuch-documentation-first-line (symbol)\r
+   "Return the first line of the documentation string for SYMBOL."\r
+@@ -216,7 +235,7 @@ For a mouse binding, return nil."\r
+     (define-key map "p" 'notmuch-search-previous-thread)\r
+     (define-key map "n" 'notmuch-search-next-thread)\r
+     (define-key map "r" 'notmuch-search-reply-to-thread)\r
+-    (define-key map "m" 'message-mail)\r
++    (define-key map "m" 'notmuch-mua-mail)\r
+     (define-key map "s" 'notmuch-search)\r
+     (define-key map "o" 'notmuch-search-toggle-order)\r
+     (define-key map "=" 'notmuch-search-refresh-view)\r
+@@ -767,14 +786,14 @@ current search results AND that are tagged with the given tag."\r
+   (interactive)\r
+   (notmuch-search "tag:inbox" notmuch-search-oldest-first))\r
\r
+-(setq mail-user-agent 'message-user-agent)\r
++(setq mail-user-agent 'notmuch-user-agent)\r
\r
+ (defvar notmuch-folder-mode-map\r
+   (let ((map (make-sparse-keymap)))\r
+     (define-key map "?" 'notmuch-help)\r
+     (define-key map "x" 'kill-this-buffer)\r
+     (define-key map "q" 'kill-this-buffer)\r
+-    (define-key map "m" 'message-mail)\r
++    (define-key map "m" 'notmuch-mua-mail)\r
+     (define-key map "e" 'notmuch-folder-show-empty-toggle)\r
+     (define-key map ">" 'notmuch-folder-last)\r
+     (define-key map "<" 'notmuch-folder-first)\r
+-- \r
+1.7.0\r
+\r