FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Invalid Content-ID generated for attachments with special characters in filename · Issue #607 · bbottema/simple-java-mail · GitHub

Invalid Content-ID generated for attachments with special characters in filename #607

Description

Summary
When building emails with attachments using emailBuilder.withAttachment(...), SimpleJavaMail generates down the road a Content-ID header based on the attachment name. For filenames that contain characters not allowed by RFC 5322’s msg-id syntax, the resulting Content-ID is invalid.

Details
The Content-ID is currently generated like this:

Content-ID: <attachment-name@random-UUID>

(see MimeMessageHelper::getBodyPartFromDatasource()).

However, the Content-ID field should use the msg-id syntax from RFC 5322, which restricts the allowed characters to letters, digits, and some symbols: ! # $ % & ' * + - / = ? ^ _ { | } ~`

Below is a snippet of an email generated by SimpleJavaMail:

------=_Part_10_854134233.1763546189190
Content-Type: text/plain;
  filename="Attachment %^$(()_()&^&^^:@/\\|{}[]#~`- special chars.txt";
  name="Attachment %^$(()_()&^&^^:@/\\|{}[]#~`- special chars.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
  filename="Attachment %^$(()_()&^&^^:@/\\|{}[]#~`- special chars.txt"
Content-ID: <Attachment %^$(()_()&^&^^:@/\|{}[]#~`- special chars.txt@c4c3733b-786d-45be-ae15-ba78f11246f9>

Attachment with special chars
------=_Part_10_854134233.1763546189190--

Notice how the Content-ID contains multiple characters not permitted by RFC 5322.

Expected result
Process the Content-ID header to replace invalid characters with underscore, or similar. For example, something like this (AI generated):

fileName.replaceAll("[^A-Za-z0-9!#$%&'*+\\-/=?^_`{|}~]", "_");

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL