Determine if an attachment should be used as an inline attachment associated to the HTML body.

@param MimePart $attachment

@return bool
977378
protected function isInlineAttachment(MimePart $attachment)
    {
        return $this->bodyHTML !== false
            && $attachment->getId()
            && in_array((string) $attachment->getDisposition(), ['', Mime::DISPOSITION_INLINE], true)
        ;
    }
951221
protected function AttachAll($disposition_type, $boundary) {
    // Return text of body
    $mime = array();
    $cidUniq = array();
    $incl = array();

    // Add all attachments
    foreach ($this->attachment as $attachment) {
      // CHECK IF IT IS A VALID DISPOSITION_FILTER
      if($attachment[6] == $disposition_type) {
        // Check for string attachment
        $bString = $attachment[5];
        if ($bString) {
          $string = $attachment[0];
        } else {
          $path = $attachment[0];
        }

        $inclhash = md5(serialize($attachment));
        if (in_array($inclhash, $incl)) { continue; }
        $incl[]      = $inclhash;
        $filename    = $attachment[1];
        $name        = $attachment[2];
        $encoding    = $attachment[3];
        $type        = $attachment[4];
        $disposition = $attachment[6];
        $cid         = $attachment[7];
        if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
        $cidUniq[$cid] = true;

        $mime[] = sprintf("--%s%s", $boundary, $this->LE);
        $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
        $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);

        if($disposition == 'inline') {
          $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
        }

        $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);

        // Encode as string attachment
        if($bString) {
          $mime[] = $this->EncodeString($string, $encoding);
          if($this->IsError()) {
            return '';
          }
          $mime[] = $this->LE.$this->LE;
        } else {
          $mime[] = $this->EncodeFile($path, $encoding);
          if($this->IsError()) {
            return '';
          }
          $mime[] = $this->LE.$this->LE;
        }
      }
    }

    $mime[] = sprintf("--%s--%s", $boundary, $this->LE);

    return implode("", $mime);
  }
1209026
protected function idPartition($attachment, $styleName = '')
	{
		$id = $attachment->getInstance()->getKey();

		if (is_numeric($id))
		{
			return implode('/', str_split(sprintf('%09d', $id), 3));
		}
		elseif (is_string($id))
		{
			return implode('/', array_slice(str_split($id, 3), 0, 3));
		}
		else
		{
			return null;
		}
	}
836906
public function isSafe($ext, $mime)
    {
        $unsafeExtensions = $this->package->config('block.extensions');
        $unsafeMimes = $this->package->config('block.mimetypes');
        $mimeSearch = function ($mimeValue) use ($mime) {
            return preg_match($mimeValue, $mime);
        };

        if (in_array($ext, $unsafeExtensions)) {
            return false;
        }

        if (collect($unsafeMimes)->search($mimeSearch)) {
            return false;
        }

        return true;
    }
655730
function part_body($p)
    {
        // encrypted attachment, see parse_plain_encrypted()
        if ($p['part']->need_decryption && $p['part']->body === null) {
            $this->load_pgp_driver();

            $storage = $this->rc->get_storage();
            $body    = $storage->get_message_part($p['object']->uid, $p['part']->mime_id, $p['part'], null, null, true, 0, false);
            $result  = $this->pgp_decrypt($body);

            // @TODO: what to do on error?
            if ($result === true) {
                $p['part']->body = $body;
                $p['part']->size = strlen($body);
                $p['part']->body_modified = true;
            }
        }

        return $p;
    }
1232331
protected function _reEncodeMessageAttachment(Horde_Mime_Part $part)
    {
        $new_part = Horde_Mime_Part::parseMessage($part->getContents());
        $part->setContents($new_part->getContents(array('stream' => true)), array('encoding' => self::ENCODE_BINARY));
        $part->setTransferEncoding('base64', array('send' => true));
    }
857276
public function isContentType($mime) {
    foreach ((array) $mime as $m) {
      $m = $this->getMime($m);
      if (strtolower($m) === $this->getContentTypeMime()) {
        return true;
      }
    }
    return false;
  }
1282367
private static function isValidUriFragment(?string $fragment): bool
    {
        if ($fragment === null || $fragment === '') {
            return true;
        }

        // http://tools.ietf.org/html/rfc3986#section-3.5
        // fragment = *( pchar / "/" / "?" )
        // pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
        $pattern = sprintf(
            '/\A(?:[%s%s\/?:@]|(?:%s))*\z/i',
            'a-z0-9\-._~',
            '!$&\'()*+,;=',
            '%[a-f0-9]{2}'
        );

        return !!preg_match($pattern, $fragment);
    }
1139043
protected function attachResourceToEnd(&$destination,$attachment)
    {
        for ($i=count($destination)-1;$i>-1;$i--) {
            if (is_array($destination[$i])) {
                if ($this->attachResourceToEnd($destination[$i], $attachment)) {
                    return true;
                }
            }
        }
        array_push($destination, $attachment);
        return true;
    }
1139159
function setAttachment(string $attachment, string $filename = '') {
        $this->attachment = $attachment;
        $this->filename = $filename;
        return $this;
    }
234226
protected function getSectionAttachments()
    {
        $output = '';

        foreach ($this->_attachments as $key => $file) {
            $tmp_file = false;

            // If the attachment is a URL, download the file to a temporary location.
            // This prevents downloading the file twice - once for info, once for data.
            if (filter_var($file['file'], FILTER_VALIDATE_URL)) {
                $gateway = new Gateway();
                $gateway->init($file['file']);
                $gateway->setopt('TIMEOUT', 30);
                $file_content = @$gateway->exec();

                $tmp_file = tempnam(TMP, 'attachment');
                General::writeFile($tmp_file, $file_content, Symphony::Configuration()->get('write_mode', 'file'));

                $original_filename = $file['file'];
                $file['file'] = $tmp_file;

                // Without this the temporary filename will be used. Ugly!
                if (is_null($file['filename'])) {
                    $file['filename'] = basename($original_filename);
                }
            } else {
                $file_content = @file_get_contents($file['file']);
            }

            if ($file_content !== false && !empty($file_content)) {
                $output .= $this->boundaryDelimiterLine('multipart/mixed')
                     . $this->contentInfoString($file['mime-type'], $file['file'], $file['filename'], $file['charset'])
                     . EmailHelper::base64ContentTransferEncode($file_content);
            } else {
                if ($this->_validate_attachment_errors) {
                    if (!$tmp_file === false) {
                        $filename = $original_filename;
                    } else {
                        $filename = $file['file'];
                    }

                    throw new EmailGatewayException(__('The content of the file `%s` could not be loaded.', array($filename)));
                }
            }

            if (!$tmp_file === false) {
                General::deleteFile($tmp_file);
            }
        }
        return $output;
    }
986416
public function saveAttachment($attachment)
    {
        try {

            return $this->_storage->saveAttachment($attachment);

        } catch (\Exception $e) {

            throw new MailException(
                new Phrase($e->getMessage()),
                $e)
            ;

        }
    }
777018
protected function isEnvelopedEmail(Part $part)
    {
        if (!$this->hasHeader($part, 'Content-Type')) {
            return false;
        }

        return $this->getContentType($part)->getType() == 'message/rfc822';
    }
590576
private static function checkFileMime($file, $validMime) {
		
		if (!function_exists('mime_content_type')) {
			$app = Application::getInstance();
			$app->enqueueError('The PHP extention mime_content_type is not installed');
			return NULL;
		}
		
		$pathParts = pathinfo($file);
		$extension = $pathParts['extension'];
		
		// force to array
		$validMime = (array)$validMime;

		foreach ($validMime as $item) {
		
			if ($item == mime_content_type($file)) {
				return TRUE;
			}
			
		}
		
		return FALSE;
		
	}
203833
public function assembleAttachmentBody()
    {
        $body = array();
        $body[] = "This is a multi-part message in MIME format.";
        $body[] = "--{$this->_uid}";
        $body[] = "Content-Type: text/html; charset=\"utf-8\"";
        $body[] = "Content-Transfer-Encoding: quoted-printable";
        $body[] = "";
        $body[] = quoted_printable_encode($this->_message);
        $body[] = "";
        $body[] = "--{$this->_uid}";

        foreach ($this->_attachments as $attachment) {
            $body[] = $this->getAttachmentMimeTemplate($attachment);
        }

        return implode(PHP_EOL, $body) . '--';
    }
843918
public function prepareAttachment($attachment)
    {
        if ($this->isFile($attachment) !== true) {
            return false;
        }
        //http://php.net/manual/en/class.finfo.php
        $fileInfo = new \finfo(FILEINFO_MIME_TYPE);
        $fileType = $fileInfo->file($attachment);
        $file = fopen($attachment, 'r');
        $fileContent = fread($file, filesize($attachment));
        $fileContent = chunk_split(base64_encode($fileContent));
        fclose($file);
        $msgContent = 'Content-Type: '.$fileType.'; name='.basename($attachment)."\r\n";
        $msgContent .= 'Content-Transfer-Encoding: base64'."\r\n";
        $msgContent .= 'Content-ID: <'.basename($attachment).'>'."\r\n";
        $msgContent .= "\r\n".$fileContent."\r\n\r\n";

        return $msgContent;
    }
870877
protected function maybeShiftAttachment() {

		if ( ! in_the_loop() || 'attachment' !== get_post_type() ) {
			return;
		}

		if ( in_array( $this->name, [ 'entry', 'post', 'entry/archive', 'entry/single' ] ) ) {

			remove_filter( 'the_content', 'prepend_attachment' );

		} elseif ( 'embed' === $this->name ) {

			remove_filter( 'the_content',       'prepend_attachment'          );
			remove_filter( 'the_excerpt_embed', 'wp_embed_excerpt_attachment' );
		}
	}