#!/usr/bin/perl
#
# elm2xcmail addressbook converter
# by Martin Poole (mpoole@uhea904.gb.ec.ps.net)
#

open(ELMF,"<~/.elm/aliases.text")
    || die("No elm alias file found\n");
open(XCADDR,">>~/.XCmail/addressbook")
    || die("Unable to open addressbook\n");
while(<ELMF>)
{
    chomp();
    ($alias,$fullname,$email) = split( /\s=\s/, $_, 3 );
    ($first,$last) = split( / /, $fullname, 2 );
	if ( /\,$/ )
	{
		print STDERR "Ignoring group $alias ($last, $first)\n";
		while ( /\,$/ )
		{
			#Get an extra line
			$_ = <ELMF>;
			chomp();
			$_ =~ s/ //g;
			$email .= $_;
		}
	} else
	{
		print XCADDR "$alias\t$last\t$first\t$email\t0\t\n";
	}
}
