From 3c1eea5646fcf33d66acb874d82f3518a75c24de Mon Sep 17 00:00:00 2001
From: Tomi Ollila <tomi.ollila@iki.fi>
Date: Sun, 2 Aug 2015 17:48:14 +0300
Subject: [PATCH] emacs: prefer notmuch-emacs-version in User-Agent: header

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.
---
 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 e16a1b97..201d7ec8 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 934f6c95..3e52d5e2 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -118,7 +118,10 @@ Note that these functions use `mail-citation-hook' if that is non-nil."
 
 (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 6564816f..5284e771 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.45.2