package BarnOwl::Style::CSV;
use lib "/afs/athena.mit.edu/user/f/u/fustflum/perl5/lib/perl5";
use Text::CSV_PP;

use base qw(BarnOwl::Style::Default);

sub description {'csv custom style'}
BarnOwl::create_style('csv', 'BarnOwl::Style::CSV');

sub chat_header {
    my $self = shift;
    my $m = shift;
    my $csv = Text::CSV_PP->new ({ binary => 1, always_quote => 1}) or die "Cannot use CSV: ". Text::CSV_PP->error_diag ();
    my @fields = ($m->context, $m->subcontext, $m->recipient, $m->sender, $m->opcode, $m->is_ping, $m->time, $m->auth, $m->host, $m->long_sender);
    map { s/\n/\\n/g } @fields;
    my $status = $csv->combine (@fields);

    return $csv->string ();
}

BarnOwl::admin_message('Style', 'Loaded csv style');
