email-db tool: extract-attachment action, streaming, filename decoding, copy path fix
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -456,7 +456,16 @@ function parseAttachments(raw: string): AttachmentMeta[] {
|
||||
|
||||
// Extract filename from Content-Disposition or Content-Type
|
||||
const fnMatch = headerBlock.match(/filename\*?=(?:"([^"]+)"|([^\s;]+))/i);
|
||||
const filename = fnMatch ? (fnMatch[1] ?? fnMatch[2] ?? 'unknown') : 'unknown';
|
||||
let rawFilename = fnMatch ? (fnMatch[1] ?? fnMatch[2] ?? 'unknown') : 'unknown';
|
||||
// RFC 5987: filename*=charset''percent-encoded
|
||||
const rfc5987Match = rawFilename.match(/^([^']*)'[^']*'(.+)/);
|
||||
if (rfc5987Match) {
|
||||
const cs = normalizeCharset(rfc5987Match[1]!.toLowerCase() || 'utf-8');
|
||||
const encoded = rfc5987Match[2]!;
|
||||
const bytes = encoded.replace(/%([0-9A-Fa-f]{2})/g, (_, h: string) => String.fromCharCode(parseInt(h, 16)));
|
||||
rawFilename = new TextDecoder(cs, { fatal: false }).decode(Buffer.from(bytes, 'binary'));
|
||||
}
|
||||
const filename = decodeMimeWords(rawFilename);
|
||||
|
||||
// Extract content-type
|
||||
const ctMatch = headerBlock.match(/^Content-Type:\s*([^\s;]+)/im);
|
||||
|
||||
Reference in New Issue
Block a user