Add potential attachments to the message object.

@param IncomingMessage $incomingMessage
@return IncomingMessage
164157
protected function addAttachments($incomingMessage)
    {
        $attachment = $this->event->get('attachment');

        if ($attachment === self::ATTACHMENT_IMAGE) {
            $images = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new Image($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(Image::PATTERN);
            $incomingMessage->setImages($images);
        } elseif ($attachment === self::ATTACHMENT_AUDIO) {
            $audio = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new Audio($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(Audio::PATTERN);
            $incomingMessage->setAudio($audio);
        } elseif ($attachment === self::ATTACHMENT_VIDEO) {
            $videos = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new Video($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(Video::PATTERN);
            $incomingMessage->setVideos($videos);
        } elseif ($attachment === self::ATTACHMENT_FILE) {
            $files = $this->files->map(function ($file) {
                if ($file instanceof UploadedFile) {
                    $path = $file->getRealPath();
                } else {
                    $path = $file['tmp_name'];
                }

                return new File($this->getDataURI($path));
            })->values()->toArray();
            $incomingMessage->setText(File::PATTERN);
            $incomingMessage->setFiles($files);
        }

        return $incomingMessage;
    }
15412
private function extractMessage(IncomingPhysicalMessage $physicalMessage)
    {
        $body = $physicalMessage->getBody();
        if ($body === null || $body === '') {
            return null;
        }

        if (!isset($physicalMessage->getHeaders()[HeaderTypeEnum::ENCLOSED_CLASS])) {
            return null;
        }

        $messageClass = $physicalMessage->getHeaders()[HeaderTypeEnum::ENCLOSED_CLASS];
        $serializer = $this->deserializerResolver->resolve($physicalMessage->getHeaders());
        $instanceMessage = $serializer->deserialize($body, $messageClass);

        return $this->logicalMessageFactory->createFromObject($instanceMessage);
    }
654791
public function attach($attachmentType, $url)
    {
        $attachmentTypes = [
            AttachmentType::FILE,
            AttachmentType::IMAGE,
            AttachmentType::VIDEO,
            AttachmentType::AUDIO,
        ];

        if (! in_array($attachmentType, $attachmentTypes)) {
            throw CouldNotCreateMessage::invalidAttachmentType();
        }

        if (! isset($url)) {
            throw CouldNotCreateMessage::urlNotProvided();
        }

        $this->attachmentType = $attachmentType;
        $this->attachmentUrl = $url;
        $this->hasAttachment = true;

        return $this;
    }
652251
protected function loadMessages()
    {
        $messages = Collection::make($this->event->get('messaging'))->filter(function ($msg) {
            return isset($msg['message']) && isset($msg['message']['attachments']) && isset($msg['message']['attachments']);
        })->transform(function ($msg) {
            $message = new IncomingMessage(File::PATTERN, $msg['sender']['id'], $msg['recipient']['id'], $msg);
            $message->setFiles($this->getFiles($msg));

            return $message;
        })->toArray();

        if (count($messages) === 0) {
            $messages = [new IncomingMessage('', '', '')];
        }

        $this->messages = $messages;
    }
466191
public function addAttachment($attachment): Letter
    {
        if (!is_file($attachment)) {
            throw new InvalidArgumentException('"%s" can not be found or is not a file');
        }

        $this->attachments[] = $attachment;

        return $this;
    }
484219
public function createLogicalMessageContext(
        IncomingLogicalMessage $logicalMessage,
        IncomingPhysicalMessageContext $parentContext
    ) {
        return new IncomingLogicalMessageContext(
            $logicalMessage,
            $parentContext->getMessageId(),
            $parentContext->getHeaders(),
            $parentContext->getIncomingPhysicalMessage(),
            $parentContext->getPendingTransportOperations(),
            $this->busOperations,
            $this->outgoingOptionsFactory,
            $parentContext->getEndpointControlToken(),
            $parentContext
        );
    }
1121780
def add_attachment(message, attachment, rfc2231=True):
    '''
    '''
    data = attachment.read()

    part = MIMEBase('application', 'octet-stream')
    part.set_payload(data)
    encoders.encode_base64(part)
    filename = attachment.name if rfc2231 else Header(attachment.name).encode()
    part.add_header('Content-Disposition', 'attachment',
                    filename=filename)

    message.attach(part)
1348016
protected function addMessagesToFile($fileFullname, $messages, $language)
    {
        if (!$this->isFileExists($fileFullname) || $this->option('force')) {
            $this->createMessageToFile($fileFullname, $messages, $language);
        } else {
            $this->appendMessageToFile($fileFullname, $messages);
        }

        return $this;
    }
680901
public function appendMessage($message)
    {
        $context = $this->_context;

        $context->messages[$message->field][] = $message;

        return $this;
    }
608077
public function send(OutgoingMessage $message)
    {
        try {
            $message = $this->mailer->send(['text' => $message->getView()], $message->getData(), function ($email) use ($message) {
                $this->generateMessage($email, $message);
            });
        } catch (InvalidArgumentException $e) {
            $message = $this->sendRaw($message);
        }

        return $message;
    }
1126638
private function extractWithExceptionHandling(IncomingPhysicalMessage $physicalMessage)
    {
        try {
            return $this->extractMessage($physicalMessage);
        } catch (\Throwable $t) {
            throw new MessageDeserializationException($physicalMessage->getMessageId(), $t);
        }
    }
142668
def incoming(message)
      (m = filter(message, :incoming)) && each {|l| l.incoming(m)}
    end
884182
public function convertToPendingTransportOperations(OutboxMessage $outboxMessage)
    {
        $transportOperations = new PendingTransportOperations();
        foreach ($outboxMessage->getTransportOperations() as $outboxOperation) {
            $transportOperations->add(
                new TransportOperation(
                    new OutgoingPhysicalMessage(
                        $outboxOperation->getMessageId(),
                        $outboxOperation->getHeaders(),
                        $outboxOperation->getBody()
                    ),
                    $this->deserializeAddressTag($outboxOperation->getOptions())
                )
            );
        }

        return $transportOperations;
    }
1045804
public function createLogicalMessageContextFromSendContext(
        array $addressTags,
        OutgoingSendContext $parentContext
    ) {
        return new OutgoingLogicalMessageContext(
            $parentContext->getMessageId(),
            $parentContext->getHeaders(),
            $parentContext->getLogicalMessage(),
            $addressTags,
            $parentContext->getSendOptions()->isImmediateDispatchEnabled(),
            $parentContext->getIncomingPhysicalMessage(),
            $parentContext->getPendingTransportOperations(),
            $parentContext
        );
    }
350067
public function addMessagesPackageReceived(\Sopinet\ChatBundle\Entity\MessagePackage $messagesPackageReceived)
    {
        $this->messagesPackageReceived[] = $messagesPackageReceived;

        return $this;
    }
493527
protected function buildAttachments($message)
    {
        foreach ($this->attachments as $attachment) {
            $message->attach($attachment['file'], $attachment['options']);
        }

        foreach ($this->rawAttachments as $attachment) {
            $message->attachData(
                $attachment['data'], $attachment['name'], $attachment['options']
            );
        }

        $this->buildDiskAttachments($message);

        return $this;
    }
1251186
public function createSendContext(
        $message,
        SendOptions $options,
        PipelineStageContext $parentContext
    ) {
        return new OutgoingSendContext(
            new OutgoingLogicalMessage($message),
            $options,
            $parentContext instanceof IncomingContext ? $parentContext->getIncomingPhysicalMessage() : null,
            $parentContext instanceof IncomingContext ? $parentContext->getPendingTransportOperations() : null,
            $parentContext
        );
    }