source: trunk/lib/Epoll/View/Mail.pm @ 311

Last change on this file since 311 was 311, checked in by nanardon, 14 years ago
  • add I18N support in mail like the html one
File size: 1.5 KB
Line 
1package Epoll::View::Mail;
2
3use strict;
4use base 'Catalyst::View::TT';
5use Mail::Mailer;
6use Epoll;
7use Epoll::DB;
8
9__PACKAGE__->config(
10    TEMPLATE_EXTENSION => '.tt',
11    INCLUDE_PATH => Epoll->path_to( 'root', 'mail' ),
12    PLUGIN_BASE => 'Epoll::Template::Plugin',
13    PRE_PROCESS => [ 'includes/loc.tt', ],
14);
15
16=head1 NAME
17
18Epoll::View::TT - TT View for Epoll
19
20=head1 DESCRIPTION
21
22TT View for Epoll.
23
24=cut
25
26sub render {
27    my ($self, $c, $template, $args) = @_;
28
29    my ($locale) = split(';', $c->req->header('Accept-Language') || '');
30    if (my $plocale = ($c->req->param('locale')|| $c->session->{'locale'})) {
31        $c->session->{'locale'} = $locale = $plocale;
32    }
33    $c->languages($locale ? [ $locale ] : '');
34    $c->stash->{locale} = $locale;
35
36    $ENV{MAILADDRESS} = $args->{From};
37    my $mailer = new Mail::Mailer 'smtp', Server => (Epoll->config->{smtp} || 'localhost');
38    $mailer->open({
39        (map { $_ => $args->{$_} } grep { $_ !~ /^(mail)$/ } keys %{ $args || {}}),
40        'Content-Type' => 'text/plain; charset=UTF-8; format=flowed',
41        'Content-Transfer-Encoding' => '8bit',
42        'X-Epoll-version' => $Epoll::DB::VERSION,
43    });
44    print $mailer
45    Catalyst::View::TT::render($self, $c, $template, { %{ $args->{mail} || {} }, c => $c });
46    $mailer->close;
47}
48
49=head1 SEE ALSO
50
51L<Epoll>
52
53=head1 AUTHOR
54
55Thauvin Olivier
56
57=head1 LICENSE
58
59This library is free software, you can redistribute it and/or modify
60it under the same terms as Perl itself or CeCILL.
61
62=cut
63
641;
Note: See TracBrowser for help on using the repository browser.