Using J-Pilot's AddressBook

I happen to use the PIM software J-pilot [1] to keep track of my contacts, both on my FBSD box and my PalmOS device. Recently, I thought it might be useful to be able to look up names/e-mail addresses out of my J-pilot address book directly from exmh (as I would from LDAP).

A little searching turned up a program, query_jpilot.sh, that required a small amount of tweaking (it printed last name first, but I wanted first name first). It accepts a string as an argument and returns address book entries that match it. It was a SMOP (simple matter of programming) to integrate this into exmh.

Here's how to use J-Pilot's address book:

Add these functions to your user.tcl file:


 proc jpilot-addr-lookup {n} {
    # look up addresses in jpilot's address book

    Exmh_Status "Querying jpilot for $n"

    if [catch {set jpilot_results [eval exec query_jpilot.sh $n]} e] {
        Exmh_Status "Error executing jpilot-dump: $e"
        return {}
    }

    # the jpilot_results looks like this:
    # e-mail@add.ress\tlastname firstname\tcompany

    set result {}
    foreach i [split $jpilot_results \n] {
        if [string match {*@*} $i] {
            lappend result "[jpilot-addr-formatformail $i]"
        }
    }

    return $result
 }

 proc jpilot-addr-formatformail { line } {
    global addr_db

    set s [split $line \t]
    # s will contain "email" "lastname firstname" "company"
    set email [lindex $s 0]
    set name [lindex $s 1]
    set company [lindex $s 2]

    return [LDAP_Entry_FormatForMail $email $name]
 }

Then make sure you have query_jpilot.sh in your PATH:


 #!/usr/local/bin/bash
 # query_jpilot.sh
 # (c) Gerhard Siegesmund (gerhard.siegesmund@epost.de)

 # Adjust the paths.
 TEMP=/tmp
 jpilotdump=/usr/local/bin/jpilot-dump

 # In which records of an entry to search. Here e.g. the 4. userdefined field
 # where I put the nickname of people. You can use (nearly) anything you like,
 # just don't use tabs in here (see jpilot-dump -? for help). If you just want
 # to search for the default, meaning name, lastname company, just set to ""
 more=""
 #more=" %U4"

 tempnumber=$RANDOM.$$.`date +%s`
 tempdb=$TEMP/jpilot-email-dump.$tempnumber
 tempresult=$TEMP/jpilot-email-result.$tempnumber

 function thatsit () {
        rm -f $tempdb
        rm -f $tempresult
        exit $1
 }

 # Is there a querystring?
 if [ -z "$1" ]; then
        echo "No querystring. Please try again with a querystring!"
        exit 1
 fi

 # Create temporary Database-File
 (for nummer in 1 2 3 4 5; do
        $jpilotdump +A"%p$nummer%t%f %l%t%c$more" -A
 done) | grep @ > $tempdb

 numall=`cat $tempdb | wc -l | sed -e "s/[^0-9]//g"`
 if [ $numall = "0" ]; then
        echo "No emails found in your jpilot-database"
        thatsit 2
 fi

 # Search for the querystring
 cat $tempdb | grep -i $1 > $tempresult

 numres=`cat $tempresult | wc -l | sed -e "s/[^0-9]//g"`
 if [ $numres = "0" ]; then
        echo "Didn't find the querystring \"$1\" in the database (Searched $numall records)."
        thatsit 3
 fi

 # Output the result
 echo "Searched $numall records. Found $numres matching records."
 cat $tempresult

 thatsit 0

Finally, in your Preferences->Address Database->Expand methods to use, add jpilot-addr-lookup as a method. Voila.

jlp@softhome.net


Updated on 28 May 2003, 15:34 GMT
Search - Recent Changes - Reference - Index - Go to Beedub's Wiki - Help