- fix [ 1160019 ] Notification content type [temp fix] - mwilson

This commit is contained in:
Matthew Wilson 2005-05-12 20:29:06 +00:00
parent 9073a95945
commit 74b83adc95

View file

@ -1,16 +1,16 @@
package WebGUI::Mail; package WebGUI::Mail;
=head1 LEGAL =head1 LEGAL
------------------------------------------------------------------- -------------------------------------------------------------------
WebGUI is Copyright 2001-2005 Plain Black Corporation. WebGUI is Copyright 2001-2005 Plain Black Corporation.
------------------------------------------------------------------- -------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using (docs/license.txt) that came with this distribution before using
this software. this software.
------------------------------------------------------------------- -------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com http://www.plainblack.com info@plainblack.com
------------------------------------------------------------------- -------------------------------------------------------------------
=cut =cut
@ -31,8 +31,8 @@ This package provides access to use SMTP based email services.
=head1 SYNOPSIS =head1 SYNOPSIS
use WebGUI::Mail; use WebGUI::Mail;
WebGUI::Mail::send($to,$subject,$message); WebGUI::Mail::send($to,$subject,$message);
=head1 METHODS =head1 METHODS
@ -75,28 +75,32 @@ The email address for the BCC line.
=cut =cut
sub send { sub send {
my ($smtp, $message, $from, $footer); my ($smtp, $message, $from, $footer);
foreach my $option (\$_[0], \$_[1], \$_[3], \$_[4], \$_[5]) { foreach my $option (\$_[0], \$_[1], \$_[3], \$_[4], \$_[5]) {
if(${$option}) { if(${$option}) {
if (${$option} =~ /(?:From|To|Date|X-Mailer|Subject|Received|Message-Id)\s*:/is) { if (${$option} =~ /(?:From|To|Date|X-Mailer|Subject|Received|Message-Id)\s*:/is) {
use WebGUI::ErrorHandler; use WebGUI::ErrorHandler;
return WebGUI::ErrorHandler::security("pass a malicious value to the mail header."); return WebGUI::ErrorHandler::security("pass a malicious value to the mail header.");
} }
} }
} }
$from = $_[4] || $session{setting}{companyEmail}; $from = $_[4] || $session{setting}{companyEmail};
#header #header
$message = "To: $_[0]\n"; $message = "To: $_[0]\n";
$message .= "From: $from\n"; $message .= "From: $from\n";
$message .= "CC: $_[3]\n" if ($_[3]); $message .= "CC: $_[3]\n" if ($_[3]);
$message .= "BCC: $_[5]\n" if ($_[5]); $message .= "BCC: $_[5]\n" if ($_[5]);
$message .= "Subject: ".$_[1]."\n"; $message .= "Subject: ".$_[1]."\n";
$message .= "Date: ".WebGUI::DateTime::epochToHuman("","%W, %d %C %y %j:%n:%s %O")."\n"; $message .= "Date: ".WebGUI::DateTime::epochToHuman("","%W, %d %C %y %j:%n:%s %O")."\n";
$message .= "Content-Type: text/plain; charset=UTF-8\n"; if (($_[2] =~ m/<html>/i) || ($_[2] =~ m/<a\sname=/i)) {
$message .= "\n"; $message .= "Content-Type: text/html; charset=UTF-8\n";
} else {
$message .= "Content-Type: text/plain; charset=UTF-8\n";
}
$message .= "\n";
$message = WebGUI::Macro::process($message); $message = WebGUI::Macro::process($message);
#body #body
$message .= $_[2]."\n"; $message .= $_[2]."\n";
#footer #footer
$message .= WebGUI::Macro::process("\n".$session{setting}{mailFooter}); $message .= WebGUI::Macro::process("\n".$session{setting}{mailFooter});
if ($session{setting}{smtpServer} =~ /\/sendmail/) { if ($session{setting}{smtpServer} =~ /\/sendmail/) {
@ -107,23 +111,20 @@ sub send {
WebGUI::ErrorHandler::warn("Couldn't connect to mail server: ".$session{setting}{smtpServer}); WebGUI::ErrorHandler::warn("Couldn't connect to mail server: ".$session{setting}{smtpServer});
} }
} else { } else {
$smtp = Net::SMTP->new($session{setting}{smtpServer}); # connect to an SMTP server $smtp = Net::SMTP->new($session{setting}{smtpServer}); # connect to an SMTP server
if (defined $smtp) { if (defined $smtp) {
$smtp->mail($from); # use the sender's address here $smtp->mail($from); # use the sender's address here
$smtp->to($_[0]); # recipient's address $smtp->to($_[0]); # recipient's address
$smtp->cc($_[3]) if ($_[3]); $smtp->cc($_[3]) if ($_[3]);
$smtp->bcc($_[5]) if ($_[5]); $smtp->bcc($_[5]) if ($_[5]);
$smtp->data(); # Start the mail $smtp->data(); # Start the mail
$smtp->datasend($message); $smtp->datasend($message);
$smtp->dataend(); # Finish sending the mail $smtp->dataend(); # Finish sending the mail
$smtp->quit; # Close the SMTP connection $smtp->quit; # Close the SMTP connection
} else { } else {
WebGUI::ErrorHandler::warn("Couldn't connect to mail server: ".$session{setting}{smtpServer}); WebGUI::ErrorHandler::warn("Couldn't connect to mail server: ".$session{setting}{smtpServer});
} }
} }
} }
1; 1;