emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ebdb b635b4e 155/350: First stab at article snarfing


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb b635b4e 155/350: First stab at article snarfing
Date: Mon, 14 Aug 2017 11:46:26 -0400 (EDT)

branch: externals/ebdb
commit b635b4e6d611a4b823942c5869de68fac77120ac
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    First stab at article snarfing
    
    * ebdb-mua.el (ebdb-mua-snarf-article): Interactive function for
      snarfing the text of an article in MUA.
      (ebdb-mua-article-body): Generic function for returning the text of
      an article.
    * ebdb-gnus.el (ebdb-mua-article-body): Implement for Gnus.
---
 ebdb-gnus.el | 16 ++++++++++++++++
 ebdb-mua.el  | 21 +++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/ebdb-gnus.el b/ebdb-gnus.el
index eef83d1..e82369a 100644
--- a/ebdb-gnus.el
+++ b/ebdb-gnus.el
@@ -456,6 +456,22 @@ Note that `\( is the backquote, NOT the quote '\(."
 (cl-defmethod ebdb-mua-prepare-article (&context (major-mode 
gnus-article-mode))
   (gnus-summary-select-article))
 
+(cl-defmethod ebdb-mua-article-body (&context (major-mode gnus-summary-mode))
+  "Return the current article body as a string.
+
+Must not include article headers, though can include headers in
+quoted replies."
+  (gnus-with-article-buffer
+    ;; This pretends that there's no such thing as mime parts, and
+    ;; will probably fail horribly.
+    (article-goto-body)
+    (buffer-substring-no-properties (point) (point-max))))
+
+(cl-defmethod ebdb-mua-article-body (&context (major-mode gnus-article-mode))
+   (gnus-with-article-buffer
+    (article-goto-body)
+    (buffer-substring-no-properties (point) (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 349e9ba..8885667 100644
--- a/ebdb-mua.el
+++ b/ebdb-mua.el
@@ -1118,6 +1118,12 @@ Ie, don't pop up at all."
   "When popping up from a random window, use half the window."
   (list (get-buffer-window) 0.5))
 
+(cl-defgeneric ebdb-mua-article-body (major-mode)
+  "Return the text of the current MUA article, as a string.
+
+This method should NOT return the message headers, only the
+article text.  This is typically used for snarfing.")
+
 ;;;###autoload
 (defun ebdb-mua-update-records (&optional header-class all)
   "Update all records associated with the message under point.
@@ -1288,6 +1294,21 @@ FIELD defaults to value of variable 
`ebdb-mua-edit-field'."
   (interactive)
   (ebdb-mua-edit-field field 'recipients))
 
+;;;###autoload
+(defun ebdb-mua-snarf-article ()
+  "Snarf the body of the current article."
+  (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)))))
+       (ebdb-mua-prepare-article)
+       (ebdb-snarf (ebdb-mua-article-body) recs))
+    (cl-no-applicable-method
+     (message "Article snarfing doesn't work in this context."))))
+
 ;; Functions for noninteractive use in MUA hooks
 
 ;;;###autoload



reply via email to

[Prev in Thread] Current Thread [Next in Thread]