<commit_before><?php

namespace Oro\Bundle\AttachmentBundle\Guesser;

use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;

use Oro\Component\PhpUtils\ArrayUtil;

class MsMimeTypeGuesser implements MimeTypeGuesserInterface
{
    /** @var array */
    protected $typesMap = [
        'd0cf11e0a1b11ae1' => [
            'msg' => 'application/vnd.ms-outlook',
        ],
    ];

    /**
     * {@inheritdoc}
     */
    public function guess($filePath)
    {
        $file = ArrayUtil::find(
            function (array $file) use ($filePath) {
                return $file['tmp_name']['file'] === $filePath;
            },
            $_FILES
        );

        if (!$file) {
            return null;
        }

        $fileName = $file['name']['file'];
        $pos = strrpos($fileName, '.');
        if (!$pos) {
            return null;
        }

        $extension = substr($fileName, $pos + 1);

        $handle = fopen($filePath, 'r');
        $bytes = bin2hex(fread($handle, 8));
        fclose($handle);

        if (!isset($this->typesMap[$bytes][$extension])) {
            return null;
        }

        return $this->typesMap[$bytes][$extension];
    }
}
<commit_msg>BAP-9254 Attachments are not shown in Comments<commit_after><?php

namespace Oro\Bundle\AttachmentBundle\Guesser;

use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;

use Oro\Component\PhpUtils\ArrayUtil;

class MsMimeTypeGuesser implements MimeTypeGuesserInterface
{
    /** @var array */
    protected $typesMap = [
        'd0cf11e0a1b11ae1' => [
            'msg' => 'application/vnd.ms-outlook',
        ],
    ];

    /**
     * {@inheritdoc}
     */
    public function guess($path)
    {
        $file = ArrayUtil::find(
            function (array $file) use ($path) {
                return $file['tmp_name']['file'] === $path;
            },
            $_FILES
        );

        if (!$file) {
            return null;
        }

        $extension = pathinfo($file['name']['file'], PATHINFO_EXTENSION);

        $handle = fopen($path, 'r');
        $bytes = bin2hex(fread($handle, 8));
        fclose($handle);

        if (!isset($this->typesMap[$bytes][$extension])) {
            return null;
        }

        return $this->typesMap[$bytes][$extension];
    }
}

{'fraction_non_alphanumeric': 0.15304798962386512, 'fraction_numerical': 0.010808473843493299, 'mean_word_length': 2.081225033288948, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2890745', 'n_tokens_mistral': 729, 'n_tokens_neox': 716, 'n_words': 121}