From 915803c5a53d002292c348ccf33c9631e37c3c71 Mon Sep 17 00:00:00 2001 From: Daniel Bergey Date: Fri, 13 Jul 2012 09:47:34 +2000 Subject: [PATCH] Re: notmuch-emacs and bbdb --- 47/27b219bb6e8d427811c93ee935351e8dea4df1 | 220 ++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 47/27b219bb6e8d427811c93ee935351e8dea4df1 diff --git a/47/27b219bb6e8d427811c93ee935351e8dea4df1 b/47/27b219bb6e8d427811c93ee935351e8dea4df1 new file mode 100644 index 000000000..fa1d529b6 --- /dev/null +++ b/47/27b219bb6e8d427811c93ee935351e8dea4df1 @@ -0,0 +1,220 @@ +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 4BEE1429E25 + for ; Thu, 12 Jul 2012 06:47:39 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.69 +X-Spam-Level: +X-Spam-Status: No, score=-0.69 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, + T_MIME_NO_TEXT=0.01] 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 B4fkGodvdu4E for ; + Thu, 12 Jul 2012 06:47:38 -0700 (PDT) +Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com + [66.111.4.27]) + (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 7FFC1431FAE + for ; Thu, 12 Jul 2012 06:47:38 -0700 (PDT) +Received: from compute2.internal (compute2.nyi.mail.srv.osa [10.202.2.42]) + by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 494D1211AC; + Thu, 12 Jul 2012 09:47:36 -0400 (EDT) +Received: from frontend1.nyi.mail.srv.osa ([10.202.2.160]) + by compute2.internal (MEProxy); Thu, 12 Jul 2012 09:47:36 -0400 +DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= + messagingengine.com; h=from:to:subject:in-reply-to:references + :date:message-id:mime-version:content-type; s=smtpout; bh=5fUly6 + 5K51AZlFKQWbovB6UjyaU=; b=ugBZvt0c42pgnqAbqj6vQIN7dzDa3JgLKss1cV + G0w2mWOSaYChLLbm+3mJurEpMYFdeq5OEYjEP58FdIlDOSGV/aevYWBEfyT6rtIA + M4N91R3aJcG4qL2J/3f0OrlskZJzXDYFRw69quRqlndwiJPYEDcezYXk2RiTcuCV + /VnLk= +X-Sasl-enc: SnTONlIDQJ/DBV6i4p5vQqEPaoSvEu/VbZTx2GcRX9z5 1342100855 +Received: from localhost (unknown [66.80.90.109]) + by mail.messagingengine.com (Postfix) with ESMTPA id 7D8888E00F9; + Thu, 12 Jul 2012 09:47:35 -0400 (EDT) +From: Daniel Bergey +To: Jameson Graef Rollins , + notmuch@notmuchmail.org +Subject: Re: notmuch-emacs and bbdb +In-Reply-To: <87mx35pji9.fsf@servo.finestructure.net> +References: <878ver1jp0.fsf@wonderlust.lan> + <87mx35pji9.fsf@servo.finestructure.net> +User-Agent: Notmuch/0.13.2 (http://notmuchmail.org) Emacs/23.4.1 + (i486-pc-linux-gnu) +Date: Thu, 12 Jul 2012 09:47:34 -0400 +Message-ID: <87txxdytu1.fsf@wonderlust.lan> +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="=-=-=" +X-Mailman-Approved-At: Thu, 12 Jul 2012 10:59:07 -0700 +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, 12 Jul 2012 13:47:39 -0000 + +--=-=-= + +I hacked together the attached elisp yesterday. It provides bindings to +put sender or recipients into bbdb. (Recipients part needs more +testing.) It also colors the from line green if the sender is in bbdb, +or orange otherwise. When it's been through a bit more testing, I'll +submit at least the first part as a patch. + +I prefer not to autocapture everything into bbdb, and for the same +reason, I don't want to use notmuch itself as my contacts DB. Mostly, +this is because I read lots of email on lists, sent by people I'm +unlikely to write back to. I don't like every John I've heard from +coming up on autocomplete. Other reasons include sync to phone and +adding contact information from channels other than email. + +bergey + + +--=-=-= +Content-Type: application/emacs-lisp +Content-Disposition: attachment; filename=bbdb-notmuch.el +Content-Transfer-Encoding: quoted-printable + +; capture addresses=20 +(defun bbdb/notmuch-snarf-header (header) + (let ((text (notmuch-show-get-header header))) + (with-temp-buffer + (insert text) + (bbdb-snarf-region (point-min) (point-max))))) + +(defun bbdb/notmuch-snarf-from () + (interactive) + (bbdb/notmuch-snarf-header :From)) + +(defun bbdb/notmuch-snarf-to () + (interactive) + (bbdb/notmuch-snarf-header :To)) + +(define-key notmuch-show-mode-map "b" 'bbdb/notmuch-snarf-from) +(define-key notmuch-show-mode-map "B" 'bbdb/notmuch-snarf-to) + +;; color from line according to known / unknown sender +; code taken from bbdb-gnus.el +(defun bbdb/notmuch-known-sender () + (let* ((from (plist-get headers :From)) + (splits (mail-extract-address-components from)) + (name (car splits)) + (net (cadr splits)) + (record (and splits + (bbdb-search-simple + name + (if (and net bbdb-canonicalize-net-hook) + (bbdb-canonicalize-address net) + net))))) + (and record net (member (downcase net) (bbdb-record-net record))))) + +(defun bbdb/check-known-sender () + (interactive) + (if (bbdb/notmuch-known-sender) (message "Sender is known") (message "Sen= +der is not known"))) + +(defface notmuch-show-known-addr + '( + (((class color) (background dark)) :foreground "spring green") + (((class color) (background light)) :background "spring green" :foregro= +und "black")) + "Face for sender or recipient already listed in bbdb" + :group 'notmuch-show + :group 'notmuch-faces) + +(defface notmuch-show-unknown-addr + '( + (((class color) (background dark)) :foreground "dark orange") + (((class color) (background light)) :background "gold" :foreground "bla= +ck")) + "Face for sender or recipient not listed in bbdb" + :group 'notmuch-show + :group 'notmuch-faces) + +; override function from notmuch-show +(defun notmuch-show-insert-headerline (headers date tags depth) + "Insert a notmuch style headerline based on HEADERS for a +message at DEPTH in the current thread." + (let ((start (point)) + (face (if (bbdb/notmuch-known-sender) 'notmuch-show-known-addr 'not= +much-show-unknown-addr)) + (end-from)) + (insert (notmuch-show-spaces-n (* notmuch-show-indent-messages-width de= +pth)) + (notmuch-show-clean-address (plist-get headers :From))) + (setq end-from (point)) + (insert + " (" + date + ") (" + (propertize (mapconcat 'identity tags " ") + 'face 'notmuch-tag-face) + ")\n") + (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summar= +y-face) + (save-excursion + (goto-char start) + (overlay-put (make-overlay start end-from) 'face face)))) + + +--=-=-= + + + +Jameson Graef Rollins writes: + +> On Tue, Jul 10 2012, Daniel Bergey wrote: +>> As far as I can tell, notmuch doesn't integrate as smoothly with bbdb as older +>> emacs mailclients. I'm especially looking for a snarf function that +>> distinguishes sender from recipient. +>> +>> How do other people use bbdb with notmuch? +>> +>> Does anyone have lisp code like that which ships with bbdb for other +>> clients? +>> +>> If I were to find time to write such code, what would you like it to do? +> +> Hey, Bergey. This is something that I think needs improvement as well. +> I've been just manually constructing the bbdb entries myself. +> +> But what I've really been meaning to get going is address +> auto-completion from the database, which I'm pretty sure could obviate +> my need for bbdb altogether: +> +> http://notmuchmail.org/emacstips/#index13h2 +> +> Getting it working seems more difficult than it should be, though, and +> the existing solutions seem a bit slower than they need to be [0]. So I +> think there's also room for improvement here. +> +> For instance, I think it would be rad if notmuch provided this +> functionality natively, in the CLI, or even in the library [1]. I think +> it's definitely doable, and it would be a nice little project. +> +> The emacs integration could be a bit smoother as well. A single config +> option should either turn the functionality on or off. That would be +> very convenient [2]. +> +> jamie. +> +> [0] id:"87r4xur3rv.fsf@plc.plecavalier.com" +> [1] For what it's worth, I would prefer a solution that didn't involve +> any caching of addresses outside of the database. +> [2] I also find it changes the behavior of the ido tab completion +> interface that I'm used to using in message mode. + +--=-=-=-- -- 2.26.2