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

Skip to content

[Mailer][Mailgun] Mailgun transport silently ignore any attachments with non-ascii characters in its name #42586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
faizanakram99 opened this issue Aug 16, 2021 · 7 comments

Comments

@faizanakram99
Copy link
Contributor

Symfony version(s) affected: 5.3.6

Description
Mailgun transport silently ignore any attachments with non-ascii characters in its name like Confirmación cliente. If I remove ó from filename, it works as expected.
Not that with smtp transport, it work fine.

NOTE: It used to work fine with swift-mailer-bundle with mailgun transport.

How to reproduce
Here is a reproducer.
https://github.com/faizanakram99/symfony-mailer-mailgun-bug-reproducer

Possible Solution

Additional context
I guess the actual problem might be in symfony/http-client , considering it works with smtp transport

@faizanakram99 faizanakram99 changed the title [MAILER] Mailgun transport silently ignore any attachments with non-ascii characters in its name [Mailer][Mailgun] Mailgun transport silently ignore any attachments with non-ascii characters in its name Aug 16, 2021
@zspine
Copy link

zspine commented Aug 16, 2021

@faizanakram99 #41651 similar?

@faizanakram99
Copy link
Contributor Author

faizanakram99 commented Aug 16, 2021

@faizanakram99 #41651 similar?

@zspine Not sure tbh. Emails are sent while attachments with non-ascii characters in its filename are ignored (no errors whatsoever).

For now I used symfony string component to fix it.

// ....
use Symfony\Component\Mime\Email;
use function Symfony\Component\String\u;
// ....

$message = new Email();

// ....

$message->attach(
    $attachmentHandle,
    u($filename)->ascii()->toString(),
    $mimeType,
);

@zspine
Copy link

zspine commented Aug 16, 2021

@faizanakram99 I haven't tested but it's definitely seems like a bug!

@hluup
Copy link
Contributor

hluup commented Aug 17, 2021

FYI. Found something similar in unrelated repositories' issue queue.
anymail/django-anymail#125 (comment)

Here's an example. I'm able to reproduce the first problem like this (using the Mailgun backend):


from django.core.mail import EmailMessage
msg = EmailMessage(to=["[email protected]"], 
                   subject="Mailgun attachment test", 
                   body="This has attachments")
msg.attach("ascii-name.txt", "some data", "text/plain")
msg.attach("unicøde-name.txt", "more data", "text/plain")
msg.send()

When this is sent, the attachment with the all-ASCII name makes it through, but the one with a Unicode character is silently dropped.

As I can understand, it seems to be related how the filenames are encoded in request's body.

@OskarStark
Copy link
Contributor

OskarStark commented Aug 19, 2021

Open for a PR and check the filenames via mb_detect_encoding($str, 'ASCII', true) and raise an exception otherwise ?

I think adding symfony/string as a dependency to mailgun mailer is a bit overkill for this case.

WDYT @nicolas-grekas ?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Aug 19, 2021

This might be similar to #41249
We need to figure out the proper way to encode UTF-8 file names before rejecting them.

@symfony symfony deleted a comment from OskarStark Aug 19, 2021
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants