Hi all,

Attached diff against current master adds basic support for
Wanderlust, a mail/news management system with IMAP4rev1 support for
Emacsen.

Side note: While implementing the support I noticed that the macro
'bbdb-mua-wrapper' seems to be one important part that prevents one
from adding support for additional muas w/o patching bbdb itself. You
could rewrite the macro to simply use a dispatch table to select an
appropriate function to select buffer based on mua:

,----
| (defmacro bbdb-mua-wrapper (&rest body)
|   "Execute BODY in a message buffer."
|   (declare (debug t))
|   (let ((mua (gensym)))
|     `(let ((,mua (bbdb-mua)))
|        (with-current-buffer (funcall (or (cdr (assq ,mua 
bbdb-mua-select-message-buffer-func-alist)) 'current-buffer))
|          ,@body))))
`----

With this modified macro in place I was able to use BBDB with
Wanderlust only be modifying variables and advicing defuns [1] since
2014.

The diff does *not* modify the macro but integrates Wanderlust using
the current convention.

Best,
  -- David

[1] https://github.com/dmj/bbdbv3/blob/t/wanderlust/lisp/bbdb-wanderlust.el

diff --git a/ChangeLog b/ChangeLog
index 295c48d..9a61d8c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2015-11-21  David Maus  <dm...@dmaus.name>
+
+       * lisp/bbdb-mua.el (bbdb-mua-mode-alist, bbdb-mua)
+       (bbdb-message-header, bbdb-mua-update-records, bbdb-mua-wrapper):
+       Add support for Wanderlust.
+       * lisp/bbdb.el (bbdb-init-forms): Add support for Wanderlust.
+       * lisp/bbdb-wanderlust.el: New file. Add basic support for
+       Wanderlust.
+
 2015-11-14  Roland Winkler  <wink...@gnu.org>
        * lisp/bbdb.el (bbdb-auto-revert, bbdb-dedicated-window)
        (bbdb-default-domain, bbdb-mua-pop-up)
diff --git a/lisp/Makefile.am b/lisp/Makefile.am
index 413dbae..8440cd6 100644
--- a/lisp/Makefile.am
+++ b/lisp/Makefile.am
@@ -38,7 +38,8 @@ dist_lisp_LISP =                              \
        bbdb-rmail.el                           \
        bbdb-sc.el                              \
        bbdb-snarf.el                           \
-       bbdb-site.el
+       bbdb-site.el                            \
+       bbdb-wanderlust.el
 
 if VM
 dist_lisp_LISP += bbdb-vm.el
diff --git a/lisp/bbdb-mua.el b/lisp/bbdb-mua.el
index 29cf223..ded1c2a 100644
--- a/lisp/bbdb-mua.el
+++ b/lisp/bbdb-mua.el
@@ -59,7 +59,9 @@
   (defvar mu4e~view-buffer-name)
 
   (autoload 'message-field-value "message")
-  (autoload 'mail-decode-encoded-word-string "mail-parse"))
+  (autoload 'mail-decode-encoded-word-string "mail-parse")
+
+  (autoload 'bbdb/wanderlust-header "bbdb-wanderlust"))
 
 (defconst bbdb-mua-mode-alist
   '((vm vm-mode vm-virtual-mode vm-summary-mode vm-presentation-mode)
@@ -68,20 +70,22 @@
     (mh mhe-mode mhe-summary-mode mh-folder-mode)
     (message message-mode)
     (mail mail-mode)
-    (mu4e mu4e-view-mode)) ; Tackle `mu4e-headers-mode' later
+    (mu4e mu4e-view-mode)  ; Tackle `mu4e-headers-mode' later
+    (wanderlust wl-summary-mode wl-draft-mode))
   "Alist of MUA modes supported by BBDB.
 Each element is of the form (MUA MODE MODE ...), where MODEs are used by MUA.")
 
 (defun bbdb-mua ()
   "For the current message return the MUA.
 Return values include
-  gnus      Newsreader Gnus
-  rmail     Reading Mail in Emacs
-  vm        Viewmail
-  mh        Emacs interface to the MH mail system (aka MH-E)
-  message   Mail and News composition mode that goes with Gnus
-  mu4e      Mu4e
-  mail      Emacs Mail Mode."
+  gnus       Newsreader Gnus
+  rmail      Reading Mail in Emacs
+  vm         Viewmail
+  mh         Emacs interface to the MH mail system (aka MH-E)
+  message    Mail and News composition mode that goes with Gnus
+  mu4e       Mu4e
+  wanderlust Wanderlust
+  mail       Emacs Mail Mode."
   (let ((mm-alist bbdb-mua-mode-alist)
         elt mua)
     (while (setq elt (pop mm-alist))
@@ -115,6 +119,7 @@ MIME encoded headers are decoded.  Return nil if HEADER 
does not exist."
                     ((eq mua 'rmail) (bbdb/rmail-header header))
                     ((eq mua 'mh) (bbdb/mh-header header))
                     ((eq mua 'mu4e) (message-field-value header))
+                    ((eq mua 'wanderlust) (bbdb/wanderlust-header header))
                     ((memq mua '(message mail)) (message-field-value header))
                     (t (error "BBDB/%s: header function undefined" mua)))))
     (if val (mail-decode-encoded-word-string val))))
@@ -602,6 +607,10 @@ If SORT is non-nil, sort records according to 
`bbdb-record-lessp'."
         (set-buffer mu4e~view-buffer-name)
         (bbdb-update-records (bbdb-get-address-components header-class)
                              update-p sort))
+       ;; Wanderlust
+       ((eq mua 'wanderlust)
+        (bbdb-update-records (bbdb-get-address-components header-class)
+                             update-p sort))
       ;; Message and Mail
        ((memq mua '(message mail))
         (bbdb-update-records (bbdb-get-address-components header-class)
@@ -619,7 +628,7 @@ 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))
+           ((memq mua '(mail message rmail mh vm mu4e wanderlust))
             (cond ((eq mua 'vm) (vm-follow-summary-cursor))
                   ((eq mua 'mh) (mh-show)))
             ;; rmail, mail, message and mu4e do not require any wrapper
diff --git a/lisp/bbdb-wanderlust.el b/lisp/bbdb-wanderlust.el
new file mode 100644
index 0000000..5d230e8
--- /dev/null
+++ b/lisp/bbdb-wanderlust.el
@@ -0,0 +1,53 @@
+;;; bbdb-wanderlust.el --- BBDB interface to Wanderlust
+
+;; Copyright (C) 2015 David Maus <dm...@dmaus.name>
+
+;; 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 Wanderlust.
+;;; See the BBDB info manual for documentation.
+
+;;; Code:
+
+(require 'bbdb)
+(require 'bbdb-mua)
+
+(eval-when-compile
+  (defvar wl-summary-mode-map)
+  (defvar wl-draft-mode-map)
+  (defvar wl-summary-buffer-elmo-folder)
+  (autoload 'wl-summary-message-number "wl-summary")
+  (autoload 'elmo-message-entity "elmo-msgdb")
+  (autoload 'elmo-message-entity-field "elmo-msgdb"))
+
+(defun bbdb/wanderlust-header (header)
+  (elmo-message-entity-field
+   (elmo-message-entity wl-summary-buffer-elmo-folder 
(wl-summary-message-number))
+   (intern (downcase header)) 'string))
+
+;;;###autoload
+(defun bbdb-insinuate-wanderlust ()
+  "Hook BBDB into Wanderlust."
+  (define-key wl-summary-mode-map (kbd ":") #'bbdb-mua-display-sender)
+  (define-key wl-summary-mode-map (kbd ";") #'bbdb-mua-edit-field-sender)
+  (when bbdb-complete-mail
+    (define-key wl-draft-mode-map (kbd "M-;") #'bbdb-complete-mail)
+    (define-key wl-draft-mode-map (kbd "M-<tab>") #'bbdb-complete-mail)))
+
+(provide 'bbdb-wanderlust)
+
+;;; bbdb-wanderlust.el ends here
diff --git a/lisp/bbdb.el b/lisp/bbdb.el
index 284341b..cdf15cc 100644
--- a/lisp/bbdb.el
+++ b/lisp/bbdb.el
@@ -1681,7 +1681,9 @@ See also `bbdb-silent'.")
     (pgp                        ; pgp-mail
      (progn
        (add-hook 'message-send-hook 'bbdb-pgp)
-       (add-hook 'mail-send-hook 'bbdb-pgp))))
+       (add-hook 'mail-send-hook 'bbdb-pgp)))
+    (wanderlust
+     (add-hook 'wl-init-hook 'bbdb-insinuate-wanderlust)))
   "Alist mapping features to insinuation forms.")
 
 (defvar bbdb-search-invert nil
diff --git a/lisp/makefile-temp b/lisp/makefile-temp
index 1aaa2b1..d91c2f9 100644
--- a/lisp/makefile-temp
+++ b/lisp/makefile-temp
@@ -64,7 +64,7 @@ SRCS =        bbdb.el bbdb-site.el bbdb-com.el bbdb-print.el 
bbdb-anniv.el \
        bbdb-migrate.el bbdb-snarf.el \
        bbdb-mua.el bbdb-message.el bbdb-rmail.el \
        bbdb-gnus.el bbdb-mhe.el bbdb-mu4e.el bbdb-vm.el bbdb-pgp.el \
-       bbdb-sc.el \
+       bbdb-sc.el bbdb-wanderlust.el \
        bbdb-ispell.el bbdb-pkg.el
 
 # ELC =        $(patsubst %.el,%.elc,$(SRCS)) # GNU Make
@@ -72,13 +72,14 @@ ELC =       bbdb.elc bbdb-site.elc bbdb-com.elc 
bbdb-print.elc bbdb-anniv.elc \
        bbdb-migrate.elc bbdb-snarf.elc \
        bbdb-mua.elc bbdb-message.elc bbdb-rmail.elc \
        bbdb-gnus.elc bbdb-mhe.elc bbdb-pgp.elc bbdb-sc.elc \
-       bbdb-ispell.elc # bbdb-pkg.elc
+       bbdb-ispell.elc bbdb-wanderlust.elc # bbdb-pkg.elc
 
 all: bbdb
 
 bbdb:  bbdb-loaddefs.el $(ELC)
 mu4e:  bbdb-mu4e.elc
 vm:    bbdb-vm.elc
+wanderlust:    bbdb-wanderlust.elc
 
 bbdb-loaddefs.el: $(SRCS)
 #      2011-12-11: We switched from bbdb-autoloads.el to bbdb-loaddefs.el.
@@ -132,6 +133,8 @@ bbdb-mhe.elc: bbdb-mhe.el bbdb-mua.elc
        $(emacs_compile) $(@:.elc=.el)
 bbdb-mu4e.elc: bbdb-mu4e.el bbdb-mua.elc
        $(emacs) $(MU4E) --funcall batch-byte-compile $(@:.elc=.el)
+bbdb-wanderlust.elc: bbdb-wanderlust.el bbdb-mua.elc
+       $(emacs_compile) $(@:.elc=.el)
 bbdb-vm.elc: bbdb-vm.el bbdb-mua.elc
        $(emacs) $(VM) --funcall batch-byte-compile $(@:.elc=.el)
 bbdb-sc.elc: bbdb-sc.el bbdb-mua.elc
------------------------------------------------------------------------------
_______________________________________________
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/

Reply via email to