1 | package Epoll::View::Mail; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use base 'Catalyst::View::TT'; |
---|
5 | use Mail::Mailer; |
---|
6 | use Epoll; |
---|
7 | use 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 | |
---|
18 | Epoll::View::TT - TT View for Epoll |
---|
19 | |
---|
20 | =head1 DESCRIPTION |
---|
21 | |
---|
22 | TT View for Epoll. |
---|
23 | |
---|
24 | =cut |
---|
25 | |
---|
26 | sub 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 | eval { |
---|
39 | $mailer->open({ |
---|
40 | (map { $_ => $args->{$_} } grep { $_ !~ /^(mail)$/ } keys %{ $args || {}}), |
---|
41 | 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed', |
---|
42 | 'Content-Transfer-Encoding' => '8bit', |
---|
43 | 'X-Epoll-version' => $Epoll::DB::VERSION, |
---|
44 | }); |
---|
45 | print $mailer |
---|
46 | Catalyst::View::TT::render($self, $c, $template, { %{ $args->{mail} || {} }, c => $c }); |
---|
47 | $mailer->close; |
---|
48 | }; |
---|
49 | if ($@) { |
---|
50 | $c->stash->{mail_error} = $@; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | =head1 SEE ALSO |
---|
55 | |
---|
56 | L<Epoll> |
---|
57 | |
---|
58 | =head1 AUTHOR |
---|
59 | |
---|
60 | Thauvin Olivier |
---|
61 | |
---|
62 | =head1 LICENSE |
---|
63 | |
---|
64 | This library is free software, you can redistribute it and/or modify |
---|
65 | it under the same terms as Perl itself or CeCILL. |
---|
66 | |
---|
67 | =cut |
---|
68 | |
---|
69 | 1; |
---|