unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v2] emacs: prefer notmuch-emacs-version in User-Agent: header
@ 2015-03-21 10:15 Tomi Ollila
  2015-04-05 16:14 ` Mark Walters
  0 siblings, 1 reply; 2+ messages in thread
From: Tomi Ollila @ 2015-03-21 10:15 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

Now that we have `notmuch-emacs-version' defined in notmuch emacs MUA
use that as a part of User-Agent: header to provide more accurate
version information when sending emails.

In case some incomplete installation of notmuch emacs MUA is used and
`notmuch-emacs-version' is defined as "unknown" then fall back to ask
version info from cli (as it used to be) -- the function to do that was
renamed from `notmuch-version' to `notmuch-cli-version' to make this
clearer and more consistent.

The hub of getting version information is new `notmuch-versions'
function. It normally returns cons pair
(notmuch-emacs-version . notmuch-cli-version).
This function takes optional argument which makes the cdr of the return
value work differently; if `notmuch-emacs-version' is "unknown", return
pair as if the option were not given; otherwise return
(notmuch-emacs-version . notmuch-emacs-version).
This special case is useful to simplify setting User-Agent: header
-- just use the cdr of the returned value.
---

This is v2 of id:1407496781-17458-1-git-send-email-tomi.ollila@iki.fi

(NEWS dropped from this one (for now) -- will arrive later)

 emacs/notmuch-hello.el | 13 +++++--------
 emacs/notmuch-lib.el   | 20 +++++++++++++++++++-
 emacs/notmuch-mua.el   |  2 +-
 emacs/notmuch.el       |  4 ----
 4 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 65d0627..62345fe 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -622,18 +622,15 @@ (defun notmuch-hello-window-configuration-change ()
       (remove-hook 'window-configuration-change-hook
 		   #'notmuch-hello-window-configuration-change))))
 
-;; the following variable is defined as being defconst in notmuch-version.el
-(defvar notmuch-emacs-version)
-
 (defun notmuch-hello-versions ()
   "Display the notmuch version(s)"
   (interactive)
-  (let ((notmuch-cli-version (notmuch-version)))
+  (let ((notmuch-versions (notmuch-versions)))
     (message "notmuch version %s"
-	     (if (string= notmuch-emacs-version notmuch-cli-version)
-		 notmuch-cli-version
-	       (concat notmuch-cli-version
-		       " (emacs mua version " notmuch-emacs-version ")")))))
+	     (if (string= (car notmuch-versions) (cdr notmuch-versions))
+		 (car notmuch-versions)
+	       (concat (cdr notmuch-versions)
+		       " (emacs mua version " (car notmuch-versions) ")")))))
 
 (defvar notmuch-hello-mode-map
   (let ((map (if (fboundp 'make-composed-keymap)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index f8e5165..370b648 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -25,6 +25,10 @@
 (require 'mm-decode)
 (require 'cl)
 
+(unless (require 'notmuch-version nil t)
+  (defconst notmuch-emacs-version "unknown"
+    "Placeholder variable when notmuch-version.el[c] is not available."))
+
 (autoload 'notmuch-jump-search "notmuch-jump"
   "Jump to a saved search by shortcut key." t)
 
@@ -192,7 +196,7 @@ (defun notmuch-assert-cli-sane ()
 "Perhaps you haven't run \"notmuch setup\" yet? Try running this
 on the command line, and then retry your notmuch command")))
 
-(defun notmuch-version ()
+(defun notmuch-cli-version ()
   "Return a string with the notmuch version number."
   (let ((long-string
 	 ;; Trim off the trailing newline.
@@ -202,6 +206,20 @@ (defun notmuch-version ()
 	(match-string 2 long-string)
       "unknown")))
 
+(defun notmuch-versions (&optional cdr-as-emacs-version-unless-unknown)
+  "Returns cons pair (notmuch-emacs-version . (`notmuch-cli-version'))
+If optional argument CDR-AS-EMACS-VERSION-UNLESS-UNKNOWN is non-nil
+and `notmuch-emacs-version' is not \"unknown\" return cons pair
+(notmuch-emacs-version . notmuch-emacs-version).
+`notmuch-mua-user-agent-notmuch' utilizes this option, and uses the cdr
+of this cons pair in User-Agent: header"
+  (interactive)
+  (cons notmuch-emacs-version
+	(if (or (not cdr-as-emacs-version-unless-unknown)
+		(string= notmuch-emacs-version "unknown"))
+	    (notmuch-cli-version)
+	  notmuch-emacs-version)))
+
 (defun notmuch-config-get (item)
   "Return a value from the notmuch configuration."
   (let* ((val (notmuch-command-to-string "config" "get" item))
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 33f1399..ac067f2 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -118,7 +118,7 @@ (defun notmuch-mua-user-agent-full ()
 
 (defun notmuch-mua-user-agent-notmuch ()
   "Generate a `User-Agent:' string suitable for notmuch."
-  (concat "Notmuch/" (notmuch-version) " (http://notmuchmail.org)"))
+  (concat "Notmuch/" (cdr (notmuch-versions t)) " (http://notmuchmail.org)"))
 
 (defun notmuch-mua-user-agent-emacs ()
   "Generate a `User-Agent:' string suitable for notmuch."
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index ab00454..0cae117 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -61,10 +61,6 @@
 (require 'notmuch-message)
 (require 'notmuch-parser)
 
-(unless (require 'notmuch-version nil t)
-  (defconst notmuch-emacs-version "unknown"
-    "Placeholder variable when notmuch-version.el[c] is not available."))
-
 (defcustom notmuch-search-result-format
   `(("date" . "%12s ")
     ("count" . "%-7s ")
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] emacs: prefer notmuch-emacs-version in User-Agent: header
  2015-03-21 10:15 [PATCH v2] emacs: prefer notmuch-emacs-version in User-Agent: header Tomi Ollila
@ 2015-04-05 16:14 ` Mark Walters
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Walters @ 2015-04-05 16:14 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila


On Sat, 21 Mar 2015, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> Now that we have `notmuch-emacs-version' defined in notmuch emacs MUA
> use that as a part of User-Agent: header to provide more accurate
> version information when sending emails.
>
> In case some incomplete installation of notmuch emacs MUA is used and
> `notmuch-emacs-version' is defined as "unknown" then fall back to ask
> version info from cli (as it used to be) -- the function to do that was
> renamed from `notmuch-version' to `notmuch-cli-version' to make this
> clearer and more consistent.
>
> The hub of getting version information is new `notmuch-versions'
> function. It normally returns cons pair
> (notmuch-emacs-version . notmuch-cli-version).
> This function takes optional argument which makes the cdr of the return
> value work differently; if `notmuch-emacs-version' is "unknown", return
> pair as if the option were not given; otherwise return
> (notmuch-emacs-version . notmuch-emacs-version).
> This special case is useful to simplify setting User-Agent: header
> -- just use the cdr of the returned value.

Hi

At the moment I am not seeing the advantages of this approach over that
Michal suggested in id:87oau1un7g.fsf@steelpick.2x.cz (with a
notmuch-guess-emacs-version) which looks a little simpler;  could you
explain?

(Just in case its not clear: I like the renaming of notmuch-version to
notmuch-cli-version but I feel putting the guessing logic in
notmuch-versions with an optional argument is overloading that function,
and I am not sure what the advantage of having that function is)


Many thanks

Mark



> ---
>
> This is v2 of id:1407496781-17458-1-git-send-email-tomi.ollila@iki.fi
>
> (NEWS dropped from this one (for now) -- will arrive later)
>
>  emacs/notmuch-hello.el | 13 +++++--------
>  emacs/notmuch-lib.el   | 20 +++++++++++++++++++-
>  emacs/notmuch-mua.el   |  2 +-
>  emacs/notmuch.el       |  4 ----
>  4 files changed, 25 insertions(+), 14 deletions(-)
>
> diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
> index 65d0627..62345fe 100644
> --- a/emacs/notmuch-hello.el
> +++ b/emacs/notmuch-hello.el
> @@ -622,18 +622,15 @@ (defun notmuch-hello-window-configuration-change ()
>        (remove-hook 'window-configuration-change-hook
>  		   #'notmuch-hello-window-configuration-change))))
>  
> -;; the following variable is defined as being defconst in notmuch-version.el
> -(defvar notmuch-emacs-version)
> -
>  (defun notmuch-hello-versions ()
>    "Display the notmuch version(s)"
>    (interactive)
> -  (let ((notmuch-cli-version (notmuch-version)))
> +  (let ((notmuch-versions (notmuch-versions)))
>      (message "notmuch version %s"
> -	     (if (string= notmuch-emacs-version notmuch-cli-version)
> -		 notmuch-cli-version
> -	       (concat notmuch-cli-version
> -		       " (emacs mua version " notmuch-emacs-version ")")))))
> +	     (if (string= (car notmuch-versions) (cdr notmuch-versions))
> +		 (car notmuch-versions)
> +	       (concat (cdr notmuch-versions)
> +		       " (emacs mua version " (car notmuch-versions) ")")))))
>  
>  (defvar notmuch-hello-mode-map
>    (let ((map (if (fboundp 'make-composed-keymap)
> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
> index f8e5165..370b648 100644
> --- a/emacs/notmuch-lib.el
> +++ b/emacs/notmuch-lib.el
> @@ -25,6 +25,10 @@
>  (require 'mm-decode)
>  (require 'cl)
>  
> +(unless (require 'notmuch-version nil t)
> +  (defconst notmuch-emacs-version "unknown"
> +    "Placeholder variable when notmuch-version.el[c] is not available."))
> +
>  (autoload 'notmuch-jump-search "notmuch-jump"
>    "Jump to a saved search by shortcut key." t)
>  
> @@ -192,7 +196,7 @@ (defun notmuch-assert-cli-sane ()
>  "Perhaps you haven't run \"notmuch setup\" yet? Try running this
>  on the command line, and then retry your notmuch command")))
>  
> -(defun notmuch-version ()
> +(defun notmuch-cli-version ()
>    "Return a string with the notmuch version number."
>    (let ((long-string
>  	 ;; Trim off the trailing newline.
> @@ -202,6 +206,20 @@ (defun notmuch-version ()
>  	(match-string 2 long-string)
>        "unknown")))
>  
> +(defun notmuch-versions (&optional cdr-as-emacs-version-unless-unknown)
> +  "Returns cons pair (notmuch-emacs-version . (`notmuch-cli-version'))
> +If optional argument CDR-AS-EMACS-VERSION-UNLESS-UNKNOWN is non-nil
> +and `notmuch-emacs-version' is not \"unknown\" return cons pair
> +(notmuch-emacs-version . notmuch-emacs-version).
> +`notmuch-mua-user-agent-notmuch' utilizes this option, and uses the cdr
> +of this cons pair in User-Agent: header"
> +  (interactive)
> +  (cons notmuch-emacs-version
> +	(if (or (not cdr-as-emacs-version-unless-unknown)
> +		(string= notmuch-emacs-version "unknown"))
> +	    (notmuch-cli-version)
> +	  notmuch-emacs-version)))
> +
>  (defun notmuch-config-get (item)
>    "Return a value from the notmuch configuration."
>    (let* ((val (notmuch-command-to-string "config" "get" item))
> diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
> index 33f1399..ac067f2 100644
> --- a/emacs/notmuch-mua.el
> +++ b/emacs/notmuch-mua.el
> @@ -118,7 +118,7 @@ (defun notmuch-mua-user-agent-full ()
>  
>  (defun notmuch-mua-user-agent-notmuch ()
>    "Generate a `User-Agent:' string suitable for notmuch."
> -  (concat "Notmuch/" (notmuch-version) " (http://notmuchmail.org)"))
> +  (concat "Notmuch/" (cdr (notmuch-versions t)) " (http://notmuchmail.org)"))
>  
>  (defun notmuch-mua-user-agent-emacs ()
>    "Generate a `User-Agent:' string suitable for notmuch."
> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index ab00454..0cae117 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -61,10 +61,6 @@
>  (require 'notmuch-message)
>  (require 'notmuch-parser)
>  
> -(unless (require 'notmuch-version nil t)
> -  (defconst notmuch-emacs-version "unknown"
> -    "Placeholder variable when notmuch-version.el[c] is not available."))
> -
>  (defcustom notmuch-search-result-format
>    `(("date" . "%12s ")
>      ("count" . "%-7s ")
> -- 
> 2.1.0
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-05 16:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-21 10:15 [PATCH v2] emacs: prefer notmuch-emacs-version in User-Agent: header Tomi Ollila
2015-04-05 16:14 ` Mark Walters

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).