@bobfrankston/mailx-imap 0.1.49 → 0.1.51

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 +21 -10
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -3039,7 +3039,13 @@ export class ImapManager extends EventEmitter {
3039
3039
  console.log(` [api] ${accountId}: flags synced UID ${action.uid}`);
3040
3040
  }
3041
3041
  else if ((action.action === "delete" || action.action === "trash") && api.trashMessage) {
3042
- await api.trashMessage(folder.path, action.uid);
3042
+ // Pass the stored Gmail message id (provider_id) so
3043
+ // the provider doesn't fall back to its capped
3044
+ // list-and-hash search — that search misses any
3045
+ // message past the most-recent ~1000 in a large
3046
+ // mailbox, fails, and the deletion un-happens.
3047
+ const env = this.db.getMessageByUid(accountId, action.uid);
3048
+ await api.trashMessage(folder.path, action.uid, env?.providerId);
3043
3049
  console.log(` [api] ${accountId}: trashed UID ${action.uid} from ${folder.path}`);
3044
3050
  }
3045
3051
  else if (action.action === "move" && api.moveMessage) {
@@ -3050,7 +3056,8 @@ export class ImapManager extends EventEmitter {
3050
3056
  this.db.completeSyncAction(action.id);
3051
3057
  continue;
3052
3058
  }
3053
- await api.moveMessage(folder.path, action.uid, target.path);
3059
+ const env = this.db.getMessageByUid(accountId, action.uid);
3060
+ await api.moveMessage(folder.path, action.uid, target.path, env?.providerId);
3054
3061
  console.log(` [api] ${accountId}: moved UID ${action.uid} ${folder.path} → ${target.path}`);
3055
3062
  }
3056
3063
  else {
@@ -4309,16 +4316,20 @@ export class ImapManager extends EventEmitter {
4309
4316
  const res = await fetch(url, {
4310
4317
  headers: { Authorization: `Bearer ${token}` },
4311
4318
  });
4312
- if (res.status === 410) {
4313
- // Sync token expired (Google retains tokens for ~7 days).
4314
- // Drop the stored token and recurse for a full sync — the
4315
- // in-flight guard is on syncGoogleContacts (the public
4316
- // wrapper), not Impl, so recursion is safe.
4317
- this.db.setKv("contacts", accountId, null);
4318
- return this.syncGoogleContactsImpl(accountId);
4319
- }
4320
4319
  if (!res.ok) {
4321
4320
  const err = await res.text();
4321
+ // Expired sync token. The People API returns HTTP 400
4322
+ // FAILED_PRECONDITION with reason EXPIRED_SYNC_TOKEN
4323
+ // (older docs / older behavior said 410 — handle both
4324
+ // by inspecting the body). The documented recovery is:
4325
+ // drop the token and re-call WITHOUT it (full sync).
4326
+ // The `syncToken` guard prevents infinite recursion if a
4327
+ // tokenless full sync itself somehow returns this.
4328
+ if (syncToken && /EXPIRED_SYNC_TOKEN|sync token is expired/i.test(err)) {
4329
+ console.log(` [contacts] ${accountId}: sync token expired — clearing for full resync`);
4330
+ this.db.setKv("contacts", accountId, null);
4331
+ return this.syncGoogleContactsImpl(accountId);
4332
+ }
4322
4333
  console.error(` [contacts] API error for ${accountId}: ${res.status} ${err}`);
4323
4334
  return changed;
4324
4335
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-imap",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
- "@bobfrankston/mailx-types": "^0.1.14",
12
+ "@bobfrankston/mailx-types": "^0.1.15",
13
13
  "@bobfrankston/mailx-settings": "^0.1.17",
14
14
  "@bobfrankston/mailx-store": "^0.1.28",
15
15
  "@bobfrankston/iflow-direct": "^0.1.50",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  ".transformedSnapshot": {
39
39
  "dependencies": {
40
- "@bobfrankston/mailx-types": "^0.1.14",
40
+ "@bobfrankston/mailx-types": "^0.1.15",
41
41
  "@bobfrankston/mailx-settings": "^0.1.17",
42
42
  "@bobfrankston/mailx-store": "^0.1.28",
43
43
  "@bobfrankston/iflow-direct": "^0.1.50",