[PATCH 2/2] emacs: prefer notmuch-emacs-version in User-Agent: header

Subject: [PATCH 2/2] emacs: prefer notmuch-emacs-version in User-Agent: header

Date: Sun, 2 Aug 2015 17:48:14 +0300

To: notmuch@notmuchmail.org, markwalters1009@gmail.com, sojkam1@fel.cvut.cz

Cc: tomi.ollila@iki.fi

From: 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 before this commit).

Requiring notmuch-version[.elc] and if that is missing setting
"fallback" notmuch-emacs-version (to "unknown") was moved from
notmuch.el to notmuch-lib.el as notmuch-mua.el (which provides
User-Agent: information) require's the latter.
---

Note that I did not create notmuch-guess-emacs-version (or something)
function. The idea is good but there is one HARD problem: naming it.
Also, I personally suspect that no-one is going to need that function in
coming years...

 emacs/notmuch-lib.el | 4 ++++
 emacs/notmuch-mua.el | 5 ++++-
 emacs/notmuch.el     | 4 ----
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index e16a1b9..201d7ec 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)
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 934f6c9..3e52d5e 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -118,7 +118,10 @@ (defun notmuch-mua-user-agent-full ()
 
 (defun notmuch-mua-user-agent-notmuch ()
   "Generate a `User-Agent:' string suitable for notmuch."
-  (concat "Notmuch/" (notmuch-cli-version) " (http://notmuchmail.org)"))
+  (let ((notmuch-version (if (string= notmuch-emacs-version "unknown")
+			     (notmuch-cli-version)
+			   notmuch-emacs-version)))
+    (concat "Notmuch/" notmuch-version " (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 6564816..5284e77 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 ")
-- 
1.9.3


Thread: