Exemple #1
0
	function GetMessage($mailbox_id, $msgnum, $msguid, $session_id)
	{
		global $DB;

		$this->SendCommand("RETR ".$msgnum);
		if(!$this->GetResponse(true))
			return CMailError::SetError("ERR_AFTER_RETR", GetMessage("MAIL_CL_ERR_RETR"), $this->GetResponseString());

		$message = $this->GetResponseBody();

		$message_id = CMailMessage::AddMessage($mailbox_id, $message, $this->charset);
		if($message_id>0)
		{
			$strSql = "INSERT INTO b_mail_message_uid(ID, MAILBOX_ID, SESSION_ID, DATE_INSERT, MESSAGE_ID) VALUES('".$DB->ForSql($msguid)."', ".IntVal($mailbox_id).", '".$DB->ForSql($session_id)."', ".$DB->GetNowFunction().", ".IntVal($message_id).")";
			$DB->Query($strSql);

		}
		return $message_id;
	} // function GetMessage(...
Exemple #2
0
 function __DataHandler()
 {
     if (strpos($this->readBuffer, "\r\n.\r\n") === false) {
         return false;
     }
     $this->readBuffer = substr($this->readBuffer, 0, -5);
     $this->readBuffer = str_replace("\r\n..", "\r\n.", $this->readBuffer);
     // Добавление сообщения куда надо
     $message = $this->readBuffer;
     $this->arMsg["MSG"] = $message;
     $this->WriteToLog('[' . $this->arMsg["LOCAL_ID"] . '] Start processing mail...', 7);
     $p = strpos($message, "\r\n\r\n");
     if ($p > 0) {
         $message_header = substr($message, 0, $p);
         $message_text = substr($message, $p + 2);
         $arLocalTo = array();
         foreach ($this->arMsg["TO"] as $to) {
             if (is_array($this->arMsg["FOR_RELAY"]) && in_array($to, $this->arMsg["FOR_RELAY"])) {
                 $message_header_add = "Received: from " . $this->host . " by " . $this->server->arFields["SERVER"] . " with Bitrix SMTP Server \r\n" . "\t" . date("r") . "\r\n" . "\tfor <" . $to . ">; \r\n" . "Return-Path: <" . $this->arMsg["FROM"] . ">\r\n";
                 $subject = "";
                 $message_header_new = $message_header;
                 if (preg_match('/(Subject:\\s*([^\\r\\n]*\\r\\n(\\t[^\\r\\n]*\\r\\n)*))\\S/is', $message_header_new . "\r\nx", $reg)) {
                     $message_header_new = trim(str_replace($reg[1], "", $message_header_new . "\r\n"));
                     $subject = trim($reg[2]);
                 }
                 $r = bxmail($to, $subject, $message_text, $message_header_add . $message_header_new);
                 $this->WriteToLog('[' . $this->arMsg["LOCAL_ID"] . '] Relay message to ' . $to . ' (' . ($r ? 'OK' : 'FAILED') . ')', 7);
             } else {
                 $arLocalTo[] = $to;
             }
         }
         if (count($arLocalTo) > 0) {
             $message_header_add = "Received: from " . $this->host . " by " . $this->server->arFields["SERVER"] . " with Bitrix SMTP Server \r\n" . "\t" . date("r") . "\r\n" . "Return-Path: <" . $this->arMsg["FROM"] . ">\r\n" . "X-Original-Rcpt-to: " . implode(", ", $arLocalTo) . "\r\n";
             $this->WriteToLog('[' . $this->arMsg["LOCAL_ID"] . '] Message add: ' . $message_header_add . $message, 9);
             if ($this->server->arFields["CHARSET"] != '') {
                 $charset = $this->server->arFields["CHARSET"];
             } else {
                 $charset = $this->server->arFields["LANG_CHARSET"];
             }
             $message_id = CMailMessage::AddMessage($this->server->arFields["ID"], $message_header_add . $message, $charset);
             $this->WriteToLog('[' . $this->arMsg["LOCAL_ID"] . '] Message sent to ' . implode(", ", $arLocalTo) . ' (' . $message_id . ')', 7);
         }
         $this->Send('250', $message_id . ' Message accepted for delivery');
     } else {
         $this->Send('554', ' Bad message format');
     }
     $this->WriteToLog('[' . $this->arMsg["LOCAL_ID"] . '] End processing mail...', 7);
     $this->readBuffer = "";
     $this->__listenFunc = false;
     $this->arMsg = array('LOCAL_ID' => md5(uniqid()));
     $this->msgCount++;
     $this->server->msgCount++;
     return true;
 }
Exemple #3
0
 function GetMessage($mailbox_id, $msgnum, $msguid, $session_id)
 {
     global $DB;
     $this->SendCommand("RETR " . $msgnum);
     if (!$this->GetResponse(true)) {
         return CMailError::SetError("ERR_AFTER_RETR", GetMessage("MAIL_CL_ERR_RETR"), $this->GetResponseString());
     }
     $message = $this->GetResponseBody();
     $message_id = CMailMessage::AddMessage($mailbox_id, $message, $this->charset);
     if ($message_id > 0) {
         /*
         $arFields = array(
         	"ID"			=> "'".$DB->ForSql($msguid)."'",
         	"MAILBOX_ID"	=> intval($mailbox_id),
         	"SESSION_ID"	=> "'".$DB->ForSql($session_id)."'",
         	"DATE_INSERT"	=> $DB->GetNowFunction(),
         	"MESSAGE_ID"	=> $message_id
         	);
         $DB->Insert("b_mail_message_uid", $arFields, "File: ".__FILE__."<br>Line: ".__LINE__);
         */
         $strSql = "INSERT INTO b_mail_message_uid(ID, MAILBOX_ID, SESSION_ID, DATE_INSERT, MESSAGE_ID) VALUES('" . $DB->ForSql($msguid) . "', " . IntVal($mailbox_id) . ", '" . $DB->ForSql($session_id) . "', " . $DB->GetNowFunction() . ", " . IntVal($message_id) . ")";
         $DB->Query($strSql);
     }
     return $message_id;
 }