Address book hack

Perl Monger pug at taut.oau.org
Sat Jan 29 13:24:01 CST 2000


PerlMongers,

Here is a hack to move your elm mailer address book to the Palm Desktop
software to HotSync to your palmtop.  Use at your own risk!


#!/usr/bin/perl -w
#
#     Author: David Billsbrough (kc4zvw at mpinet.net)
#
#        $Id: elm2palm,v 0.1 2000/01/29 18:59:48 kc4zvw Exp $:
#  $Revision: 0.1 $:
# 
#    Created: Saturday, 29 January 2000 at 06:55am EST
#   Warranty: None
#
#    Purpose: Convert an elm address book for use with
#           : 3COM PalmIIIx palmtop computer.
#
###------------------------------------------------------###

require strict;

sub get_home_dir
{
	local ($myHOME) = $ENV{"HOME"};
	print "My \$HOME directory is $myHOME.\n";
	return $myHOME;
}

sub get_timestamp
{
	local($tmstamp);
	local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);

	($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
		localtime(time);

	$tmstamp = sprintf("%02d-%02d-%04d at %02d:%02d:%02d (local)",
		$mon + 1, $mday, 1900 + $year, $hour, $min, $sec);

	return($tmstamp);
}

sub delete_comment
{
	return substr($_[0], 0, $_[1]);
}

sub get_firstname
{
	return substr($_[0], $_[1] + 2);
}

sub get_lastname
{
	return substr($_[0], 0, $_[1]);
}

sub get_fullname
{
	local ($full_name);
	local ($first_name) = $_[0];
	local ($last_name) = $_[1];

	$full_name = $first_name . " " . $last_name;
	return $full_name;
}

sub display_entry
{
	local ($full_name) = @_;

	print("Converting \"$fullname\" {$.}\n");
}

sub write_palm_entry
{
	local ($alias, $first, $last, $email) = @_;

	print OUTPUT "\"$last\",";			# Last Name
	print OUTPUT "\"$first\",";			# First Name
	print OUTPUT "title,";				# Title
	print OUTPUT "company,";			# Company
	print OUTPUT "000-0000,";
	print OUTPUT "555-1212,";
	print OUTPUT "555-1212,";
	print OUTPUT "pager,";
	print OUTPUT "\"$email\",";
	print OUTPUT "street,";
	print OUTPUT "city,";
	print OUTPUT "state,";
	print OUTPUT "zip,";
	print OUTPUT "USA,";
	print OUTPUT "\"$alias\",";
	print OUTPUT "0,";
	print OUTPUT "Unfiled";
	print OUTPUT "\n";
}

sub write_header
{
	print OUTPUT "# Address Book for Palm Pilot\n";
}

sub process_line
{
	local ($line);
	local ($pos1, $pos2);
	local ($alias, $name, $email);
	local ($first) = "";
	local ($last) = "";
	local ($fullname) = "";

	$line = readline(*INPUT);
	chomp($line);							# frag the newline
	($alias, $name, $email) = split(' = ', $line, 3);

	$pos1 = index($name, ',');				# search for a comma
	$pos2 = index($name, ';');				# search for a semicolon
	#print "comma at '$pos1', semicolon at '$pos2'\n";

	if ($pos1 > 0) {
		$name = &delete_comment($name, $pos1);
	}

	if ($pos2 > 0) {
		$first = &get_firstname($name, $pos2);
		$last = &get_lastname($name, $pos2);
	}

	$fullname = &get_fullname($first, $last);
	&display_entry($fullname);							# display progress
	&write_palm_entry($alias, $first, $last, $email)	# write CSV entry
}

###------------------- Main Routine ---------------------###

local ($home) = &get_home_dir;
local ($timestamp) = &get_timestamp;

local ($elm) = join("/", $home, ".elm", "aliases.text");
local ($palm) = join("/", $home, "email3.csv");

print "The elm mail alias file is $elm.\n";
print "The Palm address book file is $palm.\n\n";

open(INPUT, '<' . $elm) or die "Can't read input mail aliases : $!";
open(OUTPUT, '>' . $palm) or die "Can't write output address book : $!";

&write_header;
&process_line until eof(INPUT);

$timestamp = &get_timestamp;
print "\n";
print "Completed $. records on $timestamp.\n";

close INPUT;
close OUTPUT;

# End of Program


regards,

// David //



More information about the Orlando-pm mailing list