#!/usr/bin/perl -T -w use strict; use PDA::Pilot; my $ABFILE="$ENV{'HOME'}/.jpilot/AddressDB.pdb"; my ($ab, $rec, $nr, $i, $addr, $tmp, @list); my ($fname, $lname, $email, $company, $name); my $qry=shift||""; if ( ! -r $ABFILE ) { if ( ! -e $ABFILE ) { die "File \"$ABFILE\" does not exist.\n" } die "Cannot read \"$ABFILE\".\n" } $ab=PDA::Pilot::File::open($ABFILE) || die("Can't open $ABFILE: $!\n"); $nr=$ab->getRecords(); print "Searching database for '$qry' ... $nr entries ... "; for ($i=0; $i<$nr; $i++) { $rec=$ab->getRecord($i) || next; $addr=PDA::Pilot::Address::Unpack($rec); $email=""; for (3 .. 7) { # any of the 'phone' fields could be an email address $tmp=$addr->{entry}[$_]; next if (!defined($tmp)); if ($tmp =~ /\@/) { $email.=$tmp." "; } } next if ($email !~ /\@/); $email=~s/[\015\012]+/ /g; $lname=$addr->{entry}[1]; $lname="" if (!defined($lname)); $fname=$addr->{entry}[0]; $fname="" if (!defined($fname)); $company=$addr->{entry}[2]; $company="" if (!defined($company)); foreach (split(/ +/, $email)) { $tmp="$lname $fname"; $tmp=~s/^ *//; $tmp=~s/ *$//; $tmp=~s/ +/ /g; $tmp=$company if ($tmp eq ""); $name="$_\t$tmp\t$company"; $name=~s/[\015\012]+/ /g; push @list, $name if ($name =~ /$qry/i); } } $ab->close(); my $nmatch=scalar(@list); print "$nmatch match", ($nmatch==1)?"\n":"es\n"; foreach (@list) { print "$_\n"; } exit !$nmatch;