1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
smtp.php
См. документацию.
1<?
3{
4 var $arServers = Array();
5
7 var $logFileName = "/bitrix/modules/smtpd.log";
8 var $logLevel = 10;
9 var $logMaxSize = 2000000;
12
13 function WriteToLog($txt, $level)
14 {
15 $this->logLevel = intval(COption::GetOptionString("mail", "smtp_log_level", "4"));
16
17 if ($this->logLevel < $level)
18 return;
19
20 if (MicroTime(true) - $this->startPeriodTimeTruncate > 600)
21 {
22 if ($this->logFile)
23 FClose($this->logFile);
24
25 $this->logFile = null;
26
27 if (File_Exists($_SERVER["DOCUMENT_ROOT"].$this->logFileName))
28 {
29 $logSize = @FileSize($_SERVER["DOCUMENT_ROOT"].$this->logFileName);
30 $logSize = intval($logSize);
31
32 if ($logSize > $this->logMaxSize)
33 {
34 if (($fp = @FOpen($_SERVER["DOCUMENT_ROOT"].$this->logFileName, "rb"))
35 && ($fp1 = @FOpen($_SERVER["DOCUMENT_ROOT"].$this->logFileName."_", "wb")))
36 {
37 $iSeekLen = intval($logSize - $this->logMaxSize / 2.0);
38 FSeek($fp, $iSeekLen);
39
40 @FWrite($fp1, "Truncated ".Date("Y-m-d H:i:s")."\n---------------------------------\n");
41 do
42 {
43 $data = FRead($fp, 8192);
44 if ($data == '')
45 break;
46
47 @FWrite($fp1, $data);
48 }
49 while (true);
50
51 @FClose($fp);
52 @FClose($fp1);
53
54 @Copy($_SERVER["DOCUMENT_ROOT"].$this->logFileName."_", $_SERVER["DOCUMENT_ROOT"].$this->logFileName);
55 @UnLink($_SERVER["DOCUMENT_ROOT"].$this->logFileName."_");
56 }
57 }
58 ClearStatCache();
59 }
60
61 $this->startPeriodTimeTruncate = MicroTime(true);
62 }
63
64 if (!$this->logFile || $this->logFile == null)
65 $this->logFile = FOpen($_SERVER["DOCUMENT_ROOT"].$this->logFileName, "a");
66
67 if (!$this->logFile)
68 {
69 echo "Can't write to log\n---------------------------------\n";
70 return;
71 }
72
73 FWrite($this->logFile, Date("Y-m-d H:i:s")."\t".trim($txt)."\n");
74 FFlush($this->logFile);
75
76 //if ($level > 4)
77 echo trim($txt)."\n---------------------------------\n";
78 }
79
80 public static function Run()
81 {
82 $var = new CSMTPServer();
83 $var->startTime = time();
84 $var->Start();
85 $var->Listen();
86 }
87
88 function Start()
89 {
90 global $CACHE_MANAGER;
91 $CACHE_MANAGER->Clean("smtpd_stop");
92 $CACHE_MANAGER->Clean("smtpd_reload");
93
94 ini_set('max_execution_time', 0);
95 set_time_limit(0);
96 ob_implicit_flush(true);
97
98 while(@ob_end_clean());
99
100 $dbr = CMailBox::GetList(array(), array("ACTIVE"=>"Y", "SERVER_TYPE"=>"smtp"));
101 while($arr = $dbr->Fetch())
102 {
103 $server = new CSMTPServerHost($this, $arr);
104 $server->Start();
105 $this->arServers[] = $server;
106 }
107 }
108
109 function ReloadServers()
110 {
112 $BX_MAIL_FILTER_CACHE = Array();
113
114 $rnd = uniqid();
115 $dbr = CMailBox::GetList(array(), array("ACTIVE"=>"Y", "SERVER_TYPE"=>"smtp"));
116 $arFounded = Array();
117 while($arr = $dbr->Fetch())
118 {
119 $bFound = false;
120 foreach($this->arServers as $server)
121 {
122 if(
123 $server->arFields["PORT"] == $arr["PORT"]
124 && $server->arFields["SERVER"] == ($arr["SERVER"]=="*"?"0.0.0.0":$arr["SERVER"])
125 )
126 {
127 $server->arFields = $arr;
128 $server->rnd = $rnd;
129 $bFound = true;
130 break;
131 }
132 }
133
134 if(!$bFound)
135 {
136 $server = new CSMTPServerHost($this, $arr);
137 $server->rnd = $rnd;
138 $server->Start();
139 $this->arServers[] = $server;
140 }
141 }
142
144 foreach($arServers as $k=>$server)
145 {
146 if($server->rnd!=$rnd)
147 $server->Stop($k);
148 }
149 }
150
151 function Listen()
152 {
153 global $DB, $CACHE_MANAGER;
154 $cnt = 100;
155 while (true)
156 {
157 $cnt++;
158 if($cnt>5)
159 {
160 $cnt = 0;
161 $stats = Array(
162 'started'=>$this->startTime,
163 'uptime'=>time() - $this->startTime,
164 'messages'=>0,
165 'connections'=>0,
166 'connections_now'=>0,
167 'servers'=>Array()
168 );
169
170 foreach($this->arServers as $arServer)
171 {
172 $stats["servers"][] = Array(
173 'id'=>$arServer->arFields["ID"],
174 'server'=>$arServer->arFields["SERVER"],
175 'port'=>$arServer->arFields["PORT"],
176 'started'=>$arServer->startTime
177 );
178 $stats["messages"] += $arServer->msgCount;
179 $stats["connections"] += $arServer->conCount;
180 $stats["connections_now"] += count($arServer->arClients);
181 }
182
183 $CACHE_MANAGER->Read(33, "smtpd_stats");
184 $CACHE_MANAGER->SetImmediate("smtpd_stats", $stats);
185
186 if($CACHE_MANAGER->Read(3600000, "smtpd_reload"))
187 $this->ReloadServers();
188 $CACHE_MANAGER->Clean("smtpd_reload");
189
190 $bStop = $CACHE_MANAGER->Read(3600000, "smtpd_stop");
191 $CACHE_MANAGER->Clean("smtpd_stop");
192
193 if($bStop)
194 {
195 $CACHE_MANAGER->Clean("smtpd_stats");
196 return;
197 }
198
199 $DB->Query("SELECT 'x' FROM b_user WHERE 1=0"); // nop
200 }
201
202 $arReadSockets = Array();
203
204 foreach($this->arServers as $server)
205 $arReadSockets = array_merge($arReadSockets, $server->GetSockets());
206
207 if(count($arReadSockets)<=0)
208 sleep(1);
209 else
210 {
211 $n = @stream_select($arReadSockets, $w = null, $e = null, 3);
212 if($n > 0)
213 {
214 foreach($arReadSockets as $r)
215 {
216 if(($server = $this->FindServerSocket($r))!==false)
217 {
218 $server->AddConnection();
219 }
220 else
221 {
222 if(($conn = $this->FindServerConnection($r))!==false)
223 {
224 $conn->Receive();
225 }
226 }
227 }
228 }
229 }
230
232 foreach($arServers as $server)
233 $server->CheckTimeout(600);
234 }
235 }
236
237 function FindServerSocket($s)
238 {
240 foreach($arServers as $server)
241 if($s == $server->sockServer)
242 return $server;
243
244 return false;
245 }
246
248 {
250 foreach($arServers as $server)
251 if(($conn = $server->FindConnection($s))!==false)
252 return $conn;
253 return false;
254 }
255
256 function Stop()
257 {
258 if ($this->logFile)
259 FClose($this->logFile);
260 }
261
262 function RemoveHost($i)
263 {
264 unset($this->arServers[$i]);
265 }
266}
267
269{
273
277
279
281 var $arFields = Array();
282 var $msgCount = 0;
283 var $conCount = 0;
284
285 function FindConnection($s)
286 {
287 $id = array_search($s, $this->arSockets);
288 if($id !== false)
289 return $this->arClients[$id];
290 return false;
291 }
292
293 function GetSockets()
294 {
295 if($this->sockServer)
296 return array_merge(array($this->sockServer), $this->arSockets);
297
298 return array();
299 }
300
301 public function __construct($server, $arFields)
302 {
303 $this->server = $server;
304 $this->arFields = $arFields;
305
306 $this->arClients = array();
307 $this->arClientsIndex = array();
308 $this->lastClientId = -1;
309 }
310
311 function AddConnection()
312 {
313 if(Is_Resource($sock = stream_socket_accept($this->sockServer, 0, $ip)))
314 {
315 $this->lastClientId++;
317
318 $this->WriteToLog("Client connected (".$id.", ".$ip.", ".$sock.")", 5);
319
320 stream_set_timeout($sock, 5);
321 $this->arClients[$id] = new CSMTPConnection($id, $sock, $this);
322 $this->arClients[$id]->ip = $ip;
323
324 $this->arSockets[$id] = $sock;
325 $this->conCount++;
326
327 return true;
328 }
329 return false;
330 }
331
332 function RemoveConnection($id)
333 {
334 $this->WriteToLog("Connection removed (".$id.", ".$this->arClients[$id]->ip.", ".$this->arClients[$id]->sock.")", 3);
335 unset($this->arClients[$id]);
336 unset($this->arSockets[$id]);
337 if($this->_stopAfterDisconnect && count($this->arClients)<=0)
338 $this->_Stop();
339 }
340
341 function WriteToLog($txt, $level)
342 {
343 $this->server->WriteToLog($txt, $level);
344 }
345
346 function Start()
347 {
348 $this->startPeriodTime = microtime(true);
349 $this->startPeriodTimeTruncate = microtime(true);
350
351 $this->sockServer = stream_socket_server("tcp://".($this->arFields["SERVER"]=="*" ? "0.0.0.0" : $this->arFields["SERVER"]).":".$this->arFields["PORT"], $errno, $errstr);
352
353 if (!$this->sockServer)
354 {
355 $this->WriteToLog("Create socket error: $errstr ($errno)", 1);
356 return false;
357 }
358
359 $this->WriteToLog("Server #".$this->arFields["ID"]." started: ".($this->arFields["SERVER"]=="*"?"0.0.0.0":$this->arFields["SERVER"]).":".$this->arFields["PORT"], 1);
360 return true;
361 }
362
363 function Stop($num)
364 {
365 $this->num = $num;
366 if(count($this->arClients)<=0)
367 $this->_Stop();
368 else
369 $this->_stopAfterDisconnect = true;
370 }
371
372 function _Stop()
373 {
374 if($this->sockServer)
375 {
376 @FClose($this->sockServer);
377 $this->WriteToLog("Server #".$this->arFields["ID"]." stopped: ".($this->arFields["SERVER"]=="*"?"0.0.0.0":$this->arFields["SERVER"]).":".$this->arFields["PORT"], 1);
378 }
379
380 $this->server->RemoveHost($this->num);
381 }
382
383 function CheckTimeout($timeout)
384 {
385 $arConns = $this->arClients;
386 foreach($arConns as $k=>$c)
387 if(time() - $c->lastRecieve > $timeout)
388 $this->RemoveConnection($k);
389 }
390}
391
392
394{
395 var $id;
396 var $sock;
397 var $connected = false;
398 var $authenticated = false;
399 var $readBuffer = "";
400 var $__listenFunc = false;
401 var $arMsg = Array();
405 var $msgCount = 0;
406
407 public function __construct($id, $sock, $serv)
408 {
409 $this->id = $id;
410 $this->sock = $sock;
411 $this->connected = true;
412 $this->authenticated = false;
413 $this->server = $serv;
414 $this->lastRecieve = time();
415 $this->uid = md5(uniqid());
416 $this->arMsg = array('LOCAL_ID'=>md5(uniqid()));
417 $this->Send('220');
418 }
419
420 function WriteToLog($txt, $level)
421 {
422 $this->server->WriteToLog($txt." (C:".$this->uid.")", $level);
423 }
424
425 function Receive()
426 {
427 $this->readBuffer .= FRead($this->sock, 8192);
428 $this->WriteToLog("C<- (".$this->id.")\t".$this->readBuffer, 10);
429 $res = $this->__ParseBuffer();
430 $this->lastRecieve = time();
431
432 if($this->sock && feof($this->sock))
433 $this->Disconnect();
434
435 return $res;
436 }
437
438 function __ParseBuffer()
439 {
440 if($this->readBuffer == '')
441 return false;
442
443 if($this->__listenFunc == '__AuthLoginHandler')
444 return $this->__AuthLoginHandler();
445
446 if($this->__listenFunc == '__AuthPlainHandler')
447 return $this->__AuthPlainHandler();
448
449 if($this->__listenFunc == '__DataHandler')
450 return $this->__DataHandler();
451
452 if(mb_strpos($this->readBuffer, "\r\n") === false)
453 return false;
454
455 $this->readBuffer = Trim($this->readBuffer);
456
457 $res = false;
458 if(($p = mb_strpos($this->readBuffer, " "))!==false)
459 {
460 $command = mb_substr($this->readBuffer, 0, $p);
461 $res = $this->__ProcessCommand($command, mb_substr($this->readBuffer, $p + 1));
462 }
463 else
464 {
465 $res = $this->__ProcessCommand($this->readBuffer);
466 }
467
468 if($res)
469 $this->readBuffer = "";
470
471 return true;
472 }
473
474 function Send($code, $text = "")
475 {
476 if (!$this->connected)
477 return false;
478
479 if (intval($code) <= 0)
480 return false;
481
482 if($text=='')
483 {
484 $results = Array(
485 '211'=>'System status, or system help reply',
486 '214'=>'Help message', //[Information on how to use the receiver or the meaning of a particular non-standard command; this reply is useful only to the human user]
487 '220'=>'<domain> Service ready',
488 '221'=>'<domain> Service closing transmission channel',
489 '250'=>'Requested mail action okay, completed',
490 '251'=>'User not local; will forward to <forward-path>',
491 '354'=>'Start mail input; end with <CRLF>.<CRLF>',
492 '421'=>'<domain> Service not available,', //closing transmission channel [This may be a reply to any command if the service knows it must shut down]
493 '450'=>'Requested mail action not taken: mailbox unavailable', //[E.g., mailbox busy]
494 '451'=>'Requested action aborted: local error in processing',
495 '452'=>'Requested action not taken: insufficient system storage',
496 '500'=>'Syntax error, command unrecognized', //[This may include errors such as command line too long]
497 '501'=>'Syntax error in parameters or arguments',
498 '502'=>'Command not implemented',
499 '503'=>'Bad sequence of commands',
500 '504'=>'Command parameter not implemented',
501 '550'=>'Requested action not taken: mailbox unavailable', //[E.g., mailbox not found, no access]
502 '551'=>'User not local; please try <forward-path>',
503 '552'=>'Requested mail action aborted: exceeded storage allocation',
504 '553'=>'Requested action not taken: mailbox name not allowed', //[E.g., mailbox syntax incorrect]
505 '554'=>'Transaction failed',
506 );
507 $text = $results[$code];
508 }
509
510 return $this->__Send($code." ".$text."\r\n");
511 }
512
513 function __Send($message)
514 {
515 if ($message == '')
516 return false;
517
518 $this->WriteToLog("S-> (".$this->id.")\t".$message, 10);
519
520 $r = FWrite($this->sock, $message);
521
522 return ($r !== false);
523 }
524
525 function Disconnect()
526 {
527 @FClose($this->sock);
528 $this->sock = false;
529
530 $this->WriteToLog("Client disconnected (".$this->id.", ".$this->ip.")", 5);
531 $this->server->RemoveConnection($this->id);
532 }
533
535 {
536 $domains = preg_split('/[\s]+/', mb_strtolower($this->server->arFields['DOMAINS']), -1, PREG_SPLIT_NO_EMPTY);
537 if(count($domains)<=0)
538 return true;
539
540 if(!is_array($this->arMsg["FOR_RELAY"]))
541 $this->arMsg["FOR_RELAY"] = array();
542
543 $p = mb_strpos($email, "@");
544 $email_domain = mb_substr($email, $p + 1);
545
546 if(in_array($email_domain, $domains))
547 {
548 $this->WriteToLog('['.$this->arMsg["LOCAL_ID"].'] Accepted for relaying '.$email, 8);
549 return true;
550 }
551
552 if($this->server->arFields['RELAY']!='Y')
553 return false;
554
555 if($this->server->arFields['AUTH_RELAY']=='Y' && $this->auth_user_id<=0)
556 return false;
557
558 $this->WriteToLog('['.$this->arMsg["LOCAL_ID"].'] Accepted for relaying '.$email, 8);
559 $this->arMsg["FOR_RELAY"][] = $email;
560 return true;
561 }
562
563 //обработчик команд
564 function __ProcessCommand($command, $arg = '')
565 {
566 switch(mb_strtoupper($command))
567 {
568 case "HELO":
569 $this->Send('250', 'domain name should be qualified');
570 if(trim($arg) == '')
571 {
572 $this->host = $this->ip;
573 }
574 else
575 {
576 $this->host = $arg;
577 }
578 //500, 501, 504, 421
579 break;
580 case "SEND":
581 case "SOML":
582 case "SAML":
583 case "MAIL":
584 if(!preg_match('#FROM[ ]*:[ ]*(.+)#i', $arg, $arMatches))
585 {
586 $this->Send('501', 'Unrecognized parameter '.$arg);
587 }
588 elseif($this->arMsg["FROM"])
589 {
590 $this->Send('503', 'Sender already specified');
591 }
592 else
593 {
594 $email = $arMatches[1];
596 if($email == '' || !check_email($email))
597 {
598 $this->Send('501', '<'.$email.'> Invalid Address');
599 }
600 else
601 {
602 $this->arMsg["FROM"] = $email;
603 $this->arMsg["TO"] = array();
604
605 $this->Send('250', '<'.$email.'> Sender ok');
606 }
607 }
608 //F: 552, 451, 452
609 //E: 500, 501, 421
610 break;
611 case "RCPT":
612 if(!preg_match('#TO[ ]*:[ ]*(.+)#i', $arg, $arMatches))
613 {
614 $this->Send('501', 'Unrecognized parameter '.$arg);
615 }
616 else
617 {
618 $email = $arMatches[1];
620 if($email == '' || !check_email($email))
621 {
622 $this->Send('501', '<'.$email.'> Invalid Address');
623 }
624 elseif(false)
625 {
626 $this->Send('550', '<'.$email.'> User unknown');
627 }
628 elseif(!$this->CheckRelaying($email))
629 {
630 $this->Send('550', '<'.$email.'>... Relaying denied.');
631 }
632 elseif(!$this->arMsg["FROM"])
633 {
634 $this->Send('503', 'Sender is not specified');
635 }
636 else
637 {
638 $this->arMsg["TO"][] = $email;
639 $this->Send('250', '<'.$email.'> ok');
640
641 //S: 250, 251
642 //F: 550, 551, 552, 553, 450, 451, 452
643 //E: 500, 501, 503, 421
644 }
645 }
646 break;
647 case "DATA":
648 if(!$this->arMsg["FROM"] || !$this->arMsg["TO"] || count($this->arMsg["TO"]) == 0)
649 {
650 $this->Send('503');
651 }
652 else
653 {
654 $this->Send('354');
655 $this->__listenFunc = '__DataHandler';
656 }
657 // I: 354 -> data -> S: 250
658 // F: 552, 554, 451, 452
659 // F: 451, 554
660 // E: 500, 501, 503, 421
661 break;
662 case "RSET":
663 $this->Send('250', 'Resetting');
664 $this->arMsg = array('LOCAL_ID' => md5(uniqid()));
665 //E: 500, 501, 504, 421
666 break;
667 case "QUIT":
668 $this->Send('221');
669 $this->Disconnect();
670 //E: 500
671 break;
672 case "EHLO":
673 if(trim($arg) == '')
674 {
675 $this->host = $this->ip;
676 }
677 else
678 {
679 $this->host = $arg;
680 }
681
682 $this->Send('250-ehlo', '');
683 $this->Send('250-AUTH LOGIN PLAIN', '');
684 //$this->Send('250-SIZE', '');
685 $this->Send('250-HELP', '');
686 $this->Send('250', 'EHLO');
687 /*
688 250-mail.company2.tld is pleased to meet you
689 250-DSN
690 250-SIZE
691 250-STARTTLS
692 250-AUTH LOGIN PLAIN CRAM-MD5 DIGEST-MD5 GSSAPI MSN NTLM
693 250-ETRN
694 250-TURN
695 250-ATRN
696 250-NO-SOLICITING
697 250-HELP
698 250-PIPELINING
699 250 EHLO
700 */
701 break;
702 case "AUTH":
703 if($this->authorized)
704 {
705 $this->Send('503', 'Already authorized');
706 }
707 elseif(count($this->arMsg) > 1)
708 {
709 $this->Send('503', 'Mail transaction is active');
710 }
711 elseif(!preg_match('#^([A-Z0-9-_]+)[ ]*(\S*)$#i', $arg, $arMatches))
712 {
713 $this->Send('501', 'Unrecognized parameter '.$arg);
714 }
715 else
716 {
717 switch(mb_strtoupper($arMatches[1]))
718 {
719 case "LOGIN":
720 $this->Send('334', 'VXNlcm5hbWU6');
721 $this->__listenFunc = '__AuthLoginHandler';
722 $this->__login = false;
723 break;
724 case "PLAIN":
725 if($arMatches[2] && trim($arMatches[2]) != '')
726 {
727 $pwd = base64_decode($arMatches[2]);
728 $this->Authorize($pwd, $pwd);
729 }
730 else
731 {
732 $this->Send('334', '');
733 $this->__listenFunc = '__AuthPlainHandler';
734 }
735 break;
736 default:
737 $this->Send('504', 'Unrecognized authentication type.');
738 }
739 }
740
741 break;
742 case "NOOP":
743 $this->Send('250');
744 //E: 500, 421
745 break;
746 case "HELP":
747 // S: 211, 214
748 // E: 500, 501, 502, 504, 421
749 break;
750 case "EXPN":
751 //<string>
752 // S: 250
753 // F: 550
754 // E: 500, 501, 502, 504, 421
755 break;
756 case "VRFY":
757 // S: 250, 251
758 // F: 550, 551, 553
759 // E: 500, 501, 502, 504, 421
760 break;
761 default:
762 $this->Send('500', $command.' command unrecognized');
763 }
764 return true;
765 }
766
768 {
769 $authResult = $GLOBALS["USER"]->Login($login, $password, "N");
770
771 if($authResult === true)
772 {
773 $this->Send("235", "Authentication successful");
774 $this->auth_user_id = $GLOBALS["USER"]->GetID();
775 $this->authorized = true;
776 $this->WriteToLog('Authentication successful '.$this->auth_user_id, 7);
777 return true;
778 }
779
780 $this->Send("535", "authorization failed");
781
782 return false;
783 }
784
786 {
787 if(mb_strpos($this->readBuffer, "\r\n") === false)
788 return false;
789
790 $this->readBuffer = trim($this->readBuffer);
791 if($this->readBuffer=="*")
792 $this->Send('501', 'AUTH aborted');
793 else
794 {
795 $pwd = base64_decode($this->readBuffer);
796 if($this->__login === false)
797 {
798 $this->__login = $pwd;
799 $this->Send('334', 'UGFzc3dvcmQ6');
800 $this->readBuffer = "";
801 return false;
802 }
803 else
804 {
805 $this->Authorize($this->__login, $pwd);
806 }
807 }
808
809 $this->__login = false;
810 $this->readBuffer = "";
811 $this->__listenFunc = false;
812 return true;
813 }
814
816 {
817 if(mb_strpos($this->readBuffer, "\r\n") === false)
818 return false;
819 $this->readBuffer = trim($this->readBuffer);
820 if($this->readBuffer=="*")
821 $this->Send('501', 'AUTH aborted');
822 else
823 {
824 $pwd = base64_decode($this->readBuffer);
825 if($pwd == '')
826 $this->Send('501', 'Base64 decode error');
827 else
828 {
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));
831 }
832 }
833
834 $this->readBuffer = "";
835 $this->__listenFunc = false;
836 return true;
837 }
838
839 function __DataHandler()
840 {
841 if(mb_strpos($this->readBuffer, "\r\n.\r\n") === false)
842 return false;
843
844 $this->readBuffer = mb_substr($this->readBuffer, 0, -3);
845
846 $this->readBuffer = str_replace("\r\n..", "\r\n.", $this->readBuffer);
847
848 // Добавление сообщения куда надо
850 $this->arMsg["MSG"] = $message;
851
852 $this->WriteToLog('['.$this->arMsg["LOCAL_ID"].'] Start processing mail...', 7);
853
854 $p = mb_strpos($message, "\r\n\r\n");
855 if($p>0)
856 {
857 $message_header = mb_substr($message, 0, $p);
858 $message_text = mb_substr($message, $p + 2);
859
860 $arLocalTo = Array();
861 foreach($this->arMsg["TO"] as $to)
862 {
863 if(is_array($this->arMsg["FOR_RELAY"]) && in_array($to, $this->arMsg["FOR_RELAY"]))
864 {
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";
870
871 $subject = "";
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))
874 {
875 $message_header_new = trim(str_replace($reg[1], "", $message_header_new."\r\n"));
876 $subject = trim($reg[2]);
877 }
878
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);
881 }
882 else
883 $arLocalTo[] = $to;
884 }
885
886 if(count($arLocalTo)>0)
887 {
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";
893
894 $this->WriteToLog('['.$this->arMsg["LOCAL_ID"].'] Message add: '.$message_header_add.$message, 9);
895
896 if($this->server->arFields["CHARSET"]!='')
897 $charset = $this->server->arFields["CHARSET"];
898 else
899 $charset = $this->server->arFields["LANG_CHARSET"];
900
901 $message_id = CMailMessage::AddMessage($this->server->arFields["ID"], $message_header_add.$message, $charset);
902
903 $this->WriteToLog('['.$this->arMsg["LOCAL_ID"].'] Message sent to '.implode(", ", $arLocalTo).' ('.$message_id.')', 7);
904 }
905 $this->Send('250', $message_id.' Message accepted for delivery');
906 }
907 else
908 $this->Send('554', ' Bad message format');
909
910 $this->WriteToLog('['.$this->arMsg["LOCAL_ID"].'] End processing mail...', 7);
911
912 $this->readBuffer = "";
913 $this->__listenFunc = false;
914 $this->arMsg = array('LOCAL_ID'=>md5(uniqid()));
915
916 $this->msgCount++;
917 $this->server->msgCount++;
918 return true;
919 }
920}
921?>
$login
Определения change_password.php:8
static ExtractMailAddress($email)
Определения mail.php:3118
Определения smtp.php:394
CheckRelaying($email)
Определения smtp.php:534
__Send($message)
Определения smtp.php:513
__DataHandler()
Определения smtp.php:839
Receive()
Определения smtp.php:425
Send($code, $text="")
Определения smtp.php:474
__AuthLoginHandler()
Определения smtp.php:785
$arMsg
Определения smtp.php:401
__ParseBuffer()
Определения smtp.php:438
$__listenFunc
Определения smtp.php:400
$authenticated
Определения smtp.php:398
__construct($id, $sock, $serv)
Определения smtp.php:407
__AuthPlainHandler()
Определения smtp.php:815
$readBuffer
Определения smtp.php:399
$lastRecieve
Определения smtp.php:403
$sock
Определения smtp.php:396
$msgCount
Определения smtp.php:405
WriteToLog($txt, $level)
Определения smtp.php:420
$auth_user_id
Определения smtp.php:404
Authorize($login, $password)
Определения smtp.php:767
$server
Определения smtp.php:402
$connected
Определения smtp.php:397
__ProcessCommand($command, $arg='')
Определения smtp.php:564
$id
Определения smtp.php:395
Disconnect()
Определения smtp.php:525
Определения smtp.php:269
_Stop()
Определения smtp.php:372
CheckTimeout($timeout)
Определения smtp.php:383
$lastClientId
Определения smtp.php:276
$arClients
Определения smtp.php:274
RemoveConnection($id)
Определения smtp.php:332
$arFields
Определения smtp.php:281
$arClientsIndex
Определения smtp.php:275
AddConnection()
Определения smtp.php:311
$initialized
Определения smtp.php:272
Stop($num)
Определения smtp.php:363
Start()
Определения smtp.php:346
FindConnection($s)
Определения smtp.php:285
$sockServer
Определения smtp.php:270
$msgCount
Определения smtp.php:282
WriteToLog($txt, $level)
Определения smtp.php:341
__construct($server, $arFields)
Определения smtp.php:301
$arSockets
Определения smtp.php:278
$startPeriodTime
Определения smtp.php:280
$server
Определения smtp.php:271
$conCount
Определения smtp.php:283
GetSockets()
Определения smtp.php:293
Определения smtp.php:3
Stop()
Определения smtp.php:256
$startPeriodTimeTruncate
Определения smtp.php:10
static Run()
Определения smtp.php:80
$logMaxSize
Определения smtp.php:9
$startTime
Определения smtp.php:11
RemoveHost($i)
Определения smtp.php:262
Start()
Определения smtp.php:88
$logLevel
Определения smtp.php:8
$logFileName
Определения smtp.php:7
ReloadServers()
Определения smtp.php:109
Listen()
Определения smtp.php:151
FindServerSocket($s)
Определения smtp.php:237
WriteToLog($txt, $level)
Определения smtp.php:13
FindServerConnection($s)
Определения smtp.php:247
$logFile
Определения smtp.php:6
$arServers
Определения smtp.php:4
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$data['IS_AVAILABLE']
Определения .description.php:13
$arr
Определения file_new.php:624
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$bFound
Определения get_search.php:40
$p
Определения group_list_element_edit.php:23
Send()
Определения idea_email_notify.php:116
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
global $BX_MAIL_FILTER_CACHE
Определения mail.php:3149
check_email($email, $strict=false, $domainCheck=false)
Определения tools.php:4571
bxmail($to, $subject, $message, $additional_headers="", $additional_parameters="", Main\Mail\Context $context=null)
Определения tools.php:4999
$var
Определения payment.php:63
$email
Определения payment.php:49
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$text
Определения template_pdf.php:79
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$password
Определения result.php:7
$k
Определения template_pdf.php:567
$GLOBALS['_____370096793']
Определения update_client.php:1
$n
Определения update_log.php:107