Overwrite to allow mimetype detection

@param string|array $attachments String with the filename or array with filenames
@return $this
@throws \InvalidArgumentException
329524
public function setAttachments($attachments) {
		$attach = [];
		foreach ((array)$attachments as $name => $fileInfo) {
			if (!is_array($fileInfo)) {
				$fileInfo = ['file' => $fileInfo];
			}
			if (!isset($fileInfo['file'])) {
				if (!isset($fileInfo['data'])) {
					throw new InvalidArgumentException('No file or data specified.');
				}
				if (is_int($name)) {
					throw new InvalidArgumentException('No filename specified.');
				}
			} else {
				$fileName = $fileInfo['file'];
				if (!preg_match('~^https?://~i', $fileInfo['file'])) {
					$fileInfo['file'] = realpath($fileInfo['file']);
				}
				if ($fileInfo['file'] === false || !Utility::fileExists($fileInfo['file'])) {
					throw new InvalidArgumentException(sprintf('File not found: "%s"', $fileName));
				}
				if (is_int($name)) {
					$name = basename($fileInfo['file']);
				}
			}
			if (!isset($fileInfo['mimetype'])) {
				$ext = pathinfo($name, PATHINFO_EXTENSION);
				$fileInfo['mimetype'] = $this->_getMimeByExtension($ext);
			}
			$attach[$name] = $fileInfo;
		}
		$this->_attachments = $attach;

		return $this;
	}
665622
public function allowedFileExtensions($fileExtensions)
    {
        if (!is_array($fileExtensions)) {
            $fileExtensions = [$fileExtensions];
        }
        $this->extensions = array_unique(array_merge($this->extensions, $fileExtensions));

        return $this;
    }
1088148
public function mountFilesystems(array $filesystems)
    {
        foreach ($filesystems as $prefix => $filesystem) {
            $this->mountFilesystem($prefix, $filesystem);
        }

        return $this;
    }
788998
public function mountFileSystems(array $fileSystems = []): self
    {
        foreach ($fileSystems as $prefix => $fileSystem) {
            $this->mountFileSystem($prefix, $fileSystem);
        }

        return $this;
    }
738041
public function definedIn(string ...$fileNames): self
    {
        $instance = clone $this;

        foreach ($fileNames as $fileName) {
            $instance->fileNames[] = $fileName;
        }

        return $instance;
    }
441306
public function attachPostFiles($files)
    {
        if (is_array($files)) {
            foreach ($files as $file) {
                // Check whether file has been posted.
                if (is_uploaded_file($file['tmp_name'])) {
                    // Get file from its location.
                    $fileContents = file_get_contents($file['tmp_name']);
                    if ($fileContents) {
                        $this->addAttachment(
                                $file['name'], $file['type'], $fileContents
                        );
                    } else {
                        throw new Exception('Empty attachment');
                    }
                } else {
                    switch ($file['error']) {
                        case 0:
                            throw new Exception('Illegal file: ' . $file['name']);
                            break;
                        case 1:
                        case 2:
                            throw new Exception('File too large');
                            break;
                        case 3:
                            throw new Exception('File truncated');
                            break;
                        case 4:
                            // File slot is empty. Just skip it.
                            break;
                        default:
                            throw new EixMailMessageBadAttachmentException();
                            break;
                    }
                }
            }
        } else {
            throw new Exception('Unrecognised format');
        }
    }
408645
public function setFiles(array $files) {
        if(!$this->setModified('files', $files)->isModified()) {
            return $this;
        }
		$this->files = $files;
		return $this;
    }
904291
private function checkPrefixes(array $paths)
    {
        sort($paths);

        for ($i = 1; $i < count($paths); $i++) {
            $prefix = $paths[$i-1];
            $suffix = $paths[$i];

            $prefix = explode('.', $prefix);
            $suffix = explode('.', $suffix);

            $isPrefix = count($prefix) < count($suffix)
                && $prefix === array_slice($suffix, 0, count($prefix));

            if ($isPrefix) {
                throw new \InvalidArgumentException(sprintf(
                    'Field path conflict detected for field path `%s`. ' .
                    'Conflicts occur when a field path descends from another ' .
                    'path. For instance `a.b` is not allowed when `a` is also ' .
                    'provided.',
                    $prefix
                ));
            }
        }
    }
817454
public function addAttachment($attachment, $filename=null)
	{
		if (!($attachment instanceof Swift_Mime_MimeEntity))
		{
			$attachment = \Swift_Attachment::fromPath($attachment);
		}

		if ($filename && is_string($filename))
		{
			$attachment->setFilename($filename);
		}

		return $this->attach($attachment);
	}
257530
public function registerPrefixes($prefixes)
    {
        if (!is_array($prefixes) && !$prefixes instanceof Traversable) {

            throw new Zend_Loader_Exception_InvalidArgumentException('Prefix pairs must be either an array or Traversable');
        }

        foreach ($prefixes as $prefix => $directory) {
            $this->registerPrefix($prefix, $directory);
        }
        return $this;
    }
617072
public function create(array $aliases): CompressionMethodManager
    {
        $compressionMethods = [];
        foreach ($aliases as $alias) {
            if (\array_key_exists($alias, $this->compressionMethods)) {
                $compressionMethods[] = $this->compressionMethods[$alias];
            } else {
                throw new \InvalidArgumentException(\sprintf('The compression method with the alias "%s" is not supported.', $alias));
            }
        }

        return CompressionMethodManager::create($compressionMethods);
    }
20491
public static function for_mimetypes($mimetypes)
    {
        foreach ($mimetypes as $mimetype) {
            if ($formatter = self::for_mimetype($mimetype)) {
                return $formatter;
            }
        }

        return false;
    }
674560
public function withFileToSend($filePath, $attachmentName = null, $attachment = false)
    {
        if (!is_string($attachmentName)) {
            $basePath = basename($filePath);
        } else {
            $basePath = $attachmentName;
        }

        $this->file = $filePath;

        if ($attachment) {
            return $this->withHeader('Content-Description', 'File Transfer')
                ->withHeader('Content-Disposition', 'attachment; filename="' . $basePath . '"')
                ->withHeader('Content-Transfer-Encoding', 'binary');
        }

        return $this;
    }
752239
public function setAttachableObjects($attachableObjects)
    {
        if (!$this->isMergingData) {
            $attachableObjects = $this->mergePresetAttachableObjects($attachableObjects);
        }

        if (empty($attachableObjects) || is_string($attachableObjects)) {
            return false;
        }

        $out = [];
        foreach ($attachableObjects as $attType => $attMeta) {
            $label          = '';
            $filters        = [];
            $orders         = [];
            $numPerPage     = 0;
            $page           = 1;
            $skipForm       = 0;
            $formIdent      = null;
            $quickFormIdent = null;
            $faIcon         = '';
            $showIcon       = 1;
            $locked         = 0;
            $attOption      = ['label', 'filters', 'orders', 'num_per_page', 'page'];
            $attData        = array_diff_key($attMeta, $attOption);

            // Disable an attachable model
            if (isset($attMeta['active'])) {
                if (is_string($attMeta['active'])) {
                    $attMeta['active'] = $this->obj()->render($attMeta['active']);
                }
                if (!$attMeta['active']) {
                    continue;
                }
            }

            // Useful for replacing a pre-defined attachment type
            if (isset($attMeta['attachment_type'])) {
                $attType = $attMeta['attachment_type'];
            } else {
                $attMeta['attachment_type'] = $attType;
            }

            // Useful for attaching a pre-existing attachment
            $attId = (isset($attMeta['attachment_id']) ? $attMeta['attachment_id'] : null);

            if (isset($attMeta['label'])) {
                $label = $this->translator()->translation($attMeta['label']);
            }

            if (isset($attMeta['filters'])) {
                $filters = $attMeta['filters'];
            }

            if (isset($attMeta['orders'])) {
                $orders = $attMeta['orders'];
            }

            if (isset($attMeta['num_per_page'])) {
                $numPerPage = $attMeta['num_per_page'];
            }

            if (isset($attMeta['page'])) {
                $page = $attMeta['page'];
            }

            if (isset($attMeta['skip_form'])) {
                $skipForm = $attMeta['skip_form'];
            }

            if (isset($attMeta['form_ident'])) {
                $formIdent = $attMeta['form_ident'];
            }

            if (isset($attMeta['quick_form_ident'])) {
                $quickFormIdent = $attMeta['quick_form_ident'];
            }

            if (isset($attMeta['fa_icon']) && !empty($attMeta['fa_icon'])) {
                $faIcon = $attMeta['fa_icon'];
                if (!is_array($faIcon)) {
                    $faIcon = [$faIcon];
                }

                foreach ($faIcon as &$icon) {
                    $icon = 'fa fa-'.$icon;
                }
            } else {
                $attParts = explode('/', $attType);
                if (isset($this->defaultIcons[end($attParts)])) {
                    $faIcon = 'fa fa-'.$this->defaultIcons[end($attParts)];
                }
            }

            if (isset($attMeta['show_icon'])) {
                $showIcon = !!$attMeta['show_icon'];
            }

            if (isset($attMeta['locked'])) {
                $locked = $attMeta['locked'];

                if (is_string($locked)) {
                    $locked = $this->obj()->render($locked);
                }
            }

            $out[$attType] = [
                'att_id'           => $attId,
                'label'            => $label,
                'skipForm'         => $skipForm,
                'formIdent'        => $formIdent,
                'quickFormIdent'   => $quickFormIdent,
                'hasFaIcon'        => !!$faIcon,
                'faIcon'           => $faIcon,
                'showIcon'         => $showIcon,
                'filters'          => $filters,
                'orders'           => $orders,
                'page'             => $page,
                'numPerPage'       => $numPerPage,
                'locked'           => $locked,
                'data'             => $attData
            ];
        }

        $this->attachableObjects = $out;

        return $this;
    }
878918
public function addAttachment ($filePath = FALSE, $fileName = NULL, $fileData = FALSE, $mimeType = 'text/plain')
    {

        // If its an existing file

        if ($filePath !== FALSE)
        {

            // Check File Exists

            if (!file_exists ($filePath))
            {

                // Add error and return false

                new \Sonic\Message ('error', $filePath . ' doesnt exist!');
                return FALSE;

            }

            // Get MIME Type

            $objFinfo   = new finfo;

            if (!$mimeType = $objFinfo->file ($filePath, FILEINFO_MIME))
            {

                // Add error and return false

                new \Sonic\Message ('error', 'Cannot get MIME type!');
                return FALSE;

            }

            // Get File Data

            if (!$fileData = @file_get_contents ($filePath))
            {

                // Add error and return false

                new \Sonic\Message ('error', 'Cannot get attachment data!');
                return FALSE;

            }

        }
        else if (!$fileData || !$fileName)
        {

            // Add error and return false

            new \Sonic\Message ('error', 'Invalid Attachment!');
            return FALSE;

        }

        // Set attachments boolean

        $this->_attachmentsSet	= TRUE;

        // Add Attachment

        $this->_attachments[]	= array (
            'name'		=> $fileName,
            'data'		=> $fileData,
            'type'		=> $mimeType
        );

        // Return TRUE

        return TRUE;

    }
647701
public function setFormat($format, $mimeTypes)
    {
        if (null === static::$formats) {
            static::initializeFormats();
        }

        static::$formats[$format] = \is_array($mimeTypes) ? $mimeTypes : [$mimeTypes];
    }
306256
public function setPaths($paths)
    {
        if (!is_array($paths) && !$paths instanceof Traversable) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid argument provided for $paths, expecting either an array or Traversable object, "%s" given',
                is_object($paths) ? get_class($paths) : gettype($paths)
            ));
        }

        $this->clearPaths();
        $this->addPaths($paths);
    }