summaryrefslogtreecommitdiff
path: root/LedgerSMB/Mailer.pm
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2006-11-02 06:58:01 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2006-11-02 06:58:01 +0000
commit803c62d22eb4e2eb3a79a66a03dc0e8a9da23e01 (patch)
tree96f4bee9bc45b3bf4faffde4cd6aeafe4d808686 /LedgerSMB/Mailer.pm
parente0835c2fea33e86bb1411949c8c2bac2cf8519e0 (diff)
Converting Mailer to using MIME::Lite
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@464 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/Mailer.pm')
-rwxr-xr-xLedgerSMB/Mailer.pm101
1 files changed, 33 insertions, 68 deletions
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;