1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mail_entry.php
См. документацию.
1<?php
2
3//define('NO_KEEP_STATISTIC', 'Y');
4//define('NO_AGENT_STATISTIC','Y');
5//define('NO_AGENT_CHECK', true);
6//define('DisableEventsCheck', true);
7
8define('NOT_CHECK_PERMISSIONS', true);
9//define('BX_SECURITY_SESSION_READONLY', true);
10
11require $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php';
12
14
15$request = $context->getRequest();
16$response = $context->getResponse();
17
18CModule::includeModule('mail');
19
21{
23 {
24 throw new Bitrix\Mail\ReceiverException(join('; ', $rcptErrors));
25 }
26
27 throw new Bitrix\Main\SystemException(sprintf('Message processing failed (rcpt: %s)', join(', ', $rcpt)));
28}
29
30try
31{
32 $hostname = $request->getPostList()->getRaw('hostname');
33 if (empty($hostname))
34 throw new Bitrix\Mail\ReceiverException('Empty \'hostname\' request parameter');
35
36 $message = $request->getPostList()->getRaw('message');
37 if (empty($message))
38 throw new Bitrix\Mail\ReceiverException('Empty \'message\' request parameter');
39
40 try
41 {
43 }
44 catch (Exception $e)
45 {
46 throw new Bitrix\Mail\ReceiverException('Invalid \'message\' request parameter');
47 }
48
49 if (empty($message['rcpt_to']))
50 throw new Bitrix\Mail\ReceiverException('Empty recipients list');
51
53 foreach ($message['rcpt_to'] as $to)
54 {
55 if (empty($to['user']) || empty($to['host']))
56 continue;
57 if (mb_strtolower($hostname) != mb_strtolower($to['host']))
58 continue;
59 if (preg_match('/^no-?reply$/i', $to['user']))
60 continue;
61
62 $rcpt[] = sprintf('%s@%s', $to['user'], $to['host']);
63 }
64
65 if (empty($rcpt))
66 throw new Bitrix\Mail\ReceiverException('Invalid recipients list');
67
68 $preSuccess = false;
69 $success = false;
71
72 $emails = [];
73
74 foreach ($rcpt as $to)
75 {
76 $emailRecipient = null;
77 $emailRelation = null;
78
79 $emailRecipient = Bitrix\Mail\User::parseEmailRecipient($to);
80
81 $token = $emailRecipient['token'];
82
83 if($emailRecipient === false)
84 {
85 $rcptErrors[$to] = sprintf('Invalid recipient (%s)', $to);
86 break;
87 }
88
89 $emailRelation = Bitrix\Mail\User::getUserRelation($token);
90
91 if ($emailRelation === false)
92 {
93 $rcptErrors[$to] = sprintf('Unknown recipient (%s)', $to);
94 break;
95 }
96
97 $preSuccess = true;
98 $emails[$to] = [];
99 $emails[$to]['recipient'] = $emailRecipient;
100 $emails[$to]['relation'] = $emailRelation;
101 }
102
103 if (!$preSuccess)
104 {
106 }
107
108 $message['files'] = array();
109 if (!empty($message['attachments']) && is_array($message['attachments']))
110 {
111 $emptyFile = array(
112 'name' => '',
113 'type' => '',
114 'tmp_name' => '',
115 'error' => UPLOAD_ERR_NO_FILE,
116 'size' => 0
117 );
118
119 $imageExts = array(
120 'image/bmp' => array('.bmp'),
121 'image/gif' => array('.gif'),
122 'image/jpeg' => array('.jpeg', '.jpg', '.jpe'),
123 'image/png' => array('.png')
124 );
125 $jpegTypes = array('image/pjpeg', 'image/jpeg', 'image/jpg', 'image/jpe');
126
127 $tmpDir = \CTempFile::getDirectoryName(6);
128 checkDirPath($tmpDir);
129
130 foreach ($message['attachments'] as &$item)
131 {
132 $itemId = $item['uniqueId'];
133 $fileId = $item['uniqueId'] = md5($item['checksum'].$item['length']);
134
135 $item['fileName'] = trim(trim(trim($item['fileName']), '.'));
136 if (empty($item['fileName']))
137 {
138 $item['fileName'] = $fileId;
139
140 if (mb_strpos($item['contentType'], 'message/') === 0)
141 $item['fileName'] .= '.eml';
142 }
143
144 if ($item['contentType'])
145 {
146 if (in_array($item['contentType'], $jpegTypes))
147 $item['contentType'] = 'image/jpeg';
148
149 if (is_set($imageExts, $item['contentType']))
150 {
151 $extPos = mb_strrpos($item['fileName'], '.');
152 $ext = mb_substr($item['fileName'], $extPos);
153
154 if ($extPos === false || !in_array($ext, $imageExts[$item['contentType']]))
155 $item['fileName'] .= $imageExts[$item['contentType']][0];
156 }
157 }
158
159 $file = array_merge(
160 empty($_FILES[$itemId]) ? $emptyFile : $_FILES[$itemId],
161 array(
162 'name' => $item['fileName'],
163 'type' => $item['contentType'],
164 )
165 );
166
167 if (is_uploaded_file($file['tmp_name']) && $file['size'] > 0)
168 {
169 $uploadFile = $tmpDir . md5(mt_rand().$file['name']);
170 move_uploaded_file($file['tmp_name'], $uploadFile);
171
172 $file['tmp_name'] = $uploadFile;
173 }
174
175 $message['files'][$fileId] = $file;
176 }
177 unset($item);
178 }
179
180 foreach ($rcpt as $to)
181 {
182 if(!isset($emails[$to]))
183 {
184 continue;
185 }
186
187 $error = null;
188 $result = Bitrix\Mail\User::onEmailReceived(
189 $to,
190 $message,
191 $emails[$to]['recipient'],
192 $emails[$to]['relation'],
193 $error
194 );
195
196 if ($result)
197 $success = true;
198 elseif ($error)
199 $rcptErrors[$to] = $error;
200 }
201
202 if (!$success)
203 {
205 }
206
207 $response->setStatus('204 No Content');
208}
209catch (Bitrix\Mail\ReceiverException $e)
210{
211 addMessage2Log(sprintf('Mail entry: %s', $e->getMessage()), 'mail', 0, false);
212 $response->setStatus('400 Bad Request');
213}
214catch (Exception $e)
215{
216 addMessage2Log(sprintf('Mail entry: %s', $e->getMessage()), 'mail', 0, false);
217 $response->setStatus('500 Internal Server Error');
218}
219
220require $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_after.php';
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static getInstance()
Определения application.php:98
static decode($data)
Определения json.php:50
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$context
Определения csv_new_setup.php:223
$emails
Определения mail_entry.php:72
handleError($rcpt, $rcptErrors)
Определения mail_entry.php:20
$rcpt
Определения mail_entry.php:52
$success
Определения mail_entry.php:69
$preSuccess
Определения mail_entry.php:68
$rcptErrors
Определения mail_entry.php:70
is_set($a, $k=false)
Определения tools.php:2133
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</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
$response
Определения result.php:21
$error
Определения subscription_card_product.php:20