[Top][All Lists]

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

[elpa] externals/gnorb 8e705ea3 380/449: Sneakily add basic EBDB support

From: Stefan Monnier
Subject: [elpa] externals/gnorb 8e705ea3 380/449: Sneakily add basic EBDB support to Gnorb, bump to 1.3.0
Date: Fri, 27 Nov 2020 23:16:15 -0500 (EST)

branch: externals/gnorb
commit 8e705ea3b73b63067fdecd41ab54a45b84814b19
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    Sneakily add basic EBDB support to Gnorb, bump to 1.3.0
    * packages/gnorb/gnorb-utils.el (gnorb-scan-links): Generalize this
      function so it can find links of any type. Use an alist instead of a
      plist, as alist-get is setf-able.
    * packages/gnorb/gnorb-org.el (gnorb-org-handle-mail): Search for ebdb
      links as well as bbdb links, and handle them.
    * packages/gnorb/gnorb-registry.el (gnorb-registry-transition-from-props):
    * packages/gnorb/nngnorb.el (nnir-run-gnorb): Adjust.
    * packages/gnorb/gnorb.el: Bump version.
 gnorb-org.el      | 59 +++++++++++++++++++++++++++++--------------------------
 gnorb-registry.el |  2 +-
 gnorb-utils.el    | 40 +++++++++++++++----------------------
 gnorb.el          |  2 +-
 nngnorb.el        |  6 +++---
 5 files changed, 52 insertions(+), 57 deletions(-)

diff --git a/gnorb-org.el b/gnorb-org.el
index 7e42cb8..ee6665a 100644
--- a/gnorb-org.el
+++ b/gnorb-org.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2014  Free Software Foundation, Inc.
 ;; Author: Eric Abrahamsen  <eric@ericabrahamsen.net>
-;; Keywords: 
+;; Keywords:
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
 ;;; Commentary:
 ;;; Code:
@@ -213,7 +213,7 @@ we came from."
          (insert s)
          (insert "\n"))
        (goto-char (point-min))
-       (gnorb-scan-links (point-max) 'gnus 'mail 'bbdb)))))
+       (gnorb-scan-links (point-max) 'gnus 'mail 'bbdb 'ebdb)))))
 (defun gnorb-org-extract-mail-stuff (&optional arg region)
   "Decide how to hande the Org heading under point as an email task.
@@ -274,7 +274,7 @@ See the docstring of `gnorb-org-handle-mail' for details."
      ;; Otherwise ignore the other links in the subtree, and return
      ;; the latest message.
-      `(:gnus ,(list msg-id-link))))))
+      `(gnus ,msg-id-link)))))
 (defvar message-beginning-of-line)
@@ -307,7 +307,7 @@ headings."
   ;; `gnorb-gnus-check-outgoing-headers' is set unconditionally in the
   ;; `message-send-hook, so this should be redundant.  Also, we've
   ;; switched to using message-send-actions.
   ;; (add-to-list
   ;; 'message-exit-actions 'gnorb-org-restore-after-send t) Set
   ;; headers from MAIL_* properties (from, cc, and bcc).
@@ -377,11 +377,10 @@ current heading, or the heading indicated by optional 
argument ID."
 (defvar message-mode-hook)
-(defun gnorb-org-handle-mail (&optional arg text file)
+(defun gnorb-org-handle-mail (arg &optional text file)
   "Handle current headline as a mail TODO.
 How this function behaves depends on whether you're using Gnorb
-for email tracking, also on the prefix arg, and on the active
+for email tracking, also on the prefix ARG, and on the active
 If tracking is enabled and there is no prefix arg, Gnorb will
@@ -406,7 +405,10 @@ automatically tracked, as well.
 If tracking is not enabled and you want to use a specific link in
 the subtree as a basis for the email action, then put the region
-around that link before you call this message."
+around that link before you call this message.
+TEXT is text to insert into the body of the message being
+composed.  FILE is a file to attach to the message."
   (interactive "P")
   (setq gnorb-window-conf (current-window-configuration))
   (move-marker gnorb-return-marker (point))
@@ -423,7 +425,7 @@ around that link before you call this message."
       (goto-char pos)))
   (let ((region
         (when (use-region-p)
-          (cons (region-beginning) (region-end)))))
+          (region-bounds))))
       (unless (org-back-to-heading t)
@@ -438,32 +440,33 @@ around that link before you call this message."
               (cc (mp "MAIL_CC"))
               (bcc (mp "MAIL_BCC"))
               (org-id (org-id-get-create))
-              (recs (plist-get links :bbdb))
+              (b-recs (alist-get 'bbdb links))
+              (e-recs (alist-get 'ebdb links))
               (message-mode-hook (copy-sequence message-mode-hook))
          (when file
            (setq attachments (cons file attachments)))
-         (when recs
-           (setq recs
-                 (delq nil
-                       (mapcar
-                        (lambda (r)
-                          (car (bbdb-message-search
-                                (org-link-unescape r)
-                                nil)))
-                        recs))))
-         (when recs
-           (dolist (r recs)
-             (push (bbdb-mail-address r) mails)))
-         (when (and recs
+         (when (fboundp 'ebdb-org-retrieve)
+           (dolist (e (alist-get 'ebdb links))
+             (dolist (r (ebdb-org-retrieve e))
+               (let ((m (ebdb-dwim-mail r)))
+                 (when m
+                   (push m mails))))))
+         (dolist (b (alist-get 'bbdb links))
+           (let ((m (ebdb-mail-address
+                     (car (bbdb-message-search
+                           (org-link-unescape r))))))
+             (when m
+               (push m mails))))
+         (when (and b-recs
            (add-hook 'message-mode-hook
                      (lambda ()
-                       (gnorb-bbdb-configure-posting-styles (cdr recs))
-                       (gnorb-bbdb-configure-posting-styles (list (car 
+                       (gnorb-bbdb-configure-posting-styles (cdr b-recs))
+                       (gnorb-bbdb-configure-posting-styles (list (car 
-          (plist-get links :gnus)
-          (append mails (plist-get links :mail))
+          (alist-get 'gnus links)
+          (append mails (alist-get 'mail links))
           from cc bcc
           attachments text org-id))))))
diff --git a/gnorb-registry.el b/gnorb-registry.el
index 05f91f5..91910aa 100644
--- a/gnorb-registry.el
+++ b/gnorb-registry.el
@@ -287,7 +287,7 @@ your Org files."
          (setq links (gnorb-scan-links
                       (org-element-property :end (org-element-at-point))
-         (dolist (l (plist-get links :gnus))
+         (dolist (l (alist-get 'gnus links))
             (cl-second (split-string l "#")) nil nil
             id (cl-first (split-string l "#"))))
diff --git a/gnorb-utils.el b/gnorb-utils.el
index 3e3fe03..4a734cb 100644
--- a/gnorb-utils.el
+++ b/gnorb-utils.el
@@ -459,37 +459,29 @@ If the KW argument is true, add the TODO keyword into the 
 (defun gnorb-scan-links (bound &rest types)
   "Scan from point to BOUND looking for links of type in TYPES.
+TYPES is a list of symbols; we search for all links corresponding
+to those symbols."
+  ;; It may be excessive to examine *all* links, rather than just
+  ;; creating a specialized regexp for the links we want, but it's
+  ;; nice to be lazy and use `org-bracket-link-analytic-regexp', that
+  ;; seems safer.
-TYPES is a list of symbols, possible values include 'bbdb, 'mail,
-and 'gnus."
-  ;; this function could be refactored somewhat -- lots of code
-  ;; repetition. It also should be a little faster for when we're
-  ;; scanning for gnus links only, that's a little slow. We should
-  ;; probably use a different regexp based on the value of TYPES.
-  ;;
   ;; This function should also *not* be responsible for unescaping
   ;; links -- we don't know what they're going to be used for, and
   ;; unescaped is safer.
   (unless (= (point) bound)
-    (let (addr gnus mail bbdb)
-      (while (re-search-forward org-any-link-re bound t)
-       (setq addr (or (match-string-no-properties 2)
-                      (match-string-no-properties 0)))
-       (cond
-        ((and (memq 'gnus types)
-              (string-match "^<?gnus:" addr))
-         (push (substring addr (match-end 0)) gnus))
-        ((and (memq 'mail types)
-              (string-match "^<?mailto:"; addr))
-         (push (substring addr (match-end 0)) mail))
-        ((and (memq 'bbdb types)
-              (string-match "^<?bbdb:" addr))
-         (push (substring addr (match-end 0)) bbdb))))
-      `(:gnus ,(reverse gnus) :mail ,(reverse mail) :bbdb ,(reverse bbdb)))))
+    (let ((alist (mapcar #'list (copy-sequence types))))
+      (while (re-search-forward org-bracket-link-analytic-regexp bound t)
+       (let* ((type (match-string-no-properties 2))
+              (link (match-string-no-properties 3))
+              (sym (intern-soft type)))
+         (when (memq sym types)
+           (push link (alist-get sym alist)))))
+      alist)))
 (defun gnorb-msg-id-to-link (msg-id)
-  "Given a message id, try to create a full org link to the
+  "Create a full Org link to the message MSG-ID.
+The main work is figuring out which group the message is in."
   (let ((server-group (car (gnorb-msg-id-request-head msg-id))))
     (when server-group
diff --git a/gnorb.el b/gnorb.el
index 699f84b..9c369b8 100644
--- a/gnorb.el
+++ b/gnorb.el
@@ -2,7 +2,7 @@
 ;; Copyright (C) 2014  Free Software Foundation, Inc.
-;; Version: 1.2.4
+;; Version: 1.3.0
 ;; Package-Requires: ((cl-lib "0.5"))
 ;; Maintainer: Eric Abrahamsen <eric@ericabrahamsen.net>
diff --git a/nngnorb.el b/nngnorb.el
index 8b84afe..f706883 100644
--- a/nngnorb.el
+++ b/nngnorb.el
@@ -126,9 +126,9 @@ be scanned for gnus messages, and those messages displayed."
       (with-current-buffer buf
        (goto-char (point-min))
-       (setq links (append (plist-get (gnorb-scan-links (point-max) 'gnus)
-                                      :gnus)
-                           links))
+       (setq links (append
+                    (alist-get 'gnus (gnorb-scan-links (point-max) 'gnus))
+                    links))
        (goto-char (point-min)))
       ;; First add all links to messages (elements of messages should

reply via email to

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