Skip to content

[Mime] FormDataPart missing root name while processing multidimensional array of fields #33063

@wtorsi

Description

@wtorsi

Symfony 4.3

We miss name of the TextPart attachments while preparing multidimensional arrays inside FormDataPart.
To reproduce it just send multiple attachments with custom name with FormDataPart.
For example, I took code from symfony/mailer-mailgun:


$body = new FormDataPart($this->getPayload($email, $envelope));
...
private function getPayload(Email $email, SmtpEnvelope $envelope): array
    {
...
$payload = [
            'from' => $envelope->getSender()->toString(),
            'to' => implode(',', $this->stringifyAddresses($this->getRecipients($email, $envelope))),
            'subject' => $email->getSubject(),
           
            /** i'm talking about these 2 params */
            'attachment' => $attachments,
            'inline' => $inlines, 
        ];
...
   }

As a result the request attachments will be without name (or with indexed as 0,1,2.. names).
It happens, because we miss parent key name in FormDataPart::prepareFields method.

    private function prepareFields(array $fields): array
    {
        $values = [];
        array_walk_recursive($fields, function ($item, $key) use (&$values) {
            if (!\is_array($item)) {
                $values[] = $this->preparePart($key, $item);
            }
        });

        return $values;
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions