[PATCH] emacs: Re-arrange message sending code

2010-04-24 Thread David Edmondson
On Fri, 23 Apr 2010 13:25:22 -0700, Carl Worth  wrote:
> And I'm hoping that this new support makes it easier for people to hook
> in the Fcc code. Does this mean there's now a single place to add that
> that will make it work for messages composed from 'm', 'f', or 'r'?

Yes.

> The one unpleasantry I've noticed is that in the case of 'm' the headers
> are being put into the buffer in the following order:
> 
>   User-Agent:
>   To:
>   Subject:
>   From:
> 
> where I would prefer them in the following order:
> 
>   From:
>   To:
>   Subject:
>   User-Agent:

I have:

(setq message-hidden-headers
  '("^References:" "^Face:" "^X-Face:" "^X-Draft-From:" "^User-Agent:"))

so the User-Agent is not even visible.

dme.
-- 
David Edmondson, http://dme.org


Re: [PATCH] emacs: Re-arrange message sending code

2010-04-24 Thread David Edmondson
On Fri, 23 Apr 2010 13:25:22 -0700, Carl Worth cwo...@cworth.org wrote:
 And I'm hoping that this new support makes it easier for people to hook
 in the Fcc code. Does this mean there's now a single place to add that
 that will make it work for messages composed from 'm', 'f', or 'r'?

Yes.

 The one unpleasantry I've noticed is that in the case of 'm' the headers
 are being put into the buffer in the following order:
 
   User-Agent:
   To:
   Subject:
   From:
 
 where I would prefer them in the following order:
 
   From:
   To:
   Subject:
   User-Agent:

I have:

(setq message-hidden-headers
  '(^References: ^Face: ^X-Face: ^X-Draft-From: ^User-Agent:))

so the User-Agent is not even visible.

dme.
-- 
David Edmondson, http://dme.org
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs: Re-arrange message sending code

2010-04-23 Thread Carl Worth
On Thu, 22 Apr 2010 10:03:32 +0100, David Edmondson  wrote:
> Define a new `mail-user-agent' (`notmuch-user-agent') and use it by
> default. Re-arrange various routines that send mail to use this
> (compose, reply, forward). Insert a `User-Agent:' header by default.

Very nice! I've pushed this out now.

And I'm hoping that this new support makes it easier for people to hook
in the Fcc code. Does this mean there's now a single place to add that
that will make it work for messages composed from 'm', 'f', or 'r'?

The one unpleasantry I've noticed is that in the case of 'm' the headers
are being put into the buffer in the following order:

User-Agent:
To:
Subject:
From:

where I would prefer them in the following order:

From:
To:
Subject:
User-Agent:

Thanks,

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



Re: [PATCH] emacs: Re-arrange message sending code

2010-04-23 Thread Carl Worth
On Thu, 22 Apr 2010 10:03:32 +0100, David Edmondson d...@dme.org wrote:
 Define a new `mail-user-agent' (`notmuch-user-agent') and use it by
 default. Re-arrange various routines that send mail to use this
 (compose, reply, forward). Insert a `User-Agent:' header by default.

Very nice! I've pushed this out now.

And I'm hoping that this new support makes it easier for people to hook
in the Fcc code. Does this mean there's now a single place to add that
that will make it work for messages composed from 'm', 'f', or 'r'?

The one unpleasantry I've noticed is that in the case of 'm' the headers
are being put into the buffer in the following order:

User-Agent:
To:
Subject:
From:

where I would prefer them in the following order:

From:
To:
Subject:
User-Agent:

Thanks,

-Carl


pgpwdB1v813Qh.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs: Re-arrange message sending code

2010-04-22 Thread Sebastian Spaeth
On 2010-04-22, David Edmondson wrote:
> Define a new `mail-user-agent' (`notmuch-user-agent') and use it by
> default. Re-arrange various routines that send mail to use this
> (compose, reply, forward). Insert a `User-Agent:' header by default.

I've been using this or a slightly earlier version of patch

Signed-off: Sebastian Spaeth 


[PATCH] emacs: Re-arrange message sending code

2010-04-22 Thread David Edmondson
Define a new `mail-user-agent' (`notmuch-user-agent') and use it by
default. Re-arrange various routines that send mail to use this
(compose, reply, forward). Insert a `User-Agent:' header by default.
---
 emacs/Makefile.local   |5 +-
 emacs/notmuch-hello.el |2 +
 emacs/notmuch-lib.el   |   16 ++
 emacs/notmuch-mua.el   |  133 
 emacs/notmuch-show.el  |8 ++--
 emacs/notmuch.el   |   20 ++-
 6 files changed, 163 insertions(+), 21 deletions(-)
 create mode 100644 emacs/notmuch-mua.el

diff --git a/emacs/Makefile.local b/emacs/Makefile.local
index 6486d90..e5013b3 100644
--- a/emacs/Makefile.local
+++ b/emacs/Makefile.local
@@ -6,8 +6,9 @@ emacs_sources := \
$(dir)/notmuch.el \
$(dir)/notmuch-query.el \
$(dir)/notmuch-show.el \
-   $(dir)/notmuch-wash.el
-   $(dir)/notmuch-hello.el
+   $(dir)/notmuch-wash.el \
+   $(dir)/notmuch-hello.el \
+   $(dir)/notmuch-mua.el

 emacs_images := \
$(dir)/notmuch-logo.png
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 13de6f8..fa6433e 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -25,6 +25,7 @@

 (require 'notmuch-lib)
 (require 'notmuch)
+(require 'notmuch-mua)

 (declare-function notmuch-search "notmuch" (query  oldest-first 
target-thread target-line))
 (declare-function notmuch-folder-count "notmuch" (search))
@@ -335,6 +336,7 @@ diagonal."

   (use-local-map widget-keymap)
   (local-set-key "=" 'notmuch-hello-update)
+  (local-set-key "m" 'notmuch-mua-mail)
   (local-set-key "q" '(lambda () (interactive) (kill-buffer (current-buffer
   (local-set-key "s" 'notmuch-hello-goto-search)
   (local-set-key "v" '(lambda () (interactive)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 274d7ec..47c74b9 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -33,6 +33,22 @@
   :type '(alist :key-type (string) :value-type (string))
   :group 'notmuch)

+;;
+
+(defun notmuch-version ()
+  "Return a string with the notmuch version number."
+  (let ((long-string
+;; Trim off the trailing newline.
+(substring (shell-command-to-string
+(concat notmuch-command " --version"))
+   0 -1)))
+(if (string-match "^notmuch\\( version\\)? \\(.*\\)$"
+ long-string)
+   (match-string 2 long-string)
+  "unknown")))
+
+;;
+
 ;; XXX: This should be a generic function in emacs somewhere, not
 ;; here.
 (defun point-invisible-p ()
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
new file mode 100644
index 000..acb7dbf
--- /dev/null
+++ b/emacs/notmuch-mua.el
@@ -0,0 +1,133 @@
+;; notmuch-mua.el --- emacs style mail-user-agent
+;;
+;; Copyright ?? David Edmondson
+;;
+;; This file is part of Notmuch.
+;;
+;; Notmuch is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; Notmuch is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with Notmuch.  If not, see .
+;;
+;; Authors: David Edmondson 
+
+(require 'cl)
+(require 'message)
+
+(require 'notmuch-lib)
+
+;;
+
+(defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
+  "Hook run before sending messages."
+  :group 'notmuch
+  :type 'hook)
+
+(defcustom notmuch-mua-user-agent-function 'notmuch-mua-user-agent-full
+  "Function used to generate a `User-Agent:' string. If this is
+`nil' then no `User-Agent:' will be generated."
+  :group 'notmuch
+  :type 'function
+  :options '(notmuch-mua-user-agent-full
+notmuch-mua-user-agent-notmuch
+notmuch-mua-user-agent-emacs))
+
+;;
+
+(defun notmuch-mua-user-agent-full ()
+  "Generate a `User-Agent:' string suitable for notmuch."
+  (concat (notmuch-mua-user-agent-notmuch)
+ " "
+ (notmuch-mua-user-agent-emacs)))
+
+(defun notmuch-mua-user-agent-notmuch ()
+  "Generate a `User-Agent:' string suitable for notmuch."
+  (concat "Notmuch/" (notmuch-version) " (http://notmuchmail.org)"))
+
+(defun notmuch-mua-user-agent-emacs ()
+  "Generate a `User-Agent:' string suitable for notmuch."
+  (concat "Emacs/" emacs-version " (" system-configuration ")"))
+
+(defun notmuch-mua-reply (query-string)
+  (let (headers body)
+;; This make assumptions about the output of `notmuch reply', but
+;; really only that the headers come first followed by a blank
+;; line and then the body.
+(with-temp-buffer
+  (call-process notmuch-command nil t nil "reply" query-string)
+  (goto-char (point-min))
+  

[PATCH] emacs: Re-arrange message sending code

2010-04-22 Thread David Edmondson
Define a new `mail-user-agent' (`notmuch-user-agent') and use it by
default. Re-arrange various routines that send mail to use this
(compose, reply, forward). Insert a `User-Agent:' header by default.
---
 emacs/Makefile.local   |5 +-
 emacs/notmuch-hello.el |2 +
 emacs/notmuch-lib.el   |   16 ++
 emacs/notmuch-mua.el   |  133 
 emacs/notmuch-show.el  |8 ++--
 emacs/notmuch.el   |   20 ++-
 6 files changed, 163 insertions(+), 21 deletions(-)
 create mode 100644 emacs/notmuch-mua.el

diff --git a/emacs/Makefile.local b/emacs/Makefile.local
index 6486d90..e5013b3 100644
--- a/emacs/Makefile.local
+++ b/emacs/Makefile.local
@@ -6,8 +6,9 @@ emacs_sources := \
$(dir)/notmuch.el \
$(dir)/notmuch-query.el \
$(dir)/notmuch-show.el \
-   $(dir)/notmuch-wash.el
-   $(dir)/notmuch-hello.el
+   $(dir)/notmuch-wash.el \
+   $(dir)/notmuch-hello.el \
+   $(dir)/notmuch-mua.el
 
 emacs_images := \
$(dir)/notmuch-logo.png
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 13de6f8..fa6433e 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -25,6 +25,7 @@
 
 (require 'notmuch-lib)
 (require 'notmuch)
+(require 'notmuch-mua)
 
 (declare-function notmuch-search notmuch (query optional oldest-first 
target-thread target-line))
 (declare-function notmuch-folder-count notmuch (search))
@@ -335,6 +336,7 @@ diagonal.
 
   (use-local-map widget-keymap)
   (local-set-key = 'notmuch-hello-update)
+  (local-set-key m 'notmuch-mua-mail)
   (local-set-key q '(lambda () (interactive) (kill-buffer (current-buffer
   (local-set-key s 'notmuch-hello-goto-search)
   (local-set-key v '(lambda () (interactive)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 274d7ec..47c74b9 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -33,6 +33,22 @@
   :type '(alist :key-type (string) :value-type (string))
   :group 'notmuch)
 
+;;
+
+(defun notmuch-version ()
+  Return a string with the notmuch version number.
+  (let ((long-string
+;; Trim off the trailing newline.
+(substring (shell-command-to-string
+(concat notmuch-command  --version))
+   0 -1)))
+(if (string-match ^notmuch\\( version\\)? \\(.*\\)$
+ long-string)
+   (match-string 2 long-string)
+  unknown)))
+
+;;
+
 ;; XXX: This should be a generic function in emacs somewhere, not
 ;; here.
 (defun point-invisible-p ()
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
new file mode 100644
index 000..acb7dbf
--- /dev/null
+++ b/emacs/notmuch-mua.el
@@ -0,0 +1,133 @@
+;; notmuch-mua.el --- emacs style mail-user-agent
+;;
+;; Copyright © David Edmondson
+;;
+;; This file is part of Notmuch.
+;;
+;; Notmuch is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; Notmuch is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with Notmuch.  If not, see http://www.gnu.org/licenses/.
+;;
+;; Authors: David Edmondson d...@dme.org
+
+(require 'cl)
+(require 'message)
+
+(require 'notmuch-lib)
+
+;;
+
+(defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
+  Hook run before sending messages.
+  :group 'notmuch
+  :type 'hook)
+
+(defcustom notmuch-mua-user-agent-function 'notmuch-mua-user-agent-full
+  Function used to generate a `User-Agent:' string. If this is
+`nil' then no `User-Agent:' will be generated.
+  :group 'notmuch
+  :type 'function
+  :options '(notmuch-mua-user-agent-full
+notmuch-mua-user-agent-notmuch
+notmuch-mua-user-agent-emacs))
+
+;;
+
+(defun notmuch-mua-user-agent-full ()
+  Generate a `User-Agent:' string suitable for notmuch.
+  (concat (notmuch-mua-user-agent-notmuch)
+  
+ (notmuch-mua-user-agent-emacs)))
+
+(defun notmuch-mua-user-agent-notmuch ()
+  Generate a `User-Agent:' string suitable for notmuch.
+  (concat Notmuch/ (notmuch-version)  (http://notmuchmail.org)))
+
+(defun notmuch-mua-user-agent-emacs ()
+  Generate a `User-Agent:' string suitable for notmuch.
+  (concat Emacs/ emacs-version  ( system-configuration )))
+
+(defun notmuch-mua-reply (query-string)
+  (let (headers body)
+;; This make assumptions about the output of `notmuch reply', but
+;; really only that the headers come first followed by a blank
+;; line and then the body.
+(with-temp-buffer
+  (call-process notmuch-command nil t nil reply query-string)
+  (goto-char (point-min))
+  (if 

[PATCH] emacs: Re-arrange message sending code

2010-04-15 Thread David Edmondson
On Thu, 15 Apr 2010 16:50:27 +0100, David Edmondson  wrote:
> Define a new `mail-user-agent' (`notmuch-user-agent') and use it by
> default. Re-arrange various routines that send mail to use this
> (compose, reply, forward). Insert a `User-Agent:' header by default.

I meant to add that this was a proposal in response to Sebastian's
User-Agent related patch (id:87y6gtnkch.fsf at SSpaeth.de).

Setting `mail-user-agent' in notmuch.el is a bit aggressive, but without
requiring some configuration on the part of the user (which Carl
appeared to want to avoid) it's not obvious how to make things as
simple as the existing approach.

dme.
-- 
David Edmondson, http://dme.org


[PATCH] emacs: Re-arrange message sending code

2010-04-15 Thread David Edmondson
Define a new `mail-user-agent' (`notmuch-user-agent') and use it by
default. Re-arrange various routines that send mail to use this
(compose, reply, forward). Insert a `User-Agent:' header by default.
---
 emacs/notmuch-hello.el |2 +
 emacs/notmuch-mua.el   |   94 
 emacs/notmuch-show.el  |5 ++-
 emacs/notmuch.el   |   43 --
 4 files changed, 130 insertions(+), 14 deletions(-)
 create mode 100644 emacs/notmuch-mua.el

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index c49a35f..83586f2 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -25,6 +25,7 @@

 (require 'notmuch-lib)
 (require 'notmuch)
+(require 'notmuch-mua)

 (declare-function notmuch-search "notmuch" (query  oldest-first 
target-thread target-line))
 (declare-function notmuch-folder-count "notmuch" (search))
@@ -314,6 +315,7 @@ diagonal."

   (use-local-map widget-keymap)
   (local-set-key "=" 'notmuch-hello-update)
+  (local-set-key "m" 'notmuch-mua-mail)
   (local-set-key "q" '(lambda () (interactive) (kill-buffer (current-buffer
   (local-set-key "s" 'notmuch-hello-goto-search)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
new file mode 100644
index 000..c8a8743
--- /dev/null
+++ b/emacs/notmuch-mua.el
@@ -0,0 +1,94 @@
+;; notmuch-mua.el --- emacs style mail-user-agent
+;;
+;; Copyright ?? David Edmondson
+;;
+;; This file is part of Notmuch.
+;;
+;; Notmuch is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; Notmuch is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with Notmuch.  If not, see .
+;;
+;; Authors: David Edmondson 
+
+(require 'message)
+
+;;
+
+(defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
+  "Hook run before sending messages."
+  :group 'notmuch
+  :type 'hook)
+
+(defcustom notmuch-mua-user-agent-function 'notmuch-mua-user-agent
+  "Function used to generate a `User-Agent:' string. If this is
+`nil' then no `User-Agent:' will be generated."
+  :group 'notmuch
+  :type 'function)
+
+;;
+
+(defun notmuch-mua-user-agent ()
+  "Generate a `User-Agent:' string suitable for notmuch."
+  (concat
+   ;; Trim off the trailing newline.
+   (substring (shell-command-to-string
+  (concat notmuch-command " --version"))
+ 0 -1)
+   " (Emacs " emacs-version "/"
+   system-configuration ")"))
+
+(defun notmuch-mua-forward-message ()
+  (message-forward)
+  (save-excursion
+(when notmuch-mua-user-agent-function
+  (let ((user-agent (funcall notmuch-mua-user-agent-function)))
+   (when (not (string= "" user-agent))
+ (message-add-header (format "User-Agent: %s" user-agent)
+(message-sort-headers)
+(message-hide-headers))
+  (set-buffer-modified-p nil))
+
+(defun notmuch-mua-mail ( to subject other-headers continue
+  switch-function yank-action send-actions)
+  (interactive)
+
+  (when notmuch-mua-user-agent-function
+(let ((user-agent (funcall notmuch-mua-user-agent-function)))
+  (when (not (string= "" user-agent))
+   (push (cons "User-Agent" user-agent) other-headers
+
+  (message-mail to subject other-headers continue
+   switch-function yank-action send-actions)
+  (message-hide-headers))
+
+(defun notmuch-mua-send-and-exit ( arg)
+  (interactive "P")
+  (message-send-and-exit arg))
+
+(defun notmuch-mua-kill-buffer ()
+  (interactive)
+  (message-kill-buffer))
+
+(defun notmuch-mua-message-send-hook ()
+  "The default function used for `notmuch-mua-send-hook', this
+simply runs the corresponding `message-mode' hook functions."
+  (run-hooks 'message-send-hook))
+
+;;
+
+(define-mail-user-agent 'notmuch-user-agent
+  'notmuch-mua-mail 'notmuch-mua-send-and-exit
+  'notmuch-mua-kill-buffer 'notmuch-mua-send-hook)
+
+;;
+
+(provide 'notmuch-mua)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 54d1c48..d1b0f1a 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -30,6 +30,7 @@
 (require 'notmuch-lib)
 (require 'notmuch-query)
 (require 'notmuch-wash)
+(require 'notmuch-mua)

 (declare-function notmuch-call-notmuch-process "notmuch" ( args))
 (declare-function notmuch-reply "notmuch" (query-string))
@@ -519,7 +520,7 @@ function is used. "
(define-key map (kbd "M-TAB") 'notmuch-show-previous-button)
(define-key map (kbd "TAB") 'notmuch-show-next-button)
(define-key map "s" 'notmuch-search)
-   (define-key map "m" 'message-mail)
+   

[PATCH] emacs: Re-arrange message sending code

2010-04-15 Thread David Edmondson
Define a new `mail-user-agent' (`notmuch-user-agent') and use it by
default. Re-arrange various routines that send mail to use this
(compose, reply, forward). Insert a `User-Agent:' header by default.
---
 emacs/notmuch-hello.el |2 +
 emacs/notmuch-mua.el   |   94 
 emacs/notmuch-show.el  |5 ++-
 emacs/notmuch.el   |   43 --
 4 files changed, 130 insertions(+), 14 deletions(-)
 create mode 100644 emacs/notmuch-mua.el

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index c49a35f..83586f2 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -25,6 +25,7 @@
 
 (require 'notmuch-lib)
 (require 'notmuch)
+(require 'notmuch-mua)
 
 (declare-function notmuch-search notmuch (query optional oldest-first 
target-thread target-line))
 (declare-function notmuch-folder-count notmuch (search))
@@ -314,6 +315,7 @@ diagonal.
 
   (use-local-map widget-keymap)
   (local-set-key = 'notmuch-hello-update)
+  (local-set-key m 'notmuch-mua-mail)
   (local-set-key q '(lambda () (interactive) (kill-buffer (current-buffer
   (local-set-key s 'notmuch-hello-goto-search)
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
new file mode 100644
index 000..c8a8743
--- /dev/null
+++ b/emacs/notmuch-mua.el
@@ -0,0 +1,94 @@
+;; notmuch-mua.el --- emacs style mail-user-agent
+;;
+;; Copyright © David Edmondson
+;;
+;; This file is part of Notmuch.
+;;
+;; Notmuch is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; Notmuch is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with Notmuch.  If not, see http://www.gnu.org/licenses/.
+;;
+;; Authors: David Edmondson d...@dme.org
+
+(require 'message)
+
+;;
+
+(defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
+  Hook run before sending messages.
+  :group 'notmuch
+  :type 'hook)
+
+(defcustom notmuch-mua-user-agent-function 'notmuch-mua-user-agent
+  Function used to generate a `User-Agent:' string. If this is
+`nil' then no `User-Agent:' will be generated.
+  :group 'notmuch
+  :type 'function)
+
+;;
+
+(defun notmuch-mua-user-agent ()
+  Generate a `User-Agent:' string suitable for notmuch.
+  (concat
+   ;; Trim off the trailing newline.
+   (substring (shell-command-to-string
+  (concat notmuch-command  --version))
+ 0 -1)
+(Emacs  emacs-version /
+   system-configuration )))
+
+(defun notmuch-mua-forward-message ()
+  (message-forward)
+  (save-excursion
+(when notmuch-mua-user-agent-function
+  (let ((user-agent (funcall notmuch-mua-user-agent-function)))
+   (when (not (string=  user-agent))
+ (message-add-header (format User-Agent: %s user-agent)
+(message-sort-headers)
+(message-hide-headers))
+  (set-buffer-modified-p nil))
+
+(defun notmuch-mua-mail (optional to subject other-headers continue
+  switch-function yank-action send-actions)
+  (interactive)
+
+  (when notmuch-mua-user-agent-function
+(let ((user-agent (funcall notmuch-mua-user-agent-function)))
+  (when (not (string=  user-agent))
+   (push (cons User-Agent user-agent) other-headers
+
+  (message-mail to subject other-headers continue
+   switch-function yank-action send-actions)
+  (message-hide-headers))
+
+(defun notmuch-mua-send-and-exit (optional arg)
+  (interactive P)
+  (message-send-and-exit arg))
+
+(defun notmuch-mua-kill-buffer ()
+  (interactive)
+  (message-kill-buffer))
+
+(defun notmuch-mua-message-send-hook ()
+  The default function used for `notmuch-mua-send-hook', this
+simply runs the corresponding `message-mode' hook functions.
+  (run-hooks 'message-send-hook))
+
+;;
+
+(define-mail-user-agent 'notmuch-user-agent
+  'notmuch-mua-mail 'notmuch-mua-send-and-exit
+  'notmuch-mua-kill-buffer 'notmuch-mua-send-hook)
+
+;;
+
+(provide 'notmuch-mua)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 54d1c48..d1b0f1a 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -30,6 +30,7 @@
 (require 'notmuch-lib)
 (require 'notmuch-query)
 (require 'notmuch-wash)
+(require 'notmuch-mua)
 
 (declare-function notmuch-call-notmuch-process notmuch (rest args))
 (declare-function notmuch-reply notmuch (query-string))
@@ -519,7 +520,7 @@ function is used. 
(define-key map (kbd M-TAB) 'notmuch-show-previous-button)
(define-key map (kbd TAB) 'notmuch-show-next-button)
(define-key map s 'notmuch-search)
-   (define-key map m 'message-mail)
+   (define-key 

Re: [PATCH] emacs: Re-arrange message sending code

2010-04-15 Thread David Edmondson
On Thu, 15 Apr 2010 16:50:27 +0100, David Edmondson d...@dme.org wrote:
 Define a new `mail-user-agent' (`notmuch-user-agent') and use it by
 default. Re-arrange various routines that send mail to use this
 (compose, reply, forward). Insert a `User-Agent:' header by default.

I meant to add that this was a proposal in response to Sebastian's
User-Agent related patch (id:87y6gtnkch@sspaeth.de).

Setting `mail-user-agent' in notmuch.el is a bit aggressive, but without
requiring some configuration on the part of the user (which Carl
appeared to want to avoid) it's not obvious how to make things as
simple as the existing approach.

dme.
-- 
David Edmondson, http://dme.org
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch