32 $hostname =
$request->getPostList()->getRaw(
'hostname');
55 if (empty($to[
'user']) || empty($to[
'host']))
57 if (mb_strtolower($hostname) != mb_strtolower($to[
'host']))
59 if (preg_match(
'/^no-?reply$/i', $to[
'user']))
62 $rcpt[] = sprintf(
'%s@%s', $to[
'user'], $to[
'host']);
74 foreach (
$rcpt as $to)
76 $emailRecipient =
null;
77 $emailRelation =
null;
79 $emailRecipient = Bitrix\Mail\User::parseEmailRecipient($to);
81 $token = $emailRecipient[
'token'];
83 if($emailRecipient ===
false)
85 $rcptErrors[$to] = sprintf(
'Invalid recipient (%s)', $to);
89 $emailRelation = Bitrix\Mail\User::getUserRelation($token);
91 if ($emailRelation ===
false)
93 $rcptErrors[$to] = sprintf(
'Unknown recipient (%s)', $to);
99 $emails[$to][
'recipient'] = $emailRecipient;
100 $emails[$to][
'relation'] = $emailRelation;
115 'error' => UPLOAD_ERR_NO_FILE,
120 'image/bmp' =>
array(
'.bmp'),
121 'image/gif' =>
array(
'.gif'),
122 'image/jpeg' =>
array(
'.jpeg',
'.jpg',
'.jpe'),
123 'image/png' =>
array(
'.png')
125 $jpegTypes =
array(
'image/pjpeg',
'image/jpeg',
'image/jpg',
'image/jpe');
127 $tmpDir = \CTempFile::getDirectoryName(6);
128 checkDirPath($tmpDir);
130 foreach (
$message[
'attachments'] as &$item)
132 $itemId = $item[
'uniqueId'];
133 $fileId = $item[
'uniqueId'] = md5($item[
'checksum'].$item[
'length']);
135 $item[
'fileName'] = trim(trim(trim($item[
'fileName']),
'.'));
136 if (empty($item[
'fileName']))
138 $item[
'fileName'] = $fileId;
140 if (mb_strpos($item[
'contentType'],
'message/') === 0)
141 $item[
'fileName'] .=
'.eml';
144 if ($item[
'contentType'])
146 if (in_array($item[
'contentType'], $jpegTypes))
147 $item[
'contentType'] =
'image/jpeg';
149 if (
is_set($imageExts, $item[
'contentType']))
151 $extPos = mb_strrpos($item[
'fileName'],
'.');
152 $ext = mb_substr($item[
'fileName'], $extPos);
154 if ($extPos ===
false || !in_array($ext, $imageExts[$item[
'contentType']]))
155 $item[
'fileName'] .= $imageExts[$item[
'contentType']][0];
160 empty($_FILES[$itemId]) ? $emptyFile : $_FILES[$itemId],
162 'name' => $item[
'fileName'],
163 'type' => $item[
'contentType'],
167 if (is_uploaded_file($file[
'tmp_name']) && $file[
'size'] > 0)
169 $uploadFile = $tmpDir . md5(mt_rand().$file[
'name']);
170 move_uploaded_file($file[
'tmp_name'], $uploadFile);
172 $file[
'tmp_name'] = $uploadFile;
180 foreach (
$rcpt as $to)
188 $result = Bitrix\Mail\User::onEmailReceived(
209catch (
Bitrix\Mail\ReceiverException $e)
211 addMessage2Log(sprintf(
'Mail entry: %s', $e->getMessage()),
'mail', 0,
false);
216 addMessage2Log(sprintf(
'Mail entry: %s', $e->getMessage()),
'mail', 0,
false);
217 $response->setStatus(
'500 Internal Server Error');
handleError($rcpt, $rcptErrors)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)