#!/usr/bin/perl # sm2vCard - Convert SquirrelMail abook files into vCard format # # Author: # Steve Pellegrin (spellegrin at convoglio dot com) # # History: # 1.0 2008-Oct-5 Original code # # Description: use strict; # to catch stupid errors use Getopt::Long; use Pod::Usage; # ---------- End of Configuration ----------------------------------- # Extract the command line arguments GetOptions ( 'version=s' => \(my $version = '2.1'), 'help' => \(my $help = ''), ) or pod2usage(2); # Print help text and exit if requested # or if the version is invalid. pod2usage(1) if $help; pod2usage(1) unless ($version eq '2.1') or ($version eq '3.0');; # Fetch the files if available pod2usage(2) if (@ARGV == 0); foreach my $file (@ARGV) { convertFile( $file ); } sub convertFile { my ($inFile) = @_; my $outFile = "$inFile.vcard"; open IN, "<$inFile" or die "Cannot open: $inFile\n"; open OUT, ">$outFile" or die "Cannot open: $outFile\n"; while (my $line = ) { chomp($line); $line =~ s/\xa0/ /g; $line =~ s/([\'\"])/\\\1/g; $line =~ /^[^\|]+\|([^\|]+)\|([^\|]+)\|([^\|]+)\|(.*)$/; my $firstName = $1; my $lastName = $2; my $email = $3; my $phone = $4; print OUT "BEGIN:VCARD\n"; if ($version eq '3.0') { print OUT "VERSION:3.0\n"; print OUT "N:$lastName;$firstName\n"; print OUT "FN:$firstName $lastName\n"; print OUT "EMAIL;type=INTERNET;type=pref:$email\n"; print OUT "TEL:$phone\n" unless ($phone eq ''); } else { print OUT "VERSION:2.1\n"; print OUT "N:$lastName;$firstName\n"; print OUT "FN:$firstName $lastName\n"; print OUT "EMAIL;PREF;INTERNET:$email\n"; print OUT "TEL:$phone\n" unless ($phone eq ''); } print OUT "END:VCARD\n"; } close IN; close OUT; } __END__ =head1 NAME sm2vCard - Convert one or more SquirrelMail abook files to vCard format =head1 SYNOPSIS sm2vCard [options] file... =head1 OPTIONS =over 8 =item B<--version=string> vCard version to use: 2.1 and 3.0 supported (Default: 2.1) =item B<--help> Print this text =back =cut