@bobfrankston/mailx 1.0.299 → 1.0.301
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/package.json +1 -1
- package/packages/mailx-imap/index.js +25 -3
package/package.json
CHANGED
|
@@ -659,8 +659,18 @@ export class ImapManager extends EventEmitter {
|
|
|
659
659
|
let messages;
|
|
660
660
|
const firstSync = highestUid === 0;
|
|
661
661
|
const historyDays = getHistoryDays(accountId);
|
|
662
|
-
//
|
|
663
|
-
|
|
662
|
+
// IMAP: historyDays=0 (unlimited) is dangerous — "SEARCH SINCE 1970"
|
|
663
|
+
// asks the server to enumerate every message, which Dovecot times out
|
|
664
|
+
// on (300s). Cap at 90 days for IMAP. Gmail API handles 0 fine via
|
|
665
|
+
// pagination. The first-sync cap (30) applies when starting from
|
|
666
|
+
// scratch so the UI isn't empty for minutes.
|
|
667
|
+
const isGmail = this.isGmailAccount(accountId);
|
|
668
|
+
const MAX_IMAP_DAYS = 90;
|
|
669
|
+
let effectiveDays = historyDays;
|
|
670
|
+
if (historyDays === 0 && !isGmail)
|
|
671
|
+
effectiveDays = MAX_IMAP_DAYS;
|
|
672
|
+
if (effectiveDays === 0 && firstSync)
|
|
673
|
+
effectiveDays = 30;
|
|
664
674
|
const startDate = effectiveDays > 0
|
|
665
675
|
? new Date(Date.now() - effectiveDays * 86400000)
|
|
666
676
|
: new Date(0);
|
|
@@ -1060,8 +1070,20 @@ export class ImapManager extends EventEmitter {
|
|
|
1060
1070
|
console.log(` [api] ${accountId}/${folder.path}: syncing (highestUid=${highestUid})...`);
|
|
1061
1071
|
let messages;
|
|
1062
1072
|
if (highestUid > 0) {
|
|
1063
|
-
// Incremental: fetch messages since last known UID
|
|
1073
|
+
// Incremental: fetch messages since last known UID.
|
|
1074
|
+
// Gmail "UIDs" are hashed (not chronological), so fetchSince
|
|
1075
|
+
// returns messages in hash order — they can be from ANY date.
|
|
1076
|
+
// Filter by the history window so years-old messages don't
|
|
1077
|
+
// suddenly flood the inbox on every incremental sync.
|
|
1064
1078
|
messages = await api.fetchSince(folder.path, highestUid, { source: false });
|
|
1079
|
+
if (effectiveDays > 0) {
|
|
1080
|
+
const cutoff = startDate.getTime();
|
|
1081
|
+
const before = messages.length;
|
|
1082
|
+
messages = messages.filter(m => !m.date || m.date.getTime() >= cutoff);
|
|
1083
|
+
if (messages.length < before) {
|
|
1084
|
+
console.log(` [api] ${accountId}/${folder.path}: filtered ${before - messages.length} messages older than ${effectiveDays}d`);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1065
1087
|
}
|
|
1066
1088
|
else {
|
|
1067
1089
|
// First sync: fetch by date range
|