Skip to content

Encode non-ASCII SMTP attachment file names according to RFC 2231 - #6757

Open
ashrafiucse wants to merge 1 commit into
apache:masterfrom
ashrafiucse:fix/jmeter-6652-smtp-filename
Open

Encode non-ASCII SMTP attachment file names according to RFC 2231#6757
ashrafiucse wants to merge 1 commit into
apache:masterfrom
ashrafiucse:fix/jmeter-6652-smtp-filename

Conversation

@ashrafiucse

Copy link
Copy Markdown

Description

Upgrade javax.mail from the 2013 beta javax.mail:mail:1.5.0-b01 to com.sun.mail:javax.mail:1.6.2, so that attachment file names containing non-ASCII characters are encoded according to RFC 2231.

The javax.mail.* namespace is unchanged, so no code changes are required. The dependency verification metadata already trusts the com.sun.mail group (PGP key 4F7E32D440EF90A83011A8FC6425559C47CC79C4), so no verification-metadata.xml changes were needed.

Motivation and Context

Fixes #6652

The SMTP Sampler mangles attachment file names that contain non-ASCII characters. Sending an attachment named текст.txt produces:

Content-Type: text/plain; charset=us-ascii;
        name="B5:AB-attachment....txt"
Content-Disposition: attachment;
        filename="B5:AB-attachment....txt"

so recipients see garbage instead of the original file name.

Root cause: SendMailCommand builds attachments with MimeBodyPart.setFileName(String). The old javax.mail:mail:1.5.0-b01 does not encode non-ASCII file name parameters according to RFC 2231.

As suggested by @FSchumacher on the issue, upgrading to 1.6.2 fixes the encoding. With this change the same attachment is now sent as:

Content-Type: text/plain; charset=us-ascii;
        name*=UTF-8''%D1%82%D0%B5%D0%BA%D1%81%D1%82.txt
Content-Disposition: attachment;
        filename*=UTF-8''%D1%82%D0%B5%D0%BA%D1%81%D1%82.txt

How Has This Been Tested?

  • New SendMailCommandTest:
    • testNonAsciiAttachmentFileNameIsEncodedPerRfc2231: builds a message (via prepareMessage(), no SMTP server needed) with an attachment named текст.txt and asserts the raw message contains filename*=UTF-8''%D1%82%D0%B5%D0%BA%D1%81%D1%82.txt and no mangled name
    • testAsciiAttachmentFileNameIsNotEncoded: asserts pure ASCII names are still emitted as plain filename=attachment.txt (no RFC 2231 encoding)
  • Full :src:protocol:mail:test (4 tests) and :src:components:test (549 tests, MailReaderSampler shares the dependency) suites pass
  • ./gradlew classes style passes
  • Verified the original repro end-to-end against a locally built distribution

Screenshots (if appropriate):

Not applicable (raw SMTP headers shown above).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly. (release notes entry added to xdocs/changes.xml)

The SMTP Sampler used javax.mail 1.5.0-b01, which mangles attachment
file names that contain non-ASCII characters (for example a file named
"текст.txt" was sent as "B5:AB.txt"), so recipients could not see the
original file name.

Update javax.mail to 1.6.2 (com.sun.mail:javax.mail), which encodes
non-ASCII file name parameters according to RFC 2231. The javax.mail
namespace is unchanged, so no code changes are needed.

Closes apache#6652
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SMTP Sampler incorrectly encodes non-ASCII filenames in email attachments

1 participant