Index: trunk/kernel/include/emailmessage.php =================================================================== diff -u -r6428 -r7867 --- trunk/kernel/include/emailmessage.php (.../emailmessage.php) (revision 6428) +++ trunk/kernel/include/emailmessage.php (.../emailmessage.php) (revision 7867) @@ -119,6 +119,8 @@ { global $objUsers, $objTemplate; + $this->Application->InitParser(); + $res = $this->ParseTemplateText($text); /* parse email class tags */ @@ -901,107 +903,49 @@ function SendMail($From, $FromName, $ToAddr, $ToName, $Subject, $Text, $Html, $charset, $SendEvent,$FileName="",$FileLoc="",$QueueOnly=0,$extra_headers = array()) { - $charset = GetRegionalOption('Charset'); - - $HasFile = FALSE; - $HasFile = (strlen($FileName)>0); - $OB="----=_OuterBoundary_000".md5( uniqid (rand())); - $boundary = "-----=".md5( uniqid (rand())); - $f = "\"$FromName\" <".$From.">"; - $headers = "From: $f"."\n"; - $headers .= "MIME-Version: 1.0"."\n"; - - $conn = &GetADODBConnection(); - $time = adodb_mktime(); - - $sendTo = $ToName; - - if (strlen($sendTo) > 0) { - $sendTo .= "($ToAddr)"; - } - else { - $sendTo = $ToAddr; - } - $sendTo=addslashes($sendTo); - $sql = "INSERT INTO ".GetTablePrefix()."EmailLog VALUES ('', ".$conn->qstr($FromName).", ".$conn->qstr($sendTo).", ".$conn->qstr( str_replace("Subject:", "", $Subject) ).", $time, '$SendEvent')"; - $conn->Execute($sql); - - if(is_array($extra_headers)) - { - foreach ($extra_headers as $h) - { - $headers .= $h."\n"; + // $QueueOnly - {true = put in queue, false = nd now} + + $application =& kApplication::Instance(); + + $esender =& $application->recallObject('EmailSender'); + /* @var $esender kEmailSendingHelper */ + + $esender->SetFrom($From, $FromName); + $esender->AddTo($ToAddr, $ToName); + $esender->SetSubject($Subject); + $esender->SetBody(stripslashes($Html), $Text); + + // set additional headers + if (is_array($extra_headers)) { + foreach ($extra_headers as $header) { + $header = explode(':', $header, 2); + $esender->SetEncodedHeader(trim($header[0]), trim($header[1])); } } - - $msg .="This is a multi-part message in MIME format."."\n"."\n"; - if($HasFile) - { - //Messages start with text/html alternatives in OB - $headers.="Content-Type: multipart/mixed;"."\n"."\tboundary=\"".$OB."\""."\n"."\n"; - $msg.="--".$OB."\n"; - $msg.="Content-Type: multipart/alternative; boundary=\"$boundary\""."\n"."\n"."\n"; - } - else { - $headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\""."\n"; - } - - $application =& kApplication::Instance(); - $db =& $application->GetADODBConnection(); - - if (!$Text) { - $Text = strip_tags($Html); - } - else { - $Text = strip_tags($Text); - } - - $msg .= "--" . $boundary . "\n"; - $msg .= "Content-Type: text/plain; charset=\"$charset\""."\n"; - $msg .= "Content-Transfer-Encoding: 8bit"."\n"."\n"; - $msg .= stripslashes($Text); - $msg .= "\n"."\n"; - - if(strlen($Html)>0) - { - $msg .= "--" . $boundary . "\n"; - $msg .= "Content-Type: text/html; charset=\"".$charset."\""."\n"; - $msg .= "Content-Transfer-Encoding: 8bit"."\n"."\n"; - $msg .= stripslashes($Html); - $msg .= "\n"."\n"; - } - $msg .= "--" . $boundary . "--"."\n"; - if($HasFile) - { - if(!strlen($FileLoc)) { + + // add attachment if any + if (strlen($FileName) > 0) { + if(!strlen($FileLoc)) { $FileLoc = $FileName; } - $FileName = basename($FileName); - $msg .= "\n"."--".$OB."\n"; - $msg.="Content-Type: application/octetstream;"."\n"."\tname=\"".$FileName."\""."\n"; - $msg.="Content-Transfer-Encoding: base64"."\n"; - $msg.="Content-Disposition: attachment;"."\n"."\tfilename=\"".$FileName."\""."\n"."\n"; + $esender->AddAttachment($FileLoc, basename($FileName)); + } - //file goes here - $fd=fopen ($FileLoc, "r"); - if($fd) - { - $FileContent=fread($fd,filesize($FileLoc)); - fclose ($fd); - } - $FileContent=chunk_split(base64_encode($FileContent)); - $msg .= $FileContent."\n"; - $msg .= "--".$OB."--"."\n"; - } - - if($this->MessagesSent>$this->MessagesAtOnce || $QueueOnly==1) - { - $this->EnqueueMail($ToAddr,$From,$Subject,$msg,$headers); - } - else - { - $this->DeliverMail($ToAddr,$From,$Subject,$msg,$headers); - } + $status = $esender->Deliver(); + + if ($status) { + // write to log + $fields_hash = Array ( + 'fromuser' => $FromName, + 'addressto' => $ToName ? $ToName.' ('.$ToAddr.')' : $ToAddr, + 'subject' => str_replace('Subject:', '', $Subject), + 'timestamp' => adodb_mktime(), + 'event' => $SendEvent, + ); + + $db =& $application->GetADODBConnection(); + $db->doInsert($fields_hash, TABLE_PREFIX.'EmailLog'); + } } }