Bad case
String filename = "filename with ?问号.txt";
ContentDisposition cd = ContentDisposition.attachment()
.filename(filename, StandardCharsets.UTF_8)
.build();
String[] parts = cd.toString().split("; ");
// attachment; filename="=?UTF-8?Q?filename=20with=20?=E9=97=AE=E5=8F=B7.txt?="
String quotedPrintableFilename = parts[0] + "; " + parts[1];
// expected: filename with ?问号.txt
// actual: filename with
System.out.println(ContentDisposition.parse(quotedPrintableFilename).getFilename());
Cause
In previous implementation, the question mark (?) is not quoted. If a quoted character (=E9=97=AE) follows, the combination "?=" will be interpreted as end mark of "encoded-word".
8-bit values which correspond to printable ASCII characters other than "=", "?", and "_" (underscore), MAY be represented as those characters. https://www.rfc-editor.org/rfc/rfc2047#section-4.2
Comment From: poutsma
Thank you for submitting a PR. I have made a couple of changes also related to RFC 2047, so that spaces are now encoded as underscores, and that underscores themselves are handled as non-printable.