Skip to content
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

Attachment (file)names with special characters should not be encoded #271

Closed
barkep opened this issue May 26, 2020 · 5 comments
Closed

Attachment (file)names with special characters should not be encoded #271

barkep opened this issue May 26, 2020 · 5 comments

Comments

@barkep
Copy link

barkep commented May 26, 2020

When adding an attachment:
Testowy_załącznik_ąśćńółęĄŻŹĆŃÓŁĘ.txt
to an email and positive delivery, the recipient receives the attachment with the changed name:
=UTF-8_Q_Testowy=5Fza=C5=82=C4=85cznik=5F= =UTF-8_Q=C4=85=C5=9B=C4=87=C5=84=C3=B3=C5=82=C4=99=C4=84=C5=BB_= =UTF-8_Q=C5=B9=C4=86=C5=83=C3=93=C5=81=C4=98.txt_=.txt

After a small investigation, I find that the reason for this is using
MimeUtility.encodeText (name, UTF_8.name (), "B")
for the name of the attachment. I suggest using one of two solutions:

  • adding a parameter that allows you to skip this action for attachments
  • skipping this action for attachments
@barkep barkep changed the title Changing the name of the attachment when shipping Renaming the attachment when sending an email May 27, 2020
@bbottema
Copy link
Owner

This is valid encoding according to the RFC, but the client seems to parse it incorrectly. In what email client does the recipient view this result?

@barkep
Copy link
Author

barkep commented Jun 22, 2020

The attachment has an incorrect name directly, for example gmail.com.
The characters in the file name are important.

Sample code reproducing the error.

        String host = "smtp.gmail.com";
        int port = 587;
        String name = "";
        String password = "";
        TransportStrategy transportStrategy = TransportStrategy.SMTP_TLS;

        String path = "E://Testowy_załącznik_ąśćńółęĄŻŹĆŃÓŁĘ.txt";
        File file = new File(path);
        DataSource ds = new FileDataSource(file);

        Email email = EmailBuilder
                .startingBlank()
                .from("")
                .to("")
                .withSubject("test")
                .withAttachment("Testowy_załącznik_ąśćńółęĄŻŹĆŃÓŁĘ.txt", ds)
                .buildEmail();
        Mailer mailer = MailerBuilder
                .withSMTPServer(host, port, name, password)
                .withTransportStrategy(transportStrategy)
                .buildMailer();

        mailer.sendMail(email);

@bbottema
Copy link
Owner

bbottema commented Jul 12, 2020

Also see: https://javaee.github.io/javamail/FAQ#encodefilename

I'm going to turn off encoding of filenames, while making sure file names are tested for injection attacks.

@bbottema bbottema added this to the 6.3.2 milestone Jul 12, 2020
@bbottema bbottema changed the title Renaming the attachment when sending an email Attachment (file)names with special characters should not be encoded Jul 12, 2020
bbottema added a commit that referenced this issue Jul 12, 2020
…/image file names are tested for injection attacks. Update the master demo
@bbottema
Copy link
Owner

Fix released in 6.3.2

@LevStolpner
Copy link

LevStolpner commented Sep 2, 2020

@bbottema
Hi!
Thanks for this fix, was waiting for this update.
I have a related question regarding EmailConverter.
I wanted to check in test attachment file names, and was using method mimeMessageToEmail.
It was not working, I checked the call chain, and it seems that method buildEmailFromMimeMessage takes ContentId as attachment file name instead of actual not-encoded filename.
Is that a bug, or maybe I am not using EmailConverter correctly?

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

3 participants