Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Mailer] DataPart#setContentId requires @ #54162

Closed
@boesing

Description

@boesing

Symfony version(s) affected

6.2.0 - 7.0.5

Description

We are using symfony/mailer to partially forward messages with attachments as they were received i.e. from outlook, gmail, etc. accounts.

Some mail clients seem to create attachments with content-ids not containing @ which led to issues when forwarding those messages via symfony/mailer.
We do now have to generate that @-Part plus replacing the non-@-content id within HTML bodies. Tho it does work to manually search/replace cid:<contentIdWithout@>, this feels kinda weird.

From what I can read from the RFC (mentioned in the PR referenced below), there is no requirement for an @ and since there are clients out there which do generate mails without @ which are properly displayed in other mail clients, etc. I wonder if this "validation" is really necessary.

Refs: #46962

How to reproduce

Extracted from the DataPartTest#testSetContentIdInvalid of #46962

$part = new DataPart('foo');
$part->setContentId('test');

Possible Solution

Maybe, allow passing a strict boolean flag via __construct which allows projects as ours to bypass this kind of validation.
I have no idea why it had to be implemented in the first place but as I am aware of the BC contract symfony is pushing, I'd be fine with opt-in for non-strict validation.

Additional Context

    /**
     * @return $this
     */
    public function setContentId(string $cid): static
    {
        if (!str_contains($cid, '@')) {
            throw new InvalidArgumentException(sprintf('Invalid cid "%s".', $cid));
        }

        $this->cid = $cid;

        return $this;
    }
    public function testSetContentIdInvalid()
    {
        $this->expectException(InvalidArgumentException::class);

        $p = new DataPart('content');
        $p->setContentId('test');
    }

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