NetAdminTools.com
 
SignalQ Sites:
NetAdminTools - Coprolite - NoNIC - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - MCJ - FixRambler
Categories:
GNU/Linux | Homebrew designs | Perl | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS | Hail Support


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·REALbasic
·All Categories


Importing Palm PDB files into SquirrelMail
Topic: Network Services   Posted:2003-07-20
Printer Friendly: Print

spacer
In LDAP / Palm OS integration, we struggled with one of our favorite problems: integrating our Palm OS address database with email. Well, since then, we have been using SquirrelMail for most everything. We still do use our Palms as well. SquirrelMail can be configured to share the address book simply by creating a symbolic link from the individual user to the shared address book. We have updated our contacts via this for a long time. Unfortunately, we haven't been very good about having an LDAP server available, so we are just using SquirrelMail's flat file storage. There is a cool perl module called p5-Palm that lets you parse out a pdb file. Let's grab p5-Palm, install it, and test:

u-1@srv-1 r $ tar -xzf *.gz
u-1@srv-1 r $ ls
p5-Palm-1.003_000  p5-Palm-1.3.0.tar.gz
u-1@srv-1 r $ cd p*
u-1@srv-1 p5-Palm-1.003_000 $ perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for Palm
u-1@srv-1 p5-Palm-1.003_000 $ 
u-1@srv-1 p5-Palm-1.003_000 $ make
cp Palm/Mail.pm blib/lib/Palm/Mail.pm
cp Palm/Memo.pm blib/lib/Palm/Memo.pm
cp Palm/StdAppInfo.pm blib/lib/Palm/StdAppInfo.pm
cp Palm/PDB.pm blib/lib/Palm/PDB.pm
cp Palm/Address.pm blib/lib/Palm/Address.pm
cp Palm/ToDo.pm blib/lib/Palm/ToDo.pm
cp Palm/Raw.pm blib/lib/Palm/Raw.pm
cp Palm/Datebook.pm blib/lib/Palm/Datebook.pm
cp util/pdbdump blib/script/pdbdump
/usr/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/pdbdump
Manifying blib/man3/Palm::Mail.3pm
Manifying blib/man3/Palm::Memo.3pm
Manifying blib/man1/pdbdump.1
Manifying blib/man3/Palm::Address.3pm
Manifying blib/man3/Palm::PDB.3pm
Manifying blib/man3/Palm::StdAppInfo.3pm
Manifying blib/man3/Palm::Datebook.3pm
Manifying blib/man3/Palm::Raw.3pm
Manifying blib/man3/Palm::ToDo.3pm
u-1@srv-1 p5-Palm-1.003_000 $ su 
Password: 
root@srv-1 p5-Palm-1.003_000 # make install
Installing /usr/lib/perl5/site_perl/5.8.0/Palm/Mail.pm
Installing /usr/lib/perl5/site_perl/5.8.0/Palm/Memo.pm
Installing /usr/lib/perl5/site_perl/5.8.0/Palm/StdAppInfo.pm
Installing /usr/lib/perl5/site_perl/5.8.0/Palm/PDB.pm
Installing /usr/lib/perl5/site_perl/5.8.0/Palm/Address.pm
Installing /usr/lib/perl5/site_perl/5.8.0/Palm/ToDo.pm
Installing /usr/lib/perl5/site_perl/5.8.0/Palm/Raw.pm
Installing /usr/lib/perl5/site_perl/5.8.0/Palm/Datebook.pm
Installing /usr/man/man1/pdbdump.1
Installing /usr/man/man3pm/Palm::Mail.3pm
Installing /usr/man/man3pm/Palm::Memo.3pm
Installing /usr/man/man3pm/Palm::Address.3pm
Installing /usr/man/man3pm/Palm::PDB.3pm
Installing /usr/man/man3pm/Palm::StdAppInfo.3pm
Installing /usr/man/man3pm/Palm::Datebook.3pm
Installing /usr/man/man3pm/Palm::Raw.3pm
Installing /usr/man/man3pm/Palm::ToDo.3pm
Installing /usr/bin/pdbdump
Writing /usr/lib/perl5/site_perl/5.8.0/i686-linux/auto/Palm/.packlist
Appending installation info to /usr/lib/perl5/5.8.0/i686-linux/perllocal.pod
root@srv-1 p5-Palm-1.003_000 # 
root@srv-1 p5-Palm-1.003_000 # perl test.pl
1..1
ok 1
root@srv-1 p5-Palm-1.003_000 # 

To dump out a pdb file, you can use pdbdump, which is in the util directory:

root@srv-1 util # perl pdbdump -nohex -MPalm::Address AddressDB.pdb
.
.
.
Record 91
fields:
firstName -> [John]
phone3 -> [555.555.2128]
name -> [Doe]
phone2 -> [555.255.6538]
id -> [15708259]
category -> [7]
phoneLabel:
phone3 -> [1]
phone1 -> [0]
phone5 -> [4]
phone4 -> [3]
reserved -> [147]
phone2 -> [7]
display -> [1]
attributes:
dirty -> [1]

Now, there is a very nice module that will import and export csv files to and from your address book in SquirrelMail. You can get it here. It will put this on the bottom of your address page:



Now, our idea is to put all of the other info (cell phone, address, notes, etc,) in the "Info" field. Since we share the address book, and mainly Agatha wants to see the extra details, we hacked up addressbook.php:

 
[root@main src]# diff addressbook.php addressbookfull.php
60c60
<    
---
>     
312d311
<     echo html_tag( 'p', '<a href="addressbookfull.php">' . _("Full View") . 
'', 'center' ) . "\n";
397c396
<             html_tag( 'td', '&nbsp;' . htmlspecialchars($row['labelx']) . 
' ', 'left', '', 'valign="top" width="1%"' ) .
---
>             html_tag( 'td', '&nbsp;' . htmlspecialchars($row['label']) . 
'&nbsp;', 'left', '', 'valign="top" width="1%"' ) .
[root@main src]# 

This puts a link to the full view on the main addressbook page. One tidbit about the docs for p5-Palm. If you want to read the docs:

root@srv-1 p5-Palm-1.003_000 # pod2text Palm/PDB.pm | less 

OK. Now, we need to import data from our Palm pdb database. Well, this script will do it:

use Palm::PDB;
use Palm::Address;
my $pdb = new Palm::PDB;
$pdb->Load("AddressDB.pdb");
for $record (sort @{$pdb->{records}}) {
$cat = $pdb->{appinfo}{categories}->[$record->{'category'}]{'name'};
$nick = "p".$record->{fields}{firstName}.$record->{fields}{name};
$first= $record->{fields}{firstName};
$last= $record->{fields}{name};
$address= $record->{fields}{address};
$city= $record->{fields}{city};
$state= $record->{fields}{state};
$zip= $record->{fields}{zipCode};
$note= $record->{fields}{note};
$ph="";
$email="";
for($i=1;$i<6;$i++){
if($record->{fields}{"phone".$i} ne ""){
$ptype = $record->{phoneLabel}{"phone".$i};
if($ptype == 0){
$ph.=" WK:".$record->{fields}{"phone".$i};
}           
if($ptype == 1){
$ph.=" HM:".$record->{fields}{"phone".$i};
}           
if($ptype == 2){
$ph.=" FX:".$record->{fields}{"phone".$i};
}           
if($ptype == 3){
$ph.=" OT:".$record->{fields}{"phone".$i};
}           
if($ptype == 4){
$email=$record->{fields}{"phone".$i};
}           
if($ptype == 5){
$ph.=" MN:".$record->{fields}{"phone".$i};
} 
if($ptype == 6){
$ph.=" PG:".$record->{fields}{"phone".$i};
}
if($ptype == 7){
$ph.=" CL:".$record->{fields}{"phone".$i};
}
}
}
$nick=~ s/,/~/g;
$last=~ s/,/~/g;
$first=~ s/,/~/g;
$address=~ s/,/~/g;
$address=~ s/\n/ > /g;
$note=~ s/,/~/g;
$note=~ s/\n/ > /g;
print $nick.",".$first.",".$last.",".$email.",".$ph;
print " ".$address."-".$city."-".$state."-".$zip."-".$note."\n";
}
print $record;

Just put the AddressDB.pdb in the current directory. Redirect the output to a csv file, and import it into SquirrelMail. All is good.

This can even be simpler if you are willing to replace the entire address book, since the abook format is a slight variation on a csv format. Note that we get rid of returns and commas in the above script. It is probably best to leave those out of your data, as this will just mess up csv imports and exports. You can use a | character, though, in the abook format. This script will write pdb files directy to the abook format used by squirrelmail:

use Palm::PDB;
use Palm::Address;
my $pdb = new Palm::PDB;
$pdb->Load("AddressDB.pdb");
for $record (sort @{$pdb->{records}}) {
$cat = $pdb->{appinfo}{categories}->[$record->{'category'}]{'name'};
$nick = "p".$record->{fields}{firstName}.$record->{fields}{name};
$first= $record->{fields}{firstName};
$last= $record->{fields}{name};
$address= $record->{fields}{address};
$city= $record->{fields}{city};
$state= $record->{fields}{state};
$zip= $record->{fields}{zipCode};
$note= $record->{fields}{note};
$ph="";
$email="";
for($i=1;$i<6;$i++){
if($record->{fields}{"phone".$i} ne ""){
$ptype = $record->{phoneLabel}{"phone".$i};
if($ptype == 0){  
$ph.=" WK:".$record->{fields}{"phone".$i};
}                 
if($ptype == 1){  
$ph.=" HM:".$record->{fields}{"phone".$i};
}
if($ptype == 2){
$ph.=" FX:".$record->{fields}{"phone".$i};
}
if($ptype == 3){
$ph.=" OT:".$record->{fields}{"phone".$i};
}
if($ptype == 4){
$email=$record->{fields}{"phone".$i};
}
if($ptype == 5){
$ph.=" MN:".$record->{fields}{"phone".$i};
}
if($ptype == 6){
$ph.=" PG:".$record->{fields}{"phone".$i};
}
if($ptype == 7){
$ph.=" CL:".$record->{fields}{"phone".$i};
}
}
}
$nick=~ s/,/~/g;
$last=~ s/,/~/g;
$first=~ s/,/~/g;
$address=~ s/,/~/g;
$address=~ s/\n/ > /g;
$note=~ s/,/~/g;
$note=~ s/\n/ > /g;
print $nick."|".$first."|".$last."|".$email."|".$ph;
print " ".$address."-".$city."-".$state."-".$zip."-".$note."\n";
}
print $record;

Here is a copy of the pdb2abook script.




Please read our Terms of Use
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2008 NetAdminTools.com

Created by:
MCJ
MCJ CMS