From: Tomi Ollila Date: Sat, 21 Mar 2015 10:15:55 +0000 (+0200) Subject: [PATCH v2] emacs: prefer notmuch-emacs-version in User-Agent: header X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ee12cf9163716bcd9b17527a37570338f15ba6c4;p=notmuch-archives.git [PATCH v2] emacs: prefer notmuch-emacs-version in User-Agent: header --- diff --git a/b3/dbc659c9b478ba07f2fed288e784860fb2011e b/b3/dbc659c9b478ba07f2fed288e784860fb2011e new file mode 100644 index 000000000..bd4dc8294 --- /dev/null +++ b/b3/dbc659c9b478ba07f2fed288e784860fb2011e @@ -0,0 +1,177 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 295D1431FC2 + for ; Sat, 21 Mar 2015 03:16:32 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 2.438 +X-Spam-Level: ** +X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id rO88FvzUAoqU for ; + Sat, 21 Mar 2015 03:16:28 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 1EE3C431FAE + for ; Sat, 21 Mar 2015 03:16:28 -0700 (PDT) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id 81F6410008C; Sat, 21 Mar 2015 12:16:06 +0200 (EET) +From: Tomi Ollila +To: notmuch@notmuchmail.org +Subject: [PATCH v2] emacs: prefer notmuch-emacs-version in User-Agent: header +Date: Sat, 21 Mar 2015 12:15:55 +0200 +Message-Id: <1426932955-23174-1-git-send-email-tomi.ollila@iki.fi> +X-Mailer: git-send-email 2.0.0 +Cc: tomi.ollila@iki.fi +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 21 Mar 2015 10:16:32 -0000 + +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 +