#!/usr/bin/perl

=head1 NAME

csv2wl-addr - An filter convert address book from csv to Wanderlust.

=head1 SYNOPSIS

$ csv2syl-addr

STDIN:	Address book data of CSV which is exported Outlook Express etc.

STDOUT:	Address book data of Wanderlust.

=head1 DESCRIPTION

Example:

$ cat hoge.csv | csv2wl-addr >> .addresses

=head1 AUTHOR

Yasumichi Akahoshi <yasumichi@users.sourceforge.jp>

=head1 SEE ALSO

al2wl-addr, bec2wl-addr

=cut

use Jcode;

# The first line is field names.
$firstline = <STDIN>;
$firstline =~ s/\r\n/\n/g;

@fields = split(/,/, $firstline);
$fldcnt = @fields;

%items = (
	'dummy'	=>	1,
);

# convert each line.
foreach $line (<STDIN>) {
	undef %items;
	$line =~ s/\r\n/\n/g;
	@datas = split(/,/, $line);
	if(@datas == $fldcnt) {
		for($i=0; $i<$fldcnt; $i++) {
			chomp($fields[$i]);
			chomp($datas[$i]);
			$items{jcode($fields[$i])->euc} = jcode($datas[$i])->euc;
		}
		$email = $items{'Żҥ᡼ ɥ쥹'};
		$nick = jcode($items{'˥å͡'})->jis;
		$cn = jcode($items{'ɽ̾'})->jis;
		print $email."\t\"".$nick."\"\t\"".$cn."\"\n";
	}
}
