Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Classes/Domain/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ public function calculateHiddenFields(string $content = null): array
}
} elseif (substr($name, -18) == '[__collectionName]' || substr($name, -41) === '[originallySubmittedResource][__identity]') {
// ignore special fields for file uploads
} elseif (substr($name, -2) == '[]') {
// handle multiple file upload field
$formFieldNames[] = substr($name, 0, strlen($name) - 2);
} else {
$formFieldNames[] = $name;
}
Expand Down
19 changes: 19 additions & 0 deletions Classes/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace Neos\Fusion\Form\Exception;

/*
* This file is part of the Neos.Fusion.Form package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

class InvalidArgumentException extends \Exception
{

}
60 changes: 43 additions & 17 deletions Classes/Runtime/Action/EmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\ResourceManagement\PersistentResource;
use Neos\Fusion\Form\Exception\InvalidArgumentException;
use Neos\Fusion\Form\Runtime\Domain\Exception\ActionException;
use Neos\SwiftMailer\Message as SwiftMailerMessage;
use Neos\Utility\MediaTypes;
Expand Down Expand Up @@ -130,26 +131,51 @@ protected function addAttachments(SwiftMailerMessage $mail): void
{
$attachments = $this->options['attachments'] ?? null;
if (is_array($attachments)) {
foreach ($attachments as $attachment) {
if (is_string($attachment)) {
$mail->attach(\Swift_Attachment::fromPath($attachment));
} elseif (is_object($attachment) && ($attachment instanceof UploadedFileInterface)) {
$mail->attach(new \Swift_Attachment($attachment->getStream()->getContents(), $attachment->getClientFilename(), $attachment->getClientMediaType()));
} elseif (is_object($attachment) && ($attachment instanceof PersistentResource)) {
$stream = $attachment->getStream();
if (!is_bool($stream)) {
$content = stream_get_contents($stream);
if (!is_bool($content)) {
$mail->attach(new \Swift_Attachment($content, $attachment->getFilename(), $attachment->getMediaType()));
try {
foreach ($attachments as $attachment) {
try {
$this->addAttachment($attachment, $mail);
} catch (InvalidArgumentException $e) {
// handle files of multiple file upload element
if (is_array($attachment)) {
foreach ($attachment as $uploadItem) {
$this->addAttachment($uploadItem, $mail);
}
}
}
} elseif (is_array($attachment) && isset($attachment['content']) && isset($attachment['name'])) {
$content = $attachment['content'];
$name = $attachment['name'];
$type = $attachment['type'] ?? MediaTypes::getMediaTypeFromFilename($name);
$mail->attach(new \Swift_Attachment($content, $name, $type));
}
} catch (InvalidArgumentException $e) {

}
}
}
}

/**
* @param mixed $attachment
* @param SwiftMailerMessage $mail
* @throws InvalidArgumentException
*/
protected function addAttachment($attachment, SwiftMailerMessage $mail): void
{
if (is_string($attachment)) {
$mail->attach(\Swift_Attachment::fromPath($attachment));
} elseif (is_object($attachment) && ($attachment instanceof UploadedFileInterface)) {
$mail->attach(new \Swift_Attachment($attachment->getStream()->getContents(), $attachment->getClientFilename(), $attachment->getClientMediaType()));
} elseif (is_object($attachment) && ($attachment instanceof PersistentResource)) {
$stream = $attachment->getStream();
if (!is_bool($stream)) {
$content = stream_get_contents($stream);
if (!is_bool($content)) {
$mail->attach(new \Swift_Attachment($content, $attachment->getFilename(), $attachment->getMediaType()));
}
}
} elseif (is_array($attachment) && isset($attachment['content']) && isset($attachment['name'])) {
$content = $attachment['content'];
$name = $attachment['name'];
$type = $attachment['type'] ?? MediaTypes::getMediaTypeFromFilename($name);
$mail->attach(new \Swift_Attachment($content, $name, $type));
} else {
throw new InvalidArgumentException('Can not handle $attachment.', 1664442569);
}
}
}