#!/usr/bin/perl # # simple contact database display (sic) # uses vCard format file from GnomeCard # later, integrate with chosen mail client # and allow editing # and integrate with fax application # and integrate with telephone dialler # ($BCMD = $0) =~ s/.*\///; $HELPSTRING = "For help, type: $BCMD -h"; $USAGE = "Usage: $BCMD [-dhilLv] [-f contactfile] [searchterm]"; ($REVISION) = ('$Revision: 1.16 $' =~ /[^\d\.]*([\d\.]*)/); ($IDENT = '@(#)sic: display contact database records') =~ s/^[^:]*: *//; ######################################################################## # process arguments sub ParseArgs { require('getopts.pl'); if (! &Getopts('df:hilLv')) { print STDERR "$USAGE\n$HELPSTRING\n"; exit 2; } if ($opt_h) { print < This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. If you do not already have a copy of the GNU General Public License, you can obtain a copy by anonymous ftp from prep.ai.mit.edu (file COPYING in directory /pub/gnu) or write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. EOT exit 0; } $VERBOSE = $opt_v; $DEBUG = $opt_d; $LONG = $opt_l; if (@ARGV > 1) { print STDERR "$USAGE\n$HELPSTRING\n"; exit 2; } $cdbfile = $opt_f if $opt_f; print STDERR 'Argument="', @ARGV[0], "\"\n" if $DEBUG; $searchterm = ( $opt_i ? qr/@ARGV[0]/ : qr/@ARGV[0]/i ) if @ARGV[0]; } sub ReadContacts { my $dp = ($ENV{'HOME'} || '.').'/'; $/ = "\r\n\r\n"; if ( ! $cdbfile ) { $cdbfile = $dp.'.gnome/GnomeCard.gcrd'; $cdbfile = $dp.'GnomeCard.gcrd' unless -r $cdbfile; $cdbfile = $dp.'docs/GnomeCard.gcrd' unless -r $cdbfile; $cdbfile = '/usr/local/etc/GnomeCard.gcrd' unless -r $cdbfile; open( CDB, $cdbfile ) or PrintErrorQuit( "Cannot open any default address book" ); } else { open( CDB, $cdbfile ) or PrintErrorQuit( "Cannot open $cdbfile" ); } @cdb = ; return 1; } sub PrintErrorQuit { print STDERR @_, ", quitting\n"; exit 1; } sub DisplayContacts { if ( $searchterm ) { if ( $LONG ) { print grep /$searchterm/, @cdb; } else { foreach ( grep /$searchterm/, @cdb ) { s/BEGIN:VCARD\r\n//; s/END:VCARD\r\n//; s/REV:[^\r]*\r\n//; s/BDAY:[^\r]*\r\n//; s/TZ:[^\r]*\r\n//; s/CATEGORIES;QUOTED-PRINTABLE:[^\r]*\r\n//; s/FN:([^\r]*)(.*)ORG:([^\r]*)\r\n/\1 \(\3\)\2/s; s/N:[^\r]*\r\n//; s/TEL://; s/(TEL[:;].*);VOICE/\1/; s/TEL;HOME:/TEL;h:/g; s/TEL;WORK:/TEL;w:/g; s/TEL;WORK;FAX:/TEL;wf:/g; s/TEL;HOME;FAX:/TEL;hf:/g; s/TEL;CELL:/TEL;c:/g; s/TEL;FAX:/TEL;f:/g; s/TEL;PREF:/TEL;pref:/g; s/TEL;PREF;WORK:/TEL;wpref:/g; s/TEL;([^:]*):([^\r]*)/$2 ($1)/g; s/ADR(;[^:]*)?:;*([^;\r]*);+([^;\r]*);+/ADR$1:$2;$3;/g; s/ADR(;[^:]*)?:;*([^;]*)([^\r]*);*/ADR$1:$2$3/g; 1 while s/(ADR(;[^:]*)?:[^;\r]*);+(?=[^;\r])/$1, /; s/ADR;HOME:([^;\r]*);*/home: $1/g; s/ADR;WORK:([^;\r]*);*/work: $1/g; s/ADR;POSTAL:([^;\r]*);*/post: $1/g; s/ADR:([^;\r]*);*/$1/g; s/EMAIL[^:]*:([^\r]*)/<$1>/; 1 while s/(NOTE;QUOTED-PRINTABLE:.*)=0A/$1, /g; 1 while s/(NOTE;QUOTED-PRINTABLE:.*)=\r\n/$1/g; s/NOTE;QUOTED-PRINTABLE:([^\r]*\r\n)/$1/g; s/\r//g; print; # if /$searchterm/; } } } else { print @cdb; print $#cdb, " lines\n" if $DEBUG; } } sub EventLoop { } # main starts here ParseArgs(); ReadContacts() or PrintErrorQuit( "Could not read contacts database" ); DisplayContacts(); EventLoop(); exit 0;