branch: externals/ebdb
commit 851c0f12c6230d2e499d5cc5983e1252e936c41d
Author: Eric Abrahamsen <[email protected]>
Commit: Eric Abrahamsen <[email protected]>
Half-implement signature snarfing for MUAs
* ebdb-com.el: Remove commented-out customization option regarding
signature snarfing. This would have implemented automated snarfing,
which would have been a nightmare. Only snarf on user command.
* ebdb-mua.el (ebdb-mua-get-signature): New generic method for
returning the text of a message signature.
(ebdb-mua-snarf-article): Add signature snarfing as a part of this
function. Perhaps we'll want a separate function later?
* ebdb-gnus.el (ebdb-mua-get-signature): Implement for Gnus, figure
out the others later.
---
ebdb-com.el | 7 -------
ebdb-gnus.el | 10 ++++++++++
ebdb-mua.el | 31 +++++++++++++++++++++++++++----
3 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/ebdb-com.el b/ebdb-com.el
index a35e8f8..f261db1 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -80,13 +80,6 @@ Used by `ebdb-mouse-menu'."
:group 'ebdb-record-display
:type 'sexp)
-;; (defcustom ebdb-mua-auto-snarf-signature nil
-;; "If t, EBDB will attempt to snarf the mail message signature
-;; and add additional field information (ie phone or address) to
-;; the sending record.
-
-;; Valid values are nil, 'query or t, or 'auto.")
-
(defcustom ebdb-display-hook nil
"Hook run after the *EBDB* is filled in."
:group 'ebdb-record-display
diff --git a/ebdb-gnus.el b/ebdb-gnus.el
index 78394ca..4d0e318 100644
--- a/ebdb-gnus.el
+++ b/ebdb-gnus.el
@@ -472,6 +472,16 @@ quoted replies."
(article-goto-body)
(buffer-substring-no-properties (point) (point-max))))
+(cl-defmethod ebdb-mua-article-signature (&context (major-mode
gnus-summary-mode))
+ (gnus-with-article-buffer
+ (gnus-article-search-signature)
+ (forward-line)
+ (buffer-substring-no-properties
+ (point)
+ ;; Assume a blank line concludes a signature.
+ (or (re-search-forward "\n\n" nil t)
+ (point-max)))))
+
(defun ebdb-insinuate-gnus ()
"Hook EBDB into Gnus."
;; `ebdb-mua-display-sender' fails in *Article* buffers, where
diff --git a/ebdb-mua.el b/ebdb-mua.el
index 0a47580..2072f69 100644
--- a/ebdb-mua.el
+++ b/ebdb-mua.el
@@ -953,6 +953,14 @@ Dispatches on the value of major-mode."
This method should NOT return the message headers, only the
article text. This is typically used for snarfing.")
+(cl-defgeneric ebdb-mua-article-signature (major-mode)
+ "Return the text of the signature of the current article.")
+
+;; At the moment this is only implemented for Gnus.
+(cl-defmethod ebdb-mua-article-signature ()
+ "Default version returns nothing."
+ "")
+
;;;###autoload
(defun ebdb-mua-update-records (&optional header-class all)
"Update all records associated with the message under point.
@@ -1073,16 +1081,31 @@ where it was in the MUA, rather than quitting the EBDB
buffer."
;;;###autoload
(defun ebdb-mua-snarf-article ()
- "Snarf the body of the current article."
+ "Snarf the body of the current article.
+
+This snarfs all available record information in the article,
+first attempting to associate it with the senders and recipients
+of the article, afterwards prompting for the creation of new
+records.
+
+In addition, if a signature is present, snarf it and attempt at
+associate field information in it with the article sender."
(interactive)
(condition-case nil
;; If the MUA has already popped up a buffer, assume the records
;; displayed there are relevant to the article snarf.
(let* ((buf (get-buffer (ebdb-make-buffer-name)))
- (recs (when (buffer-live-p buf)
- (mapcar #'car (buffer-local-value 'ebdb-records buf)))))
+ (all-recs (ebdb-update-records
+ (ebdb-get-address-components)
+ 'existing))
+ (sender (ebdb-update-records
+ (ebdb-get-address-components 'sender)
+ 'existing))
+ (signature (ebdb-mua-get-signature)))
(ebdb-mua-prepare-article)
- (ebdb-snarf (ebdb-mua-article-body) nil nil recs))
+ (unless (or (null (stringp signature)) (string-blank-p signature))
+ (ebdb-snarf signature nil nil sender))
+ (ebdb-snarf (ebdb-mua-article-body) nil nil all-recs))
(cl-no-applicable-method
(message "Article snarfing doesn't work in this context."))))