Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id A5F56414BA9 for ; Thu, 7 Feb 2013 10:51:08 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xxMOZUDuhkob for ; Thu, 7 Feb 2013 10:51:04 -0800 (PST) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8A3D0416456 for ; Thu, 7 Feb 2013 10:51:04 -0800 (PST) Received: from compute1.internal (compute1.nyi.mail.srv.osa [10.202.2.41]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 520F220B2E; Thu, 7 Feb 2013 13:51:02 -0500 (EST) Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute1.internal (MEProxy); Thu, 07 Feb 2013 13:51:02 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=from:to:cc:subject:in-reply-to:references :date:message-id:mime-version:content-type; s=smtpout; bh=EkGqWn yZXJIr5/hdX46yeRz4Jyk=; b=PszpgNbhDlXhUgm/PWO9JVFp1Wi9Yy0jECLQ5N SuJwoyL6UGgc2l1wxX33H8kgjDNvYZwVQgM59sFOx7IAkL8eFlAytRy12/nVf+Vl lWQLS3J+Z5V0iX0R852E6j0sFXFeWn1uzVfuE9u4vW2/cb7rdMBHwaBGTk7ewPPD Gf7Xc= X-Sasl-enc: 5QLE9Cq8hPMhBKKjvWMixHDczAheWytLPMAVHLdKsRM/ 1360263062 Received: from localhost (unknown [66.80.90.109]) by mail.messagingengine.com (Postfix) with ESMTPA id F2AED4827DE; Thu, 7 Feb 2013 13:51:01 -0500 (EST) From: Daniel Bergey To: Notmuch Mail List , Ethan Glasser-Camp Subject: Re: [PATCH] emacs: functions to import sender or recipient into BBDB In-Reply-To: <87ip92zc6m.fsf@wonderlust.lan> References: <87lii62sk2.fsf@wonderlust.lan> <87ipa66pne.fsf@betacantrips.com> <87ip92zc6m.fsf@wonderlust.lan> User-Agent: Notmuch/0.13.2 (http://notmuchmail.org) Emacs/24.2.1 (x86_64-pc-linux-gnu) Date: Thu, 07 Feb 2013 13:51:07 -0500 Message-ID: <87ip64gdpg.fsf@chladni.lan> MIME-Version: 1.0 Content-Type: text/plain Cc: Chris Thachuk X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Feb 2013 18:51:08 -0000 >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