#!/usr/bin/perl

=head1 NAME

bec2wl-addr - An filter convert address book from Becky! to Wanderlust.

=head1 SYNOPSIS

$ bec2wl-addr

STDIN:	Address book data of Becky!

STDOUT:	Address book data of Wanderlust.

=head1 DESCRIPTION

Example:

$ cat *.bab | iconv -f sjis -t iso-2022-jp | perl bec2wl-addr >> ~/.addresses

=head1 AUTHOR

Yasumichi Akahoshi <yasumichi@users.sourceforge.jp>

=head1 SEE ALSO

al2wl-addr, bec2syl-addr

=cut

foreach $line (<STDIN>) {
	$line =~ s/\r\n/\n/g;	# convert code of new line.
	chomp($line);		# remove code of new line.
	next if($line =~ /^BEGIN:VCARD$/);
	if($line =~ /^END:VCARD$/) {
		$uid = &putperson(%vCard);
		undef %vCard;
		next;
	}
	if ($line =~ /^([^:]*):(.*)$/) {
		$vCard{$1} = $2;
	}
}

# generate datas of person.

sub putperson {
	my(%vCard) = @_;

	my $email = $vCard{'EMAIL;PREF'};	# e-mail
	my $nick = $vCard{'X-BECKY-NICKNAME'};	# nickname
	my $fullname = $vCard{'FN'};		# fullname

	print "$email\t\"$nick\"\t\"$fullname\"\n";
}
