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

2013-02-07 Thread Daniel Bergey
>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



[PATCH 0/6] notmuch cli config changes

2013-02-07 Thread Jani Nikula
On Wed, 06 Feb 2013, Jameson Graef Rollins  
wrote:
> On Tue, Jan 29 2013, Jani Nikula  wrote:
>> Hi all, the goal here is to add support for --config=FILE option at the
>> notmuch top level (e.g. 'notmuch --config=FILE search foo'). In order to
>> achieve this neatly, I ended up moving config open/close to main() from
>> subcommands. This isn't a bad thing, because all notmuch commands opened
>> the config file anyway.
>
> Hi, Jani.  I appreciate you've put a lot of work into this series, but
> I'll be the same devil's advocate that I was to David previously.  Why
> do we need a command line option here when we already have an
> environment variable that handles just this?  Is there some benefit to
> having a command line option for this that I don't see?  I see this as
> another instance of an option that regular users will rarely use, if
> ever.

Fair enough.

In any case I see patches 1-4, and to an extent also patch 5, as useful
refactoring and cleanup. Also, if we ever end up having any top level
arguments that need to be passed to subcommands, I think patches 1-5 are
good prep work. The config struct could be extended to include both
settings from the config file and settings from the top level
arguments. But this is just a bonus in addition to the refactoring part.

> In general, I am a strong advocate of keeping the CLI slim.  IMHO,
> adding more options makes the interface clunkier, and the manual harder
> to parse, and I'm against adding things that a normal user would likely
> never use.  In retrospect, I should have had the same objection to the
> --format-version option, which I think could have just been an env var
> as well.

What is a "normal user"? I'm a user too.


BR,
Jani.


Re: [PATCH 0/6] notmuch cli config changes

2013-02-07 Thread David Bremner
Jameson Graef Rollins jroll...@finestructure.net writes:

  Is there some benefit to having a command line option for this that I
 don't see?

In my experience the environment variable is somewhat dangerous to use
while testing. If left set to the wrong value, it can lead the loss of
tag information.

  I see this as another instance of an option that regular users will
 rarely use, if ever.

I don't see this as really comparable with a debugging option:
temporarily changing the configuration is something that can be useful
outside of debugging and testing. Although I'm fuzzy on the details now,
I remember telling someone to do this, I think to temporarily modify
what was ignored.

 In general, I am a strong advocate of keeping the CLI slim.  IMHO,
 adding more options makes the interface clunkier, and the manual harder
 to parse, and I'm against adding things that a normal user would likely
 never use. 

Well, it's are reasonable heuristic, although I might disagree in
general where the cutoff for normal use is, as I do in this case.

 In retrospect, I should have had the same objection to the
 --format-version option, which I think could have just been an env var
 as well.

I don't follow this part of your argument. I don't think replacing
command line arguments by environment variables makes the interface or
documentation simpler; at least if we document the environment variables
properly.  Note that non-shell based invokation (which is often
desirable from e.g. scripting languages or Emacs) is typically, more
complicated using environment variables. It's also more complicated for
the user if they do have to use these options in a shell or a script.

d
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2013-02-07 Thread Daniel Bergey
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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch