Removes the 'inline' part with the passed contentType, at the given index
defaulting to the first

@param Message $message
@param string $mimeType
@param int $index
@return boolean true on success
191986
public function removePartByMimeType(Message $message, $mimeType, $index = 0)
    {
        $parts = $message->getAllParts(PartFilter::fromInlineContentType($mimeType));
        $alt = $message->getPart(0, PartFilter::fromInlineContentType('multipart/alternative'));
        if ($parts === null || !isset($parts[$index])) {
            return false;
        } elseif (count($parts) === 1) {
            return $this->removeAllContentPartsByMimeType($message, $mimeType, true);
        }
        $part = $parts[$index];
        $message->removePart($part);
        if ($alt !== null && $alt->getChildCount() === 1) {
            $this->genericHelper->replacePart($message, $alt, $alt->getChild(0));
        }
        return true;
    }
501722
public function addMimeTypeToExtension($mime_type, $extension)
    {
        if (is_array($extension)) {
            $this->mime_type_to_extensions[$mime_type] = $extension;
        } else {
            $this->mime_type_to_extensions[$mime_type] = array($extension);
        }

        return true;
    }
738481
public function deleteDocument($indexName, $indexType, $uid)
    {
        $this->mapProviders(function (SearchProviderInterface $provider) use ($indexName, $indexType, $uid) {
            $provider->deleteDocument($this->indexNamePrefix . $indexName, $indexType, $uid);
        });
    }
1245129
public function getMailjetMessage(Swift_Mime_Message $message) {
        $contentType = $this->getMessagePrimaryContentType($message);
        $fromAddresses = $message->getFrom();
        $fromEmails = array_keys($fromAddresses);
        $toAddresses = $message->getTo();
        $ccAddresses = $message->getCc() ? $message->getCc() : [];
        $bccAddresses = $message->getBcc() ? $message->getBcc() : [];

        $attachments = array();
        $inline_attachments = array();

        // Process Headers
        $customHeaders = $this->prepareHeaders($message, $this->getMailjetHeaders());
        $userDefinedHeaders = $this->findUserDefinedHeaders($message);


        // @TODO only Format To, Cc, Bcc
        //@TODO array_push is not recommended
        $to = array();
        foreach ($toAddresses as $toEmail => $toName) {
            if (!is_null($toName)) {
                array_push($to, ['Email' => $toEmail, 'Name' => $toName]);
            } else {
                array_push($to, ['Email' => $toEmail]);
            }
        }
        $cc = array();
        foreach ($ccAddresses as $ccEmail => $ccName) {
            if (!is_null($ccName)) {
                array_push($cc, ['Email' => $ccEmail, 'Name' => $ccName]);
            } else {
                array_push($cc, ['Email' => $ccEmail]);
            }
        }
        $bcc = array();
        foreach ($bccAddresses as $bccEmail => $bccName) {
            if (!is_null($bccName)) {
                array_push($bcc, ['Email' => $bccEmail, 'Name' => $bccName]);
            } else {
                array_push($bcc, ['Email' => $bccEmail]);
            }
        }

        // Handle content
        $bodyHtml = $bodyText = null;
        if ($contentType === 'text/plain') {
            $bodyText = $message->getBody();
        } else {
            $bodyHtml = $message->getBody();
        }


        // Handle attachments
        foreach ($message->getChildren() as $child) {
            if ($child instanceof Swift_Attachment) {
                //Handle regular attachments
                if ($child->getDisposition() === "attachment") {
                    $attachments[] = array(
                        'ContentType' => $child->getContentType(),
                        'Filename' => $child->getFilename(),
                        'Base64Content' => base64_encode($child->getBody())
                    );
                }
                //Handle inline attachments
                elseif ($child->getDisposition() === "inline") {
                    $inline_attachments[] = array(
                        'ContentType' => $child->getContentType(),
                        'Filename' => $child->getFilename(),
                        'ContentID' => $child->getId(),
                        'Base64Content' => base64_encode($child->getBody())
                    );
                }
            } elseif ($child instanceof Swift_MimePart && $this->supportsContentType($child->getContentType())) {
                if ($child->getContentType() == "text/html") {
                    $bodyHtml = $child->getBody();
                } elseif ($child->getContentType() == "text/plain") {
                    $bodyText = $child->getBody();
                }
            }
        }
        $mailjetMessage = array();
        $from = array(
            'Email' => $fromEmails[0],
            'Name' => $fromAddresses[$fromEmails[0]]
        );

        if (!empty($from)) {
            if (is_null($from['Name'])) {
                unset($from['Name']);
            }
            $mailjetMessage['From'] = $from;
        }
        if (!empty($to)) {
            $mailjetMessage['To'] = $to;
        }
        if (!empty($cc)) {
            $mailjetMessage['Cc'] = $cc;
        }
        if (!empty($bcc)) {
            $mailjetMessage['Bcc'] = $bcc;
        }
        if (!is_null($message->getSubject())) {
            $mailjetMessage['Subject'] = $message->getSubject();
        }
        if (!is_null($bodyHtml)) {
            $mailjetMessage['HTMLPart'] = $bodyHtml;
        }
        if (!is_null($bodyText)) {
            $mailjetMessage['TextPart'] = $bodyText;
        }
        if ($replyTo = $this->getReplyTo($message)) {
            $mailjetMessage['ReplyTo'] = $replyTo;
        }

        if (count($userDefinedHeaders) > 0) {
            $mailjetMessage['Headers'] = $userDefinedHeaders;
        }

        if (count($customHeaders) > 0) {
            $mailjetMessage = array_merge($mailjetMessage, $customHeaders);
        }

        if (count($attachments) > 0) {
            $mailjetMessage['Attachments'] = $attachments;
        }
        if (count($inline_attachments) > 0) {
            $mailjetMessage['InlinedAttachments'] = $inline_attachments;
        }


        return array('Messages' => array($mailjetMessage));
    }
655023
public function setSignature(Message $message, $body)
    {
        $signedPart = $message->getSignaturePart();
        if ($signedPart === null) {
            $signedPart = $this->partBuilderFactory->newPartBuilder($this->mimePartFactory)->createMessagePart();
            $message->addChild($signedPart);
        }
        $signedPart->setRawHeader(
            'Content-Type',
            $message->getHeaderParameter('Content-Type', 'protocol')
        );
        $signedPart->setContent($body);
    }
983291
public static function is_defaulticon_allowed($mimetype, $oldextension = '') {
        $mimeinfo = get_mimetypes_array();
        if ($oldextension !== '') {
            unset($mimeinfo[$oldextension]);
        }
        foreach ($mimeinfo as $extension => $values) {
            if ($values['type'] !== $mimetype) {
                continue;
            }
            if (!empty($values['defaulticon'])) {
                return false;
            }
        }
        return true;
    }
191564
public function createAlternativeContentPart(Message $message, MessagePart $contentPart)
    {
        $altPart = $this->partBuilderFactory->newPartBuilder($this->mimePartFactory)->createMessagePart();
        $this->setMimeHeaderBoundaryOnPart($altPart, 'multipart/alternative');
        $message->removePart($contentPart);
        $message->addChild($altPart, 0);
        $altPart->addChild($contentPart, 0);
        return $altPart;
    }
1332282
function clearMime(mimeType) {
  if (!mimeType || (String(mimeType) !== mimeType)) { return ''; }
  return mimeType.split(';')[0].trim().toLowerCase();
}
244721
public function remove(string $type, int $index)
    {
        if (isset($this->values[$type][$index])) {
            unset($this->values[$type][$index]);

            --$this->valuesCount;
        }

        return $this;
    }
1044615
public function MapMimeTypeToExtension($extension, $mime_type)
    {
        if (!isset($this->extension_to_mime_types[$extension])) {
            $this->extension_to_mime_types[$extension] = array($mime_type);
        } else {
            $this->extension_to_mime_types[$extension][] = $mime_stype;
        }

        return true;
    }
582340
public function mimeToExt($mime, $incl_dot = true, $ret_typeid = false)
	{
		$this->debug->groupCollapsed(__METHOD__, $mime);
		$ext = '';
		// map to image_type
		$type = isset($this->imageTypes[$mime])
			? $this->imageTypes[$mime]
			: null;
		if ($type) {
			if ($incl_dot) {
				$ext = '.';
			}
			$ext .= image_type_to_extension($type);
			if ($ret_typeid) {
				$ext = $type;
			}
		} else {
			$this->debug->warn('unknown mime type');
		}
		$this->debug->groupEnd();
		return $ext;
	}
1069363
public function getTextContent($index = 0, $charset = MailMimeParser::DEFAULT_CHARSET)
    {
        $part = $this->getTextPart($index);
        if ($part !== null) {
            return $part->getContent($charset);
        }
        return null;
    }
565104
public function deleteDuplicateDocumentNotMatchingType(Index $index, string $documentIdentifier, NodeType $nodeType): void
    {
        $result = $index->request('GET', '/_search?scroll=1m', [], json_encode([
            'sort' => ['_doc'],
            'query' => [
                'bool' => [
                    'must' => [
                        'ids' => [
                            'values' => [$documentIdentifier]
                        ]
                    ],
                    'must_not' => [
                        'term' => [
                            '_type' => $this->nodeTypeMappingBuilder->convertNodeTypeNameToMappingName($nodeType->getName())
                        ]
                    ]
                ]
            ]
        ]));
        $treatedContent = $result->getTreatedContent();
        $scrollId = $treatedContent['_scroll_id'];
        $mapHitToDeleteRequest = function ($hit) {
            return json_encode([
                'delete' => [
                    '_type' => $hit['_type'],
                    '_id' => $hit['_id']
                ]
            ]);
        };
        $bulkRequest = [];
        while (isset($treatedContent['hits']['hits']) && $treatedContent['hits']['hits'] !== []) {
            $hits = $treatedContent['hits']['hits'];
            $bulkRequest = array_merge($bulkRequest, array_map($mapHitToDeleteRequest, $hits));
            $result = $index->request('GET', '/_search/scroll?scroll=1m', [], $scrollId, false);
            $treatedContent = $result->getTreatedContent();
        }
        $this->logger->log(sprintf('NodeIndexer: Check duplicate nodes for %s (%s), found %d document(s)', $documentIdentifier, $nodeType->getName(), count($bulkRequest)), LOG_DEBUG, null, 'ElasticSearch (CR)');
        if ($bulkRequest !== []) {
            $index->request('POST', '/_bulk', [], implode("\n", $bulkRequest) . "\n");
        }
        $this->searchClient->request('DELETE', '/_search/scroll', [], json_encode([
            'scroll_id' => [
                $scrollId
            ]
        ]));
    }
1111729
public function allowMimetype($Mimetype) {
        if ( ! $this->returnUrl() ) return false;
        if ( isset($this->claim->accept_media_types) ) {
            $ma = $Mimetype;
            if ( ! is_array($ma) ) $ma = array($Mimetype);
            $m = new Mimeparse;
            $allowed = $m->best_match($ma, $this->claim->accept_media_types);
            if ( $Mimetype != $allowed ) return false;
            return true;
        }
        return false;
    }
163875
public function addMimeType($mimeType)
    {
        if (!in_array($mimeType, $this->mimeTypes)) {
            $this->mimeTypes[] = $mimeType;
        }

        return $this;
    }
155450
public static function mimeType($input, $mimes) {
        if (static::file($input)) {
            $input = $input['tmp_name'];
        }

        if (!file_exists($input)) {
            return false;
        }

        $file = finfo_open(FILEINFO_MIME_TYPE);
        $type = finfo_file($file, $input);
        finfo_close($file);

        return in_array($type, (array) $mimes);
    }
1341351
protected function message($message = null, array $params = null, $type = 'message')
    {
        return is_array($params) ? strtr(isset($this->$type) ? $this->$type : $message, $params) : $message;
    }