summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Build.PL1
-rwxr-xr-xLedgerSMB/AM.pm5
-rwxr-xr-xLedgerSMB/Form.pm5
-rwxr-xr-xLedgerSMB/Mailer.pm101
-rwxr-xr-xbin/am.pl4
5 files changed, 42 insertions, 74 deletions
diff --git a/Build.PL b/Build.PL
index d469f118..18f95d79 100644
--- a/Build.PL
+++ b/Build.PL
@@ -25,6 +25,7 @@ my $build = Module::Build->new (
'Time::Local' => 0,
'Cwd' => 0,
'Config::Std' => 0,
+ 'MIME::Lite' => 0,
},
recommends => {
'HTML::LinkExtor' => 0,
diff --git a/LedgerSMB/AM.pm b/LedgerSMB/AM.pm
index 8014c41e..cf4b5df8 100755
--- a/LedgerSMB/AM.pm
+++ b/LedgerSMB/AM.pm
@@ -1591,6 +1591,7 @@ sub backup {
my $boundary = time;
my $tmpfile = "${LedgerSMB::Sysconfig::userspath}/$boundary.$myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sql";
+ $tmpfile .= ".gz" if ${LedgerSMB::Sysconfig::gzip};
my $out = $form->{OUT};
$form->{OUT} = ">$tmpfile";
@@ -1624,11 +1625,13 @@ sub backup {
@{ $mail->{attachments} } = ($tmpfile);
$mail->{version} = $form->{version};
$mail->{fileid} = "$boundary.";
+ $mail->{format} = "plain";
+ $mail->{format} = "octet-stream" if ${LedgerSMB::Sysconfig::gzip};
$myconfig->{signature} =~ s/\\n/\n/g;
$mail->{message} = "-- \n$myconfig->{signature}";
- $err = $mail->send($out);
+ $err = $mail->send;
}
if ($form->{media} eq 'file') {
diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm
index 8a7f5571..166fcbbb 100755
--- a/LedgerSMB/Form.pm
+++ b/LedgerSMB/Form.pm
@@ -390,7 +390,6 @@ sub format_amount {
my ($self, $myconfig, $amount, $places, $dash) = @_;
-
my $negative ;
if ($amount){
$amount = $self->parse_amount($myconfig, $amount);
@@ -929,7 +928,7 @@ sub parse_template {
}
- if ($err = $mail->send($out)) {
+ if ($err = $mail->send) {
$self->cleanup;
$self->error($err);
}
@@ -2548,7 +2547,7 @@ sub get_recurring {
WHERE s.id = ?/;
my $sth = $dbh->prepare($query);
- $sth->execute($self->{id}) || $form->dberror($query);
+ $sth->execute($self->{id}) || $self->dberror($query);
for (qw(email print)) { $self->{"recurring$_"} = "" }
diff --git a/LedgerSMB/Mailer.pm b/LedgerSMB/Mailer.pm
index 54155c56..79e7bf7d 100755
--- a/LedgerSMB/Mailer.pm
+++ b/LedgerSMB/Mailer.pm
@@ -35,6 +35,10 @@
package Mailer;
+use MIME::Lite;
+use MIME::Base64;
+use LedgerSMB::Sysconfig;
+
sub new {
my ($type) = @_;
my $self = {};
@@ -44,21 +48,12 @@ sub new {
sub send {
- my ($self, $out) = @_;
+ my ($self) = @_;
- my $boundary = time;
- $boundary = "LedgerSMB-$self->{version}-$boundary";
my $domain = $self->{from};
$domain =~ s/(.*?\@|>)//g;
my $msgid = "$boundary\@$domain";
- $self->{charset} = "ISO-8859-1" unless $self->{charset};
-
- if ($out) {
- open(OUT, $out) or return "$out : $!";
- } else {
- open(OUT, ">-") or return "STDOUT : $!";
- }
$self->{contenttype} = "text/plain" unless $self->{contenttype};
@@ -70,36 +65,26 @@ sub send {
$h{$_} = $self->{$_};
}
- $h{cc} = "Cc: $h{cc}\n" if $self->{cc};
- $h{bcc} = "Bcc: $h{bcc}\n" if $self->{bcc};
- $h{notify} = "Disposition-Notification-To: $h{from}\n"
- if $self->{notify};
$h{subject} =
($self->{subject} =~ /([\x00-\x1F]|[\x7B-\xFFFF])/)
? "Subject: =?$self->{charset}?B?".
- &encode_base64($self->{subject},"")."?="
+ MIME::Base64::encode($self->{subject},"")."?="
: "Subject: $self->{subject}";
- print OUT "From: $h{from}\n".
- "To: $h{to}\n".
- "$h{cc}$h{bcc}$h{subject}\n".
- "Message-ID: <$msgid>\n".
- "$h{notify}X-Mailer: LedgerSMB $self->{version}\n".
- "MIME-Version: 1.0\n\n";
-
+ my $msg = MIME::Lite->new(
+ 'From' => $self->{from},
+ 'To' => $self->{to},
+ 'Cc' => $self->{cc},
+ 'Bcc' => $self->{bcc},
+ 'Subject' => $self->{subject},
+ 'Type' => 'TEXT',
+ 'Data' => $self->{message},
+ );
+ $msg->add('Disposition-Notification-To' => $self->{from})
+ if $self->{notify};
+ $msg->replace('X-Mailer' => "LedgerSMB $self->{version}");
if (@{ $self->{attachments} }) {
- print OUT
- qq|Content-Type: multipart/mixed; |.
- qq|boundary="$boundary"\n\n|;
- if ($self->{message} ne "") {
- print OUT qq|--${boundary}\n|.
- qq|Content-Type: $self->{contenttype};|.
- qq| charset="$self->{charset}"\n\n|.
- qq|$self->{message}|;
-
- }
-
foreach my $attachment (@{ $self->{attachments} }) {
my $application =
@@ -108,53 +93,33 @@ sub send {
? "text"
: "application";
- unless (open IN, $attachment) {
- close(OUT);
- return "$attachment : $!";
- }
-
my $filename = $attachment;
# strip path
$filename =~ s/(.*\/|$self->{fileid})//g;
-
- print OUT qq|--${boundary}\n|.
- qq|Content-Type: $application/$self->{format}; |
- . qq|name="$filename"; |.
- qq|charset="$self->{charset}"\n|.
- qq|Content-Transfer-Encoding: BASE64\n|.
- qq|Content-Disposition: attachment; |.
- qq|filename="$filename"\n\n|;
-
- my $msg = "";
- while (<IN>) {;
- $msg .= $_;
- }
- print OUT &encode_base64($msg);
-
- close(IN);
-
+ printf STDERR "$self->{format}\n";
+ $msg->attach(
+ 'Type' => "$application/$self->{format}",
+ 'Path' => $attachment,
+ 'Filename' => $filename,
+ 'Disposition' => 'attachment',
+ );
}
- print OUT qq|--${boundary}--\n|;
- } else {
- print OUT qq|Content-Type: $self->{contenttype}; |.
- qq|charset="$self->{charset}"\n\n|.
- qq|$self->{message}|;
}
- close(OUT);
+ if (${LedgerSMB::Sysconfig::smtphost}) {
+ $msg->send('smtp', ${LedgerSMB::Sysconfig::smtphost},
+ Timeout => ${LedgerSMB::Sysconfig::smtptimeout}) ||
+ return $!;
+ } else {
+ $msg->send('sendmail', ${LedgerSMB::Sysconfig::sendmail}) ||
+ return $!;
+ }
return "";
}
-sub encode_base64 ($;$) {
- use MIME::Base64;
- return MIME::Base64::encode($_[0], $_[1]);
-
-}
-
-
1;
diff --git a/bin/am.pl b/bin/am.pl
index 76423e9a..54f93163 100755
--- a/bin/am.pl
+++ b/bin/am.pl
@@ -2245,7 +2245,7 @@ sub save_preferences {
sub backup {
if ($form->{media} eq 'email') {
- $form->error($locale->text('No email address for')." $myconfig{name}") unless ($myconfig{email});
+ $form->error($locale->text('No email address for [_1]', $myconfig{name})) unless ($myconfig{email});
$form->{OUT} = "${LedgerSMB::Sysconfig::sendmail}";
@@ -2255,7 +2255,7 @@ sub backup {
AM->backup(\%myconfig, \%$form, ${LedgerSMB::Sysconfig::userspath}, ${LedgerSMB::Sysconfig::gzip});
if ($form->{media} eq 'email') {
- $form->redirect($locale->text('Backup sent to').qq| $myconfig{email}|);
+ $form->redirect($locale->text('Backup sent to [_1]', $myconfig{email}));
}
}