#!/usr/bin/perl -w # # an application to find a phone number in a palm addressbook and display it # # the idea is to call this from the isdnlog incoming call script and display # the palm name for the number, to stop the need to sync the callerid.conf # file with your palm # # Koos van den Hout, 2003.10.17 # # Docs: # # perldoc Palm::PDB # perldoc Palm::Address # perldoc Palm::StdAppInfo # Be strict! use strict; use Palm::PDB; use Palm::Address; use Palm::StdAppInfo(); use vars qw/$pdb $addressbookfile @ISA $record $searchfor $found $countrycode /; # tunables # location of your addressbook backup file $addressbookfile="/home/koos/pilotbackup/AddressDB.pdb"; # your country code as a string $countrycode="+31"; @ISA = qw(Palm::StdAppInfo); my $rcsid='$Id$'; sub trynumber($); if ($ARGV[0]){ $searchfor=$ARGV[0]; } else { die "Usage: findnumber +xxyyyyyzzzzz\n"; } $pdb = new Palm::PDB; $pdb->Load($addressbookfile); foreach $record (@{$pdb->{"records"}}){ $found=0; if ($record->{fields}{phone1}){ $found=trynumber($record->{fields}{phone1}); if ($found) { goto PRINTTHIS; } } if ($record->{fields}{phone2}){ $found=trynumber($record->{fields}{phone2}); if ($found) { goto PRINTTHIS; } } if ($record->{fields}{phone3}){ $found=trynumber($record->{fields}{phone3}); if ($found) { goto PRINTTHIS; } } if ($record->{fields}{phone4}){ $found=trynumber($record->{fields}{phone4}); if ($found) { goto PRINTTHIS; } } if ($record->{fields}{phone5}){ $found=trynumber($record->{fields}{phone5}); if ($found) { goto PRINTTHIS; } } next if (!$found); PRINTTHIS: if ($found){ if ($record->{fields}{"firstName"}) { print $record->{fields}{"firstName"}." "; } if ($record->{fields}{"name"}) { print $record->{fields}{"name"}." "; } if ($record->{fields}{"company"}) { print $record->{fields}{"company"}; } # add fields to taste print "\n"; } } sub trynumber($){ my ($number)=@_; # fix +31..0 $number=~s/^(\+[\d]{1,3})[^\d]+0/$1/; # remove weird chars $number=~s/[ \-\(\)\n]//g; # internationalize $number=~s/^0/$countrycode/; return ($number eq $searchfor); }