[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] Querying Org-contacts with lbdb (e.g. for mutt)
From: |
Karl Voit |
Subject: |
[O] Querying Org-contacts with lbdb (e.g. for mutt) |
Date: |
Tue, 25 Oct 2011 15:31:24 +0200 |
User-agent: |
slrn/0.9.9 (Linux) |
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 = <MYFILE>; ## 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [O] Querying Org-contacts with lbdb (e.g. for mutt),
Karl Voit <=