@bobfrankston/mailx-imap 0.1.34 → 0.1.35

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.
Files changed (2) hide show
  1. package/index.js +44 -23
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -3124,33 +3124,54 @@ export class ImapManager extends EventEmitter {
3124
3124
  return;
3125
3125
  if (!draftUid && !draftId)
3126
3126
  return;
3127
- await this.withConnection(accountId, async (client) => {
3128
- if (draftUid) {
3129
- try {
3130
- await client.deleteMessageByUid(drafts.path, draftUid);
3131
- console.log(` [drafts] Deleted draft UID ${draftUid}`);
3132
- }
3133
- catch (e) {
3134
- console.error(` [drafts] Delete by UID ${draftUid} failed: ${e.message}`);
3127
+ let succeeded = false;
3128
+ try {
3129
+ await this.withConnection(accountId, async (client) => {
3130
+ if (draftUid) {
3131
+ try {
3132
+ await client.deleteMessageByUid(drafts.path, draftUid);
3133
+ console.log(` [drafts] Deleted draft UID ${draftUid}`);
3134
+ succeeded = true;
3135
+ }
3136
+ catch (e) {
3137
+ console.error(` [drafts] Delete by UID ${draftUid} failed: ${e.message}`);
3138
+ }
3135
3139
  }
3136
- }
3137
- if (draftId) {
3138
- try {
3139
- const uids = await client.searchByHeader(drafts.path, "X-Mailx-Draft-ID", draftId);
3140
- for (const uid of uids) {
3141
- try {
3142
- await client.deleteMessageByUid(drafts.path, uid);
3140
+ if (draftId) {
3141
+ try {
3142
+ const uids = await client.searchByHeader(drafts.path, "X-Mailx-Draft-ID", draftId);
3143
+ for (const uid of uids) {
3144
+ try {
3145
+ await client.deleteMessageByUid(drafts.path, uid);
3146
+ succeeded = true;
3147
+ }
3148
+ catch { /* next */ }
3143
3149
  }
3144
- catch { /* next */ }
3150
+ if (uids.length > 0)
3151
+ console.log(` [drafts] Deleted ${uids.length} draft(s) by ID ${draftId}`);
3152
+ }
3153
+ catch (e) {
3154
+ console.error(` [drafts] searchByHeader for ${draftId} failed: ${e.message}`);
3145
3155
  }
3146
- if (uids.length > 0)
3147
- console.log(` [drafts] Deleted ${uids.length} draft(s) by ID ${draftId}`);
3148
- }
3149
- catch (e) {
3150
- console.error(` [drafts] searchByHeader for ${draftId} failed: ${e.message}`);
3151
3156
  }
3152
- }
3153
- });
3157
+ });
3158
+ }
3159
+ catch (e) {
3160
+ // withConnection itself failed (no socket, auth refresh wedged) —
3161
+ // fall through to queue a retry if we have a UID to anchor on.
3162
+ console.error(` [drafts] withConnection failed for ${accountId}: ${e?.message || e}`);
3163
+ }
3164
+ // Reliable cleanup: if the inline attempt didn't actually delete the
3165
+ // draft, queue a sync_action so the regular processSyncActions loop
3166
+ // retries it later. Without this, transient IMAP failures left stale
3167
+ // drafts in the folder ("draft droppings" that pile up after sends).
3168
+ // Only the UID path can be queued — searchByHeader retries on every
3169
+ // future call anyway, and queuing a header-lookup isn't a real
3170
+ // sync_action shape.
3171
+ if (!succeeded && draftUid) {
3172
+ console.log(` [drafts] Queueing sync_action for retry: delete UID ${draftUid} in ${drafts.path}`);
3173
+ this.db.queueSyncAction(accountId, "delete", draftUid, drafts.id);
3174
+ }
3154
3175
  }
3155
3176
  /** Queue outgoing message locally — never fails, worker handles IMAP+SMTP.
3156
3177
  * Single path: write `~/.mailx/outbox/<acct>/*.ltr` synchronously, then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-imap",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@bobfrankston/mailx-types": "^0.1.10",
13
13
  "@bobfrankston/mailx-settings": "^0.1.14",
14
- "@bobfrankston/mailx-store": "^0.1.16",
14
+ "@bobfrankston/mailx-store": "^0.1.17",
15
15
  "@bobfrankston/iflow-direct": "^0.1.39",
16
16
  "@bobfrankston/tcp-transport": "^0.1.6",
17
17
  "@bobfrankston/smtp-direct": "^0.1.8",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@bobfrankston/mailx-types": "^0.1.10",
41
41
  "@bobfrankston/mailx-settings": "^0.1.14",
42
- "@bobfrankston/mailx-store": "^0.1.16",
42
+ "@bobfrankston/mailx-store": "^0.1.17",
43
43
  "@bobfrankston/iflow-direct": "^0.1.39",
44
44
  "@bobfrankston/tcp-transport": "^0.1.6",
45
45
  "@bobfrankston/smtp-direct": "^0.1.8",