aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MGA/Mirrors/View/Mail.pm
blob: 0c694be37a630c0c101ca642ca0c9c8a756b86af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package MGA::Mirrors::View::Mail;

use strict;
use base 'Catalyst::View::TT';
use Mail::Mailer;
use MGA::Mirrors;

__PACKAGE__->config(
    TEMPLATE_EXTENSION => '.tt',
    INCLUDE_PATH => MGA::Mirrors->path_to( 'root', 'mail' ),
);

=head1 NAME

MGA::Mirrors::View::TT - TT View for MGA::Mirrors

=head1 DESCRIPTION

TT View for MGA::Mirrors. 

=cut

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

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

=head1 SEE ALSO

L<MGA::Mirrors>

=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;