Re: [PATCH] emacs: functions to import sender or recipient into BBDB
authorDaniel Bergey <bergey@alum.mit.edu>
Thu, 7 Feb 2013 18:51:07 +0000 (13:51 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:30 +0000 (09:53 -0800)
5d/9ce433a929eaead1d2d00634f64ad45d81843f [new file with mode: 0644]

diff --git a/5d/9ce433a929eaead1d2d00634f64ad45d81843f b/5d/9ce433a929eaead1d2d00634f64ad45d81843f
new file mode 100644 (file)
index 0000000..74441f2
--- /dev/null
@@ -0,0 +1,143 @@
+Return-Path: <bergey@alum.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A5F56414BA9\r
+       for <notmuch@notmuchmail.org>; Thu,  7 Feb 2013 10:51:08 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id xxMOZUDuhkob for <notmuch@notmuchmail.org>;\r
+       Thu,  7 Feb 2013 10:51:04 -0800 (PST)\r
+Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com\r
+       [66.111.4.29])\r
+       (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 8A3D0416456\r
+       for <notmuch@notmuchmail.org>; Thu,  7 Feb 2013 10:51:04 -0800 (PST)\r
+Received: from compute1.internal (compute1.nyi.mail.srv.osa [10.202.2.41])\r
+       by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 520F220B2E;\r
+       Thu,  7 Feb 2013 13:51:02 -0500 (EST)\r
+Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161])\r
+       by compute1.internal (MEProxy); Thu, 07 Feb 2013 13:51:02 -0500\r
+DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=\r
+       messagingengine.com; h=from:to:cc:subject:in-reply-to:references\r
+       :date:message-id:mime-version:content-type; s=smtpout; bh=EkGqWn\r
+       yZXJIr5/hdX46yeRz4Jyk=; b=PszpgNbhDlXhUgm/PWO9JVFp1Wi9Yy0jECLQ5N\r
+       SuJwoyL6UGgc2l1wxX33H8kgjDNvYZwVQgM59sFOx7IAkL8eFlAytRy12/nVf+Vl\r
+       lWQLS3J+Z5V0iX0R852E6j0sFXFeWn1uzVfuE9u4vW2/cb7rdMBHwaBGTk7ewPPD\r
+       Gf7Xc=\r
+X-Sasl-enc: 5QLE9Cq8hPMhBKKjvWMixHDczAheWytLPMAVHLdKsRM/ 1360263062\r
+Received: from localhost (unknown [66.80.90.109])\r
+       by mail.messagingengine.com (Postfix) with ESMTPA id F2AED4827DE;\r
+       Thu,  7 Feb 2013 13:51:01 -0500 (EST)\r
+From: Daniel Bergey <bergey@alum.mit.edu>\r
+To: Notmuch Mail List <notmuch@notmuchmail.org>,\r
+       Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>\r
+Subject: Re: [PATCH] emacs: functions to import sender or recipient into BBDB\r
+In-Reply-To: <87ip92zc6m.fsf@wonderlust.lan>\r
+References: <87lii62sk2.fsf@wonderlust.lan> <87ipa66pne.fsf@betacantrips.com>\r
+       <87ip92zc6m.fsf@wonderlust.lan>\r
+User-Agent: Notmuch/0.13.2 (http://notmuchmail.org) Emacs/24.2.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Thu, 07 Feb 2013 13:51:07 -0500\r
+Message-ID: <87ip64gdpg.fsf@chladni.lan>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+Cc: Chris Thachuk <chris.thachuk@cs.ox.ac.uk>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 07 Feb 2013 18:51:08 -0000\r
+\r
+>From a show buffer, notmuch-bbdb/snarf-from imports the sender into\r
+bbdb.  notmuch-bbdb/snarf-to imports all recipients.  Newly imported\r
+concacts are reported in the minibuffer / Messages buffer.\r
+\r
+Both functions use the BBDB parser to recognize email address formats.\r
+---\r
+Following discussion upthread, I put everything in notmuch-address.  I\r
+renamed the functions to put notmuch before bbdb.  And I replaced the\r
+horrid comma-splitting from my first version with the functions BBDB\r
+provides for parsing email headers.\r
+\r
+It looks as though Reply-To is not exposed in the :headers plist.  I\r
+assume the Resent-* headers are not, either.  Therefore none of these\r
+are imported (nil entries in notmuch-bbdb/header-by-name).  They would be\r
+easy to add if the plist is expanded.\r
+\r
+Thanks, and sorry it's taken me so long to get back to this patch.\r
+\r
+ emacs/notmuch-address.el |   43 +++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 43 insertions(+)\r
+\r
+diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el\r
+index 2bf762b..8d5f727 100644\r
+--- a/emacs/notmuch-address.el\r
++++ b/emacs/notmuch-address.el\r
+@@ -98,4 +98,47 @@ line."\r
\r
+ ;;\r
\r
++;; functions to add sender / recipients to BBDB\r
++\r
++(defun notmuch-bbdb/snarf-headers (headers)\r
++  ;; Helper function to avoid code duplication in the two below\r
++  ;; headers should have the same format as bbdb-get-addresses-headers\r
++\r
++  ;; bbdb-get-addresses reads these\r
++  ;; Ugh, pass-by-global\r
++  (let ((addrs (bbdb-get-addresses nil nil 'notmuch-bbdb/get-header-content))\r
++        (bbdb-get-addresses-headers headers) ; headers to read\r
++        (bbdb-gag-messages t) ; suppress m/n processed message\r
++        )\r
++    (bbdb-update-records addrs t t)))\r
++\r
++(defun notmuch-bbdb/snarf-from ()\r
++  "Import the sender of the current message into BBDB"\r
++  (interactive)\r
++  (notmuch-bbdb/snarf-headers\r
++   (list  (assoc 'authors bbdb-get-addresses-headers))))\r
++\r
++(defun notmuch-bbdb/snarf-to ()\r
++  "Import all recipients of the current message into BBDB"\r
++  (interactive)\r
++  (notmuch-bbdb/snarf-headers\r
++   (list  (assoc 'recipients bbdb-get-addresses-headers))))\r
++\r
++(defvar notmuch-bbdb/header-by-name\r
++  ;; both are case sensitive\r
++  '( ("From" . :From)\r
++      ("To" . :To)\r
++      ("CC" . :Cc)\r
++      ("BCC" . :Bcc)\r
++      ("Resent-From" . nil)\r
++      ("Reply-To" . nil)\r
++      ("Resent-To" . nil)\r
++      ("Resent-CC" . nil))\r
++  "Alist for dispatching header symbols as used by notmuch-show-get-header\r
++from strings as used by bbdb-get-addresses")\r
++\r
++(defun notmuch-bbdb/get-header-content (name)\r
++  (notmuch-show-get-header (cdr (assoc name notmuch-bbdb/header-by-name))))\r
++\r
++\r
+ (provide 'notmuch-address)\r
+-- \r
+1.7.10.4\r
+\r