Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions imap-core/lib/indexer/parse-mime-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ class MIMEParser {
// which are encoded with lang/charset info as well as a continuation.
// See https://tools.ietf.org/html/rfc2231 section 4.1.

if ((match = key.match(/^([^*]+)\*(\d)?\*?$/))) {
if ((match = key.match(/^([^*]+)\*(\d+)?\*?$/))) {
if (!processEncodedWords[match[1]]) {
processEncodedWords[match[1]] = [];

// Additionally allow RFC5987 section 3.2.1 encoded values
// Additionally allow RFC2231 encoded values
if (key.match(/^([^*]+)\*(?:\d+\*)?$/)) {
// must have charset
charsetRequired.add(processEncodedWords[match[1]]);
Expand Down
26 changes: 26 additions & 0 deletions imap-core/test/parse-mime-tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,24 @@ describe('#parseFilename (MIMEParser-driven)', function () {
});
});

it('continuation concatenates out-of-order sections in numeric order (unencoded)', function () {
let headers =
'Content-Disposition: attachment; ' +
'filename*0="part-0"; filename*3="part-3"; filename*2="part-2"; filename*5="part-5"; filename*4="part-4"';
expect(parseFilename(headers)).to.deep.equal({
filename: 'part-0part-2part-3part-4part-5',
source: 'filename*0'
});
});

it('continuation supports multi-digit section numbers (unencoded)', function () {
let headers = 'Content-Disposition: attachment; filename*0="part-A"; filename*10="part-K"';
expect(parseFilename(headers)).to.deep.equal({
filename: 'part-Apart-K',
source: 'filename*0'
});
});

it('continuation with missing segment concatenates existing parts (encoded)', function () {
let headers = "Content-Disposition: attachment; filename*0*=UTF-8''A; filename*2*=C";
expect(parseFilename(headers)).to.deep.equal({
Expand All @@ -408,6 +426,14 @@ describe('#parseFilename (MIMEParser-driven)', function () {
});
});

it('continuation concatenates out-of-order sections in numeric order (encoded)', function () {
let headers = "Content-Disposition: attachment; filename*0*=UTF-8''A; filename*3*=D; filename*2*=C; filename*5*=F; filename*4*=E";
expect(parseFilename(headers)).to.deep.equal({
filename: 'ACDEF',
source: 'filename*0*'
});
});

// 4) Malformed/no-charset behavior in current MIMEParser (lenient/quirky by design).
it('malformed filename* with empty charset does not fall back automatically', function () {
let headers = "Content-Disposition: attachment; filename*=''r%C3%A9sum%C3%A9.pdf";
Expand Down