unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Daniel Bergey <bergey@alum.mit.edu>
To: Notmuch Mail List <notmuch@notmuchmail.org>
Subject: [PATCH] emacs: functions to import sender or recipient into BBDB
Date: Thu, 26 Jul 2012 16:09:17 -0400	[thread overview]
Message-ID: <87lii62sk2.fsf@wonderlust.lan> (raw)

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@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

             reply	other threads:[~2012-07-26 20:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-26 20:09 Daniel Bergey [this message]
2012-10-19 22:52 ` [PATCH] emacs: functions to import sender or recipient into BBDB Ethan Glasser-Camp
2012-10-20  9:14   ` Tomi Ollila
2012-10-20 18:23     ` Jameson Graef Rollins
2012-10-20 19:35       ` Tomi Ollila
2012-10-20 21:10         ` Jani Nikula
2012-10-21 12:16           ` Tomi Ollila
2012-11-19  0:08   ` Daniel Bergey
2013-02-07 18:51     ` Daniel Bergey
2013-02-19  7:24       ` Tomi Ollila
2013-03-31 18:20         ` Daniel Bergey
2013-03-31 18:40           ` Tomi Ollila
2013-04-06 11:37           ` David Bremner
2013-04-06 19:43             ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lii62sk2.fsf@wonderlust.lan \
    --to=bergey@alum.mit.edu \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).