440 if($this->readBuffer ==
'')
443 if($this->__listenFunc ==
'__AuthLoginHandler')
446 if($this->__listenFunc ==
'__AuthPlainHandler')
449 if($this->__listenFunc ==
'__DataHandler')
452 if(mb_strpos($this->readBuffer,
"\r\n") ===
false)
455 $this->readBuffer = Trim($this->readBuffer);
458 if((
$p = mb_strpos($this->readBuffer,
" "))!==
false)
460 $command = mb_substr($this->readBuffer, 0,
$p);
469 $this->readBuffer =
"";
536 $domains = preg_split(
'/[\s]+/', mb_strtolower($this->server->arFields[
'DOMAINS']), -1, PREG_SPLIT_NO_EMPTY);
537 if(
count($domains)<=0)
540 if(!is_array($this->arMsg[
"FOR_RELAY"]))
541 $this->arMsg[
"FOR_RELAY"] =
array();
544 $email_domain = mb_substr(
$email,
$p + 1);
546 if(in_array($email_domain, $domains))
548 $this->
WriteToLog(
'['.$this->arMsg[
"LOCAL_ID"].
'] Accepted for relaying '.
$email, 8);
552 if($this->server->arFields[
'RELAY']!=
'Y')
555 if($this->server->arFields[
'AUTH_RELAY']==
'Y' && $this->auth_user_id<=0)
558 $this->
WriteToLog(
'['.$this->arMsg[
"LOCAL_ID"].
'] Accepted for relaying '.
$email, 8);
559 $this->arMsg[
"FOR_RELAY"][] =
$email;
817 if(mb_strpos($this->readBuffer,
"\r\n") ===
false)
819 $this->readBuffer = trim($this->readBuffer);
820 if($this->readBuffer==
"*")
821 $this->
Send(
'501',
'AUTH aborted');
824 $pwd = base64_decode($this->readBuffer);
826 $this->
Send(
'501',
'Base64 decode error');
829 $pwd = ltrim($pwd, chr(0));
830 $this->
Authorize(mb_substr($pwd, 0, mb_strpos($pwd, chr(0))), mb_substr($pwd, mb_strpos($pwd, chr(0)) + 1));
834 $this->readBuffer =
"";
835 $this->__listenFunc =
false;
841 if(mb_strpos($this->readBuffer,
"\r\n.\r\n") ===
false)
844 $this->readBuffer = mb_substr($this->readBuffer, 0, -3);
846 $this->readBuffer = str_replace(
"\r\n..",
"\r\n.", $this->readBuffer);
852 $this->
WriteToLog(
'['.$this->arMsg[
"LOCAL_ID"].
'] Start processing mail...', 7);
860 $arLocalTo = Array();
861 foreach($this->arMsg[
"TO"] as $to)
863 if(is_array($this->arMsg[
"FOR_RELAY"]) && in_array($to, $this->arMsg[
"FOR_RELAY"]))
865 $message_header_add =
866 "Received: from ".$this->host.
" by ".$this->server->arFields[
"SERVER"].
" with Bitrix SMTP Server \r\n".
867 "\t".date(
"r").
"\r\n".
868 "\tfor <".$to.
">; \r\n".
869 "Return-Path: <".$this->arMsg[
"FROM"].
">\r\n";
872 $message_header_new = $message_header;
873 if(preg_match(
'/(Subject:\s*([^\r\n]*\r\n(\t[^\r\n]*\r\n)*))\S/is', $message_header_new.
"\r\nx", $reg))
875 $message_header_new = trim(str_replace($reg[1],
"", $message_header_new.
"\r\n"));
876 $subject = trim($reg[2]);
879 $r =
bxmail($to, $subject, $message_text, $message_header_add.$message_header_new);
880 $this->
WriteToLog(
'['.$this->arMsg[
"LOCAL_ID"].
'] Relay message to '.$to.
' ('.($r?
'OK':
'FAILED').
')', 7);
886 if(
count($arLocalTo)>0)
888 $message_header_add =
889 "Received: from ".$this->host.
" by ".$this->server->arFields[
"SERVER"].
" with Bitrix SMTP Server \r\n".
890 "\t".date(
"r").
"\r\n".
891 "Return-Path: <".$this->arMsg[
"FROM"].
">\r\n".
892 "X-Original-Rcpt-to: ".implode(
", ", $arLocalTo).
"\r\n";
894 $this->
WriteToLog(
'['.$this->arMsg[
"LOCAL_ID"].
'] Message add: '.$message_header_add.$message, 9);
896 if($this->server->arFields[
"CHARSET"]!=
'')
897 $charset = $this->server->arFields[
"CHARSET"];
899 $charset = $this->server->arFields[
"LANG_CHARSET"];
901 $message_id = CMailMessage::AddMessage($this->server->arFields[
"ID"], $message_header_add.$message, $charset);
903 $this->
WriteToLog(
'['.$this->arMsg[
"LOCAL_ID"].
'] Message sent to '.implode(
", ", $arLocalTo).
' ('.$message_id.
')', 7);
905 $this->
Send(
'250', $message_id.
' Message accepted for delivery');
908 $this->
Send(
'554',
' Bad message format');
910 $this->
WriteToLog(
'['.$this->arMsg[
"LOCAL_ID"].
'] End processing mail...', 7);
912 $this->readBuffer =
"";
913 $this->__listenFunc =
false;
914 $this->arMsg =
array(
'LOCAL_ID'=>md5(uniqid()));
917 $this->server->msgCount++;