Email Attachment Filename Issue

Hi,

Since I’ve upgraded to framework v7 I’m having trouble with sending emails with attachments that have long filenames. The Content-Disposition header is;

Content-disposition: attachment;
filename="=UTF-8Q12345678901234562173736783287487787897989237894322342342342423433434578797897983535.pdf="
Content-transfer-encoding: base64

I believe that the filename is wrongly formatted, it should be something like:

filename*=UTF-8’'Na%C3%AFve%20file.txt

WIth the * in. Anyone know why this occurs only for long filenames? It used to work okay, not the attachments have =UTF in the actual filename

Hi,

Can you please provide the exact attachment file name you have used?

Also, what is your deployment environment? Maybe there is another version of javax.mail implementation library on the classpath which causes the trouble?

Hi Alex,

The filename for instance could be:

{supplier_reference} AUTO_TEST_GTC Gas MeterGas Service And Met.pdf

In the email headers it’s shown as

=UTF-8Q{supplier=5Freference} AUTO=5FTEST=5FGTC Gas Service And Met.pdf=

With smaller (around 20 character filenames) filenames the problem doesn’t occur. Delving into java mailer I can see the class ParameterList splits the name if more than 60 characters if mail.mime.splitlongparameters is true. I am trying to set that as false in JAVA_OPTS to see if that helps but not successful at the moment (am I setting that in the right place?)

For the deployment environment I’m using the uberJar configuration.

Java.mail is coming from the jar “javaee-api:8.0.jar”

I have been able to replicate on a standard project with the following code to send a test email (I can’t work out how to zip the project otherwise I would attach it all)

`
// Queues an email for sending asynchronously
private void sendByEmail() {
//public EmailInfo(String addresses, String caption, @Nullable String from, String body, String bodyContentType,
// EmailAttachment… attachments) {

    EmailAttachment emailAttachment = EmailAttachment.createTextAttachment("test attachment", "utf8", "test4787429379473927894789732895774375893248975893427895789324789578934275897342897589732489758932479857923475984334897598.txt");

    EmailInfo emailInfo = new EmailInfo(
            "test@example.com", // recipients
            "test send", // subject
            null, // the "from" address will be taken from the "cuba.email.fromAddress" app property
            "This is a test email 2", // template parameters
            EmailInfo.TEXT_CONTENT_TYPE,
            emailAttachment

    );
    emailService.sendEmailAsync(emailInfo);
}

`

Hi Mark.

We have found the reason for this behavior and are now deciding whether it should be changed and how. I will let you know when any updates appear.

Regards,
Oleg.

Hi Oleg,

Many thanks. If it helps, this used to work in v6.x and in the standalone project in v7 I set the system property “mail.mime.splitlongparameters” to false and the filename comes across as expected when that is set.

The email naming conventions and standards obviously allow for the splitting of names so it is odd that it doesn’t work as expected.

GitHub issue for this problem: Email Attachment Filename Issue · Issue #2352 · cuba-platform/cuba · GitHub

1 Like

The issue was closed.
The problem with attachment names should disappear in upcoming releases.