@marlinjai/email-mcp 1.2.6 → 1.2.7
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/dist/index.js +36 -42
- package/dist/index.js.map +2 -2
- package/dist/setup/wizard.js +36 -42
- package/dist/setup/wizard.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8398,34 +8398,28 @@ var init_adapter3 = __esm({
|
|
|
8398
8398
|
throw formatImapError(error48, `Failed to open folder "${folder}"`);
|
|
8399
8399
|
}
|
|
8400
8400
|
try {
|
|
8401
|
-
|
|
8401
|
+
const mailboxExists = this.client.mailbox?.exists ?? 0;
|
|
8402
|
+
let statusCount = 0;
|
|
8402
8403
|
try {
|
|
8403
8404
|
const status = await this.client.status(folder, { messages: true });
|
|
8404
|
-
|
|
8405
|
+
statusCount = status.messages ?? 0;
|
|
8405
8406
|
} catch {
|
|
8406
8407
|
}
|
|
8407
|
-
const
|
|
8408
|
-
|
|
8409
|
-
if (effectiveCount <= 0) {
|
|
8408
|
+
const effectiveCount = Math.max(mailboxExists, statusCount);
|
|
8409
|
+
if (effectiveCount === 0) {
|
|
8410
8410
|
return [];
|
|
8411
8411
|
}
|
|
8412
8412
|
const criteria = this.buildSearchCriteria(query);
|
|
8413
8413
|
const hasCriteria = Object.keys(criteria).length > 0;
|
|
8414
|
-
let allUids;
|
|
8414
|
+
let allUids = [];
|
|
8415
8415
|
try {
|
|
8416
8416
|
const searchResult = await this.client.search(
|
|
8417
8417
|
hasCriteria ? criteria : { all: true },
|
|
8418
8418
|
{ uid: true }
|
|
8419
8419
|
);
|
|
8420
8420
|
allUids = Array.isArray(searchResult) ? searchResult : [];
|
|
8421
|
-
} catch
|
|
8422
|
-
|
|
8423
|
-
const isInvalidMessage = errorMsg.includes("invalid message");
|
|
8424
|
-
if (isInvalidMessage || !hasCriteria) {
|
|
8425
|
-
allUids = await this.collectUidsViaFetch(query);
|
|
8426
|
-
} else {
|
|
8427
|
-
throw searchError;
|
|
8428
|
-
}
|
|
8421
|
+
} catch {
|
|
8422
|
+
allUids = await this.collectUidsViaFetch(query);
|
|
8429
8423
|
}
|
|
8430
8424
|
const offset = query.offset || 0;
|
|
8431
8425
|
const slicedUids = query.limit ? allUids.slice(offset, offset + query.limit) : allUids.slice(offset);
|
|
@@ -8447,39 +8441,39 @@ var init_adapter3 = __esm({
|
|
|
8447
8441
|
async collectUidsViaFetch(query) {
|
|
8448
8442
|
if (!this.client) return [];
|
|
8449
8443
|
const uids = [];
|
|
8450
|
-
|
|
8451
|
-
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
const exists = this.client.mailbox?.exists ?? 0;
|
|
8459
|
-
if (exists > 0) {
|
|
8460
|
-
try {
|
|
8461
|
-
for await (const msg of this.client.fetch(`1:${exists}`, { uid: true, flags: true })) {
|
|
8462
|
-
if (query.unreadOnly && msg.flags?.has("\\Seen")) continue;
|
|
8463
|
-
if (query.starredOnly && !msg.flags?.has("\\Flagged")) continue;
|
|
8464
|
-
uids.push(msg.uid);
|
|
8465
|
-
}
|
|
8466
|
-
return uids;
|
|
8467
|
-
} catch {
|
|
8444
|
+
const exists = this.client.mailbox?.exists ?? 0;
|
|
8445
|
+
const safeFetch = async (range) => {
|
|
8446
|
+
try {
|
|
8447
|
+
const messages = await this.client.fetchAll(range, { uid: true, flags: true });
|
|
8448
|
+
for (const msg of messages) {
|
|
8449
|
+
if (query.unreadOnly && msg.flags?.has("\\Seen")) continue;
|
|
8450
|
+
if (query.starredOnly && !msg.flags?.has("\\Flagged")) continue;
|
|
8451
|
+
uids.push(msg.uid);
|
|
8468
8452
|
}
|
|
8453
|
+
return uids.length > 0;
|
|
8454
|
+
} catch {
|
|
8455
|
+
return false;
|
|
8469
8456
|
}
|
|
8470
|
-
|
|
8471
|
-
|
|
8472
|
-
|
|
8473
|
-
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8457
|
+
};
|
|
8458
|
+
if (await safeFetch("1:*")) return uids;
|
|
8459
|
+
uids.length = 0;
|
|
8460
|
+
if (exists > 0) {
|
|
8461
|
+
if (await safeFetch(`1:${exists}`)) return uids;
|
|
8462
|
+
uids.length = 0;
|
|
8463
|
+
}
|
|
8464
|
+
const count = exists > 0 ? exists : 50;
|
|
8465
|
+
for (let seq = 1; seq <= count; seq++) {
|
|
8466
|
+
try {
|
|
8467
|
+
const msgs = await this.client.fetchAll(String(seq), { uid: true, flags: true });
|
|
8468
|
+
for (const msg of msgs) {
|
|
8469
|
+
if (query.unreadOnly && msg.flags?.has("\\Seen")) continue;
|
|
8470
|
+
if (query.starredOnly && !msg.flags?.has("\\Flagged")) continue;
|
|
8471
|
+
uids.push(msg.uid);
|
|
8479
8472
|
}
|
|
8473
|
+
} catch {
|
|
8480
8474
|
}
|
|
8481
|
-
return uids;
|
|
8482
8475
|
}
|
|
8476
|
+
return uids;
|
|
8483
8477
|
}
|
|
8484
8478
|
/**
|
|
8485
8479
|
* Fetches email data for a set of UIDs, either with full body or lightweight headers.
|