1#! @PERL@
2#
3#     palm_lsaddr - Palm address database helper utility for lbdb
4#     Copyright (C) 2000 Dave Pearson <davep@davep.org>
5#               (C) 2003 Nikolaus Rath <Nikolaus@rath.org>
6#
7#     This program is free software; you can redistribute it and/or modify
8#     it under the terms of the GNU General Public License as published by
9#     the Free Software Foundation; either version 2 of the License, or
10#     (at your option) any later version.
11#
12#     This program is distributed in the hope that it will be useful,
13#     but WITHOUT ANY WARRANTY; without even the implied warranty of
14#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#     GNU General Public License for more details.
16#
17#     You should have received a copy of the GNU General Public License
18#     along with this program; if not, write to the Free Software Foundation,
19#     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,, USA.
20
21use Palm::PDB;
22use Palm::Address;
23
24if ( $#ARGV > -1 )
25{
26    my $pdb = new Palm::PDB;
27
28    if ( $pdb )
29    {
30        $pdb->Load( $ARGV[ 0 ] );
31
32        my $record;
33
34        for ( $i = 0, $record = $pdb->{records}[ $i ]; $record; $i++, $record = $pdb->{records}[ $i ] )
35        {
36            my $name = $record->{fields}{firstName} . " " . $record->{fields}{name};
37
38            # Remove leading and trailing whitespace.
39            $name =~ s/\s+$//;
40            $name =~ s/^\s+//;
41
42            # If the name is empty, use the company name instead.
43            $name = $record->{fields}{company} unless ( length( $name ) > 0 );
44
45            if ( length( $name ) > 0 )
46            {
47                my $entry;
48
49                # Find fields containing e-mail addresses
50                for($entry=1; $entry <= 5; $entry++)
51                {
52                    # 0 = Work, 1 = Home, 2 = Fax, 3 = Other, 4 = email,
53                    # 5 = Main, 6 = Pager, 7 = Mobile
54                    if($record->{phoneLabel}{"phone${entry}"} == 4) {
55                        # A field can also contain multiple lines.
56                        print map "$_\t$name\t(Palm)\n",
57                            split(/\n/, $record->{fields}{"phone${entry}"});
58                    }
59                }
60            }
61        }
62    }
63}
64