@bobfrankston/mailx-store 0.1.36 → 0.1.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/file-store.d.ts +10 -1
- package/file-store.js +26 -1
- package/package.json +3 -3
- package/store.d.ts +5 -0
- package/store.js +2 -0
package/file-store.d.ts
CHANGED
|
@@ -26,7 +26,16 @@ export declare class FileMessageStore implements MessageStore {
|
|
|
26
26
|
private resolveStored;
|
|
27
27
|
/** Write a new body. Returns a path RELATIVE to basePath; caller stores
|
|
28
28
|
* it in `body_path`. The (folderId, uid) args are kept for interface
|
|
29
|
-
* compatibility; they do NOT affect the filename.
|
|
29
|
+
* compatibility; they do NOT affect the filename.
|
|
30
|
+
*
|
|
31
|
+
* Defensive content check: if the FIRST line of the would-be .eml
|
|
32
|
+
* matches an IMAP client-command pattern (`<tag> <UPPERCASE_CMD> ...`),
|
|
33
|
+
* the upstream IMAP parser desynced and wrote one of mailx's own
|
|
34
|
+
* outbound commands into the response stream — see the
|
|
35
|
+
* a39a84e1853441bcac09e1b3e1463e8d.eml corruption (2026-05-23). Refuse
|
|
36
|
+
* the write rather than persist garbage that the message-viewer will
|
|
37
|
+
* later render as broken. The caller's exception path treats this the
|
|
38
|
+
* same as any other transient fetch error; the reconciler re-enqueues. */
|
|
30
39
|
putMessage(accountId: string, _folderId: number, _uid: number, raw: Buffer): Promise<string>;
|
|
31
40
|
/** Resolve a stored body_path (relative or absolute) to an absolute
|
|
32
41
|
* filesystem path. Returns "" if the input doesn't resolve to a file
|
package/file-store.js
CHANGED
|
@@ -43,8 +43,33 @@ export class FileMessageStore {
|
|
|
43
43
|
}
|
|
44
44
|
/** Write a new body. Returns a path RELATIVE to basePath; caller stores
|
|
45
45
|
* it in `body_path`. The (folderId, uid) args are kept for interface
|
|
46
|
-
* compatibility; they do NOT affect the filename.
|
|
46
|
+
* compatibility; they do NOT affect the filename.
|
|
47
|
+
*
|
|
48
|
+
* Defensive content check: if the FIRST line of the would-be .eml
|
|
49
|
+
* matches an IMAP client-command pattern (`<tag> <UPPERCASE_CMD> ...`),
|
|
50
|
+
* the upstream IMAP parser desynced and wrote one of mailx's own
|
|
51
|
+
* outbound commands into the response stream — see the
|
|
52
|
+
* a39a84e1853441bcac09e1b3e1463e8d.eml corruption (2026-05-23). Refuse
|
|
53
|
+
* the write rather than persist garbage that the message-viewer will
|
|
54
|
+
* later render as broken. The caller's exception path treats this the
|
|
55
|
+
* same as any other transient fetch error; the reconciler re-enqueues. */
|
|
47
56
|
async putMessage(accountId, _folderId, _uid, raw) {
|
|
57
|
+
if (raw.length >= 6) {
|
|
58
|
+
// Look at the first ≤512 bytes to spot a leaked IMAP command.
|
|
59
|
+
// Pattern: optional CRLFs, then `<tag> <CMD> ...` where tag
|
|
60
|
+
// starts with a letter+digits (iflow tags are like `A123`,
|
|
61
|
+
// `B47`) and CMD is all-caps with at least 4 chars.
|
|
62
|
+
const sniff = raw.subarray(0, Math.min(512, raw.length)).toString("ascii");
|
|
63
|
+
const firstNonBlank = sniff.replace(/^\s+/, "");
|
|
64
|
+
// Strict: tag is letter + digits, then a space, then an
|
|
65
|
+
// all-caps IMAP command keyword. Real RFC822 headers can't
|
|
66
|
+
// match because they require a `Name: value` shape (colon),
|
|
67
|
+
// and `Return-Path:`, `Received:`, `Subject:` etc. are
|
|
68
|
+
// capitalized but include a colon and mixed case in tokens.
|
|
69
|
+
if (/^[A-Z]+\d+ (UID )?(FETCH|SEARCH|STORE|COPY|MOVE|EXPUNGE|SELECT|EXAMINE|APPEND|LIST|LSUB|STATUS|NOOP|IDLE|DONE|LOGIN|LOGOUT|CAPABILITY|AUTHENTICATE)\b/.test(firstNonBlank)) {
|
|
70
|
+
throw new Error(`putMessage: refusing to write corrupt body — IMAP command leaked into response stream (first line: ${firstNonBlank.split(/\r?\n/)[0].substring(0, 100)})`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
48
73
|
const rel = this.newRelativePath(accountId);
|
|
49
74
|
const abs = path.join(this.basePath, rel);
|
|
50
75
|
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bobfrankston/mailx-store",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@bobfrankston/mailx-types": "^0.1.18",
|
|
13
|
-
"@bobfrankston/mailx-settings": "^0.1.
|
|
13
|
+
"@bobfrankston/mailx-settings": "^0.1.24",
|
|
14
14
|
"@bobfrankston/mailx-bus": "^0.1.2",
|
|
15
15
|
"mailparser": "^3.7.2"
|
|
16
16
|
},
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
".transformedSnapshot": {
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@bobfrankston/mailx-types": "^0.1.18",
|
|
33
|
-
"@bobfrankston/mailx-settings": "^0.1.
|
|
33
|
+
"@bobfrankston/mailx-settings": "^0.1.24",
|
|
34
34
|
"@bobfrankston/mailx-bus": "^0.1.2",
|
|
35
35
|
"mailparser": "^3.7.2"
|
|
36
36
|
}
|
package/store.d.ts
CHANGED
|
@@ -58,6 +58,11 @@ export interface StoreMessage extends MessageEnvelope {
|
|
|
58
58
|
listUnsubscribeOneClick: boolean;
|
|
59
59
|
emlPath: string;
|
|
60
60
|
isFlagged: boolean;
|
|
61
|
+
/** X-Mailx-Draft-ID header value (empty for non-draft messages). When
|
|
62
|
+
* the user re-opens a draft for edit, the compose layer threads this
|
|
63
|
+
* back into saveDraft so the server-side dedup keeps replacing the
|
|
64
|
+
* same draft instead of stacking up a new one every save. */
|
|
65
|
+
mailxDraftId: string;
|
|
61
66
|
}
|
|
62
67
|
export declare class Store {
|
|
63
68
|
/** SQLite metadata index. Exposed as a public field — sync clients
|
package/store.js
CHANGED
|
@@ -400,6 +400,7 @@ export class Store {
|
|
|
400
400
|
return String(v);
|
|
401
401
|
};
|
|
402
402
|
const returnPath = hdr("return-path").replace(/[<>]/g, "");
|
|
403
|
+
const mailxDraftId = hdr("x-mailx-draft-id").trim();
|
|
403
404
|
const { listUnsubscribeMail, listUnsubscribeHttp, listUnsubscribeOneClick } = parseListUnsubscribe(parsed.headers);
|
|
404
405
|
const listUnsubscribe = listUnsubscribeHttp || listUnsubscribeMail;
|
|
405
406
|
const result = {
|
|
@@ -416,6 +417,7 @@ export class Store {
|
|
|
416
417
|
// basePath every time.
|
|
417
418
|
emlPath: this.bodyStore.absolutePath(storedPath),
|
|
418
419
|
isFlagged,
|
|
420
|
+
mailxDraftId,
|
|
419
421
|
};
|
|
420
422
|
// Memoize for instant re-view of the same message. cacheKey is
|
|
421
423
|
// path+mtime so a re-fetch (mtime changes) invalidates naturally.
|