@bobfrankston/rmfmail 1.1.2 → 1.1.3
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/bin/mailx.js +9 -1
- package/bin/mailx.js.map +1 -1
- package/bin/mailx.ts +10 -1
- package/client/android-bootstrap.bundle.js +1 -1
- package/client/android-bootstrap.bundle.js.map +2 -2
- package/client/app.bundle.js +58 -1
- package/client/app.bundle.js.map +2 -2
- package/client/compose/compose.bundle.js +41 -1
- package/client/compose/compose.bundle.js.map +2 -2
- package/client/lib/api-client.js +41 -0
- package/client/lib/api-client.js.map +1 -1
- package/client/lib/api-client.ts +29 -0
- package/client/lib/message-state.js +23 -0
- package/client/lib/message-state.js.map +1 -1
- package/client/lib/message-state.ts +21 -0
- package/package.json +3 -3
- package/packages/mailx-bus/index.d.ts +2 -0
- package/packages/mailx-bus/index.d.ts.map +1 -1
- package/packages/mailx-bus/index.js +9 -0
- package/packages/mailx-bus/index.js.map +1 -1
- package/packages/mailx-bus/index.ts +11 -0
- package/packages/mailx-bus/package.json +1 -1
- package/packages/mailx-bus/store-events.d.ts +79 -0
- package/packages/mailx-bus/store-events.d.ts.map +1 -0
- package/packages/mailx-bus/store-events.js +155 -0
- package/packages/mailx-bus/store-events.js.map +1 -0
- package/packages/mailx-bus/store-events.ts +165 -0
- package/packages/mailx-core/index.d.ts.map +1 -1
- package/packages/mailx-core/index.js +25 -3
- package/packages/mailx-core/index.js.map +1 -1
- package/packages/mailx-core/index.ts +23 -3
- package/packages/mailx-host/package.json +1 -1
- package/packages/mailx-imap/index.d.ts +0 -37
- package/packages/mailx-imap/index.d.ts.map +1 -1
- package/packages/mailx-imap/index.js +17 -172
- package/packages/mailx-imap/index.js.map +1 -1
- package/packages/mailx-imap/index.ts +17 -179
- package/packages/mailx-imap/package-lock.json +2 -2
- package/packages/mailx-imap/package.json +1 -1
- package/packages/mailx-service/index.d.ts +16 -0
- package/packages/mailx-service/index.d.ts.map +1 -1
- package/packages/mailx-service/index.js +89 -77
- package/packages/mailx-service/index.js.map +1 -1
- package/packages/mailx-service/index.ts +83 -75
- package/packages/mailx-service/local-store.d.ts +54 -2
- package/packages/mailx-service/local-store.d.ts.map +1 -1
- package/packages/mailx-service/local-store.js +147 -2
- package/packages/mailx-service/local-store.js.map +1 -1
- package/packages/mailx-service/local-store.ts +147 -3
- package/packages/mailx-service/reconciler.d.ts.map +1 -1
- package/packages/mailx-service/reconciler.js +28 -8
- package/packages/mailx-service/reconciler.js.map +1 -1
- package/packages/mailx-service/reconciler.ts +28 -8
- package/packages/mailx-service/sync-queue.d.ts +16 -0
- package/packages/mailx-service/sync-queue.d.ts.map +1 -1
- package/packages/mailx-service/sync-queue.js +33 -3
- package/packages/mailx-service/sync-queue.js.map +1 -1
- package/packages/mailx-service/sync-queue.ts +33 -3
- package/packages/mailx-settings/package.json +1 -1
- package/packages/mailx-store/bus.d.ts +79 -0
- package/packages/mailx-store/bus.d.ts.map +1 -0
- package/packages/mailx-store/bus.js +155 -0
- package/packages/mailx-store/bus.js.map +1 -0
- package/packages/mailx-store/index.d.ts +2 -0
- package/packages/mailx-store/index.d.ts.map +1 -1
- package/packages/mailx-store/index.js +5 -0
- package/packages/mailx-store/index.js.map +1 -1
- package/packages/mailx-store/index.ts +7 -0
- package/packages/mailx-store/package.json +2 -1
- package/packages/mailx-store-web/db.d.ts.map +1 -1
- package/packages/mailx-store-web/db.js +9 -1
- package/packages/mailx-store-web/db.js.map +1 -1
- package/packages/mailx-store-web/db.ts +9 -1
- package/packages/mailx-store-web/package.json +2 -1
- package/packages/mailx-store-web/sync-manager.d.ts +4 -0
- package/packages/mailx-store-web/sync-manager.d.ts.map +1 -1
- package/packages/mailx-store-web/sync-manager.js +32 -4
- package/packages/mailx-store-web/sync-manager.js.map +1 -1
- package/packages/mailx-store-web/sync-manager.ts +28 -4
- /package/packages/mailx-imap/{node_modules.npmglobalize-stash-36832 → node_modules.npmglobalize-stash-444}/.package-lock.json +0 -0
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { createAutoImapConfig, CompatImapClient } from "@bobfrankston/iflow-direct";
|
|
7
7
|
import { authenticateOAuth } from "@bobfrankston/oauthsupport";
|
|
8
|
-
import { FileMessageStore, parseSerial } from "@bobfrankston/mailx-store";
|
|
8
|
+
import { FileMessageStore, parseSerial, storeBus } from "@bobfrankston/mailx-store";
|
|
9
9
|
import { loadSettings, getStorePath, getConfigDir, getHistoryDays, getPrefetch } from "@bobfrankston/mailx-settings";
|
|
10
10
|
import { EventEmitter } from "node:events";
|
|
11
11
|
import * as fs from "node:fs";
|
|
@@ -216,6 +216,22 @@ export class ImapManager extends EventEmitter {
|
|
|
216
216
|
console.log(` [reconcile-cancel] ${info.accountId} ${info.fromFolderId}/${info.fromUid}: deferred delete cancelled (move-detect rebound to ${info.toFolderId}/${info.toUid})`);
|
|
217
217
|
}
|
|
218
218
|
});
|
|
219
|
+
// Bridge legacy EventEmitter "folderCountsChanged" to the Store bus
|
|
220
|
+
// so subscribers can listen on a single mechanism. Done in-class
|
|
221
|
+
// rather than at every call site (~20 emit points in this file) to
|
|
222
|
+
// keep the diff small and avoid a per-call regression risk during
|
|
223
|
+
// the refactor. The Store bus is the long-term home; once every
|
|
224
|
+
// consumer subscribes via the bus, the legacy listeners in
|
|
225
|
+
// bin/mailx.ts get retired and the `this.emit("folderCountsChanged"...)`
|
|
226
|
+
// calls can convert in bulk.
|
|
227
|
+
this.on("folderCountsChanged", (accountId, payload) => {
|
|
228
|
+
storeBus.publish({
|
|
229
|
+
topic: `account:${accountId}`,
|
|
230
|
+
kind: "folderCountsChanged",
|
|
231
|
+
accountId,
|
|
232
|
+
folderId: payload?.folderId,
|
|
233
|
+
});
|
|
234
|
+
});
|
|
219
235
|
}
|
|
220
236
|
/** Get OAuth access token for an account (for SMTP auth) */
|
|
221
237
|
async getOAuthToken(accountId) {
|
|
@@ -2928,131 +2944,6 @@ export class ImapManager extends EventEmitter {
|
|
|
2928
2944
|
getBodyStore() {
|
|
2929
2945
|
return this.bodyStore;
|
|
2930
2946
|
}
|
|
2931
|
-
/** Bulk trash messages — local-first, single IMAP connection for all */
|
|
2932
|
-
async trashMessages(accountId, messages) {
|
|
2933
|
-
if (messages.length === 0)
|
|
2934
|
-
return;
|
|
2935
|
-
const trash = this.findFolder(accountId, "trash");
|
|
2936
|
-
// Tombstone each Message-ID so sync won't re-import the source-folder
|
|
2937
|
-
// row before the server-side MOVE completes. Cleared on permanent
|
|
2938
|
-
// failure (clearTombstoneForUid in processSyncActions).
|
|
2939
|
-
for (const msg of messages) {
|
|
2940
|
-
const env = this.db.getMessageByUid(accountId, msg.uid, msg.folderId);
|
|
2941
|
-
if (env?.messageId)
|
|
2942
|
-
this.db.addTombstone(accountId, env.messageId, env.subject || "");
|
|
2943
|
-
}
|
|
2944
|
-
// Local first — move to trash folder locally so the row stays
|
|
2945
|
-
// visible in Trash and Ctrl+Z can restore it. Body file stays in
|
|
2946
|
-
// its original folder dir; the next sync rebinds path on
|
|
2947
|
-
// membership uid change. Old behavior was `db.deleteMessage` +
|
|
2948
|
-
// `unlinkBodyFile` which made undelete impossible (no row to
|
|
2949
|
-
// restore, no body to read). For folders that ARE the trash
|
|
2950
|
-
// already, fall through to hard delete (the action will EXPUNGE
|
|
2951
|
-
// and reconciliation cleans up).
|
|
2952
|
-
for (const msg of messages) {
|
|
2953
|
-
if (trash && trash.id !== msg.folderId) {
|
|
2954
|
-
this.db.moveMessageLocal(accountId, msg.uid, msg.folderId, trash.id);
|
|
2955
|
-
}
|
|
2956
|
-
else {
|
|
2957
|
-
this.unlinkBodyFile(accountId, msg.uid, msg.folderId).catch(() => { });
|
|
2958
|
-
this.db.deleteMessage(accountId, msg.uid, "user-initiated trash (already in trash → expunge)", "mailx-imap trashMessages");
|
|
2959
|
-
}
|
|
2960
|
-
}
|
|
2961
|
-
console.log(` Trashed ${messages.length} messages locally (moved to trash folder, body files retained)`);
|
|
2962
|
-
// Queue IMAP actions
|
|
2963
|
-
for (const msg of messages) {
|
|
2964
|
-
if (trash && trash.id !== msg.folderId) {
|
|
2965
|
-
this.db.queueSyncAction(accountId, "move", msg.uid, msg.folderId, { targetFolderId: trash.id });
|
|
2966
|
-
}
|
|
2967
|
-
else {
|
|
2968
|
-
this.db.queueSyncAction(accountId, "delete", msg.uid, msg.folderId);
|
|
2969
|
-
}
|
|
2970
|
-
}
|
|
2971
|
-
// Recalc folder counts so the tree badge updates immediately instead
|
|
2972
|
-
// of showing stale numbers until the next full sync.
|
|
2973
|
-
const sourceFolderIds = new Set(messages.map(m => m.folderId));
|
|
2974
|
-
for (const fid of sourceFolderIds)
|
|
2975
|
-
this.db.recalcFolderCounts(fid);
|
|
2976
|
-
if (trash)
|
|
2977
|
-
this.db.recalcFolderCounts(trash.id);
|
|
2978
|
-
this.emit("folderCountsChanged", accountId, {});
|
|
2979
|
-
// Process all queued actions in one IMAP session
|
|
2980
|
-
this.debounceSyncActions(accountId);
|
|
2981
|
-
}
|
|
2982
|
-
/** Bulk move messages — queues the IMAP action only. The service layer
|
|
2983
|
-
* (MailxService.moveMessages) owns the local DB mutation via
|
|
2984
|
-
* updateMessageFolder; this method used to ALSO deleteMessage here,
|
|
2985
|
-
* which wiped the row the service just updated — the message vanished
|
|
2986
|
-
* on the next reconcile and "spam folder empty" was the symptom. */
|
|
2987
|
-
async moveMessages(accountId, messages, targetFolderId) {
|
|
2988
|
-
if (messages.length === 0)
|
|
2989
|
-
return;
|
|
2990
|
-
for (const msg of messages) {
|
|
2991
|
-
this.db.queueSyncAction(accountId, "move", msg.uid, msg.folderId, { targetFolderId });
|
|
2992
|
-
}
|
|
2993
|
-
console.log(` [move] ${accountId}: queued IMAP MOVE for ${messages.length} message(s) → folder ${targetFolderId}`);
|
|
2994
|
-
this.debounceSyncActions(accountId);
|
|
2995
|
-
}
|
|
2996
|
-
/** Debounced sync actions — batches rapid local changes into one IMAP operation */
|
|
2997
|
-
syncActionTimers = new Map();
|
|
2998
|
-
debounceSyncActions(accountId) {
|
|
2999
|
-
const existing = this.syncActionTimers.get(accountId);
|
|
3000
|
-
if (existing)
|
|
3001
|
-
clearTimeout(existing);
|
|
3002
|
-
this.syncActionTimers.set(accountId, setTimeout(() => {
|
|
3003
|
-
this.syncActionTimers.delete(accountId);
|
|
3004
|
-
this.processSyncActions(accountId).catch(() => { });
|
|
3005
|
-
}, 1000));
|
|
3006
|
-
}
|
|
3007
|
-
/** Move a message to Trash (delete) — local-first, queues IMAP sync */
|
|
3008
|
-
async trashMessage(accountId, folderId, uid) {
|
|
3009
|
-
const trash = this.findFolder(accountId, "trash");
|
|
3010
|
-
// Tombstone the Message-ID so sync won't re-import the row in the
|
|
3011
|
-
// source folder before the server-side move completes. Cleared on
|
|
3012
|
-
// permanent failure of the queued sync_action (see processSyncActions
|
|
3013
|
-
// catch block, where clearTombstoneForUid runs after attempts >= 5)
|
|
3014
|
-
// so the user sees the row reappear when their action didn't take.
|
|
3015
|
-
const env = this.db.getMessageByUid(accountId, uid, folderId);
|
|
3016
|
-
if (env?.messageId)
|
|
3017
|
-
this.db.addTombstone(accountId, env.messageId, env.subject || "");
|
|
3018
|
-
// Local first — move to trash folder so the row stays visible in
|
|
3019
|
-
// Trash and Ctrl+Z can restore. Body file retained for undelete.
|
|
3020
|
-
// If we're already in trash (or no trash configured), fall through
|
|
3021
|
-
// to hard delete + EXPUNGE.
|
|
3022
|
-
if (trash && trash.id !== folderId) {
|
|
3023
|
-
this.db.moveMessageLocal(accountId, uid, folderId, trash.id);
|
|
3024
|
-
}
|
|
3025
|
-
else {
|
|
3026
|
-
this.unlinkBodyFile(accountId, uid, folderId).catch(() => { });
|
|
3027
|
-
this.db.deleteMessage(accountId, uid, "user-initiated trash (already in trash → expunge)", "mailx-imap trashMessage");
|
|
3028
|
-
}
|
|
3029
|
-
// Queue IMAP action + log the resolution so "I deleted a message and
|
|
3030
|
-
// now it's in neither trash nor deleted" is diagnosable from the log.
|
|
3031
|
-
if (trash && trash.id !== folderId) {
|
|
3032
|
-
const trashFolder = this.db.getFolders(accountId).find(f => f.id === trash.id);
|
|
3033
|
-
this.db.queueSyncAction(accountId, "move", uid, folderId, { targetFolderId: trash.id });
|
|
3034
|
-
console.log(` [trash] ${accountId} UID ${uid}: queued MOVE to "${trashFolder?.path || trash.path}" (id=${trash.id}, specialUse=trash)`);
|
|
3035
|
-
}
|
|
3036
|
-
else {
|
|
3037
|
-
this.db.queueSyncAction(accountId, "delete", uid, folderId);
|
|
3038
|
-
console.log(` [trash] ${accountId} UID ${uid}: queued EXPUNGE in folder ${folderId} (already in trash or no trash configured)`);
|
|
3039
|
-
}
|
|
3040
|
-
// Folder counts moved — refresh both source and trash so the
|
|
3041
|
-
// tree badges update immediately, not at the next sync.
|
|
3042
|
-
this.db.recalcFolderCounts(folderId);
|
|
3043
|
-
if (trash && trash.id !== folderId)
|
|
3044
|
-
this.db.recalcFolderCounts(trash.id);
|
|
3045
|
-
this.emit("folderCountsChanged", accountId, {});
|
|
3046
|
-
// Debounced sync — batches multiple deletes into one IMAP session
|
|
3047
|
-
this.debounceSyncActions(accountId);
|
|
3048
|
-
}
|
|
3049
|
-
/** Move a message between folders — queues IMAP sync only. Service
|
|
3050
|
-
* layer owns the local DB update (see MailxService.moveMessage). */
|
|
3051
|
-
async moveMessage(accountId, uid, fromFolderId, toFolderId) {
|
|
3052
|
-
this.db.queueSyncAction(accountId, "move", uid, fromFolderId, { targetFolderId: toFolderId });
|
|
3053
|
-
console.log(` [move] ${accountId}: queued IMAP MOVE UID ${uid} folder ${fromFolderId} → ${toFolderId}`);
|
|
3054
|
-
this.debounceSyncActions(accountId);
|
|
3055
|
-
}
|
|
3056
2947
|
/** Move message across accounts using iflow's moveMessageToServer */
|
|
3057
2948
|
async moveMessageCrossAccount(fromAccountId, uid, fromFolderId, toAccountId, toFolderId) {
|
|
3058
2949
|
const fromFolders = this.db.getFolders(fromAccountId);
|
|
@@ -3078,52 +2969,6 @@ export class ImapManager extends EventEmitter {
|
|
|
3078
2969
|
});
|
|
3079
2970
|
});
|
|
3080
2971
|
}
|
|
3081
|
-
/** Undelete — move from Trash back to original folder. Local-first:
|
|
3082
|
-
* the row was moved (not deleted) on trash, so we just move it back
|
|
3083
|
-
* in the local DB and reconcile the IMAP queue. Two cases:
|
|
3084
|
-
* (a) the to-trash MOVE is still pending — cancel it; the server
|
|
3085
|
-
* never saw the delete, so no counter-action is needed.
|
|
3086
|
-
* (b) the to-trash MOVE drained — the message is now in Trash on
|
|
3087
|
-
* the server with a new uid. Queue a counter-move from
|
|
3088
|
-
* trash → original. The IMAP processor's fetchByUid in trash
|
|
3089
|
-
* will use the local membership uid (which the reconciler
|
|
3090
|
-
* rebound to the server's new trash uid via Message-ID match).
|
|
3091
|
-
* If reconcile hasn't run yet (unlikely race), action retries
|
|
3092
|
-
* until it does. */
|
|
3093
|
-
async undeleteMessage(accountId, uid, originalFolderId) {
|
|
3094
|
-
const trash = this.findFolder(accountId, "trash");
|
|
3095
|
-
if (!trash)
|
|
3096
|
-
throw new Error("No Trash folder found");
|
|
3097
|
-
// Move locally back to the original folder.
|
|
3098
|
-
const moved = this.db.moveMessageLocal(accountId, uid, trash.id, originalFolderId);
|
|
3099
|
-
if (!moved) {
|
|
3100
|
-
console.log(` [undelete] ${accountId} UID ${uid}: no row in trash — nothing to restore locally (sync may have already pruned)`);
|
|
3101
|
-
}
|
|
3102
|
-
// (a) cancel still-pending to-trash action.
|
|
3103
|
-
const pending = this.db.findPendingSyncAction(accountId, "move", uid, originalFolderId, trash.id);
|
|
3104
|
-
if (pending) {
|
|
3105
|
-
this.db.completeSyncAction(pending.id);
|
|
3106
|
-
console.log(` [undelete] ${accountId} UID ${uid}: cancelled pending MOVE to trash (server never saw delete)`);
|
|
3107
|
-
this.emit("folderCountsChanged", accountId, {});
|
|
3108
|
-
return;
|
|
3109
|
-
}
|
|
3110
|
-
// (b) queue counter-move from trash → original.
|
|
3111
|
-
this.db.queueSyncAction(accountId, "move", uid, trash.id, { targetFolderId: originalFolderId });
|
|
3112
|
-
console.log(` [undelete] ${accountId} UID ${uid}: queued counter-MOVE trash → folder ${originalFolderId}`);
|
|
3113
|
-
this.debounceSyncActions(accountId);
|
|
3114
|
-
this.emit("folderCountsChanged", accountId, {});
|
|
3115
|
-
}
|
|
3116
|
-
/** Update flags — local-first, queues IMAP sync */
|
|
3117
|
-
async updateFlagsLocal(accountId, uid, folderId, flags) {
|
|
3118
|
-
this.db.updateMessageFlags(accountId, uid, flags);
|
|
3119
|
-
this.db.queueSyncAction(accountId, "flags", uid, folderId, { flags });
|
|
3120
|
-
// User-visible pink-dot pending state stays until the action drains.
|
|
3121
|
-
// The 30-second periodic tick was too slow — opening one message to
|
|
3122
|
-
// auto-mark-as-read left it pink for half a minute. Same 1-second
|
|
3123
|
-
// debounce as moves/deletes batches rapid flag churn without the
|
|
3124
|
-
// visual lag.
|
|
3125
|
-
this.debounceSyncActions(accountId);
|
|
3126
|
-
}
|
|
3127
2972
|
/** Process pending sync actions for an account */
|
|
3128
2973
|
async processSyncActions(accountId) {
|
|
3129
2974
|
const actions = this.db.getPendingSyncActions(accountId);
|