package Vote::View::Mail;

use strict;
use base 'Catalyst::View::TT';
use Mail::Mailer;
use Vote::DB;

__PACKAGE__->config(
    TEMPLATE_EXTENSION => '.tt',
    INCLUDE_PATH => Vote->path_to( 'root', 'mail' ),
    PLUGIN_BASE => 'Vote::Template::Plugin',
);

=head1 NAME

Vote::View::TT - TT View for Vote

=head1 DESCRIPTION

TT View for Vote. 

=cut

sub render {
    my ($self, $c, $template, $args) = @_;

    $ENV{MAILADDRESS} = $args->{From};
    my $mailer = new Mail::Mailer 'smtp', Server => (Vote->config->{smtp} || 'localhost');
    $mailer->open({
        (map { $_ => $args->{$_} } grep { $_ !~ /^(mail)$/ } keys %{ $args || {}}),
        'Content-Type' => 'text/plain; charset=UTF-8; format=flowed',
        'Content-Transfer-Encoding' => '8bit',
        'X-Epoll-version' => $Vote::DB::VERSION,
    });
    print $mailer
    Catalyst::View::TT::render($self, $c, $template, { %{ $args->{mail} || {} }, c => $c });
    $mailer->close;
}

=head1 SEE ALSO

L<Vote>

=head1 AUTHOR

Thauvin Olivier

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself or CeCILL.

=cut

1;
