From mboxrd@z Thu Jan 1 00:00:00 1970 From: Karl Voit Subject: Querying Org-contacts with lbdb (e.g. for mutt) Date: Tue, 25 Oct 2011 15:31:24 +0200 Message-ID: <2011-10-25T15-15-52@devnull.Karl-Voit.at> Reply-To: news1142@Karl-Voit.at Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:35126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIh6c-0005uA-Oq for emacs-orgmode@gnu.org; Tue, 25 Oct 2011 09:31:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RIh6X-0004oW-Nw for emacs-orgmode@gnu.org; Tue, 25 Oct 2011 09:31:50 -0400 Received: from lo.gmane.org ([80.91.229.12]:50488) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIh6W-0004oF-HF for emacs-orgmode@gnu.org; Tue, 25 Oct 2011 09:31:45 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RIh6V-0008SR-3D for emacs-orgmode@gnu.org; Tue, 25 Oct 2011 15:31:43 +0200 Received: from mail.michael-prokop.at ([88.198.6.110]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 25 Oct 2011 15:31:43 +0200 Received: from news1142 by mail.michael-prokop.at with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 25 Oct 2011 15:31:43 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi! I want to share a solution that allows lbdb[1] queries return Org-contacts[2] email addresses. The solution is done by Russell Adams who encouraged me to post it here because he did only mention it in [3] but did not post the results yet. I took Russells solution and modified it to be of more general use and added a few comments in the Perl script. If you are interested in my personal approach for managing contact information with Org-contacts, please refer to [4]. The set up requires three things: 1. configuration file .lbdbrc (usually in ~ or ~/.lbdb/) - add «m_orgcontact» to the variable «METHODS» - add «$HOME/.lbdb/modules» to the variable «MODULES_PATH» ,----[ example lines ] | METHODS="m_orgcontact m_muttalias m_inmail" | MODULES_PATH="/usr/lib/lbdb $HOME/.lbdb/modules" `---- 2. ~/.lbdb/modules/m_orgcontact (just a small interface to connect lbdb to the script) ,----[ m_orgcontact ] | #!/bin/sh | | m_orgcontact_query() | { | ${HOME}/.lbdb/modules/orgcontact.pl $1 | } | #end `---- 3. ~/.lbdb/modules/orgcontact.pl (the actual script that queries) See below footnotes for the whole script. 1. http://www.spinnaker.de/lbdb/ 2. http://julien.danjou.info/org-contacts.html 3. http://lists.gnu.org/archive/html/emacs-orgmode/2011-02/msg00459.html 4. http://article.gmane.org/gmane.emacs.orgmode/47478/ ---- ~/.lbdb/modules/orgcontact.pl -------------------------- #!/usr/bin/env perl use strict; use warnings; ## FIXXME: error handling when no argument is given (though unlikely) $/="\n*"; ## split between Org-mode headings (i.e. newline followed by asterisk) ## the path to your Org-contacts file: my $orgmodefile=$ENV{"HOME"} . "/share/all/org-mode/contacts.org"; open(MYFILE,$orgmodefile); my @rawcontacts = ; ## read in whole contact file, heading by heading close(MYFILE); $/="\n"; ## reset split string to newlines (only) foreach (@rawcontacts) { if ( $_ =~ m/$ARGV[0]/i ){ ## ARGV[0] is the query string my $name; foreach (split("\n",$_)) { ## go through it line by line # The first line consists of the contact name (followed by tag(s)) unless (defined $name) { $name = $_; $name =~ s/^\*+\s(.*)\s+:\S+:.*$/$1/g; ## extract string between asterisks and tags } # if (m/^\s+:.*EMAIL.*:/i) { if (m/^:EMAIL:/i) { ## for each property «:EMAIL:» print out result my $email = $_; $email =~ s/^:\S+:\s+(\S+)/$1/g; $email =~ s/\s*$//; printf("%s\t%s\t(Org)\n", $email, $name); } } } } ------------------------------------------------------------- -- Karl Voit