* [PATCH] emacs: functions to import sender or recipient into BBDB
@ 2012-07-26 20:09 Daniel Bergey
2012-10-19 22:52 ` Ethan Glasser-Camp
0 siblings, 1 reply; 14+ messages in thread
From: Daniel Bergey @ 2012-07-26 20:09 UTC (permalink / raw)
To: Notmuch Mail List
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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2012-07-26 20:09 [PATCH] emacs: functions to import sender or recipient into BBDB Daniel Bergey
@ 2012-10-19 22:52 ` Ethan Glasser-Camp
2012-10-20 9:14 ` Tomi Ollila
2012-11-19 0:08 ` Daniel Bergey
0 siblings, 2 replies; 14+ messages in thread
From: Ethan Glasser-Camp @ 2012-10-19 22:52 UTC (permalink / raw)
To: Daniel Bergey, Notmuch Mail List
Daniel Bergey <bergey@alum.mit.edu> writes:
> 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.
>
> This is my first notmuch patch. Comments very welcome.
Hi!
> emacs/notmuch-show.el | 28 ++++++++++++++++++++++++++++
I don't think this belongs in notmuch-show. My first inclination is that
this should go into a new file contrib/notmuch-bbdb.el (assuming there's
no other notmuch-bbdb integration stuff floating around).
> 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>?
Most comments in emacslisp start with two semicolons.
I do think more sophisticated parsing is necessary. If you're lucky,
somebody else already has a library to parse email addresses in this
form.
> + (goto-char (point-min))
I'm not crazy about this. It's probably fine for something limited to
bbdb users (especially since bbdb-snarf uses a very similar technique),
but I think the better approach here is to just take a region and go
from region-beginning and region-end.
> + (let ((comma (point)))
> + (while (search-forward "," nil "end")
The third argument of search-forward is NOERROR. I don't understand what
the value "end" means. The help says "Optional third argument, if t..."
> + (bbdb-snarf-region comma (point))
> + (setq comma (point)))
> + (bbdb-snarf-region comma (point)) ; last entry
> + ))
Doesn't this cause snarf the comma into any of those entries? It seems
like point starts before the first entry but then goes before each
comma. Obviously this wouldn't be here if it didn't work. I thought
bbdb-snarf handled this kind of thing, but it doesn't. Could you explain
this?
Ethan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2012-10-19 22:52 ` Ethan Glasser-Camp
@ 2012-10-20 9:14 ` Tomi Ollila
2012-10-20 18:23 ` Jameson Graef Rollins
2012-11-19 0:08 ` Daniel Bergey
1 sibling, 1 reply; 14+ messages in thread
From: Tomi Ollila @ 2012-10-20 9:14 UTC (permalink / raw)
To: Daniel Bergey, Notmuch Mail List
On Sat, Oct 20 2012, Ethan Glasser-Camp wrote:
> Daniel Bergey <bergey@alum.mit.edu> writes:
>
>> 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.
>>
>> This is my first notmuch patch. Comments very welcome.
>
> Hi!
>
>> emacs/notmuch-show.el | 28 ++++++++++++++++++++++++++++
>
> I don't think this belongs in notmuch-show. My first inclination is that
> this should go into a new file contrib/notmuch-bbdb.el (assuming there's
> no other notmuch-bbdb integration stuff floating around).
>
>> 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>?
>
> Most comments in emacslisp start with two semicolons.
3 quick comments.
I was thinking notmuch-bbdb.el but contrib/notmuch-bbdb.el could be
good start.
then functions like notmuch-bbdb/snarf-between-commas etc...
and yes, ;; comments -- that also keeps indent-region happy.
Tomi
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2012-10-20 9:14 ` Tomi Ollila
@ 2012-10-20 18:23 ` Jameson Graef Rollins
2012-10-20 19:35 ` Tomi Ollila
0 siblings, 1 reply; 14+ messages in thread
From: Jameson Graef Rollins @ 2012-10-20 18:23 UTC (permalink / raw)
To: Tomi Ollila, Daniel Bergey, Notmuch Mail List
[-- Attachment #1: Type: text/plain, Size: 380 bytes --]
On Sat, Oct 20 2012, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> I was thinking notmuch-bbdb.el but contrib/notmuch-bbdb.el could be
> good start.
I find this functionality to be really useful. I don't know if we have
a method of distributing/packaging stuff in contrib, and since I would
prefer to see this actually integrated, lets just put it in
emacs/notmuch-bbdb.el.
jamie.
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2012-10-20 18:23 ` Jameson Graef Rollins
@ 2012-10-20 19:35 ` Tomi Ollila
2012-10-20 21:10 ` Jani Nikula
0 siblings, 1 reply; 14+ messages in thread
From: Tomi Ollila @ 2012-10-20 19:35 UTC (permalink / raw)
To: Jameson Graef Rollins, Daniel Bergey, Notmuch Mail List
On Sat, Oct 20 2012, Jameson Graef Rollins <jrollins@finestructure.net> wrote:
> On Sat, Oct 20 2012, Tomi Ollila <tomi.ollila@iki.fi> wrote:
>> I was thinking notmuch-bbdb.el but contrib/notmuch-bbdb.el could be
>> good start.
>
> I find this functionality to be really useful. I don't know if we have
> a method of distributing/packaging stuff in contrib, and since I would
> prefer to see this actually integrated, lets just put it in
> emacs/notmuch-bbdb.el.
Fine by me. I suggest:
file emacs/notmuch-bbdb.el
functions
notmuch-bbdb/snarf-between-commas
notmuch-bbdb/snarf-header
notmuch-bbdb/snarf-from
notmuch-bbdb/snarf-to
(or if the format in origina patch is in line what has been done elsewhere, then:)
bbdb/notmuch-snarf-header
bbdb/notmuch-snarf-from
bbdb/notmuch-snarf-to
(and, with Ethan's comments addressed)
And then, to notmuch.el or notmuch-show.el:
(autoload 'notmuch-bbdb/snarf-from "notmuch-bbdb"
"Import the sender of the current message into BBDB" t)
(autoload 'notmuch-bbdb/snarf-to "notmuch-bbdb"
"Import all recipients of the current message into BBDB" t)
>
> jamie.
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2012-10-20 19:35 ` Tomi Ollila
@ 2012-10-20 21:10 ` Jani Nikula
2012-10-21 12:16 ` Tomi Ollila
0 siblings, 1 reply; 14+ messages in thread
From: Jani Nikula @ 2012-10-20 21:10 UTC (permalink / raw)
To: Tomi Ollila; +Cc: Notmuch Mail
[-- Attachment #1: Type: text/plain, Size: 269 bytes --]
On Oct 20, 2012 10:35 PM, "Tomi Ollila" <tomi.ollila@iki.fi> wrote:
> Fine by me. I suggest:
>
> file emacs/notmuch-bbdb.el
Bikeshedding, but how about the existing notmuch-address.el? Surely bbdb
isn't the only address db, and there's bound to be code to share.
J.
[-- Attachment #2: Type: text/html, Size: 385 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2012-10-20 21:10 ` Jani Nikula
@ 2012-10-21 12:16 ` Tomi Ollila
0 siblings, 0 replies; 14+ messages in thread
From: Tomi Ollila @ 2012-10-21 12:16 UTC (permalink / raw)
Cc: Notmuch Mail
On Sun, Oct 21 2012, Jani Nikula wrote:
> On Oct 20, 2012 10:35 PM, "Tomi Ollila" <tomi.ollila@iki.fi> wrote:
>
>> Fine by me. I suggest:
>>
>> file emacs/notmuch-bbdb.el
>
> Bikeshedding, but how about the existing notmuch-address.el? Surely bbdb
> isn't the only address db, and there's bound to be code to share.
Good point -- this is the most consistent suggestion.
-- and customized insinuation (or something) for enable (??!!)
>
> J.
Tomi
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2012-10-19 22:52 ` Ethan Glasser-Camp
2012-10-20 9:14 ` Tomi Ollila
@ 2012-11-19 0:08 ` Daniel Bergey
2013-02-07 18:51 ` Daniel Bergey
1 sibling, 1 reply; 14+ messages in thread
From: Daniel Bergey @ 2012-11-19 0:08 UTC (permalink / raw)
To: Notmuch Mail List, Ethan Glasser-Camp
On 2012-10-19 at 18:52, Ethan Glasser-Camp <ethan.glasser.camp@gmail.com> wrote:
> Daniel Bergey <bergey@alum.mit.edu> writes:
>
>> 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.
>>
>> This is my first notmuch patch. Comments very welcome.
>>
>> +(defun bbdb/snarf-between-commas ()
>> + ; What about names written "Surname, First M" <user@server.tld>?
>
> I do think more sophisticated parsing is necessary. If you're lucky,
> somebody else already has a library to parse email addresses in this
> form.
I spent the afternoon digging around in BBDB internals. They include a
function that parses the contents of a header, and handles commas
intelligently. It replaces essentially all the code in my small patch,
so I won't respond to your detailed comments, much as I appreciated
them.
I have working code using bbdb-get-addresses, but I have a few questions
before I email the revised patch.
1) Is there a canonical list of header names used by notmuch? I'm
trying to fill in this alist to match the BBDB interface. It should be
fine to leave blank any that notmuch doesn't handle.
(defvar bbdb/notmuch-header-by-name
;; both are case sensitive
'( ("From" . :From)
("To" . :To)
("CC" . :Cc)
("BCC" . :Bcc)
("Resent-From" . )
("Reply-To" . )
("Resent-To" . )
("Resent-CC" . ))
"Alist for dispatching header symbols as used by notmuch-show-get-header
from strings as used by notmuch-show-get-header")
2) What's the consensus on naming conventions? BBDB has functions for
other mail clients with names like bbdb/gnus-* and bbdb/vm-*. I
imitated this convention, but maybe it's better to leave the bbdb/*
namespace to BBDB itself, and use a prefix like notmuch-bbdb-* or
notmuch-bbdb/* (Regardless, I moved everything to notmuch-address.el, as
suggested)
Thanks,
Daniel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2012-11-19 0:08 ` Daniel Bergey
@ 2013-02-07 18:51 ` Daniel Bergey
2013-02-19 7:24 ` Tomi Ollila
0 siblings, 1 reply; 14+ messages in thread
From: Daniel Bergey @ 2013-02-07 18:51 UTC (permalink / raw)
To: Notmuch Mail List, Ethan Glasser-Camp; +Cc: Chris Thachuk
From a show buffer, notmuch-bbdb/snarf-from imports the sender into
bbdb. notmuch-bbdb/snarf-to imports all recipients. Newly imported
concacts are reported in the minibuffer / Messages buffer.
Both functions use the BBDB parser to recognize email address formats.
---
Following discussion upthread, I put everything in notmuch-address. I
renamed the functions to put notmuch before bbdb. And I replaced the
horrid comma-splitting from my first version with the functions BBDB
provides for parsing email headers.
It looks as though Reply-To is not exposed in the :headers plist. I
assume the Resent-* headers are not, either. Therefore none of these
are imported (nil entries in notmuch-bbdb/header-by-name). They would be
easy to add if the plist is expanded.
Thanks, and sorry it's taken me so long to get back to this patch.
emacs/notmuch-address.el | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 2bf762b..8d5f727 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -98,4 +98,47 @@ line."
;;
+;; functions to add sender / recipients to BBDB
+
+(defun notmuch-bbdb/snarf-headers (headers)
+ ;; Helper function to avoid code duplication in the two below
+ ;; headers should have the same format as bbdb-get-addresses-headers
+
+ ;; bbdb-get-addresses reads these
+ ;; Ugh, pass-by-global
+ (let ((addrs (bbdb-get-addresses nil nil 'notmuch-bbdb/get-header-content))
+ (bbdb-get-addresses-headers headers) ; headers to read
+ (bbdb-gag-messages t) ; suppress m/n processed message
+ )
+ (bbdb-update-records addrs t t)))
+
+(defun notmuch-bbdb/snarf-from ()
+ "Import the sender of the current message into BBDB"
+ (interactive)
+ (notmuch-bbdb/snarf-headers
+ (list (assoc 'authors bbdb-get-addresses-headers))))
+
+(defun notmuch-bbdb/snarf-to ()
+ "Import all recipients of the current message into BBDB"
+ (interactive)
+ (notmuch-bbdb/snarf-headers
+ (list (assoc 'recipients bbdb-get-addresses-headers))))
+
+(defvar notmuch-bbdb/header-by-name
+ ;; both are case sensitive
+ '( ("From" . :From)
+ ("To" . :To)
+ ("CC" . :Cc)
+ ("BCC" . :Bcc)
+ ("Resent-From" . nil)
+ ("Reply-To" . nil)
+ ("Resent-To" . nil)
+ ("Resent-CC" . nil))
+ "Alist for dispatching header symbols as used by notmuch-show-get-header
+from strings as used by bbdb-get-addresses")
+
+(defun notmuch-bbdb/get-header-content (name)
+ (notmuch-show-get-header (cdr (assoc name notmuch-bbdb/header-by-name))))
+
+
(provide 'notmuch-address)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2013-02-07 18:51 ` Daniel Bergey
@ 2013-02-19 7:24 ` Tomi Ollila
2013-03-31 18:20 ` Daniel Bergey
0 siblings, 1 reply; 14+ messages in thread
From: Tomi Ollila @ 2013-02-19 7:24 UTC (permalink / raw)
To: Daniel Bergey, Notmuch Mail List, Ethan Glasser-Camp; +Cc: Chris Thachuk
On Thu, Feb 07 2013, Daniel Bergey wrote:
>From a show buffer, notmuch-bbdb/snarf-from imports the sender into
> bbdb. notmuch-bbdb/snarf-to imports all recipients. Newly imported
> concacts are reported in the minibuffer / Messages buffer.
>
> Both functions use the BBDB parser to recognize email address formats.
> ---
> Following discussion upthread, I put everything in notmuch-address. I
> renamed the functions to put notmuch before bbdb. And I replaced the
> horrid comma-splitting from my first version with the functions BBDB
> provides for parsing email headers.
>
> It looks as though Reply-To is not exposed in the :headers plist. I
> assume the Resent-* headers are not, either. Therefore none of these
> are imported (nil entries in notmuch-bbdb/header-by-name). They would be
> easy to add if the plist is expanded.
>
> Thanks, and sorry it's taken me so long to get back to this patch.
From my understanding the code looks pretty good; I have only some
whitespace consistency things that jist briefly passes the threshold
to mention -- comments inline.
But before doing a potential cleanup patch the users of notmuch-bbdb
please test and comment
> emacs/notmuch-address.el | 43 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 43 insertions(+)
>
> diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
> index 2bf762b..8d5f727 100644
> --- a/emacs/notmuch-address.el
> +++ b/emacs/notmuch-address.el
> @@ -98,4 +98,47 @@ line."
>
> ;;
This ';;' used to be 3rd last line in notmuch-address.el.
Running 'tail -n 5 emacs/*.el' reveals that it is (somewhat) consistent
to use it as "separator" between code above and (provide 'notmuch-...)
that follows.
> +;; functions to add sender / recipients to BBDB
> +
> +(defun notmuch-bbdb/snarf-headers (headers)
> + ;; Helper function to avoid code duplication in the two below
> + ;; headers should have the same format as bbdb-get-addresses-headers
> +
> + ;; bbdb-get-addresses reads these
> + ;; Ugh, pass-by-global
> + (let ((addrs (bbdb-get-addresses nil nil 'notmuch-bbdb/get-header-content))
> + (bbdb-get-addresses-headers headers) ; headers to read
> + (bbdb-gag-messages t) ; suppress m/n processed message
> + )
> + (bbdb-update-records addrs t t)))
> +
> +(defun notmuch-bbdb/snarf-from ()
> + "Import the sender of the current message into BBDB"
> + (interactive)
> + (notmuch-bbdb/snarf-headers
> + (list (assoc 'authors bbdb-get-addresses-headers))))
Two spaces above.
> +
> +(defun notmuch-bbdb/snarf-to ()
> + "Import all recipients of the current message into BBDB"
> + (interactive)
> + (notmuch-bbdb/snarf-headers
> + (list (assoc 'recipients bbdb-get-addresses-headers))))
Ditto.
> +
> +(defvar notmuch-bbdb/header-by-name
> + ;; both are case sensitive
> + '( ("From" . :From)
> + ("To" . :To)
> + ("CC" . :Cc)
> + ("BCC" . :Bcc)
> + ("Resent-From" . nil)
> + ("Reply-To" . nil)
> + ("Resent-To" . nil)
> + ("Resent-CC" . nil))
> + "Alist for dispatching header symbols as used by notmuch-show-get-header
> +from strings as used by bbdb-get-addresses")
> +
> +(defun notmuch-bbdb/get-header-content (name)
> + (notmuch-show-get-header (cdr (assoc name notmuch-bbdb/header-by-name))))
> +
> +
2 empty lines --- somewhat consistent with notmuch-lib.el ... but
not with anything else ;D
> (provide 'notmuch-address)
> --
> 1.7.10.4
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
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
0 siblings, 2 replies; 14+ messages in thread
From: Daniel Bergey @ 2013-03-31 18:20 UTC (permalink / raw)
To: Tomi Ollila, Notmuch Mail List, Ethan Glasser-Camp; +Cc: Chris Thachuk
From fbaf5c568876a6f1e3d8c02446bd83331b6325f0 Mon Sep 17 00:00:00 2001
From: Daniel Bergey <bergey@alum.mit.edu>
Date: Thu, 26 Jul 2012 15:44:01 -0400
Subject: [PATCH] emacs: functions to import sender or recipients into BBDB
From a show buffer, notmuch-bbdb/snarf-from imports the sender into
bbdb. notmuch-bbdb/snarf-to imports all recipients. Newly imported
contacts are reported in the minibuffer / Messages buffer.
Both functions use the BBDB parser to recognize email address formats.
---
This differs from the last version of the patch only in whitespace. In
addition to changes pointed out by Tomi Ollila, I fixed a ')' on a line
alone, and aligned the lines of notmuch-bbdb/header-by-name.
I've been using this code (prior to whitespace changes) for a month and
a half, as far as testing goes.
I wonder if I can get whitespace-mode to warn me about double-spacing....
emacs/notmuch-address.el | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 2bf762b..32c8490 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -96,6 +96,47 @@ line."
(when (notmuch-address-locate-command notmuch-address-command)
(notmuch-address-message-insinuate))
+;; functions to add sender / recipients to BBDB
+
+(defun notmuch-bbdb/snarf-headers (headers)
+ ;; Helper function to avoid code duplication in the two below
+ ;; headers should have the same format as bbdb-get-addresses-headers
+
+ ;; bbdb-get-addresses reads these
+ ;; Ugh, pass-by-global
+ (let ((addrs (bbdb-get-addresses nil nil 'notmuch-bbdb/get-header-content))
+ (bbdb-get-addresses-headers headers) ; headers to read
+ (bbdb-gag-messages t)) ; suppress m/n processed message)
+ (bbdb-update-records addrs t t))
+
+ (defun notmuch-bbdb/snarf-from ()
+ "Import the sender of the current message into BBDB"
+ (interactive)
+ (notmuch-bbdb/snarf-headers
+ (list (assoc 'authors bbdb-get-addresses-headers))))
+
+(defun notmuch-bbdb/snarf-to ()
+ "Import all recipients of the current message into BBDB"
+ (interactive)
+ (notmuch-bbdb/snarf-headers
+ (list (assoc 'recipients bbdb-get-addresses-headers))))
+
+(defvar notmuch-bbdb/header-by-name
+ ;; both are case sensitive
+ '( ("From" . :From)
+ ("To" . :To)
+ ("CC" . :Cc)
+ ("BCC" . :Bcc)
+ ("Resent-From" . nil)
+ ("Reply-To" . nil)
+ ("Resent-To" . nil)
+ ("Resent-CC" . nil))
+ "Alist for dispatching header symbols as used by notmuch-show-get-header
+from strings as used by bbdb-get-addresses")
+
+(defun notmuch-bbdb/get-header-content (name)
+ (notmuch-show-get-header (cdr (assoc name notmuch-bbdb/header-by-name))))
+
;;
(provide 'notmuch-address)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2013-03-31 18:20 ` Daniel Bergey
@ 2013-03-31 18:40 ` Tomi Ollila
2013-04-06 11:37 ` David Bremner
1 sibling, 0 replies; 14+ messages in thread
From: Tomi Ollila @ 2013-03-31 18:40 UTC (permalink / raw)
To: Daniel Bergey, Notmuch Mail List, Ethan Glasser-Camp; +Cc: Chris Thachuk
On Sun, Mar 31 2013, Daniel Bergey wrote:
>From fbaf5c568876a6f1e3d8c02446bd83331b6325f0 Mon Sep 17 00:00:00 2001
> From: Daniel Bergey <bergey@alum.mit.edu>
> Date: Thu, 26 Jul 2012 15:44:01 -0400
> Subject: [PATCH] emacs: functions to import sender or recipients into BBDB
>
>From a show buffer, notmuch-bbdb/snarf-from imports the sender into
> bbdb. notmuch-bbdb/snarf-to imports all recipients. Newly imported
> contacts are reported in the minibuffer / Messages buffer.
>
> Both functions use the BBDB parser to recognize email address formats.
> ---
LGTM, although git commit --amend is needed after git am to clean
the junk in commit message (just deleting content).
Tomi
> This differs from the last version of the patch only in whitespace. In
> addition to changes pointed out by Tomi Ollila, I fixed a ')' on a line
> alone, and aligned the lines of notmuch-bbdb/header-by-name.
>
> I've been using this code (prior to whitespace changes) for a month and
> a half, as far as testing goes.
>
> I wonder if I can get whitespace-mode to warn me about double-spacing....
> emacs/notmuch-address.el | 41 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
> diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
> index 2bf762b..32c8490 100644
> --- a/emacs/notmuch-address.el
> +++ b/emacs/notmuch-address.el
> @@ -96,6 +96,47 @@ line."
> (when (notmuch-address-locate-command notmuch-address-command)
> (notmuch-address-message-insinuate))
>
> +;; functions to add sender / recipients to BBDB
> +
> +(defun notmuch-bbdb/snarf-headers (headers)
> + ;; Helper function to avoid code duplication in the two below
> + ;; headers should have the same format as bbdb-get-addresses-headers
> +
> + ;; bbdb-get-addresses reads these
> + ;; Ugh, pass-by-global
> + (let ((addrs (bbdb-get-addresses nil nil 'notmuch-bbdb/get-header-content))
> + (bbdb-get-addresses-headers headers) ; headers to read
> + (bbdb-gag-messages t)) ; suppress m/n processed message)
> + (bbdb-update-records addrs t t))
> +
> + (defun notmuch-bbdb/snarf-from ()
> + "Import the sender of the current message into BBDB"
> + (interactive)
> + (notmuch-bbdb/snarf-headers
> + (list (assoc 'authors bbdb-get-addresses-headers))))
> +
> +(defun notmuch-bbdb/snarf-to ()
> + "Import all recipients of the current message into BBDB"
> + (interactive)
> + (notmuch-bbdb/snarf-headers
> + (list (assoc 'recipients bbdb-get-addresses-headers))))
> +
> +(defvar notmuch-bbdb/header-by-name
> + ;; both are case sensitive
> + '( ("From" . :From)
> + ("To" . :To)
> + ("CC" . :Cc)
> + ("BCC" . :Bcc)
> + ("Resent-From" . nil)
> + ("Reply-To" . nil)
> + ("Resent-To" . nil)
> + ("Resent-CC" . nil))
> + "Alist for dispatching header symbols as used by notmuch-show-get-header
> +from strings as used by bbdb-get-addresses")
> +
> +(defun notmuch-bbdb/get-header-content (name)
> + (notmuch-show-get-header (cdr (assoc name notmuch-bbdb/header-by-name))))
> +
> ;;
>
> (provide 'notmuch-address)
> --
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
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
1 sibling, 1 reply; 14+ messages in thread
From: David Bremner @ 2013-04-06 11:37 UTC (permalink / raw)
To: Daniel Bergey, Tomi Ollila, Notmuch Mail List, Ethan Glasser-Camp
Cc: Chris Thachuk
Daniel Bergey <bergey@alum.mit.edu> writes:
>
> From a show buffer, notmuch-bbdb/snarf-from imports the sender into
> bbdb. notmuch-bbdb/snarf-to imports all recipients. Newly imported
> contacts are reported in the minibuffer / Messages buffer.
>
> Both functions use the BBDB parser to recognize email address formats.
Pushed,
d
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] emacs: functions to import sender or recipient into BBDB
2013-04-06 11:37 ` David Bremner
@ 2013-04-06 19:43 ` David Bremner
0 siblings, 0 replies; 14+ messages in thread
From: David Bremner @ 2013-04-06 19:43 UTC (permalink / raw)
To: Notmuch Mail List
David Bremner <david@tethera.net> writes:
> Daniel Bergey <bergey@alum.mit.edu> writes:
>>
>> From a show buffer, notmuch-bbdb/snarf-from imports the sender into
>> bbdb. notmuch-bbdb/snarf-to imports all recipients. Newly imported
>> contacts are reported in the minibuffer / Messages buffer.
>>
>> Both functions use the BBDB parser to recognize email address formats.
>
> Pushed,
>
> d
And reverted. It was causing a build failure.
d
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2013-04-06 19:43 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-26 20:09 [PATCH] emacs: functions to import sender or recipient into BBDB Daniel Bergey
2012-10-19 22:52 ` 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
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).