• Модуль: mail
  • Путь к файлу: ~/bitrix/modules/mail/lib/helper/mailbox/imap.php
  • Класс: BitrixMailHelperMailboxImap
  • Вызов: Imap::downloadAttachments
public function downloadAttachments(array &$excerpt)
{
	if (empty($excerpt['MSG_UID']) || empty($excerpt['DIR_MD5']))
	{
		return false;
	}

	$dirPath = $this->getDirsHelper()->getDirPathByHash($excerpt['DIR_MD5']);
	if (empty($dirPath))
	{
		return false;
	}

	$message = $this->client->fetch(true, $dirPath, $excerpt['MSG_UID'], '(BODYSTRUCTURE)', $error);
	if (empty($message['BODYSTRUCTURE']))
	{
		// @TODO: fallback

		if (false === $message)
		{
			$this->errors = new MainErrorCollection($this->client->getErrors()->toArray());
		}

		return false;
	}

	if (!is_array($message['BODYSTRUCTURE']))
	{
		$this->errors = new MainErrorCollection(array(
			new MainError('HelperMailboxImap: Invalid BODYSTRUCTURE', 0),
			new MainError((string)$message['BODYSTRUCTURE'], -1),
		));
		return false;
	}

	$message['__bodystructure'] = new MailImapBodyStructure($message['BODYSTRUCTURE']);

	$parts = $this->downloadMessageParts(
		$excerpt,
		$message['__bodystructure'],
		self::MESSAGE_PARTS_ATTACHMENT
	);

	$attachments = array();

	$message['__bodystructure']->traverse(
		function (MailImapBodyStructure $item) use (&$parts, &$attachments)
		{
			if ($item->isMultipart() || $item->isBodyText())
			{
				return;
			}

			$attachments[] = CMailMessage::decodeMessageBody(
				CMailMessage::parseHeader(
					$parts[sprintf('BODY[%s.MIME]', $item->getNumber())],
					$this->mailbox['LANG_CHARSET']
				),
				$parts[sprintf('BODY[%s]', $item->getNumber())],
				$this->mailbox['LANG_CHARSET']
			);
		}
	);

	return $attachments;
}