branch: externals/bbdb
commit f69bf82b80f142f9de44ce2e2b6858081752caaf
Author: jao <j...@gnu.org>
Commit: Roland Winkler <wink...@gnu.org>

    Support for notmuch mua
---
 README               | 11 +++++++----
 lisp/bbdb-mua.el     | 17 ++++++++++++++---
 lisp/bbdb-notmuch.el | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 lisp/bbdb.el         |  7 +++++--
 4 files changed, 80 insertions(+), 9 deletions(-)

diff --git a/README b/README
index 233ed4f3bf..eb3c95b1d0 100644
--- a/README
+++ b/README
@@ -4,8 +4,8 @@ See the end of the file for license conditions.
 BBDB is the Insidious Big Brother Database for GNU Emacs.
 It provides an address book for email and snail mail addresses,
 phone numbers and the like.  It can be linked with various Emacs mail
-clients (Message and Mail mode, Rmail, Gnus, MH-E, Mu4e, VM, and 
-Wanderlust).  BBDB is fully customizable.
+clients (Message and Mail mode, Rmail, Gnus, MH-E, Mu4e, VM, Notmuch,
+and Wanderlust).  BBDB is fully customizable.
 
 BBDB is available at
 http://elpa.gnu.org/packages/bbdb.html
@@ -56,6 +56,9 @@ To compile and install BBDB from Savannah with `make'
    `--with-wl-dir=DIR' specifies the path where Wanderlust can be found.
      Without this option the resulting BBDB build does not support WL.
 
+   `--with-notmuch-dir=DIR' specifies the path where Notmuch can be found.
+     Without this option the resulting BBDB build does not support Notmuch.
+
    `--with-lispdir=DIR' specifies where to install the lisp files.
 
    Use `configure --help' to see all available options.
@@ -129,8 +132,8 @@ BBDB interface with mail user agents (MUAs)
 ===========================================
 
 BBDB can interface with various mail user agents (MUAs).
-These include Rmail, Gnus, VM, MH-E, Mu4e, Wanderlust, Message and Mail mode.
-This lets you
+These include Rmail, Gnus, VM, MH-E, Mu4e, Notmuch, Wanderlust, Message
+and Mail mode.  This lets you
 
  - display the BBDB records for the sender and/or recipients of a
    message you are viewing
diff --git a/lisp/bbdb-mua.el b/lisp/bbdb-mua.el
index df0366a722..da9d56a499 100644
--- a/lisp/bbdb-mua.el
+++ b/lisp/bbdb-mua.el
@@ -65,6 +65,8 @@
 
   (autoload 'bbdb/wl-header "bbdb-wl")
 
+  (autoload 'bbdb/notmuch-header "bbdb-notmuch")
+
   (autoload 'message-field-value "message")
   (autoload 'mail-decode-encoded-word-string "mail-parse"))
 
@@ -74,6 +76,7 @@
     (rmail rmail-mode rmail-summary-mode)
     (mh mhe-mode mhe-summary-mode mh-folder-mode)
     (mu4e mu4e-view-mode)  ; Tackle `mu4e-headers-mode' later
+    (notmuch notmuch-show-mode notmuch-tree-mode)
     (wl wl-summary-mode wl-draft-mode mime-view-mode)
     (message message-mode mu4e-compose-mode notmuch-message-mode)
     (mail mail-mode))
@@ -88,6 +91,7 @@ Return values include
   vm        Viewmail
   mh        Emacs interface to the MH mail system (aka MH-E)
   mu4e      Mu4e
+  notmuch   Notmuch
   wl        Wanderlust
   message   Mail and News composition mode that goes with Gnus
   mail      Emacs Mail Mode."
@@ -138,6 +142,7 @@ MIME encoded headers are decoded.  Return nil if HEADER 
does not exist."
                        (rmail-get-header header)))
                     ((eq mua 'mh) (bbdb/mh-header header))
                     ((eq mua 'mu4e) (message-field-value header))
+                    ((eq mua 'notmuch) (bbdb/notmuch-header header))
                     ((eq mua 'wl) (bbdb/wl-header header))
                     ((memq mua '(message mail)) (message-field-value header))
                     (t (error "BBDB/%s: header function undefined" mua)))))
@@ -638,11 +643,16 @@ If SORT is non-nil, sort records according to 
`bbdb-record-lessp'."
                       gnus-article-buffer))
         (bbdb-update-records (bbdb-get-address-components header-class)
                              action sort))
+       ;; notmuch
+       ((eq mua 'notmuch)
+        (bbdb-update-records (bbdb-get-address-components header-class)
+                             action sort))
+
        ;; Wanderlust
        ((eq mua 'wl)
         (bbdb-update-records (bbdb-get-address-components header-class)
                              action sort))
-      ;; Message and Mail
+       ;; Message and Mail
        ((memq mua '(message mail))
         (bbdb-update-records (bbdb-get-address-components header-class)
                              action sort))))))
@@ -659,10 +669,11 @@ If SORT is non-nil, sort records according to 
`bbdb-record-lessp'."
             (save-current-buffer
               (gnus-summary-select-article) ; sets buffer `gnus-summary-buffer'
               ,@body))
-           ((memq mua '(mail message rmail mh vm mu4e wl))
+           ((memq mua '(mail message rmail mh vm mu4e notmuch wl))
             (cond ((eq mua 'vm) (vm-follow-summary-cursor))
                   ((eq mua 'mh) (mh-show)))
-            ;; rmail, mail, message, mu4e and wl do not require any wrapper
+            ;; rmail, mail, message, mu4e, notmuch and wl do not require
+            ;; any wrapper
             ,@body))))
 
 (define-obsolete-function-alias 'bbdb-mua-update-interactive-p
diff --git a/lisp/bbdb-notmuch.el b/lisp/bbdb-notmuch.el
new file mode 100644
index 0000000000..504f546eba
--- /dev/null
+++ b/lisp/bbdb-notmuch.el
@@ -0,0 +1,54 @@
+;;; bbdb-notmuch.el --- BBDB interface to notmuch -*- lexical-binding: t -*-
+
+;; Copyright (C) 2022  Free Software Foundation, Inc.
+
+;; This file is part of the Insidious Big Brother Database (aka BBDB),
+
+;; BBDB is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; BBDB is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with BBDB.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;; This file contains the BBDB interface to notmuch.
+;; See the BBDB info manual for documentation.
+
+;;; Code:
+
+(require 'bbdb)
+(require 'notmuch-show)
+(require 'notmuch-tree)
+
+(defvar notmuch-show-mode-map)
+(defvar notmuch-tree-mode-map)
+
+;;;###autoload
+(defun bbdb/notmuch-header (header)
+  "Find and return the value of HEADER in the current buffer.
+Return nil if HEADER is not in the message.  This function works
+in notmuch-show-mode and notmuch-tree-mode buffers."
+  (let ((ps (if (derived-mode-p 'notmuch-tree-mode)
+                (notmuch-tree-get-message-properties)
+              (notmuch-show-get-message-properties)))
+        (hdk (cond ((stringp header)
+                    (intern (format ":%s" (capitalize header))))
+                   ((keywordp header) header))))
+    (plist-get (plist-get ps :headers) hdk)))
+
+;;;###autoload
+(defun bbdb-insinuate-notmuch ()
+  "Hook BBDB into notmuch.
+Do not call this in your init file.  Use `bbdb-initialize'."
+  (dolist (m (list notmuch-show-mode-map notmuch-tree-mode-map))
+    (define-key m ":" 'bbdb-mua-display-sender)
+    (define-key m ";" 'bbdb-mua-edit-field-sender)))
+
+;;; bbdb-notmuch.el ends here
diff --git a/lisp/bbdb.el b/lisp/bbdb.el
index 99316926f4..a29306f156 100644
--- a/lisp/bbdb.el
+++ b/lisp/bbdb.el
@@ -1707,6 +1707,7 @@ See also `bbdb-silent'.")
 (declare-function bbdb-insinuate-mail "bbdb-message" ())
 (declare-function bbdb-insinuate-message "bbdb-message" ())
 (declare-function bbdb-insinuate-mu4e "bbdb-m4e" ())
+(declare-function bbdb-insinuate-notmuch "bbdb-notmuch" ())
 (declare-function bbdb-insinuate-sc "bbdb-sc" ())
 (declare-function bbdb-pgp "bbdb-pgp" ())
 (declare-function bbdb-insinuate-wl "bbdb-wl" ())
@@ -1732,8 +1733,9 @@ See also `bbdb-silent'.")
      ,(lambda () (add-hook 'message-setup-hook #'bbdb-insinuate-message)))
     (mu4e                       ; the mu4e user agent
      ,(lambda () (add-hook 'mu4e-main-mode-hook #'bbdb-insinuate-mu4e)))
-
-    (sc                         ; supercite
+    (notmuch                    ; the notmuch user agent
+     ,(lambda () (add-hook 'notmuch-hello-mode-hook #'bbdb-insinuate-notmuch)))
+    (sc                                 ; supercite
      ,(lambda () (add-hook 'sc-load-hook #'bbdb-insinuate-sc)))
     (anniv                      ; anniversaries
      ,(lambda () (add-hook 'diary-list-entries-hook 
#'bbdb-anniv-diary-entries)))
@@ -4816,6 +4818,7 @@ mail/news readers, composers, and miscellaneous packages:
   gnus       Gnus mail/news reader.
   mh-e       MH-E mail reader.
   mu4e       Mu4e mail reader.
+  notmuch    Notmuch mail reader.
   rmail      Rmail mail reader.
   vm         VM mail reader.
   mail       Mail (M-x mail).

Reply via email to