fix(mail-ingest): read a mail of bare sender lines in one pass

isBareHeaderBlock rescanned the header run below every sender line, so a
plain-text mail of nothing but "From:" lines without a subject took
quadratic time and held the event loop for seconds before the address was
even checked. The block starts are now worked out for all lines in one pass
from the bottom up, with the same rule.
This commit is contained in:
Maurice
2026-11-16 10:45:21 +01:00
parent aa8d041a33
commit 5b0412bc2c
2 changed files with 61 additions and 10 deletions
@@ -240,6 +240,41 @@ describe('walkMail: forwarded and quoted messages', () => {
expect(walked.body).toBe('');
expect(walked.forwardLayers).toBe(10);
});
it('MIME-WALK-016: a run of sender lines ending in a subject goes, the run without one under it stays', () => {
const walked = walk(
mail(
'From: ana@example.org',
'Content-Type: text/plain; charset=utf-8',
'',
'From: a',
'From: b',
'From: Ferry <info@ferry.example>',
'Subject: Ticket',
'',
'From: Naxos',
'To: Piraeus',
'',
'Ferry ticket F-12',
'',
),
);
expect(walked.body).toBe('From: Naxos\nTo: Piraeus\n\nFerry ticket F-12');
expect(walked.forwardLayers).toBe(1);
});
it(
'MIME-WALK-017: a mail of nothing but sender lines is read in one pass instead of rescanning them per line',
{ timeout: 5_000 },
() => {
const lines = 30_000;
const walked = walk(
mail('From: ana@example.org', 'Content-Type: text/plain', '', ...Array<string>(lines).fill('From: a'), ''),
);
expect(walked.body.split('\n')).toHaveLength(lines);
expect(walked.forwardLayers).toBe(0);
},
);
});
describe('walkMail: attachments', () => {