From 6247324f8e4d9f9d141cf4a814c1d75540bd49fb Mon Sep 17 00:00:00 2001 From: tetragon Date: Fri, 19 Oct 2007 01:50:19 +0000 Subject: Add email support to new templating system, ex-parse_template email needs update Add email output to GL report for a simple test (hardcoded addresses) git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1791 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Template.pm | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'LedgerSMB/Template.pm') diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index 5248ab78..03bcbc34 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -228,6 +228,11 @@ sub render { my $post = $format->can('postprocess')->($self); if (!$self->{'noauto'}) { $self->output; + # Clean up + if ($self->{rendered}) { + unlink($self->{rendered}) or + throw Error::Simple 'Unable to delete output file'; + } } return $post; } @@ -296,12 +301,46 @@ sub _http_output_file { sub _email_output { my $self = shift; - my $mail = new LedgerSMB::Mailer; - #TODO stub + my $args = $self->{output_args}; + + my @mailmime; + if (!$self->{rendered} and !$args->{attach}) { + $args->{message} .= $self->{output}; + @mailmime = ('contenttype', $self->{mimeytype}); + } + + my $mail = new LedgerSMB::Mailer( + from => $args->{from} || $self->{user}->{email}, + to => $args->{to}, + cc => $args->{cc}, + bcc => $args->{bcc}, + subject => $args->{subject}, + notify => $args->{notify}, + message => $args->{message}, + @mailmime, + ); + if ($args->{attach} or $self->{mimetype} !~ m#^text/# or $self->{rendered}) { + my @attachment; + my $name = $args->{filename}; + if ($self->{rendered}) { + @attachment = ('file', $self->{rendered}); + $name ||= $self->{rendered}; + } else { + @attachment = ('data', $self->{output}); + } + $mail->attach( + mimetype => $self->{mimetype}, + filename => $name, + strip => $$, + @attachment, + ); + } + $mail->send; } sub _lpr_output { my $self = shift; #TODO stub } + 1; -- cgit v1.2.3