[PATCH] emacs: Re-arrange message sending code
authorDavid Edmondson <dme@dme.org>
Thu, 22 Apr 2010 09:03:32 +0000 (10:03 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:46 +0000 (09:36 -0800)
57/1d3125be033b8b7d6dfc3d0e8439f304d5c14e [new file with mode: 0644]

diff --git a/57/1d3125be033b8b7d6dfc3d0e8439f304d5c14e b/57/1d3125be033b8b7d6dfc3d0e8439f304d5c14e
new file mode 100644 (file)
index 0000000..fa0a263
--- /dev/null
@@ -0,0 +1,374 @@
+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 D7F1D4196F2\r
+       for <notmuch@notmuchmail.org>; Thu, 22 Apr 2010 02:03:38 -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 O9sQ1hHT86iU for <notmuch@notmuchmail.org>;\r
+       Thu, 22 Apr 2010 02:03:37 -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 F0774431FC1\r
+       for <notmuch@notmuchmail.org>; Thu, 22 Apr 2010 02:03:36 -0700 (PDT)\r
+Received: by wyf23 with SMTP id 23so540793wyf.26\r
+       for <notmuch@notmuchmail.org>; Thu, 22 Apr 2010 02:03:36 -0700 (PDT)\r
+Received: by 10.216.87.66 with SMTP id x44mr120881wee.183.1271927016146;\r
+       Thu, 22 Apr 2010 02:03:36 -0700 (PDT)\r
+Received: from ut.hh.sledj.net (host83-217-165-81.dsl.vispa.com\r
+       [83.217.165.81])\r
+       by mx.google.com with ESMTPS id z3sm74111044wbs.10.2010.04.22.02.03.34\r
+       (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+       Thu, 22 Apr 2010 02:03:35 -0700 (PDT)\r
+Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
+       id 76A03594163; Thu, 22 Apr 2010 10:03:33 +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, 22 Apr 2010 10:03:32 +0100\r
+Message-Id: <1271927012-10062-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, 22 Apr 2010 09:03: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/Makefile.local   |    5 +-\r
+ emacs/notmuch-hello.el |    2 +\r
+ emacs/notmuch-lib.el   |   16 ++++++\r
+ emacs/notmuch-mua.el   |  133 ++++++++++++++++++++++++++++++++++++++++++++++++\r
+ emacs/notmuch-show.el  |    8 ++--\r
+ emacs/notmuch.el       |   20 ++-----\r
+ 6 files changed, 163 insertions(+), 21 deletions(-)\r
+ create mode 100644 emacs/notmuch-mua.el\r
+\r
+diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
+index 6486d90..e5013b3 100644\r
+--- a/emacs/Makefile.local\r
++++ b/emacs/Makefile.local\r
+@@ -6,8 +6,9 @@ emacs_sources := \\r
+       $(dir)/notmuch.el \\r
+       $(dir)/notmuch-query.el \\r
+       $(dir)/notmuch-show.el \\r
+-      $(dir)/notmuch-wash.el\r
+-      $(dir)/notmuch-hello.el\r
++      $(dir)/notmuch-wash.el \\r
++      $(dir)/notmuch-hello.el \\r
++      $(dir)/notmuch-mua.el\r
\r
+ emacs_images := \\r
+       $(dir)/notmuch-logo.png\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 13de6f8..fa6433e 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
+@@ -335,6 +336,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
+   (local-set-key "v" '(lambda () (interactive)\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 274d7ec..47c74b9 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -33,6 +33,22 @@\r
+   :type '(alist :key-type (string) :value-type (string))\r
+   :group 'notmuch)\r
\r
++;;\r
++\r
++(defun notmuch-version ()\r
++  "Return a string with the notmuch version number."\r
++  (let ((long-string\r
++       ;; Trim off the trailing newline.\r
++       (substring (shell-command-to-string\r
++                   (concat notmuch-command " --version"))\r
++                  0 -1)))\r
++    (if (string-match "^notmuch\\( version\\)? \\(.*\\)$"\r
++                    long-string)\r
++      (match-string 2 long-string)\r
++      "unknown")))\r
++\r
++;;\r
++\r
+ ;; XXX: This should be a generic function in emacs somewhere, not\r
+ ;; here.\r
+ (defun point-invisible-p ()\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+new file mode 100644\r
+index 0000000..acb7dbf\r
+--- /dev/null\r
++++ b/emacs/notmuch-mua.el\r
+@@ -0,0 +1,133 @@\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 'cl)\r
++(require 'message)\r
++\r
++(require 'notmuch-lib)\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-full\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
++  :options '(notmuch-mua-user-agent-full\r
++           notmuch-mua-user-agent-notmuch\r
++           notmuch-mua-user-agent-emacs))\r
++\r
++;;\r
++\r
++(defun notmuch-mua-user-agent-full ()\r
++  "Generate a `User-Agent:' string suitable for notmuch."\r
++  (concat (notmuch-mua-user-agent-notmuch)\r
++        " "\r
++        (notmuch-mua-user-agent-emacs)))\r
++\r
++(defun notmuch-mua-user-agent-notmuch ()\r
++  "Generate a `User-Agent:' string suitable for notmuch."\r
++  (concat "Notmuch/" (notmuch-version) " (http://notmuchmail.org)"))\r
++\r
++(defun notmuch-mua-user-agent-emacs ()\r
++  "Generate a `User-Agent:' string suitable for notmuch."\r
++  (concat "Emacs/" emacs-version " (" system-configuration ")"))\r
++\r
++(defun notmuch-mua-reply (query-string)\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-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 9775fb4..379e344 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -30,9 +30,9 @@\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
+ (declare-function notmuch-fontify-headers "notmuch" nil)\r
+ (declare-function notmuch-select-tag-with-completion "notmuch" (prompt &rest search-terms))\r
+ (declare-function notmuch-search-show-thread "notmuch" nil)\r
+@@ -507,7 +507,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
+@@ -805,13 +805,13 @@ any effects from previous calls to\r
+ (defun notmuch-show-reply ()\r
+   "Reply to the current message."\r
+   (interactive)\r
+-  (notmuch-reply (notmuch-show-get-message-id)))\r
++  (notmuch-mua-reply (notmuch-show-get-message-id)))\r
\r
+ (defun notmuch-show-forward-message ()\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 4c13f32..f96394a 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
+@@ -116,17 +117,6 @@ For example:\r
+             (mm-save-part p))))\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
+-\r
+ (defun notmuch-documentation-first-line (symbol)\r
+   "Return the first line of the documentation string for SYMBOL."\r
+   (let ((doc (documentation symbol)))\r
+@@ -216,7 +206,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
+@@ -408,7 +398,7 @@ Complete list of currently available key bindings:\r
+   "Begin composing a reply to the entire current thread in a new buffer."\r
+   (interactive)\r
+   (let ((message-id (notmuch-search-find-thread-id)))\r
+-    (notmuch-reply message-id)))\r
++    (notmuch-mua-reply message-id)))\r
\r
+ (defun notmuch-call-notmuch-process (&rest args)\r
+   "Synchronously invoke \"notmuch\" with the given list of arguments.\r
+@@ -796,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