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:
2026-03-02 20:00:45 +00:00
co-authored by Claude Opus 4.6
parent 2752102a7e
commit 192ae63c0e
4 changed files with 118 additions and 24 deletions
+10 -1
View File
@@ -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);
@@ -384,12 +384,12 @@ export const useFileBrowserApp = (basePath: string, rootOverride?: string, initi
};
const handleCopyPath = (entry: DirEntry) => {
navigator.clipboard.writeText(absPath(entryPath(entry.name)));
navigator.clipboard.writeText(`~${entryPath(entry.name)}`);
toast.success('Path copied');
};
const handleCopyCurrentPath = () => {
navigator.clipboard.writeText(absPath(currentPath));
navigator.clipboard.writeText(`~${currentPath}`);
toast.success('Path copied');
};