@bobfrankston/mailx-imap 0.1.23 → 0.1.24
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/index.js +67 -13
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -1871,19 +1871,70 @@ export class ImapManager extends EventEmitter {
|
|
|
1871
1871
|
// is parked in IDLE, it's unusable for any other command, so
|
|
1872
1872
|
// it can't share the ops queue. Counts against the per-host
|
|
1873
1873
|
// semaphore (one slot for the IDLE socket).
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1874
|
+
//
|
|
1875
|
+
// We watch INBOX (incoming mail) and Sent + Drafts (outgoing
|
|
1876
|
+
// changes from another client — Thunderbird, phone, web).
|
|
1877
|
+
// Without IDLE on Sent, a message just sent from another
|
|
1878
|
+
// device would only show in mailx after the next periodic
|
|
1879
|
+
// full sync.
|
|
1880
|
+
const stops = [];
|
|
1881
|
+
const clients = [];
|
|
1882
|
+
const watchOne = async (mailboxLabel, path) => {
|
|
1883
|
+
const client = await this.createClient(accountId, "idle");
|
|
1884
|
+
clients.push(client);
|
|
1885
|
+
const stop = await client.watchMailbox(path, (newCount) => {
|
|
1886
|
+
console.log(` [idle] ${accountId} ${path}: ${newCount} new message(s)`);
|
|
1887
|
+
if (mailboxLabel === "inbox") {
|
|
1888
|
+
// Fast path: incremental fetch of NEW UIDs only.
|
|
1889
|
+
// Heavy reconcile runs on the 5-minute STATUS poll.
|
|
1890
|
+
this.syncInboxNewOnly(accountId).catch(e => console.error(` [idle] inbox sync error: ${e.message}`));
|
|
1891
|
+
}
|
|
1892
|
+
else {
|
|
1893
|
+
// Sent / Drafts changed elsewhere. Use the
|
|
1894
|
+
// standard folder sync — picks up the new UID,
|
|
1895
|
+
// rebinds any optimistic local row by Message-ID.
|
|
1896
|
+
const folder = this.findFolder(accountId, mailboxLabel);
|
|
1897
|
+
if (folder) {
|
|
1898
|
+
this.syncFolder(accountId, folder.id).catch(e => console.error(` [idle] ${path} sync error: ${e.message}`));
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
});
|
|
1902
|
+
stops.push(stop);
|
|
1903
|
+
};
|
|
1904
|
+
await watchOne("inbox", "INBOX");
|
|
1905
|
+
const sent = this.findFolder(accountId, "sent");
|
|
1906
|
+
if (sent) {
|
|
1907
|
+
try {
|
|
1908
|
+
await watchOne("sent", sent.path);
|
|
1909
|
+
}
|
|
1910
|
+
catch (e) {
|
|
1911
|
+
console.error(` [idle] Failed to watch ${sent.path}: ${e.message}`);
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
const drafts = this.findFolder(accountId, "drafts");
|
|
1915
|
+
if (drafts) {
|
|
1916
|
+
try {
|
|
1917
|
+
await watchOne("drafts", drafts.path);
|
|
1918
|
+
}
|
|
1919
|
+
catch (e) {
|
|
1920
|
+
console.error(` [idle] Failed to watch ${drafts.path}: ${e.message}`);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1882
1923
|
this.watchers.set(accountId, async () => {
|
|
1883
|
-
|
|
1884
|
-
|
|
1924
|
+
for (const stop of stops) {
|
|
1925
|
+
try {
|
|
1926
|
+
await stop();
|
|
1927
|
+
}
|
|
1928
|
+
catch { /* ignore */ }
|
|
1929
|
+
}
|
|
1930
|
+
for (const c of clients) {
|
|
1931
|
+
try {
|
|
1932
|
+
await c.logout();
|
|
1933
|
+
}
|
|
1934
|
+
catch { /* ignore */ }
|
|
1935
|
+
}
|
|
1885
1936
|
});
|
|
1886
|
-
console.log(` [idle] Watching INBOX for ${accountId}`);
|
|
1937
|
+
console.log(` [idle] Watching INBOX${sent ? "+Sent" : ""}${drafts ? "+Drafts" : ""} for ${accountId}`);
|
|
1887
1938
|
}
|
|
1888
1939
|
catch (e) {
|
|
1889
1940
|
console.error(` [idle] Failed to watch ${accountId}: ${e.message}`);
|
|
@@ -2612,9 +2663,12 @@ export class ImapManager extends EventEmitter {
|
|
|
2612
2663
|
bodyPath,
|
|
2613
2664
|
});
|
|
2614
2665
|
// Folder-tree badge refresh + message-list reload if the user
|
|
2615
|
-
// is currently on Sent — same event the sync path emits.
|
|
2666
|
+
// is currently on Sent — same event shape the sync path emits.
|
|
2667
|
+
// (Was sending {accountId,folderId} as a single arg, which the
|
|
2668
|
+
// IPC forwarder + UI handler decoded as garbage — the optimistic
|
|
2669
|
+
// row landed in the DB but never appeared in the list.)
|
|
2616
2670
|
this.db.recalcFolderCounts(sent.id);
|
|
2617
|
-
this.emit("folderCountsChanged",
|
|
2671
|
+
this.emit("folderCountsChanged", accountId, {});
|
|
2618
2672
|
console.log(` [sent-local] wrote optimistic row in Sent (uid=${synthUid}) for ${accountId}: ${envelope.subject}`);
|
|
2619
2673
|
}
|
|
2620
2674
|
catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bobfrankston/mailx-imap",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@bobfrankston/mailx-types": "^0.1.10",
|
|
13
|
-
"@bobfrankston/mailx-settings": "^0.1.
|
|
14
|
-
"@bobfrankston/mailx-store": "^0.1.
|
|
13
|
+
"@bobfrankston/mailx-settings": "^0.1.13",
|
|
14
|
+
"@bobfrankston/mailx-store": "^0.1.10",
|
|
15
15
|
"@bobfrankston/iflow-direct": "^0.1.30",
|
|
16
16
|
"@bobfrankston/tcp-transport": "^0.1.5",
|
|
17
17
|
"@bobfrankston/smtp-direct": "^0.1.5",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
".transformedSnapshot": {
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@bobfrankston/mailx-types": "^0.1.10",
|
|
41
|
-
"@bobfrankston/mailx-settings": "^0.1.
|
|
42
|
-
"@bobfrankston/mailx-store": "^0.1.
|
|
41
|
+
"@bobfrankston/mailx-settings": "^0.1.13",
|
|
42
|
+
"@bobfrankston/mailx-store": "^0.1.10",
|
|
43
43
|
"@bobfrankston/iflow-direct": "^0.1.30",
|
|
44
44
|
"@bobfrankston/tcp-transport": "^0.1.5",
|
|
45
45
|
"@bobfrankston/smtp-direct": "^0.1.5",
|