[PATCH] emacs: functions to import sender or recipient into BBDB

Daniel Bergey bergey at alum.mit.edu
Thu Jul 26 13:09:17 PDT 2012


>From a show buffer, bbdb/notmuch-snarf-from imports the sender into
bbdb.  bbdb/notmuch-snarf-to attempts to import all recipients.  BBDB
displays a buffer with each contact; C-g displays the next contact, or
returns to the notmuch-show buffer.

Both functions assume that email contacts are seperated by commas.  If a
comma is included in a name, it will try to make two separate
contacts.
---
This is my first notmuch patch.  Comments very welcome.

 emacs/notmuch-show.el |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 6335d45..3bc1da0 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1895,6 +1895,34 @@ the user (see `notmuch-show-stash-mlarchive-link-alist')."
 		       (button-get button :notmuch-filename)
 		       (button-get button :notmuch-content-type)))))))
 
+;; bbdb interaction functions, awaiting user keybindings
+
+(defun bbdb/snarf-between-commas ()
+  ; What about names written "Surname, First M" <user at server.tld>?
+  (goto-char (point-min))
+  (let ((comma (point)))
+    (while (search-forward "," nil "end")
+      (bbdb-snarf-region comma (point))
+      (setq comma (point)))
+    (bbdb-snarf-region comma (point)) ; last entry
+   ))
+
+(defun bbdb/notmuch-snarf-header (header)
+  (let ((text (notmuch-show-get-header header)))
+    (with-temp-buffer
+      (insert text)
+      (bbdb/snarf-between-commas))))
+
+(defun bbdb/notmuch-snarf-from ()
+  "Import the sender of the current message into BBDB"
+  (interactive)
+  (bbdb/notmuch-snarf-header :From))
+
+(defun bbdb/notmuch-snarf-to ()
+  "Import all recipients of the current message into BBDB"
+  (interactive)
+  (bbdb/notmuch-snarf-header :To))
+
 ;;
 
 (provide 'notmuch-show)
-- 
1.7.10.4



More information about the notmuch mailing list