[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb: [464] trunk
- Subject: SF.net SVN: ledger-smb: [464] trunk
- From: ..hidden..
- Date: Wed, 01 Nov 2006 22:58:51 -0800
Revision: 464
http://svn.sourceforge.net/ledger-smb/?rev=464&view=rev
Author: tetragon
Date: 2006-11-01 22:58:01 -0800 (Wed, 01 Nov 2006)
Log Message:
-----------
Converting Mailer to using MIME::Lite
Modified Paths:
--------------
trunk/Build.PL
trunk/LedgerSMB/AM.pm
trunk/LedgerSMB/Form.pm
trunk/LedgerSMB/Mailer.pm
trunk/bin/am.pl
Modified: trunk/Build.PL
===================================================================
--- trunk/Build.PL 2006-11-02 06:57:25 UTC (rev 463)
+++ trunk/Build.PL 2006-11-02 06:58:01 UTC (rev 464)
@@ -25,6 +25,7 @@
'Time::Local' => 0,
'Cwd' => 0,
'Config::Std' => 0,
+ 'MIME::Lite' => 0,
},
recommends => {
'HTML::LinkExtor' => 0,
Modified: trunk/LedgerSMB/AM.pm
===================================================================
--- trunk/LedgerSMB/AM.pm 2006-11-02 06:57:25 UTC (rev 463)
+++ trunk/LedgerSMB/AM.pm 2006-11-02 06:58:01 UTC (rev 464)
@@ -1591,6 +1591,7 @@
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 @@
@{ $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') {
Modified: trunk/LedgerSMB/Form.pm
===================================================================
--- trunk/LedgerSMB/Form.pm 2006-11-02 06:57:25 UTC (rev 463)
+++ trunk/LedgerSMB/Form.pm 2006-11-02 06:58:01 UTC (rev 464)
@@ -390,7 +390,6 @@
my ($self, $myconfig, $amount, $places, $dash) = @_;
-
my $negative ;
if ($amount){
$amount = $self->parse_amount($myconfig, $amount);
@@ -929,7 +928,7 @@
}
- if ($err = $mail->send($out)) {
+ if ($err = $mail->send) {
$self->cleanup;
$self->error($err);
}
@@ -2548,7 +2547,7 @@
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$_"} = "" }
Modified: trunk/LedgerSMB/Mailer.pm
===================================================================
--- trunk/LedgerSMB/Mailer.pm 2006-11-02 06:57:25 UTC (rev 463)
+++ trunk/LedgerSMB/Mailer.pm 2006-11-02 06:58:01 UTC (rev 464)
@@ -35,6 +35,10 @@
package Mailer;
+use MIME::Lite;
+use MIME::Base64;
+use LedgerSMB::Sysconfig;
+
sub new {
my ($type) = @_;
my $self = {};
@@ -44,22 +48,13 @@
sub send {
- my ($self, $out) = @_;
+ my ($self) = @_;
- my $boundary = time;
- $boundary = "LedgerSMB-$self->{version}-$boundary";
my $domain = $self->{from};
$domain =~ s/(.*?\@|>)//g;
my $msgid = "..hidden..";
- $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};
my %h;
@@ -70,36 +65,26 @@
$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 @@
? "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|;
+ }
+
+ if (${LedgerSMB::Sysconfig::smtphost}) {
+ $msg->send('smtp', ${LedgerSMB::Sysconfig::smtphost},
+ Timeout => ${LedgerSMB::Sysconfig::smtptimeout}) ||
+ return $!;
} else {
- print OUT qq|Content-Type: $self->{contenttype}; |.
- qq|charset="$self->{charset}"\n\n|.
- qq|$self->{message}|;
+ $msg->send('sendmail', ${LedgerSMB::Sysconfig::sendmail}) ||
+ return $!;
}
- close(OUT);
-
return "";
}
-sub encode_base64 ($;$) {
- use MIME::Base64;
- return MIME::Base64::encode($_[0], $_[1]);
-
-}
-
-
1;
Modified: trunk/bin/am.pl
===================================================================
--- trunk/bin/am.pl 2006-11-02 06:57:25 UTC (rev 463)
+++ trunk/bin/am.pl 2006-11-02 06:58:01 UTC (rev 464)
@@ -2245,7 +2245,7 @@
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 @@
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}));
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.