[PATCH 13/13] notmuch.el: Add a function to insert a notmuch user-agent header

2010-04-14 Thread Sebastian Spaeth
On 2010-04-14, David Edmondson wrote:
> This really should be done with `define-mail-user-agent' and associated
> paraphernalia.

Which might be correct but beyond what I can provide :). 

So, either we take this and get a followup patch, or someone improves
it, or we drop it.

Sebastian


[PATCH 13/13] notmuch.el: Add a function to insert a notmuch user-agent header

2010-04-14 Thread Sebastian Spaeth
This adds a function (and a hook) to have notmuch insert a User-Agent header
into composed mails (even if invoked from not-notmuch ways, such as with
ctrl-x m. This is invariably added for now without the possibility to
turn it off, a task left as a homework for others.

Signed-off-by: Sebastian Spaeth 
---
 emacs/notmuch.el |   24 
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 517c53a..8a7df15 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -54,6 +54,30 @@
 (require 'notmuch-lib)
 (require 'notmuch-show)

+(defun notmuch-set-user-agent-header ()
+  "Sets variables so that  message mode inserts a notmuch User-Agent 
+   header into send mails"
+  ;; check if User-Agent is a 'required' mail header and set it if not
+  (if (not (memq 'User-Agent message-required-mail-headers))
+  (setq message-required-mail-headers 
+(append message-required-mail-headers '(User-Agent
+  ;; hide the User-Agent header when composing a mail
+  (if (not (memq '"^User-Agent:" message-hidden-headers))
+  (setq message-hidden-headers 
+(append message-hidden-headers '("^User-Agent:"
+  ;; create the notmuch user agent string
+  (let ((notmuch-user-agent (concat 
+ (substring (shell-command-to-string 
+ (concat notmuch-command 
+ " --version")) 0 -1)
+ " (Emacs " emacs-version "/"
+ system-configuration ")")))
+(setq message-newsreader notmuch-user-agent)))
+
+;; set the User-Agent string whenever we invoke message mode
+;; TODO: use a variable that allows disabling.
+(add-hook 'message-mode-hook 'notmuch-set-user-agent-header)
+
 (defun notmuch-select-tag-with-completion (prompt  search-terms)
   (let ((tag-list
 (with-output-to-string
-- 
1.6.3.3



[PATCH 13/13] notmuch.el: Add a function to insert a notmuch user-agent header

2010-04-14 Thread David Edmondson
On Wed, 14 Apr 2010 09:38:05 +0200, Sebastian Spaeth  
wrote:
> This adds a function (and a hook) to have notmuch insert a User-Agent header
> into composed mails (even if invoked from not-notmuch ways, such as with
> ctrl-x m. This is invariably added for now without the possibility to
> turn it off, a task left as a homework for others.

This really should be done with `define-mail-user-agent' and associated
paraphernalia.

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


[PATCH 13/13] notmuch.el: Add a function to insert a notmuch user-agent header

2010-04-14 Thread Sebastian Spaeth
This adds a function (and a hook) to have notmuch insert a User-Agent header
into composed mails (even if invoked from not-notmuch ways, such as with
ctrl-x m. This is invariably added for now without the possibility to
turn it off, a task left as a homework for others.

Signed-off-by: Sebastian Spaeth sebast...@sspaeth.de
---
 emacs/notmuch.el |   24 
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 517c53a..8a7df15 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -54,6 +54,30 @@
 (require 'notmuch-lib)
 (require 'notmuch-show)
 
+(defun notmuch-set-user-agent-header ()
+  Sets variables so that  message mode inserts a notmuch User-Agent 
+   header into send mails
+  ;; check if User-Agent is a 'required' mail header and set it if not
+  (if (not (memq 'User-Agent message-required-mail-headers))
+  (setq message-required-mail-headers 
+(append message-required-mail-headers '(User-Agent
+  ;; hide the User-Agent header when composing a mail
+  (if (not (memq '^User-Agent: message-hidden-headers))
+  (setq message-hidden-headers 
+(append message-hidden-headers '(^User-Agent:
+  ;; create the notmuch user agent string
+  (let ((notmuch-user-agent (concat 
+ (substring (shell-command-to-string 
+ (concat notmuch-command 
+  --version)) 0 -1)
+  (Emacs  emacs-version /
+ system-configuration 
+(setq message-newsreader notmuch-user-agent)))
+
+;; set the User-Agent string whenever we invoke message mode
+;; TODO: use a variable that allows disabling.
+(add-hook 'message-mode-hook 'notmuch-set-user-agent-header)
+
 (defun notmuch-select-tag-with-completion (prompt rest search-terms)
   (let ((tag-list
 (with-output-to-string
-- 
1.6.3.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 13/13] notmuch.el: Add a function to insert a notmuch user-agent header

2010-04-14 Thread David Edmondson
On Wed, 14 Apr 2010 09:38:05 +0200, Sebastian Spaeth sebast...@sspaeth.de 
wrote:
 This adds a function (and a hook) to have notmuch insert a User-Agent header
 into composed mails (even if invoked from not-notmuch ways, such as with
 ctrl-x m. This is invariably added for now without the possibility to
 turn it off, a task left as a homework for others.

This really should be done with `define-mail-user-agent' and associated
paraphernalia.

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


Re: [PATCH 13/13] notmuch.el: Add a function to insert a notmuch user-agent header

2010-04-14 Thread Sebastian Spaeth
On 2010-04-14, David Edmondson wrote:
 This really should be done with `define-mail-user-agent' and associated
 paraphernalia.

Which might be correct but beyond what I can provide :). 

So, either we take this and get a followup patch, or someone improves
it, or we drop it.

Sebastian
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch