Construct the specified attachment and add it to the message
@param array $attachment Attachment to construct
@param string $boundary Pary Boundary
return string
434465
private function constructAttachment ($attachment, $boundary)
    {

        // Set variables

        $output	= NULL;

        // Add the boundary

        $output	.= '--' . $boundary . $this->_nl;

        // Add the attachment to the message

        $output	.= 'Content-Type: ' . $attachment['type'];

        if ($attachment['name'])
        {
            $output	.= '; name="' . $attachment['name'] . '"';
        }

        $output	.= $this->_nl;
        $output	.= 'Content-Transfer-Encoding: base64' . $this->_nl;

        // Add attachment as plain text if its the body, otherwise add as a file attachment

        if ($attachment['type'] == 'text/plain')
        {
            $output	.= $this->_nl;
        }
        else
        {
            $output	.= 'Content-Disposition: attachment; filename="' . $attachment['name'] . '"' . str_repeat ($this->_nl, 2);
        }

        $output	.= chunk_split (base64_encode ($attachment['data']), 70) . $this->_nl;

        // Return attachment part

        return $output;

    }
1023059
protected function addAttachment($attach)
    {
        if (is_array($attach)) {
            if ($this->is_assoc($attach)) {
                $attach = [ $attach ];
            }

            foreach ($attach as $attachElement) {
                $this->client = $this->client->attach($attachElement);
            }
        }
    }
1135515
def add_attachment(self, attachment):
        
        self._attachments = self._ensure_append(attachment, self._attachments)
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;
    }
761541
private function renderAttachments(&$content, $boundary)
    {
        foreach($this->attachments as $file => $name) {
            if (!is_readable($file)) {
                throw new MailException('File could not be read: ' . $file); // @codeCoverageIgnore
            }
            $data = chunk_split(base64_encode(file_get_contents($file)));
            $type = mime_content_type($file);
            $content .= "\r\n";
            $content .= "--$boundary\r\n";
            $content .= "Content-Type: $type;\r\n\tname=\"$name\"\r\n";
            $content .= "Content-Transfer-Encoding: base64\r\n";
            $content .= "Content-Description: \"$name\"\r\n";
            $content .= "Content-Disposition: attachment;\r\n\tfilename=\"$name\"\r\n";
            $content .= "\r\n";
            $content .= "$data";
        }
    }
724768
public function addBlobAttachment($content, $filename, $mimeType = null, $fileInfo = []) {
		if ($mimeType === null) {
			$ext = pathinfo($filename, PATHINFO_EXTENSION);
			$mimeType = $this->_getMimeByExtension($ext);
		}
		$fileInfo['data'] = $content;
		$fileInfo['mimetype'] = $mimeType;
		$file = [$filename => $fileInfo];
		return $this->addAttachments($file);
	}
650107
public function addAttachment($attachment)
    {
        if ($attachment instanceof \SplFileObject && $attachment->isFile() && $attachment->isReadable()) {
            $file['filename'] = method_exists($attachment, 'getAttachmentFilename') ?
                $attachment->getAttachmentFilename() :
                $attachment->getBasename();

            $file['is_embedded'] = method_exists($attachment, 'getIsEmbedded') ? $attachment->getIsEmbedded() : false;
            $file['id'] = method_exists($attachment, 'getId') ? $attachment->getId() : null;

            if (method_exists($attachment, 'getMimeType')) {
                $file['mime_type'] = $attachment->getMimeType();
            } else {
                $resource = finfo_open(FILEINFO_MIME_TYPE);
                $file['mime_type'] = finfo_file($resource, $attachment->getRealPath());
            }

            $file['contents'] = '';
            while (!$attachment->eof()) {
                $file['contents'] .= $attachment->fgets();
            }
            $file['contents'] = base64_encode($file['contents']);

            $this->attachments[] = $file;
        } elseif (is_array($attachment)) {
            $this->attachments[] = $attachment;
        }

        return $this;
    }
494636
public function getAttachmentMimeTemplate($attachment)
    {
        $file = $attachment['file'];
        $data = $attachment['data'];

        $head = array();
        $head[] = "Content-Type: application/octet-stream; name=\"{$file}\"";
        $head[] = "Content-Transfer-Encoding: base64";
        $head[] = "Content-Disposition: attachment; filename=\"{$file}\"";
        $head[] = "";
        $head[] = $data;
        $head[] = "";
        $head[] = "--{$this->_uid}";

        return implode(PHP_EOL, $head);
    }
1182983
@InterfaceAudience.Private
    protected void addAttachment(Attachment attachment, String name) {
        Map<String, Object> attachments = (Map<String, Object>) properties.get("_attachments");
        if (attachments == null) {
            attachments = new HashMap<String, Object>();
        }
        attachments.put(name, attachment);
        properties.put("_attachments", attachments);
        if (attachment != null) {
            attachment.setName(name);
        }
    }
1066996
private function doParseBoundary($boundary)
    {
        $result = array();
        $prefix = "--".$boundary;

        $this->consumeRegexp("/\n*/");
        $this->consumeTo($prefix);
        $this->consume($prefix);

        while ($this->expects("\n")) {
            $content = $this->consumeTo("\n".$prefix);

            $part = new Part();
            $part->loadSource($content);
            if ($part->isMultipart()) {
                $result = array_merge($result, $part->getParts());
            } else {
                $result[] = $part;
            }

            $this->consume("\n".$prefix);
        }

        return $result;
    }
707255
private function renderTextAndHtmlWithEmbededFiles(&$content, $text, $html, $encoding, $boundary)
    {
        $uid = uniqid();
        $boundary2 = "x----_=_NextPart_002_$uid";
        $content .= "\r\n--$boundary\r\n";
        $content .= "Content-Type: multipart/related;\r\n\tboundary=\"$boundary2\";\r\n\ttype=\"multipart/alternative\"\r\n";
        $this->renderTextAndHtml($content, $text, $html, $encoding, $boundary2);
        $this->renderEmbeddedFiles($content, $boundary2);
        $content .= "\r\n--$boundary2--\r\n";
    }
473476
public function setTextMessage(array $to,
                                   string $subject,
                                   string $body,
                                   array $attachment = null,
                                   array $cc = null,
                                   array $bcc = EMAIL_BCC): void
    {
        $this->email->setFrom($this->from);
        foreach ($to as $value) {
            $this->email->addTo($value);
        }
        if ($cc != null) {
            foreach ($cc as $value) {
                $this->email->addCc($value);
            }
        }
        if ($bcc != null) {
            foreach ($bcc as $value) {
                $this->email->addBcc($value);
            }
        }
        if ($attachment != null) {
            foreach ($attachment as $file) {
                $this->email->addAttachment($file);
            }
        }
        $this->email->setSubject($subject);
        $this->email->setBody($body);
    }
468735
private void addAttachment(Multipart multipart, Attachment attachment) throws AttachmentResourceHandlerException {
		MimeBodyPart part = new MimeBodyPart();
		try {
			part.setFileName(attachment.getResource().getName());
			part.setDisposition(attachment.getDisposition());
			part.setDescription(attachment.getDescription());
			part.setContentID(attachment.getContentId());
			attachmentHandler.setData(part, attachment.getResource(), attachment);
			multipart.addBodyPart(part);
		} catch (MessagingException e) {
			throw new AttachmentResourceHandlerException("Failed to attach " + attachment.getResource().getName(), attachment, e);
		}
	}
841013
protected function prepAttachment($attachment, $options = [])
    {
        // First we will check for a MIME type on the message, which instructs the
        // mail client on what type of attachment the file is so that it may be
        // downloaded correctly by the user. The MIME option is not required.
        if (isset($options['mime'])) {
            $attachment->setContentType($options['mime']);
        }

        // If an alternative name was given as an option, we will set that on this
        // attachment so that it will be downloaded with the desired names from
        // the developer, otherwise the default file names will get assigned.
        if (isset($options['as'])) {
            $attachment->setFilename($options['as']);
        }

        $this->swiftMessage->attach($attachment);

        return $this;
    }
556838
protected function parserContent($boundary, $content)
    {
        if ($boundary) {
            $parts = preg_split('#--'.$boundary.'(--)?\s*#si', $content, -1, PREG_SPLIT_NO_EMPTY);
            foreach ($parts as $part) {
                $part = trim($part);
                if (empty($part)) {
                    continue;
                }

                if (preg_match('/(Content-Type:)(.*)/i', $part, $math)) {
                    if (preg_match(Headers::BOUNDARY_PATTERN, str_replace("\r\n\t", ' ', $part), $subBoundary)) {
                        if ($subBoundary[1] != $boundary) {
                            $this->parserContent($subBoundary[1], $part);
                        } else {
                            continue;
                        }
                    } else {
                        $data = explode(';', $math[2]);
                        $type = trim($data[0]);

                        $isAttachment = (strpos($part, 'Content-Disposition: attachment;') !== false);

                        //get body message
                        if (($type == Content::CT_MULTIPART_ALTERNATIVE || $type == Content::CT_TEXT_HTML || $type == Content::CT_TEXT_PLAIN
                                || $type == Content::CT_MESSAGE_DELIVERY)
                            && !$isAttachment
                        ) {
                            $this->parserBodyMessage($part);
                        } elseif ($type == Content::CT_MESSAGE_RFC822) {
                            $this->parserBodyMessage($part);
                            $this->parserAttachment($part);
                        } else { //attachment
                            $this->parserAttachment($part);
                        }
                    }
                }
            }
        } else {
            $content = new Content();
            $content->content = $this->_content;
            $content->charset = $this->_header->getCharset();
            $content->contentType = $this->getHeaders()->getMessageContentType();
            $content->transferEncoding = $this->_header->getTransferEncoding();

            $this->_parts[] = $content;
        }
    }
986416
public function saveAttachment($attachment)
    {
        try {

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

        } catch (\Exception $e) {

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

        }
    }
1177861
private function createStringAttachments($attachments)
    {
        if (array_key_exists('string', $attachments)) {
            $this->mailer->addStringAttachment($attachments['string'], $attachments['name']);
        } else {
            foreach ($attachments as $attachment) {
                $this->mailer->addStringAttachment($attachment['string'], $attachment['name']);
            }
        }
    }