@essentialai/cogent-bridge-bundled 3.23.4 → 3.23.6
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/cogent-bridge.mjs +455 -275
- package/package.json +1 -1
package/cogent-bridge.mjs
CHANGED
|
@@ -1259,8 +1259,8 @@ var init_parseUtil = __esm({
|
|
|
1259
1259
|
init_errors();
|
|
1260
1260
|
init_en();
|
|
1261
1261
|
makeIssue = (params) => {
|
|
1262
|
-
const { data, path:
|
|
1263
|
-
const fullPath = [...
|
|
1262
|
+
const { data, path: path25, errorMaps, issueData } = params;
|
|
1263
|
+
const fullPath = [...path25, ...issueData.path || []];
|
|
1264
1264
|
const fullIssue = {
|
|
1265
1265
|
...issueData,
|
|
1266
1266
|
path: fullPath
|
|
@@ -1540,11 +1540,11 @@ var init_types = __esm({
|
|
|
1540
1540
|
init_parseUtil();
|
|
1541
1541
|
init_util();
|
|
1542
1542
|
ParseInputLazyPath = class {
|
|
1543
|
-
constructor(parent, value,
|
|
1543
|
+
constructor(parent, value, path25, key) {
|
|
1544
1544
|
this._cachedPath = [];
|
|
1545
1545
|
this.parent = parent;
|
|
1546
1546
|
this.data = value;
|
|
1547
|
-
this._path =
|
|
1547
|
+
this._path = path25;
|
|
1548
1548
|
this._key = key;
|
|
1549
1549
|
}
|
|
1550
1550
|
get path() {
|
|
@@ -4996,10 +4996,10 @@ function assignProp(target, prop, value) {
|
|
|
4996
4996
|
configurable: true
|
|
4997
4997
|
});
|
|
4998
4998
|
}
|
|
4999
|
-
function getElementAtPath(obj,
|
|
5000
|
-
if (!
|
|
4999
|
+
function getElementAtPath(obj, path25) {
|
|
5000
|
+
if (!path25)
|
|
5001
5001
|
return obj;
|
|
5002
|
-
return
|
|
5002
|
+
return path25.reduce((acc, key) => acc?.[key], obj);
|
|
5003
5003
|
}
|
|
5004
5004
|
function promiseAllObject(promisesObj) {
|
|
5005
5005
|
const keys = Object.keys(promisesObj);
|
|
@@ -5248,11 +5248,11 @@ function aborted(x, startIndex = 0) {
|
|
|
5248
5248
|
}
|
|
5249
5249
|
return false;
|
|
5250
5250
|
}
|
|
5251
|
-
function prefixIssues(
|
|
5251
|
+
function prefixIssues(path25, issues) {
|
|
5252
5252
|
return issues.map((iss) => {
|
|
5253
5253
|
var _a;
|
|
5254
5254
|
(_a = iss).path ?? (_a.path = []);
|
|
5255
|
-
iss.path.unshift(
|
|
5255
|
+
iss.path.unshift(path25);
|
|
5256
5256
|
return iss;
|
|
5257
5257
|
});
|
|
5258
5258
|
}
|
|
@@ -17058,8 +17058,8 @@ var require_utils = __commonJS({
|
|
|
17058
17058
|
}
|
|
17059
17059
|
return ind;
|
|
17060
17060
|
}
|
|
17061
|
-
function removeDotSegments(
|
|
17062
|
-
let input =
|
|
17061
|
+
function removeDotSegments(path25) {
|
|
17062
|
+
let input = path25;
|
|
17063
17063
|
const output = [];
|
|
17064
17064
|
let nextSlash = -1;
|
|
17065
17065
|
let len = 0;
|
|
@@ -17258,8 +17258,8 @@ var require_schemes = __commonJS({
|
|
|
17258
17258
|
wsComponent.secure = void 0;
|
|
17259
17259
|
}
|
|
17260
17260
|
if (wsComponent.resourceName) {
|
|
17261
|
-
const [
|
|
17262
|
-
wsComponent.path =
|
|
17261
|
+
const [path25, query] = wsComponent.resourceName.split("?");
|
|
17262
|
+
wsComponent.path = path25 && path25 !== "/" ? path25 : void 0;
|
|
17263
17263
|
wsComponent.query = query;
|
|
17264
17264
|
wsComponent.resourceName = void 0;
|
|
17265
17265
|
}
|
|
@@ -20612,12 +20612,12 @@ var require_dist = __commonJS({
|
|
|
20612
20612
|
throw new Error(`Unknown format "${name}"`);
|
|
20613
20613
|
return f;
|
|
20614
20614
|
};
|
|
20615
|
-
function addFormats(ajv, list,
|
|
20615
|
+
function addFormats(ajv, list, fs23, exportName) {
|
|
20616
20616
|
var _a;
|
|
20617
20617
|
var _b;
|
|
20618
20618
|
(_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
20619
20619
|
for (const f of list)
|
|
20620
|
-
ajv.addFormat(f,
|
|
20620
|
+
ajv.addFormat(f, fs23[f]);
|
|
20621
20621
|
}
|
|
20622
20622
|
module.exports = exports = formatsPlugin;
|
|
20623
20623
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -21729,8 +21729,8 @@ var require_parseUtil = __commonJS({
|
|
|
21729
21729
|
var errors_js_1 = require_errors2();
|
|
21730
21730
|
var en_js_1 = __importDefault(require_en());
|
|
21731
21731
|
var makeIssue2 = (params) => {
|
|
21732
|
-
const { data, path:
|
|
21733
|
-
const fullPath = [...
|
|
21732
|
+
const { data, path: path25, errorMaps, issueData } = params;
|
|
21733
|
+
const fullPath = [...path25, ...issueData.path || []];
|
|
21734
21734
|
const fullIssue = {
|
|
21735
21735
|
...issueData,
|
|
21736
21736
|
path: fullPath
|
|
@@ -21884,11 +21884,11 @@ var require_types2 = __commonJS({
|
|
|
21884
21884
|
var parseUtil_js_1 = require_parseUtil();
|
|
21885
21885
|
var util_js_1 = require_util2();
|
|
21886
21886
|
var ParseInputLazyPath2 = class {
|
|
21887
|
-
constructor(parent, value,
|
|
21887
|
+
constructor(parent, value, path25, key) {
|
|
21888
21888
|
this._cachedPath = [];
|
|
21889
21889
|
this.parent = parent;
|
|
21890
21890
|
this.data = value;
|
|
21891
|
-
this._path =
|
|
21891
|
+
this._path = path25;
|
|
21892
21892
|
this._key = key;
|
|
21893
21893
|
}
|
|
21894
21894
|
get path() {
|
|
@@ -26389,8 +26389,8 @@ var init_stdio2 = __esm({
|
|
|
26389
26389
|
// src/constants.ts
|
|
26390
26390
|
import { createRequire } from "node:module";
|
|
26391
26391
|
function resolveVersion() {
|
|
26392
|
-
if ("3.23.
|
|
26393
|
-
return "3.23.
|
|
26392
|
+
if ("3.23.6") {
|
|
26393
|
+
return "3.23.6";
|
|
26394
26394
|
}
|
|
26395
26395
|
try {
|
|
26396
26396
|
const require2 = createRequire(import.meta.url);
|
|
@@ -27826,7 +27826,7 @@ var init_http_backend = __esm({
|
|
|
27826
27826
|
* in cloud mode we ignore it and use this.sessionId (the cloud session).
|
|
27827
27827
|
*/
|
|
27828
27828
|
async registerPeer(peerId, _sessionId, cwd, label, clientVersion, mode, _channelSessionId, capabilities, workspaceId, threadId, peerSecret) {
|
|
27829
|
-
const
|
|
27829
|
+
const path25 = PATHS.peers.replace(":sessionId", this.sessionId);
|
|
27830
27830
|
const body = {
|
|
27831
27831
|
peerId,
|
|
27832
27832
|
cwd,
|
|
@@ -27857,7 +27857,7 @@ var init_http_backend = __esm({
|
|
|
27857
27857
|
if (peerSecret !== void 0 && await relaySupports(this.http, "peer-ownership")) {
|
|
27858
27858
|
body.peerSecret = peerSecret;
|
|
27859
27859
|
}
|
|
27860
|
-
return this.http.post(
|
|
27860
|
+
return this.http.post(path25, body);
|
|
27861
27861
|
}
|
|
27862
27862
|
/**
|
|
27863
27863
|
* Deregister a peer from the cloud session.
|
|
@@ -27869,9 +27869,9 @@ var init_http_backend = __esm({
|
|
|
27869
27869
|
* local mail creds. A 404 (peer not found) resolves to `{ removed: false, ... }`, not a throw.
|
|
27870
27870
|
*/
|
|
27871
27871
|
async deregisterPeer(peerId) {
|
|
27872
|
-
const
|
|
27872
|
+
const path25 = PATHS.peer.replace(":sessionId", this.sessionId).replace(":peerId", peerId);
|
|
27873
27873
|
try {
|
|
27874
|
-
const headers = await this.http.delete(
|
|
27874
|
+
const headers = await this.http.delete(path25, {});
|
|
27875
27875
|
const mailboxDeprovisioned = headers.get(MAILBOX_DEPROVISIONED_HEADER) === "true";
|
|
27876
27876
|
return { removed: true, mailboxDeprovisioned };
|
|
27877
27877
|
} catch (err) {
|
|
@@ -27895,8 +27895,8 @@ var init_http_backend = __esm({
|
|
|
27895
27895
|
* GET /api/sessions/:sessionId/peers
|
|
27896
27896
|
*/
|
|
27897
27897
|
async listPeers() {
|
|
27898
|
-
const
|
|
27899
|
-
const result = await this.http.get(
|
|
27898
|
+
const path25 = PATHS.peers.replace(":sessionId", this.sessionId);
|
|
27899
|
+
const result = await this.http.get(path25);
|
|
27900
27900
|
return result.peers;
|
|
27901
27901
|
}
|
|
27902
27902
|
/**
|
|
@@ -27904,8 +27904,8 @@ var init_http_backend = __esm({
|
|
|
27904
27904
|
* Calls the lightweight heartbeat endpoint on the cloud relay server.
|
|
27905
27905
|
*/
|
|
27906
27906
|
async updateLastSeen(peerId) {
|
|
27907
|
-
const
|
|
27908
|
-
await this.http.post(
|
|
27907
|
+
const path25 = PATHS.heartbeat.replace(":sessionId", this.sessionId);
|
|
27908
|
+
await this.http.post(path25, { peerId });
|
|
27909
27909
|
}
|
|
27910
27910
|
/**
|
|
27911
27911
|
* Record a message in the cloud session.
|
|
@@ -27916,7 +27916,7 @@ var init_http_backend = __esm({
|
|
|
27916
27916
|
* the input record to construct a full MessageRecord.
|
|
27917
27917
|
*/
|
|
27918
27918
|
async recordMessage(record2) {
|
|
27919
|
-
const
|
|
27919
|
+
const path25 = PATHS.messages.replace(":sessionId", this.sessionId);
|
|
27920
27920
|
const body = {
|
|
27921
27921
|
fromPeerId: record2.fromPeerId,
|
|
27922
27922
|
toPeerId: record2.toPeerId,
|
|
@@ -27939,7 +27939,7 @@ var init_http_backend = __esm({
|
|
|
27939
27939
|
if (record2.attachments && record2.attachments.length > 0) {
|
|
27940
27940
|
body.attachments = record2.attachments;
|
|
27941
27941
|
}
|
|
27942
|
-
const resp = await this.http.post(
|
|
27942
|
+
const resp = await this.http.post(path25, body);
|
|
27943
27943
|
return {
|
|
27944
27944
|
...record2,
|
|
27945
27945
|
id: resp.id,
|
|
@@ -27953,7 +27953,7 @@ var init_http_backend = __esm({
|
|
|
27953
27953
|
* Supports optional peerId filter and limit (default 300).
|
|
27954
27954
|
*/
|
|
27955
27955
|
async getHistory(peerId, limit, includeRelayEchoes, metadataOnly, dedupInferredEchoes) {
|
|
27956
|
-
const
|
|
27956
|
+
const path25 = PATHS.messages.replace(":sessionId", this.sessionId);
|
|
27957
27957
|
const query = {};
|
|
27958
27958
|
if (peerId) {
|
|
27959
27959
|
query.peerId = peerId;
|
|
@@ -27968,7 +27968,7 @@ var init_http_backend = __esm({
|
|
|
27968
27968
|
if (dedupInferredEchoes) {
|
|
27969
27969
|
query.dedupInferredEchoes = "true";
|
|
27970
27970
|
}
|
|
27971
|
-
const result = await this.http.get(
|
|
27971
|
+
const result = await this.http.get(path25, query);
|
|
27972
27972
|
return result.messages;
|
|
27973
27973
|
}
|
|
27974
27974
|
/**
|
|
@@ -27979,12 +27979,12 @@ var init_http_backend = __esm({
|
|
|
27979
27979
|
* so that get-history shows the actual response (not null).
|
|
27980
27980
|
*/
|
|
27981
27981
|
async updateMessageResponse(messageId, response, durationMs, pending) {
|
|
27982
|
-
const
|
|
27982
|
+
const path25 = PATHS.message.replace(":sessionId", this.sessionId).replace(":messageId", messageId);
|
|
27983
27983
|
const body = { response, durationMs };
|
|
27984
27984
|
if (pending === true) {
|
|
27985
27985
|
body.pending = true;
|
|
27986
27986
|
}
|
|
27987
|
-
await this.http.patch(
|
|
27987
|
+
await this.http.patch(path25, body);
|
|
27988
27988
|
}
|
|
27989
27989
|
/**
|
|
27990
27990
|
* Validate a session.
|
|
@@ -28126,8 +28126,8 @@ var init_http_client = __esm({
|
|
|
28126
28126
|
* Perform an authenticated GET request.
|
|
28127
28127
|
* Appends query parameters to the URL if provided.
|
|
28128
28128
|
*/
|
|
28129
|
-
async get(
|
|
28130
|
-
const url = new URL(
|
|
28129
|
+
async get(path25, query) {
|
|
28130
|
+
const url = new URL(path25, this.baseUrl);
|
|
28131
28131
|
if (query) {
|
|
28132
28132
|
for (const [k, v] of Object.entries(query)) {
|
|
28133
28133
|
url.searchParams.set(k, v);
|
|
@@ -28142,8 +28142,8 @@ var init_http_client = __esm({
|
|
|
28142
28142
|
/**
|
|
28143
28143
|
* Perform an authenticated POST request with a JSON body.
|
|
28144
28144
|
*/
|
|
28145
|
-
async post(
|
|
28146
|
-
const url = new URL(
|
|
28145
|
+
async post(path25, body) {
|
|
28146
|
+
const url = new URL(path25, this.baseUrl);
|
|
28147
28147
|
const resp = await this.fetchWithTimeout(url, {
|
|
28148
28148
|
method: "POST",
|
|
28149
28149
|
headers: this.headers(),
|
|
@@ -28161,8 +28161,8 @@ var init_http_client = __esm({
|
|
|
28161
28161
|
* Perform an authenticated PATCH request with a JSON body.
|
|
28162
28162
|
* Used to update existing resources (e.g., message response fields).
|
|
28163
28163
|
*/
|
|
28164
|
-
async patch(
|
|
28165
|
-
const url = new URL(
|
|
28164
|
+
async patch(path25, body) {
|
|
28165
|
+
const url = new URL(path25, this.baseUrl);
|
|
28166
28166
|
const resp = await this.fetchWithTimeout(url, {
|
|
28167
28167
|
method: "PATCH",
|
|
28168
28168
|
headers: this.headers(),
|
|
@@ -28187,8 +28187,8 @@ var init_http_client = __esm({
|
|
|
28187
28187
|
* "Malformed JSON in request body" 400 from cogent-server <=3.1.2 when
|
|
28188
28188
|
* any client (including third-party tools) DELETEd a peer without a body.
|
|
28189
28189
|
*/
|
|
28190
|
-
async delete(
|
|
28191
|
-
const url = new URL(
|
|
28190
|
+
async delete(path25, body) {
|
|
28191
|
+
const url = new URL(path25, this.baseUrl);
|
|
28192
28192
|
const headers = {
|
|
28193
28193
|
"Authorization": `Bearer ${this.token}`
|
|
28194
28194
|
};
|
|
@@ -32393,14 +32393,14 @@ var init_ws_client = __esm({
|
|
|
32393
32393
|
if (this.pollTimer) return;
|
|
32394
32394
|
const poll = async () => {
|
|
32395
32395
|
try {
|
|
32396
|
-
const
|
|
32396
|
+
const path25 = `/api/sessions/${this.opts.sessionId}/poll`;
|
|
32397
32397
|
const query = {
|
|
32398
32398
|
peerId: this.opts.peerId
|
|
32399
32399
|
};
|
|
32400
32400
|
if (this.lastMessageId) {
|
|
32401
32401
|
query.lastMessageId = this.lastMessageId;
|
|
32402
32402
|
}
|
|
32403
|
-
const result = await this.opts.http.get(
|
|
32403
|
+
const result = await this.opts.http.get(path25, query);
|
|
32404
32404
|
if (result.messages && result.messages.length > 0) {
|
|
32405
32405
|
this.opts.onMessages(result.messages);
|
|
32406
32406
|
this.lastMessageId = result.messages[result.messages.length - 1].id;
|
|
@@ -33741,6 +33741,162 @@ var init_wake_ownership = __esm({
|
|
|
33741
33741
|
}
|
|
33742
33742
|
});
|
|
33743
33743
|
|
|
33744
|
+
// src/services/stale-bridge-reaper.ts
|
|
33745
|
+
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
33746
|
+
import fs18 from "node:fs";
|
|
33747
|
+
import path19 from "node:path";
|
|
33748
|
+
function isBridgeCommand(argv) {
|
|
33749
|
+
if (!argv) return false;
|
|
33750
|
+
if (/\.test\.|-test\.mjs|scripts\//.test(argv)) return false;
|
|
33751
|
+
return /\/bridge\/cogent-bridge\.mjs(\s|$)/.test(argv) || // plugin bundle (Claude + codex)
|
|
33752
|
+
/\/cogent-bridge(\s|$)/.test(argv) || // npx / global bin shim
|
|
33753
|
+
/@essentialai\/cogent-bridge(-bundled)?\/dist\/(cli|index)\.js(\s|$)/.test(argv);
|
|
33754
|
+
}
|
|
33755
|
+
function versionFromArgv(argv) {
|
|
33756
|
+
const m = argv.match(/\/cogent\/(\d+\.\d+\.\d+)\//);
|
|
33757
|
+
return m ? m[1] : null;
|
|
33758
|
+
}
|
|
33759
|
+
function listProcesses() {
|
|
33760
|
+
let out;
|
|
33761
|
+
try {
|
|
33762
|
+
out = execFileSync2("ps", ["-eo", "pid=,ppid=,lstart=,args="], {
|
|
33763
|
+
encoding: "utf-8",
|
|
33764
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
33765
|
+
timeout: 1e4
|
|
33766
|
+
});
|
|
33767
|
+
} catch (err) {
|
|
33768
|
+
logger.debug(`stale-bridge-reaper: ps failed (${err.message})`);
|
|
33769
|
+
return [];
|
|
33770
|
+
}
|
|
33771
|
+
const procs = [];
|
|
33772
|
+
for (const line of out.split("\n")) {
|
|
33773
|
+
const m = line.match(/^\s*(\d+)\s+(\d+)\s+(\S+\s+\S+\s+\S+\s+\S+\s+\S+)\s+(.*)$/);
|
|
33774
|
+
if (!m) continue;
|
|
33775
|
+
const started = Date.parse(m[3]);
|
|
33776
|
+
procs.push({
|
|
33777
|
+
pid: Number(m[1]),
|
|
33778
|
+
ppid: Number(m[2]),
|
|
33779
|
+
startedAt: Number.isFinite(started) ? started : NaN,
|
|
33780
|
+
argv: m[4]
|
|
33781
|
+
});
|
|
33782
|
+
}
|
|
33783
|
+
return procs;
|
|
33784
|
+
}
|
|
33785
|
+
function processCwd(pid) {
|
|
33786
|
+
try {
|
|
33787
|
+
if (process.platform === "linux") {
|
|
33788
|
+
return path19.resolve(fs18.readlinkSync(`/proc/${pid}/cwd`));
|
|
33789
|
+
}
|
|
33790
|
+
if (process.platform === "darwin") {
|
|
33791
|
+
const out = execFileSync2("lsof", ["-a", "-d", "cwd", "-p", String(pid), "-Fn"], {
|
|
33792
|
+
encoding: "utf-8",
|
|
33793
|
+
timeout: 1e4,
|
|
33794
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
33795
|
+
});
|
|
33796
|
+
const line = out.split("\n").find((l) => l.startsWith("n"));
|
|
33797
|
+
return line ? path19.resolve(line.slice(1)) : null;
|
|
33798
|
+
}
|
|
33799
|
+
} catch {
|
|
33800
|
+
}
|
|
33801
|
+
return null;
|
|
33802
|
+
}
|
|
33803
|
+
function canonicalPath(p) {
|
|
33804
|
+
try {
|
|
33805
|
+
return fs18.realpathSync(path19.resolve(p));
|
|
33806
|
+
} catch {
|
|
33807
|
+
return path19.resolve(p);
|
|
33808
|
+
}
|
|
33809
|
+
}
|
|
33810
|
+
function ancestorsOf(pid, procs) {
|
|
33811
|
+
const byPid = new Map(procs.map((p) => [p.pid, p]));
|
|
33812
|
+
const seen = /* @__PURE__ */ new Set();
|
|
33813
|
+
let cur = byPid.get(pid)?.ppid;
|
|
33814
|
+
while (cur && cur > 1 && !seen.has(cur)) {
|
|
33815
|
+
seen.add(cur);
|
|
33816
|
+
cur = byPid.get(cur)?.ppid;
|
|
33817
|
+
}
|
|
33818
|
+
return seen;
|
|
33819
|
+
}
|
|
33820
|
+
function announcedPidsFor(cwd) {
|
|
33821
|
+
const pids = /* @__PURE__ */ new Set();
|
|
33822
|
+
try {
|
|
33823
|
+
const base = path19.dirname(bridgeDirFor(cwd, "x"));
|
|
33824
|
+
const prefix = path19.basename(bridgeDirFor(cwd, "x")).split(".")[0];
|
|
33825
|
+
for (const dir of fs18.readdirSync(base)) {
|
|
33826
|
+
if (!dir.startsWith(`${prefix}.`)) continue;
|
|
33827
|
+
const peerId = dir.slice(prefix.length + 1);
|
|
33828
|
+
for (const e of listLiveBridges(cwd, peerId)) pids.add(e.pid);
|
|
33829
|
+
}
|
|
33830
|
+
} catch {
|
|
33831
|
+
}
|
|
33832
|
+
return pids;
|
|
33833
|
+
}
|
|
33834
|
+
function findStaleBridges(cwd, procs = listProcesses(), opts = {}) {
|
|
33835
|
+
const selfPid = opts.selfPid ?? process.pid;
|
|
33836
|
+
const selfStartedAt = opts.selfStartedAt ?? Date.now() - Math.floor(process.uptime() * 1e3);
|
|
33837
|
+
const cwdOf = opts.cwdOf ?? processCwd;
|
|
33838
|
+
const announced = opts.announced ?? announcedPidsFor(cwd);
|
|
33839
|
+
const target = canonicalPath(cwd);
|
|
33840
|
+
const ancestors = ancestorsOf(selfPid, procs);
|
|
33841
|
+
const out = [];
|
|
33842
|
+
for (const p of procs) {
|
|
33843
|
+
if (p.pid === selfPid) continue;
|
|
33844
|
+
if (ancestors.has(p.pid)) continue;
|
|
33845
|
+
if (!isBridgeCommand(p.argv)) continue;
|
|
33846
|
+
if (announced.has(p.pid)) continue;
|
|
33847
|
+
if (!Number.isFinite(p.startedAt) || p.startedAt >= selfStartedAt) continue;
|
|
33848
|
+
const theirCwd = cwdOf(p.pid);
|
|
33849
|
+
if (!theirCwd || canonicalPath(theirCwd) !== target) continue;
|
|
33850
|
+
const ver = versionFromArgv(p.argv);
|
|
33851
|
+
out.push({
|
|
33852
|
+
proc: p,
|
|
33853
|
+
reason: `pid ${p.pid}${ver ? ` (plugin ${ver})` : ""} is a cogent bridge in this exact checkout, started ${new Date(p.startedAt).toISOString()} \u2014 before this process \u2014 and has not announced itself, so it predates self-supersession and would keep waking this session forever`
|
|
33854
|
+
});
|
|
33855
|
+
}
|
|
33856
|
+
return out;
|
|
33857
|
+
}
|
|
33858
|
+
function reaperEnabled(env = process.env) {
|
|
33859
|
+
const v = env.COGENT_REAP_STALE_BRIDGES;
|
|
33860
|
+
if (v === void 0 || v === "") return true;
|
|
33861
|
+
return !/^(0|false|no|off)$/i.test(v.trim());
|
|
33862
|
+
}
|
|
33863
|
+
function reapStaleBridges(cwd, opts = {}) {
|
|
33864
|
+
if (!reaperEnabled()) {
|
|
33865
|
+
logger.debug("stale-bridge-reaper: disabled by COGENT_REAP_STALE_BRIDGES");
|
|
33866
|
+
return [];
|
|
33867
|
+
}
|
|
33868
|
+
let candidates;
|
|
33869
|
+
try {
|
|
33870
|
+
candidates = findStaleBridges(cwd, listProcesses(), opts);
|
|
33871
|
+
} catch (err) {
|
|
33872
|
+
logger.warn(`stale-bridge-reaper: scan failed (${err.message}) \u2014 reaping nothing`);
|
|
33873
|
+
return [];
|
|
33874
|
+
}
|
|
33875
|
+
const reaped = [];
|
|
33876
|
+
for (const c2 of candidates) {
|
|
33877
|
+
logger.warn(`Cogent: terminating a stale bridge \u2014 ${c2.reason}`);
|
|
33878
|
+
try {
|
|
33879
|
+
process.kill(c2.proc.pid, "SIGTERM");
|
|
33880
|
+
reaped.push(c2);
|
|
33881
|
+
} catch (err) {
|
|
33882
|
+
logger.warn(`stale-bridge-reaper: could not signal pid ${c2.proc.pid}: ${err.message}`);
|
|
33883
|
+
}
|
|
33884
|
+
}
|
|
33885
|
+
if (reaped.length) {
|
|
33886
|
+
logger.warn(
|
|
33887
|
+
`Cogent: reaped ${reaped.length} stale bridge process(es) left behind by an earlier plugin version. They could not stand down on their own because they predate 3.23.4.`
|
|
33888
|
+
);
|
|
33889
|
+
}
|
|
33890
|
+
return reaped;
|
|
33891
|
+
}
|
|
33892
|
+
var init_stale_bridge_reaper = __esm({
|
|
33893
|
+
"src/services/stale-bridge-reaper.ts"() {
|
|
33894
|
+
"use strict";
|
|
33895
|
+
init_logger();
|
|
33896
|
+
init_wake_ownership();
|
|
33897
|
+
}
|
|
33898
|
+
});
|
|
33899
|
+
|
|
33744
33900
|
// src/services/auto-relay.ts
|
|
33745
33901
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
33746
33902
|
function buildStatusNotice(status, peerId, traceId) {
|
|
@@ -33883,6 +34039,7 @@ var init_auto_relay = __esm({
|
|
|
33883
34039
|
init_wake_claim();
|
|
33884
34040
|
init_wake_lock();
|
|
33885
34041
|
init_wake_ownership();
|
|
34042
|
+
init_stale_bridge_reaper();
|
|
33886
34043
|
init_constants();
|
|
33887
34044
|
init_logger();
|
|
33888
34045
|
init_npm_update_check();
|
|
@@ -33932,6 +34089,8 @@ var init_auto_relay = __esm({
|
|
|
33932
34089
|
processing = false;
|
|
33933
34090
|
/** Senders already told this bridge is superseded — one notice each, not one per message. */
|
|
33934
34091
|
supersededNotified = /* @__PURE__ */ new Set();
|
|
34092
|
+
/** Reaping leftovers is a one-shot per process, not a per-registration action. */
|
|
34093
|
+
reapedStaleBridges = false;
|
|
33935
34094
|
queue = [];
|
|
33936
34095
|
// Message ids to be handled inject-only (full-group-chat awareness) rather than
|
|
33937
34096
|
// full-wake+reply. Shares the `processing` lock + `queue` so an awareness inject
|
|
@@ -33980,6 +34139,14 @@ var init_auto_relay = __esm({
|
|
|
33980
34139
|
);
|
|
33981
34140
|
announceBridge(cwd, peerId, CLIENT_VERSION, getConfig().COGENT_ENDPOINT ?? "local");
|
|
33982
34141
|
this.supersededNotified.clear();
|
|
34142
|
+
if (!this.reapedStaleBridges) {
|
|
34143
|
+
this.reapedStaleBridges = true;
|
|
34144
|
+
try {
|
|
34145
|
+
reapStaleBridges(cwd);
|
|
34146
|
+
} catch (err) {
|
|
34147
|
+
logger.debug(`stale-bridge reap skipped: ${err.message}`);
|
|
34148
|
+
}
|
|
34149
|
+
}
|
|
33983
34150
|
}
|
|
33984
34151
|
/**
|
|
33985
34152
|
* Emit one content-free wake-trace line (ids/decisions/timings only — NEVER
|
|
@@ -35101,8 +35268,8 @@ __export(startup_exports, {
|
|
|
35101
35268
|
triggerReRegistration: () => triggerReRegistration
|
|
35102
35269
|
});
|
|
35103
35270
|
import os14 from "node:os";
|
|
35104
|
-
import
|
|
35105
|
-
import
|
|
35271
|
+
import path20 from "node:path";
|
|
35272
|
+
import fs19 from "node:fs/promises";
|
|
35106
35273
|
import readline2 from "node:readline";
|
|
35107
35274
|
import { execFile as execFile5 } from "node:child_process";
|
|
35108
35275
|
import { promisify as promisify4 } from "node:util";
|
|
@@ -35120,7 +35287,7 @@ function bindInboxNotifier() {
|
|
|
35120
35287
|
}
|
|
35121
35288
|
async function loadPersistedConfig() {
|
|
35122
35289
|
try {
|
|
35123
|
-
const raw = await
|
|
35290
|
+
const raw = await fs19.readFile(PERSIST_PATH, "utf-8");
|
|
35124
35291
|
return JSON.parse(raw);
|
|
35125
35292
|
} catch {
|
|
35126
35293
|
return {};
|
|
@@ -35128,7 +35295,7 @@ async function loadPersistedConfig() {
|
|
|
35128
35295
|
}
|
|
35129
35296
|
async function savePersistedConfig(config2) {
|
|
35130
35297
|
try {
|
|
35131
|
-
await
|
|
35298
|
+
await fs19.writeFile(PERSIST_PATH, JSON.stringify(config2, null, 2) + "\n", "utf-8");
|
|
35132
35299
|
} catch (err) {
|
|
35133
35300
|
const msg = err instanceof Error ? err.message : String(err);
|
|
35134
35301
|
logger.warn(`Could not save config to ${PERSIST_PATH}: ${msg}`);
|
|
@@ -35163,11 +35330,11 @@ First run detected. Where should cogent-bridge store its data?
|
|
|
35163
35330
|
});
|
|
35164
35331
|
}
|
|
35165
35332
|
async function validateStateDir(statePath) {
|
|
35166
|
-
await
|
|
35167
|
-
const testFile =
|
|
35333
|
+
await fs19.mkdir(statePath, { recursive: true });
|
|
35334
|
+
const testFile = path20.join(statePath, ".write-test");
|
|
35168
35335
|
try {
|
|
35169
|
-
await
|
|
35170
|
-
await
|
|
35336
|
+
await fs19.writeFile(testFile, "test", "utf-8");
|
|
35337
|
+
await fs19.unlink(testFile);
|
|
35171
35338
|
} catch {
|
|
35172
35339
|
throw new BridgeError(
|
|
35173
35340
|
"STARTUP_FAILED" /* STARTUP_FAILED */,
|
|
@@ -35355,10 +35522,10 @@ async function runStartup() {
|
|
|
35355
35522
|
if (envStatePath) {
|
|
35356
35523
|
statePath = envStatePath;
|
|
35357
35524
|
} else {
|
|
35358
|
-
const defaultPath =
|
|
35525
|
+
const defaultPath = path20.join(os14.homedir(), ".cogent");
|
|
35359
35526
|
statePath = await firstRunPrompt(defaultPath);
|
|
35360
35527
|
}
|
|
35361
|
-
if (!envStatePath && statePath !==
|
|
35528
|
+
if (!envStatePath && statePath !== path20.join(os14.homedir(), ".cogent")) {
|
|
35362
35529
|
process.env.COGENT_STATE_PATH = statePath;
|
|
35363
35530
|
} else if (!envStatePath) {
|
|
35364
35531
|
process.env.COGENT_STATE_PATH = statePath;
|
|
@@ -35422,7 +35589,7 @@ async function runStartup() {
|
|
|
35422
35589
|
}
|
|
35423
35590
|
initLogger(
|
|
35424
35591
|
config2.COGENT_LOG_LEVEL,
|
|
35425
|
-
|
|
35592
|
+
path20.join(config2.COGENT_STATE_PATH, "logs")
|
|
35426
35593
|
);
|
|
35427
35594
|
if (isCloud && effectiveSessionId && effectiveToken) {
|
|
35428
35595
|
cloudInbox = new MessageInbox();
|
|
@@ -35484,7 +35651,7 @@ var init_startup = __esm({
|
|
|
35484
35651
|
init_auto_relay();
|
|
35485
35652
|
UUID_V4_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
35486
35653
|
execFileAsync3 = promisify4(execFile5);
|
|
35487
|
-
PERSIST_PATH =
|
|
35654
|
+
PERSIST_PATH = path20.join(os14.homedir(), ".cogent-config.json");
|
|
35488
35655
|
legacyWarnEmitted = false;
|
|
35489
35656
|
cloudWsClient = null;
|
|
35490
35657
|
cloudInbox = null;
|
|
@@ -35499,12 +35666,12 @@ var init_startup = __esm({
|
|
|
35499
35666
|
|
|
35500
35667
|
// src/cloud/mail-credential-store.ts
|
|
35501
35668
|
import crypto9 from "node:crypto";
|
|
35502
|
-
import
|
|
35503
|
-
import
|
|
35669
|
+
import fs20 from "node:fs/promises";
|
|
35670
|
+
import path21 from "node:path";
|
|
35504
35671
|
import os15 from "node:os";
|
|
35505
35672
|
function defaultMailCredentialPath(cwd = process.cwd()) {
|
|
35506
|
-
const hash = crypto9.createHash("sha256").update(
|
|
35507
|
-
return
|
|
35673
|
+
const hash = crypto9.createHash("sha256").update(path21.resolve(cwd)).digest("hex").slice(0, 16);
|
|
35674
|
+
return path21.join(os15.homedir(), ".cogent", "mail-credentials", `${hash}.json`);
|
|
35508
35675
|
}
|
|
35509
35676
|
function resolveMailCredentialPath(credentialPath) {
|
|
35510
35677
|
if (credentialPath) return credentialPath;
|
|
@@ -35515,16 +35682,16 @@ function resolveMailCredentialPath(credentialPath) {
|
|
|
35515
35682
|
async function loadMailCredentials(credentialPath) {
|
|
35516
35683
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35517
35684
|
try {
|
|
35518
|
-
return JSON.parse(await
|
|
35685
|
+
return JSON.parse(await fs20.readFile(filePath, "utf-8"));
|
|
35519
35686
|
} catch {
|
|
35520
35687
|
return null;
|
|
35521
35688
|
}
|
|
35522
35689
|
}
|
|
35523
35690
|
async function saveMailCredentials(creds, credentialPath) {
|
|
35524
35691
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35525
|
-
await
|
|
35526
|
-
await
|
|
35527
|
-
await
|
|
35692
|
+
await fs20.mkdir(path21.dirname(filePath), { recursive: true, mode: 448 });
|
|
35693
|
+
await fs20.writeFile(filePath, JSON.stringify(creds, null, 2) + "\n", { encoding: "utf-8", mode: 384 });
|
|
35694
|
+
await fs20.chmod(filePath, 384);
|
|
35528
35695
|
}
|
|
35529
35696
|
async function persistProvisionedMailbox(mailbox, credentialPath) {
|
|
35530
35697
|
if (!mailbox?.address || !mailbox.password) return false;
|
|
@@ -35545,7 +35712,7 @@ async function persistProvisionedMailbox(mailbox, credentialPath) {
|
|
|
35545
35712
|
async function clearMailCredentials(credentialPath) {
|
|
35546
35713
|
const filePath = resolveMailCredentialPath(credentialPath);
|
|
35547
35714
|
try {
|
|
35548
|
-
await
|
|
35715
|
+
await fs20.unlink(filePath);
|
|
35549
35716
|
} catch (err) {
|
|
35550
35717
|
if (err.code !== "ENOENT") throw err;
|
|
35551
35718
|
}
|
|
@@ -37217,11 +37384,24 @@ function registerJoinSessionTool(server) {
|
|
|
37217
37384
|
);
|
|
37218
37385
|
}
|
|
37219
37386
|
const data = await resp.json();
|
|
37387
|
+
let carried = {};
|
|
37388
|
+
try {
|
|
37389
|
+
const prior = await loadCredentials();
|
|
37390
|
+
if (prior && prior.endpoint === endpoint && prior.sessionId === data.sessionId) {
|
|
37391
|
+
carried = {
|
|
37392
|
+
...prior.peerId ? { peerId: prior.peerId } : {},
|
|
37393
|
+
...prior.peerSecret ? { peerSecret: prior.peerSecret } : {}
|
|
37394
|
+
};
|
|
37395
|
+
}
|
|
37396
|
+
} catch (err) {
|
|
37397
|
+
logger.debug(`join-session: could not read prior credentials: ${err.message}`);
|
|
37398
|
+
}
|
|
37220
37399
|
await saveCredentials({
|
|
37221
37400
|
endpoint,
|
|
37222
37401
|
sessionId: data.sessionId,
|
|
37223
37402
|
token: data.token,
|
|
37224
37403
|
label: resolvedLabel ?? data.label,
|
|
37404
|
+
...carried,
|
|
37225
37405
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
37226
37406
|
});
|
|
37227
37407
|
markJoinedInProcess();
|
|
@@ -37497,8 +37677,8 @@ var require_cookies = __commonJS({
|
|
|
37497
37677
|
if (urlparts.hostname !== cookie.domain && (cookie.domain.charAt(0) !== "." || ("." + urlparts.hostname).substr(-cookie.domain.length) !== cookie.domain)) {
|
|
37498
37678
|
return false;
|
|
37499
37679
|
}
|
|
37500
|
-
let
|
|
37501
|
-
if (
|
|
37680
|
+
let path25 = this.getPath(urlparts.pathname);
|
|
37681
|
+
if (path25.substr(0, cookie.path.length) !== cookie.path) {
|
|
37502
37682
|
return false;
|
|
37503
37683
|
}
|
|
37504
37684
|
if (cookie.secure && urlparts.protocol !== "https:") {
|
|
@@ -37558,16 +37738,16 @@ var require_cookies = __commonJS({
|
|
|
37558
37738
|
* @returns {String} Normalized path
|
|
37559
37739
|
*/
|
|
37560
37740
|
getPath(pathname) {
|
|
37561
|
-
let
|
|
37562
|
-
|
|
37563
|
-
|
|
37564
|
-
if (
|
|
37565
|
-
|
|
37741
|
+
let path25 = (pathname || "/").split("/");
|
|
37742
|
+
path25.pop();
|
|
37743
|
+
path25 = path25.join("/").trim();
|
|
37744
|
+
if (path25.charAt(0) !== "/") {
|
|
37745
|
+
path25 = "/" + path25;
|
|
37566
37746
|
}
|
|
37567
|
-
if (
|
|
37568
|
-
|
|
37747
|
+
if (path25.substr(-1) !== "/") {
|
|
37748
|
+
path25 += "/";
|
|
37569
37749
|
}
|
|
37570
|
-
return
|
|
37750
|
+
return path25;
|
|
37571
37751
|
}
|
|
37572
37752
|
};
|
|
37573
37753
|
module.exports = Cookies;
|
|
@@ -37868,7 +38048,7 @@ var require_shared = __commonJS({
|
|
|
37868
38048
|
"use strict";
|
|
37869
38049
|
var urllib = __require("url");
|
|
37870
38050
|
var util2 = __require("util");
|
|
37871
|
-
var
|
|
38051
|
+
var fs23 = __require("fs");
|
|
37872
38052
|
var nmfetch = require_fetch();
|
|
37873
38053
|
var dns = __require("dns");
|
|
37874
38054
|
var net = __require("net");
|
|
@@ -38254,7 +38434,7 @@ var require_shared = __commonJS({
|
|
|
38254
38434
|
}
|
|
38255
38435
|
return callback(null, parsedDataUri.data);
|
|
38256
38436
|
} else if (content.path) {
|
|
38257
|
-
return resolveStream(
|
|
38437
|
+
return resolveStream(fs23.createReadStream(content.path), callback);
|
|
38258
38438
|
}
|
|
38259
38439
|
}
|
|
38260
38440
|
if (typeof data[key].content === "string" && !["utf8", "usascii", "ascii"].includes(encoding)) {
|
|
@@ -38378,7 +38558,7 @@ var require_shared = __commonJS({
|
|
|
38378
38558
|
var require_mime_types = __commonJS({
|
|
38379
38559
|
"node_modules/nodemailer/lib/mime-funcs/mime-types.js"(exports, module) {
|
|
38380
38560
|
"use strict";
|
|
38381
|
-
var
|
|
38561
|
+
var path25 = __require("path");
|
|
38382
38562
|
var defaultMimeType = "application/octet-stream";
|
|
38383
38563
|
var defaultExtension = "bin";
|
|
38384
38564
|
var mimeTypes = /* @__PURE__ */ new Map([
|
|
@@ -40436,7 +40616,7 @@ var require_mime_types = __commonJS({
|
|
|
40436
40616
|
if (!filename) {
|
|
40437
40617
|
return defaultMimeType;
|
|
40438
40618
|
}
|
|
40439
|
-
let parsed =
|
|
40619
|
+
let parsed = path25.parse(filename);
|
|
40440
40620
|
let extension = (parsed.ext.substr(1) || parsed.name || "").split("?").shift().trim().toLowerCase();
|
|
40441
40621
|
let value = defaultMimeType;
|
|
40442
40622
|
if (extensions.has(extension)) {
|
|
@@ -41838,7 +42018,7 @@ var require_mime_node = __commonJS({
|
|
|
41838
42018
|
"node_modules/nodemailer/lib/mime-node/index.js"(exports, module) {
|
|
41839
42019
|
"use strict";
|
|
41840
42020
|
var crypto12 = __require("crypto");
|
|
41841
|
-
var
|
|
42021
|
+
var fs23 = __require("fs");
|
|
41842
42022
|
var punycode = require_punycode();
|
|
41843
42023
|
var PassThrough = __require("stream").PassThrough;
|
|
41844
42024
|
var shared = require_shared();
|
|
@@ -42553,7 +42733,7 @@ var require_mime_node = __commonJS({
|
|
|
42553
42733
|
setImmediate(() => contentStream.emit("error", new Error("File access rejected for " + content.path)));
|
|
42554
42734
|
return contentStream;
|
|
42555
42735
|
}
|
|
42556
|
-
return
|
|
42736
|
+
return fs23.createReadStream(content.path);
|
|
42557
42737
|
} else if (content && typeof content.href === "string") {
|
|
42558
42738
|
if (this.disableUrlAccess) {
|
|
42559
42739
|
contentStream = new PassThrough();
|
|
@@ -43574,8 +43754,8 @@ var require_dkim = __commonJS({
|
|
|
43574
43754
|
var RelaxedBody = require_relaxed_body();
|
|
43575
43755
|
var sign = require_sign();
|
|
43576
43756
|
var PassThrough = __require("stream").PassThrough;
|
|
43577
|
-
var
|
|
43578
|
-
var
|
|
43757
|
+
var fs23 = __require("fs");
|
|
43758
|
+
var path25 = __require("path");
|
|
43579
43759
|
var crypto12 = __require("crypto");
|
|
43580
43760
|
var DKIM_ALGO = "sha256";
|
|
43581
43761
|
var MAX_MESSAGE_SIZE = 128 * 1024;
|
|
@@ -43589,7 +43769,7 @@ var require_dkim = __commonJS({
|
|
|
43589
43769
|
this.chunks = [];
|
|
43590
43770
|
this.chunklen = 0;
|
|
43591
43771
|
this.readPos = 0;
|
|
43592
|
-
this.cachePath = this.cacheDir ?
|
|
43772
|
+
this.cachePath = this.cacheDir ? path25.join(this.cacheDir, "message." + Date.now() + "-" + crypto12.randomBytes(14).toString("hex")) : false;
|
|
43593
43773
|
this.cache = false;
|
|
43594
43774
|
this.headers = false;
|
|
43595
43775
|
this.bodyHash = false;
|
|
@@ -43609,10 +43789,10 @@ var require_dkim = __commonJS({
|
|
|
43609
43789
|
if (!this.cache || !this.cachePath) {
|
|
43610
43790
|
return;
|
|
43611
43791
|
}
|
|
43612
|
-
|
|
43792
|
+
fs23.unlink(this.cachePath, () => false);
|
|
43613
43793
|
}
|
|
43614
43794
|
createReadCache() {
|
|
43615
|
-
this.cache =
|
|
43795
|
+
this.cache = fs23.createReadStream(this.cachePath);
|
|
43616
43796
|
this.cache.once("error", (err) => {
|
|
43617
43797
|
this.cleanup();
|
|
43618
43798
|
this.output.emit("error", err);
|
|
@@ -43668,7 +43848,7 @@ var require_dkim = __commonJS({
|
|
|
43668
43848
|
}
|
|
43669
43849
|
createWriteCache() {
|
|
43670
43850
|
this.output.usingCache = true;
|
|
43671
|
-
this.cache =
|
|
43851
|
+
this.cache = fs23.createWriteStream(this.cachePath);
|
|
43672
43852
|
this.cache.once("error", (err) => {
|
|
43673
43853
|
this.cleanup();
|
|
43674
43854
|
this.relaxedBody.unpipe(this.cache);
|
|
@@ -48557,13 +48737,13 @@ var require_nodemailer = __commonJS({
|
|
|
48557
48737
|
});
|
|
48558
48738
|
|
|
48559
48739
|
// src/mail/mail-sender.ts
|
|
48560
|
-
import
|
|
48561
|
-
import
|
|
48740
|
+
import fs21 from "node:fs/promises";
|
|
48741
|
+
import path22 from "node:path";
|
|
48562
48742
|
async function buildAndSendMail(sender, creds, params) {
|
|
48563
48743
|
const attachments = [];
|
|
48564
48744
|
for (const p of params.attachmentPaths ?? []) {
|
|
48565
|
-
const content = await
|
|
48566
|
-
attachments.push({ filename:
|
|
48745
|
+
const content = await fs21.readFile(p);
|
|
48746
|
+
attachments.push({ filename: path22.basename(p), content });
|
|
48567
48747
|
}
|
|
48568
48748
|
const { messageId } = await sender.send({
|
|
48569
48749
|
from: creds.address,
|
|
@@ -48952,8 +49132,8 @@ var require_req = __commonJS({
|
|
|
48952
49132
|
if (req.originalUrl) {
|
|
48953
49133
|
_req.url = req.originalUrl;
|
|
48954
49134
|
} else {
|
|
48955
|
-
const
|
|
48956
|
-
_req.url = typeof
|
|
49135
|
+
const path25 = req.path;
|
|
49136
|
+
_req.url = typeof path25 === "string" ? path25 : req.url ? req.url.path || req.url : void 0;
|
|
48957
49137
|
}
|
|
48958
49138
|
if (req.query) {
|
|
48959
49139
|
_req.query = req.query;
|
|
@@ -49118,14 +49298,14 @@ var require_redact = __commonJS({
|
|
|
49118
49298
|
}
|
|
49119
49299
|
return obj;
|
|
49120
49300
|
}
|
|
49121
|
-
function parsePath(
|
|
49301
|
+
function parsePath(path25) {
|
|
49122
49302
|
const parts = [];
|
|
49123
49303
|
let current = "";
|
|
49124
49304
|
let inBrackets = false;
|
|
49125
49305
|
let inQuotes = false;
|
|
49126
49306
|
let quoteChar = "";
|
|
49127
|
-
for (let i = 0; i <
|
|
49128
|
-
const char =
|
|
49307
|
+
for (let i = 0; i < path25.length; i++) {
|
|
49308
|
+
const char = path25[i];
|
|
49129
49309
|
if (!inBrackets && char === ".") {
|
|
49130
49310
|
if (current) {
|
|
49131
49311
|
parts.push(current);
|
|
@@ -49256,10 +49436,10 @@ var require_redact = __commonJS({
|
|
|
49256
49436
|
return current;
|
|
49257
49437
|
}
|
|
49258
49438
|
function redactPaths(obj, paths, censor, remove = false) {
|
|
49259
|
-
for (const
|
|
49260
|
-
const parts = parsePath(
|
|
49439
|
+
for (const path25 of paths) {
|
|
49440
|
+
const parts = parsePath(path25);
|
|
49261
49441
|
if (parts.includes("*")) {
|
|
49262
|
-
redactWildcardPath(obj, parts, censor,
|
|
49442
|
+
redactWildcardPath(obj, parts, censor, path25, remove);
|
|
49263
49443
|
} else {
|
|
49264
49444
|
if (remove) {
|
|
49265
49445
|
removeKey(obj, parts);
|
|
@@ -49344,8 +49524,8 @@ var require_redact = __commonJS({
|
|
|
49344
49524
|
}
|
|
49345
49525
|
} else {
|
|
49346
49526
|
if (afterWildcard.includes("*")) {
|
|
49347
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49348
|
-
const fullPath = [...pathArray.slice(0, pathLength), ...
|
|
49527
|
+
const wrappedCensor = typeof censor === "function" ? (value, path25) => {
|
|
49528
|
+
const fullPath = [...pathArray.slice(0, pathLength), ...path25];
|
|
49349
49529
|
return censor(value, fullPath);
|
|
49350
49530
|
} : censor;
|
|
49351
49531
|
redactWildcardPath(current, afterWildcard, wrappedCensor, originalPath, remove);
|
|
@@ -49380,8 +49560,8 @@ var require_redact = __commonJS({
|
|
|
49380
49560
|
return null;
|
|
49381
49561
|
}
|
|
49382
49562
|
const pathStructure = /* @__PURE__ */ new Map();
|
|
49383
|
-
for (const
|
|
49384
|
-
const parts = parsePath(
|
|
49563
|
+
for (const path25 of pathsToClone) {
|
|
49564
|
+
const parts = parsePath(path25);
|
|
49385
49565
|
let current = pathStructure;
|
|
49386
49566
|
for (let i = 0; i < parts.length; i++) {
|
|
49387
49567
|
const part = parts[i];
|
|
@@ -49433,24 +49613,24 @@ var require_redact = __commonJS({
|
|
|
49433
49613
|
}
|
|
49434
49614
|
return cloneSelectively(obj, pathStructure);
|
|
49435
49615
|
}
|
|
49436
|
-
function validatePath(
|
|
49437
|
-
if (typeof
|
|
49616
|
+
function validatePath(path25) {
|
|
49617
|
+
if (typeof path25 !== "string") {
|
|
49438
49618
|
throw new Error("Paths must be (non-empty) strings");
|
|
49439
49619
|
}
|
|
49440
|
-
if (
|
|
49620
|
+
if (path25 === "") {
|
|
49441
49621
|
throw new Error("Invalid redaction path ()");
|
|
49442
49622
|
}
|
|
49443
|
-
if (
|
|
49444
|
-
throw new Error(`Invalid redaction path (${
|
|
49623
|
+
if (path25.includes("..")) {
|
|
49624
|
+
throw new Error(`Invalid redaction path (${path25})`);
|
|
49445
49625
|
}
|
|
49446
|
-
if (
|
|
49447
|
-
throw new Error(`Invalid redaction path (${
|
|
49626
|
+
if (path25.includes(",")) {
|
|
49627
|
+
throw new Error(`Invalid redaction path (${path25})`);
|
|
49448
49628
|
}
|
|
49449
49629
|
let bracketCount = 0;
|
|
49450
49630
|
let inQuotes = false;
|
|
49451
49631
|
let quoteChar = "";
|
|
49452
|
-
for (let i = 0; i <
|
|
49453
|
-
const char =
|
|
49632
|
+
for (let i = 0; i < path25.length; i++) {
|
|
49633
|
+
const char = path25[i];
|
|
49454
49634
|
if ((char === '"' || char === "'") && bracketCount > 0) {
|
|
49455
49635
|
if (!inQuotes) {
|
|
49456
49636
|
inQuotes = true;
|
|
@@ -49464,20 +49644,20 @@ var require_redact = __commonJS({
|
|
|
49464
49644
|
} else if (char === "]" && !inQuotes) {
|
|
49465
49645
|
bracketCount--;
|
|
49466
49646
|
if (bracketCount < 0) {
|
|
49467
|
-
throw new Error(`Invalid redaction path (${
|
|
49647
|
+
throw new Error(`Invalid redaction path (${path25})`);
|
|
49468
49648
|
}
|
|
49469
49649
|
}
|
|
49470
49650
|
}
|
|
49471
49651
|
if (bracketCount !== 0) {
|
|
49472
|
-
throw new Error(`Invalid redaction path (${
|
|
49652
|
+
throw new Error(`Invalid redaction path (${path25})`);
|
|
49473
49653
|
}
|
|
49474
49654
|
}
|
|
49475
49655
|
function validatePaths(paths) {
|
|
49476
49656
|
if (!Array.isArray(paths)) {
|
|
49477
49657
|
throw new TypeError("paths must be an array");
|
|
49478
49658
|
}
|
|
49479
|
-
for (const
|
|
49480
|
-
validatePath(
|
|
49659
|
+
for (const path25 of paths) {
|
|
49660
|
+
validatePath(path25);
|
|
49481
49661
|
}
|
|
49482
49662
|
}
|
|
49483
49663
|
function slowRedact(options = {}) {
|
|
@@ -49645,8 +49825,8 @@ var require_redaction = __commonJS({
|
|
|
49645
49825
|
if (shape[k] === null) {
|
|
49646
49826
|
o[k] = (value) => topCensor(value, [k]);
|
|
49647
49827
|
} else {
|
|
49648
|
-
const wrappedCensor = typeof censor === "function" ? (value,
|
|
49649
|
-
return censor(value, [k, ...
|
|
49828
|
+
const wrappedCensor = typeof censor === "function" ? (value, path25) => {
|
|
49829
|
+
return censor(value, [k, ...path25]);
|
|
49650
49830
|
} : censor;
|
|
49651
49831
|
o[k] = Redact({
|
|
49652
49832
|
paths: shape[k],
|
|
@@ -49864,10 +50044,10 @@ var require_atomic_sleep = __commonJS({
|
|
|
49864
50044
|
var require_sonic_boom = __commonJS({
|
|
49865
50045
|
"node_modules/sonic-boom/index.js"(exports, module) {
|
|
49866
50046
|
"use strict";
|
|
49867
|
-
var
|
|
50047
|
+
var fs23 = __require("fs");
|
|
49868
50048
|
var EventEmitter = __require("events");
|
|
49869
50049
|
var inherits = __require("util").inherits;
|
|
49870
|
-
var
|
|
50050
|
+
var path25 = __require("path");
|
|
49871
50051
|
var sleep4 = require_atomic_sleep();
|
|
49872
50052
|
var assert2 = __require("assert");
|
|
49873
50053
|
var BUSY_WRITE_TIMEOUT = 100;
|
|
@@ -49921,20 +50101,20 @@ var require_sonic_boom = __commonJS({
|
|
|
49921
50101
|
const mode = sonic.mode;
|
|
49922
50102
|
if (sonic.sync) {
|
|
49923
50103
|
try {
|
|
49924
|
-
if (sonic.mkdir)
|
|
49925
|
-
const fd =
|
|
50104
|
+
if (sonic.mkdir) fs23.mkdirSync(path25.dirname(file), { recursive: true });
|
|
50105
|
+
const fd = fs23.openSync(file, flags, mode);
|
|
49926
50106
|
fileOpened(null, fd);
|
|
49927
50107
|
} catch (err) {
|
|
49928
50108
|
fileOpened(err);
|
|
49929
50109
|
throw err;
|
|
49930
50110
|
}
|
|
49931
50111
|
} else if (sonic.mkdir) {
|
|
49932
|
-
|
|
50112
|
+
fs23.mkdir(path25.dirname(file), { recursive: true }, (err) => {
|
|
49933
50113
|
if (err) return fileOpened(err);
|
|
49934
|
-
|
|
50114
|
+
fs23.open(file, flags, mode, fileOpened);
|
|
49935
50115
|
});
|
|
49936
50116
|
} else {
|
|
49937
|
-
|
|
50117
|
+
fs23.open(file, flags, mode, fileOpened);
|
|
49938
50118
|
}
|
|
49939
50119
|
}
|
|
49940
50120
|
function SonicBoom(opts) {
|
|
@@ -49975,8 +50155,8 @@ var require_sonic_boom = __commonJS({
|
|
|
49975
50155
|
this.flush = flushBuffer;
|
|
49976
50156
|
this.flushSync = flushBufferSync;
|
|
49977
50157
|
this._actualWrite = actualWriteBuffer;
|
|
49978
|
-
fsWriteSync = () =>
|
|
49979
|
-
fsWrite = () =>
|
|
50158
|
+
fsWriteSync = () => fs23.writeSync(this.fd, this._writingBuf);
|
|
50159
|
+
fsWrite = () => fs23.write(this.fd, this._writingBuf, this.release);
|
|
49980
50160
|
} else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
|
|
49981
50161
|
this._writingBuf = "";
|
|
49982
50162
|
this.write = write;
|
|
@@ -49985,15 +50165,15 @@ var require_sonic_boom = __commonJS({
|
|
|
49985
50165
|
this._actualWrite = actualWrite;
|
|
49986
50166
|
fsWriteSync = () => {
|
|
49987
50167
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
49988
|
-
return
|
|
50168
|
+
return fs23.writeSync(this.fd, this._writingBuf);
|
|
49989
50169
|
}
|
|
49990
|
-
return
|
|
50170
|
+
return fs23.writeSync(this.fd, this._writingBuf, "utf8");
|
|
49991
50171
|
};
|
|
49992
50172
|
fsWrite = () => {
|
|
49993
50173
|
if (Buffer.isBuffer(this._writingBuf)) {
|
|
49994
|
-
return
|
|
50174
|
+
return fs23.write(this.fd, this._writingBuf, this.release);
|
|
49995
50175
|
}
|
|
49996
|
-
return
|
|
50176
|
+
return fs23.write(this.fd, this._writingBuf, "utf8", this.release);
|
|
49997
50177
|
};
|
|
49998
50178
|
} else {
|
|
49999
50179
|
throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
|
|
@@ -50050,7 +50230,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50050
50230
|
}
|
|
50051
50231
|
}
|
|
50052
50232
|
if (this._fsync) {
|
|
50053
|
-
|
|
50233
|
+
fs23.fsyncSync(this.fd);
|
|
50054
50234
|
}
|
|
50055
50235
|
const len = this._len;
|
|
50056
50236
|
if (this._reopening) {
|
|
@@ -50164,7 +50344,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50164
50344
|
const onDrain = () => {
|
|
50165
50345
|
if (!this._fsync) {
|
|
50166
50346
|
try {
|
|
50167
|
-
|
|
50347
|
+
fs23.fsync(this.fd, (err) => {
|
|
50168
50348
|
this._flushPending = false;
|
|
50169
50349
|
cb(err);
|
|
50170
50350
|
});
|
|
@@ -50266,7 +50446,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50266
50446
|
const fd = this.fd;
|
|
50267
50447
|
this.once("ready", () => {
|
|
50268
50448
|
if (fd !== this.fd) {
|
|
50269
|
-
|
|
50449
|
+
fs23.close(fd, (err) => {
|
|
50270
50450
|
if (err) {
|
|
50271
50451
|
return this.emit("error", err);
|
|
50272
50452
|
}
|
|
@@ -50315,7 +50495,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50315
50495
|
buf = this._bufs[0];
|
|
50316
50496
|
}
|
|
50317
50497
|
try {
|
|
50318
|
-
const n = Buffer.isBuffer(buf) ?
|
|
50498
|
+
const n = Buffer.isBuffer(buf) ? fs23.writeSync(this.fd, buf) : fs23.writeSync(this.fd, buf, "utf8");
|
|
50319
50499
|
const releasedBufObj = releaseWritingBuf(buf, this._len, n);
|
|
50320
50500
|
buf = releasedBufObj.writingBuf;
|
|
50321
50501
|
this._len = releasedBufObj.len;
|
|
@@ -50331,7 +50511,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50331
50511
|
}
|
|
50332
50512
|
}
|
|
50333
50513
|
try {
|
|
50334
|
-
|
|
50514
|
+
fs23.fsyncSync(this.fd);
|
|
50335
50515
|
} catch {
|
|
50336
50516
|
}
|
|
50337
50517
|
}
|
|
@@ -50352,7 +50532,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50352
50532
|
buf = mergeBuf(this._bufs[0], this._lens[0]);
|
|
50353
50533
|
}
|
|
50354
50534
|
try {
|
|
50355
|
-
const n =
|
|
50535
|
+
const n = fs23.writeSync(this.fd, buf);
|
|
50356
50536
|
buf = buf.subarray(n);
|
|
50357
50537
|
this._len = Math.max(this._len - n, 0);
|
|
50358
50538
|
if (buf.length <= 0) {
|
|
@@ -50380,13 +50560,13 @@ var require_sonic_boom = __commonJS({
|
|
|
50380
50560
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
|
|
50381
50561
|
if (this.sync) {
|
|
50382
50562
|
try {
|
|
50383
|
-
const written = Buffer.isBuffer(this._writingBuf) ?
|
|
50563
|
+
const written = Buffer.isBuffer(this._writingBuf) ? fs23.writeSync(this.fd, this._writingBuf) : fs23.writeSync(this.fd, this._writingBuf, "utf8");
|
|
50384
50564
|
release(null, written);
|
|
50385
50565
|
} catch (err) {
|
|
50386
50566
|
release(err);
|
|
50387
50567
|
}
|
|
50388
50568
|
} else {
|
|
50389
|
-
|
|
50569
|
+
fs23.write(this.fd, this._writingBuf, release);
|
|
50390
50570
|
}
|
|
50391
50571
|
}
|
|
50392
50572
|
function actualWriteBuffer() {
|
|
@@ -50395,7 +50575,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50395
50575
|
this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
|
|
50396
50576
|
if (this.sync) {
|
|
50397
50577
|
try {
|
|
50398
|
-
const written =
|
|
50578
|
+
const written = fs23.writeSync(this.fd, this._writingBuf);
|
|
50399
50579
|
release(null, written);
|
|
50400
50580
|
} catch (err) {
|
|
50401
50581
|
release(err);
|
|
@@ -50404,7 +50584,7 @@ var require_sonic_boom = __commonJS({
|
|
|
50404
50584
|
if (kCopyBuffer) {
|
|
50405
50585
|
this._writingBuf = Buffer.from(this._writingBuf);
|
|
50406
50586
|
}
|
|
50407
|
-
|
|
50587
|
+
fs23.write(this.fd, this._writingBuf, release);
|
|
50408
50588
|
}
|
|
50409
50589
|
}
|
|
50410
50590
|
function actualClose(sonic) {
|
|
@@ -50420,12 +50600,12 @@ var require_sonic_boom = __commonJS({
|
|
|
50420
50600
|
sonic._lens = [];
|
|
50421
50601
|
assert2(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
|
|
50422
50602
|
try {
|
|
50423
|
-
|
|
50603
|
+
fs23.fsync(sonic.fd, closeWrapped);
|
|
50424
50604
|
} catch {
|
|
50425
50605
|
}
|
|
50426
50606
|
function closeWrapped() {
|
|
50427
50607
|
if (sonic.fd !== 1 && sonic.fd !== 2) {
|
|
50428
|
-
|
|
50608
|
+
fs23.close(sonic.fd, done);
|
|
50429
50609
|
} else {
|
|
50430
50610
|
done();
|
|
50431
50611
|
}
|
|
@@ -51261,15 +51441,15 @@ var require_transport = __commonJS({
|
|
|
51261
51441
|
if (!unquoted) {
|
|
51262
51442
|
return false;
|
|
51263
51443
|
}
|
|
51264
|
-
let
|
|
51265
|
-
if (
|
|
51444
|
+
let path25 = unquoted;
|
|
51445
|
+
if (path25.startsWith("file://")) {
|
|
51266
51446
|
try {
|
|
51267
|
-
|
|
51447
|
+
path25 = fileURLToPath(path25);
|
|
51268
51448
|
} catch {
|
|
51269
51449
|
return false;
|
|
51270
51450
|
}
|
|
51271
51451
|
}
|
|
51272
|
-
return isAbsolute(
|
|
51452
|
+
return isAbsolute(path25) && !existsSync(path25);
|
|
51273
51453
|
}
|
|
51274
51454
|
function stripQuotes(value) {
|
|
51275
51455
|
const first = value[0];
|
|
@@ -85336,15 +85516,15 @@ var require_tools2 = __commonJS({
|
|
|
85336
85516
|
* @param {String} path - Mailbox path to encode
|
|
85337
85517
|
* @returns {String} Encoded mailbox path
|
|
85338
85518
|
*/
|
|
85339
|
-
encodePath(connection,
|
|
85340
|
-
|
|
85341
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(
|
|
85519
|
+
encodePath(connection, path25) {
|
|
85520
|
+
path25 = (path25 || "").toString();
|
|
85521
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(path25)) {
|
|
85342
85522
|
try {
|
|
85343
|
-
|
|
85523
|
+
path25 = iconv.encode(path25, "utf-7-imap").toString();
|
|
85344
85524
|
} catch {
|
|
85345
85525
|
}
|
|
85346
85526
|
}
|
|
85347
|
-
return
|
|
85527
|
+
return path25;
|
|
85348
85528
|
},
|
|
85349
85529
|
/**
|
|
85350
85530
|
* Decodes a mailbox path from modified UTF-7 if the server does not support UTF8=ACCEPT.
|
|
@@ -85353,15 +85533,15 @@ var require_tools2 = __commonJS({
|
|
|
85353
85533
|
* @param {String} path - Mailbox path to decode
|
|
85354
85534
|
* @returns {String} Decoded mailbox path
|
|
85355
85535
|
*/
|
|
85356
|
-
decodePath(connection,
|
|
85357
|
-
|
|
85358
|
-
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(
|
|
85536
|
+
decodePath(connection, path25) {
|
|
85537
|
+
path25 = (path25 || "").toString();
|
|
85538
|
+
if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(path25)) {
|
|
85359
85539
|
try {
|
|
85360
|
-
|
|
85540
|
+
path25 = iconv.decode(Buffer.from(path25), "utf-7-imap").toString();
|
|
85361
85541
|
} catch {
|
|
85362
85542
|
}
|
|
85363
85543
|
}
|
|
85364
|
-
return
|
|
85544
|
+
return path25;
|
|
85365
85545
|
},
|
|
85366
85546
|
/**
|
|
85367
85547
|
* Normalizes a mailbox path by joining array segments with the namespace delimiter,
|
|
@@ -85372,17 +85552,17 @@ var require_tools2 = __commonJS({
|
|
|
85372
85552
|
* @param {Boolean} [skipNamespace] - If true, skips prepending the namespace prefix
|
|
85373
85553
|
* @returns {String} Normalized mailbox path
|
|
85374
85554
|
*/
|
|
85375
|
-
normalizePath(connection,
|
|
85376
|
-
if (Array.isArray(
|
|
85377
|
-
|
|
85555
|
+
normalizePath(connection, path25, skipNamespace) {
|
|
85556
|
+
if (Array.isArray(path25)) {
|
|
85557
|
+
path25 = path25.join(connection.namespace && connection.namespace.delimiter || "");
|
|
85378
85558
|
}
|
|
85379
|
-
if (
|
|
85559
|
+
if (path25.toUpperCase() === "INBOX") {
|
|
85380
85560
|
return "INBOX";
|
|
85381
85561
|
}
|
|
85382
|
-
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !
|
|
85383
|
-
|
|
85562
|
+
if (!skipNamespace && connection.namespace && connection.namespace.prefix && !path25.startsWith(connection.namespace.prefix)) {
|
|
85563
|
+
path25 = connection.namespace.prefix + path25;
|
|
85384
85564
|
}
|
|
85385
|
-
return
|
|
85565
|
+
return path25;
|
|
85386
85566
|
},
|
|
85387
85567
|
/**
|
|
85388
85568
|
* Compares two mailbox paths for equality after normalization.
|
|
@@ -85713,14 +85893,14 @@ var require_tools2 = __commonJS({
|
|
|
85713
85893
|
}
|
|
85714
85894
|
}
|
|
85715
85895
|
if (map.emailId || map.uid) {
|
|
85716
|
-
let
|
|
85717
|
-
if (/[\u0080-\uffff]/.test(
|
|
85896
|
+
let path25 = mailbox.path;
|
|
85897
|
+
if (/[\u0080-\uffff]/.test(path25)) {
|
|
85718
85898
|
try {
|
|
85719
|
-
|
|
85899
|
+
path25 = iconv.encode(path25, "utf-7-imap").toString();
|
|
85720
85900
|
} catch {
|
|
85721
85901
|
}
|
|
85722
85902
|
}
|
|
85723
|
-
map.id = map.emailId || createHash2("md5").update([
|
|
85903
|
+
map.id = map.emailId || createHash2("md5").update([path25, mailbox.uidValidity?.toString() || "", map.uid.toString()].join(":")).digest("hex");
|
|
85724
85904
|
}
|
|
85725
85905
|
if (map.flags) {
|
|
85726
85906
|
let flagColor = tools.getFlagColor(map.flags);
|
|
@@ -85895,16 +86075,16 @@ var require_tools2 = __commonJS({
|
|
|
85895
86075
|
* @returns {Object} Parsed body structure tree with part numbers, types, parameters, and child nodes
|
|
85896
86076
|
*/
|
|
85897
86077
|
parseBodystructure(entry) {
|
|
85898
|
-
let walk = (node,
|
|
85899
|
-
|
|
86078
|
+
let walk = (node, path25) => {
|
|
86079
|
+
path25 = path25 || [];
|
|
85900
86080
|
let curNode = {}, i = 0, part = 0;
|
|
85901
|
-
if (
|
|
85902
|
-
curNode.part =
|
|
86081
|
+
if (path25.length) {
|
|
86082
|
+
curNode.part = path25.join(".");
|
|
85903
86083
|
}
|
|
85904
86084
|
if (Array.isArray(node[0])) {
|
|
85905
86085
|
curNode.childNodes = [];
|
|
85906
86086
|
while (Array.isArray(node[i])) {
|
|
85907
|
-
curNode.childNodes.push(walk(node[i],
|
|
86087
|
+
curNode.childNodes.push(walk(node[i], path25.concat(++part)));
|
|
85908
86088
|
i++;
|
|
85909
86089
|
}
|
|
85910
86090
|
curNode.type = "multipart/" + ((node[i++] || {}).value || "").toString().toLowerCase();
|
|
@@ -85947,7 +86127,7 @@ var require_tools2 = __commonJS({
|
|
|
85947
86127
|
// the encapsulated message shares the part number with its wrapper.
|
|
85948
86128
|
// Distinction is via suffixes: path.MIME = wrapper headers,
|
|
85949
86129
|
// path.HEADER = encapsulated message headers.
|
|
85950
|
-
walk(node[i],
|
|
86130
|
+
walk(node[i], path25)
|
|
85951
86131
|
];
|
|
85952
86132
|
}
|
|
85953
86133
|
i++;
|
|
@@ -87909,14 +88089,14 @@ var require_select = __commonJS({
|
|
|
87909
88089
|
// update into a silent no-op for the rest of the session.
|
|
87910
88090
|
permanentflags: { key: "permanentFlags", parse: (value) => Array.isArray(value) && new Set(value) }
|
|
87911
88091
|
});
|
|
87912
|
-
module.exports = async (connection,
|
|
88092
|
+
module.exports = async (connection, path25, options) => {
|
|
87913
88093
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
87914
88094
|
return;
|
|
87915
88095
|
}
|
|
87916
88096
|
options = options || {};
|
|
87917
|
-
|
|
87918
|
-
if (!connection.folders.has(
|
|
87919
|
-
let folders = await connection.run("LIST", "",
|
|
88097
|
+
path25 = normalizePath(connection, path25);
|
|
88098
|
+
if (!connection.folders.has(path25)) {
|
|
88099
|
+
let folders = await connection.run("LIST", "", path25);
|
|
87920
88100
|
if (!folders) {
|
|
87921
88101
|
throw new Error("Failed to fetch folders");
|
|
87922
88102
|
}
|
|
@@ -87924,10 +88104,10 @@ var require_select = __commonJS({
|
|
|
87924
88104
|
connection.folders.set(folder.path, folder);
|
|
87925
88105
|
});
|
|
87926
88106
|
}
|
|
87927
|
-
let folderListData = connection.folders.has(
|
|
88107
|
+
let folderListData = connection.folders.has(path25) ? connection.folders.get(path25) : false;
|
|
87928
88108
|
let response;
|
|
87929
88109
|
try {
|
|
87930
|
-
let map = { path:
|
|
88110
|
+
let map = { path: path25 };
|
|
87931
88111
|
if (folderListData) {
|
|
87932
88112
|
["delimiter", "specialUse", "subscribed", "listed"].forEach((key) => {
|
|
87933
88113
|
if (folderListData[key]) {
|
|
@@ -87946,7 +88126,7 @@ var require_select = __commonJS({
|
|
|
87946
88126
|
]);
|
|
87947
88127
|
map.qresync = true;
|
|
87948
88128
|
}
|
|
87949
|
-
let encodedPath = encodePath(connection,
|
|
88129
|
+
let encodedPath = encodePath(connection, path25);
|
|
87950
88130
|
let selectCommand = {
|
|
87951
88131
|
command: !options.readOnly ? "SELECT" : "EXAMINE",
|
|
87952
88132
|
/* c8 ignore next */
|
|
@@ -88006,12 +88186,12 @@ var require_select = __commonJS({
|
|
|
88006
88186
|
// since the client's last known state. Only received when QRESYNC was requested.
|
|
88007
88187
|
// A dummy mailbox object is passed because the mailbox isn't officially open yet.
|
|
88008
88188
|
VANISHED: async (untagged) => {
|
|
88009
|
-
await connection.untaggedVanished(untagged, { path:
|
|
88189
|
+
await connection.untaggedVanished(untagged, { path: path25, uidNext: false, uidValidity: false });
|
|
88010
88190
|
},
|
|
88011
88191
|
// Untagged FETCH during SELECT/EXAMINE: only occurs with QRESYNC, delivering
|
|
88012
88192
|
// updated flags for messages that changed since the client's last modseq.
|
|
88013
88193
|
FETCH: async (untagged) => {
|
|
88014
|
-
await connection.untaggedFetch(untagged, { path:
|
|
88194
|
+
await connection.untaggedFetch(untagged, { path: path25, uidNext: false, uidValidity: false });
|
|
88015
88195
|
}
|
|
88016
88196
|
}
|
|
88017
88197
|
});
|
|
@@ -88025,13 +88205,13 @@ var require_select = __commonJS({
|
|
|
88025
88205
|
}
|
|
88026
88206
|
let currentMailbox = connection.mailbox;
|
|
88027
88207
|
connection.mailbox = false;
|
|
88028
|
-
if (currentMailbox && currentMailbox.path !==
|
|
88208
|
+
if (currentMailbox && currentMailbox.path !== path25) {
|
|
88029
88209
|
connection.emit("mailboxClose", currentMailbox);
|
|
88030
88210
|
}
|
|
88031
88211
|
connection.mailbox = map;
|
|
88032
88212
|
connection.currentSelectCommand = selectCommand;
|
|
88033
88213
|
connection.state = connection.states.SELECTED;
|
|
88034
|
-
if (!currentMailbox || currentMailbox.path !==
|
|
88214
|
+
if (!currentMailbox || currentMailbox.path !== path25) {
|
|
88035
88215
|
connection.emit("mailboxOpen", connection.mailbox);
|
|
88036
88216
|
}
|
|
88037
88217
|
response.next();
|
|
@@ -88246,17 +88426,17 @@ var require_create = __commonJS({
|
|
|
88246
88426
|
"node_modules/imapflow/lib/commands/create.js"(exports, module) {
|
|
88247
88427
|
"use strict";
|
|
88248
88428
|
var { encodePath, normalizePath, getStatusCode, enhanceCommandError } = require_tools2();
|
|
88249
|
-
module.exports = async (connection,
|
|
88429
|
+
module.exports = async (connection, path25) => {
|
|
88250
88430
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88251
88431
|
return;
|
|
88252
88432
|
}
|
|
88253
|
-
|
|
88433
|
+
path25 = normalizePath(connection, path25);
|
|
88254
88434
|
let response;
|
|
88255
88435
|
try {
|
|
88256
88436
|
let map = {
|
|
88257
|
-
path:
|
|
88437
|
+
path: path25
|
|
88258
88438
|
};
|
|
88259
|
-
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection,
|
|
88439
|
+
response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection, path25) }]);
|
|
88260
88440
|
let section = response.response.attributes && response.response.attributes[0] && response.response.attributes[0].section && response.response.attributes[0].section.length ? response.response.attributes[0].section : false;
|
|
88261
88441
|
if (section) {
|
|
88262
88442
|
let key;
|
|
@@ -88282,13 +88462,13 @@ var require_create = __commonJS({
|
|
|
88282
88462
|
}
|
|
88283
88463
|
map.created = true;
|
|
88284
88464
|
response.next();
|
|
88285
|
-
await connection.run("SUBSCRIBE",
|
|
88465
|
+
await connection.run("SUBSCRIBE", path25);
|
|
88286
88466
|
return map;
|
|
88287
88467
|
} catch (err) {
|
|
88288
88468
|
let errorCode = getStatusCode(err.response);
|
|
88289
88469
|
if (errorCode === "ALREADYEXISTS") {
|
|
88290
88470
|
return {
|
|
88291
|
-
path:
|
|
88471
|
+
path: path25,
|
|
88292
88472
|
created: false
|
|
88293
88473
|
};
|
|
88294
88474
|
}
|
|
@@ -88305,20 +88485,20 @@ var require_delete = __commonJS({
|
|
|
88305
88485
|
"node_modules/imapflow/lib/commands/delete.js"(exports, module) {
|
|
88306
88486
|
"use strict";
|
|
88307
88487
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88308
|
-
module.exports = async (connection,
|
|
88488
|
+
module.exports = async (connection, path25) => {
|
|
88309
88489
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88310
88490
|
return;
|
|
88311
88491
|
}
|
|
88312
|
-
|
|
88313
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88492
|
+
path25 = normalizePath(connection, path25);
|
|
88493
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path25) {
|
|
88314
88494
|
await connection.run("CLOSE");
|
|
88315
88495
|
}
|
|
88316
88496
|
let response;
|
|
88317
88497
|
try {
|
|
88318
88498
|
let map = {
|
|
88319
|
-
path:
|
|
88499
|
+
path: path25
|
|
88320
88500
|
};
|
|
88321
|
-
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection,
|
|
88501
|
+
response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection, path25) }]);
|
|
88322
88502
|
response.next();
|
|
88323
88503
|
return map;
|
|
88324
88504
|
} catch (err) {
|
|
@@ -88335,23 +88515,23 @@ var require_rename = __commonJS({
|
|
|
88335
88515
|
"node_modules/imapflow/lib/commands/rename.js"(exports, module) {
|
|
88336
88516
|
"use strict";
|
|
88337
88517
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88338
|
-
module.exports = async (connection,
|
|
88518
|
+
module.exports = async (connection, path25, newPath) => {
|
|
88339
88519
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88340
88520
|
return;
|
|
88341
88521
|
}
|
|
88342
|
-
|
|
88522
|
+
path25 = normalizePath(connection, path25);
|
|
88343
88523
|
newPath = normalizePath(connection, newPath);
|
|
88344
|
-
if (connection.state === connection.states.SELECTED && connection.mailbox.path ===
|
|
88524
|
+
if (connection.state === connection.states.SELECTED && connection.mailbox.path === path25) {
|
|
88345
88525
|
await connection.run("CLOSE");
|
|
88346
88526
|
}
|
|
88347
88527
|
let response;
|
|
88348
88528
|
try {
|
|
88349
88529
|
let map = {
|
|
88350
|
-
path:
|
|
88530
|
+
path: path25,
|
|
88351
88531
|
newPath
|
|
88352
88532
|
};
|
|
88353
88533
|
response = await connection.exec("RENAME", [
|
|
88354
|
-
{ type: "ATOM", value: encodePath(connection,
|
|
88534
|
+
{ type: "ATOM", value: encodePath(connection, path25) },
|
|
88355
88535
|
{ type: "ATOM", value: encodePath(connection, newPath) }
|
|
88356
88536
|
]);
|
|
88357
88537
|
response.next();
|
|
@@ -88398,14 +88578,14 @@ var require_subscribe = __commonJS({
|
|
|
88398
88578
|
"node_modules/imapflow/lib/commands/subscribe.js"(exports, module) {
|
|
88399
88579
|
"use strict";
|
|
88400
88580
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88401
|
-
module.exports = async (connection,
|
|
88581
|
+
module.exports = async (connection, path25) => {
|
|
88402
88582
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88403
88583
|
return;
|
|
88404
88584
|
}
|
|
88405
|
-
|
|
88585
|
+
path25 = normalizePath(connection, path25);
|
|
88406
88586
|
let response;
|
|
88407
88587
|
try {
|
|
88408
|
-
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88588
|
+
response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path25) }]);
|
|
88409
88589
|
response.next();
|
|
88410
88590
|
return true;
|
|
88411
88591
|
} catch (err) {
|
|
@@ -88422,14 +88602,14 @@ var require_unsubscribe = __commonJS({
|
|
|
88422
88602
|
"node_modules/imapflow/lib/commands/unsubscribe.js"(exports, module) {
|
|
88423
88603
|
"use strict";
|
|
88424
88604
|
var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
|
|
88425
|
-
module.exports = async (connection,
|
|
88605
|
+
module.exports = async (connection, path25) => {
|
|
88426
88606
|
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
|
|
88427
88607
|
return;
|
|
88428
88608
|
}
|
|
88429
|
-
|
|
88609
|
+
path25 = normalizePath(connection, path25);
|
|
88430
88610
|
let response;
|
|
88431
88611
|
try {
|
|
88432
|
-
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection,
|
|
88612
|
+
response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path25) }]);
|
|
88433
88613
|
response.next();
|
|
88434
88614
|
return true;
|
|
88435
88615
|
} catch (err) {
|
|
@@ -89235,11 +89415,11 @@ var require_status = __commonJS({
|
|
|
89235
89415
|
var { encodePath, normalizePath, buildStatusQueryAttributes, isRev2Active } = require_tools2();
|
|
89236
89416
|
var { parseStatusList } = require_status_fields();
|
|
89237
89417
|
var MAILBOX_UPDATERS = {
|
|
89238
|
-
messages: (value, connection,
|
|
89418
|
+
messages: (value, connection, path25) => {
|
|
89239
89419
|
let prevCount = connection.mailbox.exists;
|
|
89240
89420
|
if (prevCount !== value) {
|
|
89241
89421
|
connection.mailbox.exists = value;
|
|
89242
|
-
connection.emit("exists", { path:
|
|
89422
|
+
connection.emit("exists", { path: path25, count: value, prevCount });
|
|
89243
89423
|
}
|
|
89244
89424
|
},
|
|
89245
89425
|
uidNext: (value, connection) => {
|
|
@@ -89249,28 +89429,28 @@ var require_status = __commonJS({
|
|
|
89249
89429
|
connection.mailbox.highestModseq = value;
|
|
89250
89430
|
}
|
|
89251
89431
|
};
|
|
89252
|
-
module.exports = async (connection,
|
|
89253
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89432
|
+
module.exports = async (connection, path25, query) => {
|
|
89433
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path25) {
|
|
89254
89434
|
return false;
|
|
89255
89435
|
}
|
|
89256
|
-
|
|
89257
|
-
let encodedPath = encodePath(connection,
|
|
89436
|
+
path25 = normalizePath(connection, path25);
|
|
89437
|
+
let encodedPath = encodePath(connection, path25);
|
|
89258
89438
|
let attributes = [{ type: encodedPath.indexOf("&") >= 0 ? "STRING" : "ATOM", value: encodedPath }];
|
|
89259
89439
|
let queryAttributes = buildStatusQueryAttributes(connection, query);
|
|
89260
89440
|
let syntheticRecent = query && query.recent && isRev2Active(connection);
|
|
89261
89441
|
if (!queryAttributes.length) {
|
|
89262
|
-
return syntheticRecent ? { path:
|
|
89442
|
+
return syntheticRecent ? { path: path25, recent: 0 } : false;
|
|
89263
89443
|
}
|
|
89264
89444
|
attributes.push(queryAttributes);
|
|
89265
89445
|
let response;
|
|
89266
89446
|
try {
|
|
89267
|
-
let map = { path:
|
|
89447
|
+
let map = { path: path25 };
|
|
89268
89448
|
response = await connection.exec("STATUS", attributes, {
|
|
89269
89449
|
untagged: {
|
|
89270
89450
|
// STATUS response: * STATUS <mailbox> (<key> <value> <key> <value> ...)
|
|
89271
89451
|
// Parsed as alternating key-value pairs (i % 2 pattern).
|
|
89272
89452
|
STATUS: async (untagged) => {
|
|
89273
|
-
let updateCurrent = connection.state === connection.states.SELECTED &&
|
|
89453
|
+
let updateCurrent = connection.state === connection.states.SELECTED && path25 === connection.mailbox.path;
|
|
89274
89454
|
let list = untagged.attributes && Array.isArray(untagged.attributes[1]) ? untagged.attributes[1] : false;
|
|
89275
89455
|
if (!list) {
|
|
89276
89456
|
return;
|
|
@@ -89278,7 +89458,7 @@ var require_status = __commonJS({
|
|
|
89278
89458
|
parseStatusList(list, (key, value) => {
|
|
89279
89459
|
map[key] = value;
|
|
89280
89460
|
if (updateCurrent && MAILBOX_UPDATERS[key]) {
|
|
89281
|
-
MAILBOX_UPDATERS[key](value, connection,
|
|
89461
|
+
MAILBOX_UPDATERS[key](value, connection, path25);
|
|
89282
89462
|
}
|
|
89283
89463
|
});
|
|
89284
89464
|
}
|
|
@@ -89291,9 +89471,9 @@ var require_status = __commonJS({
|
|
|
89291
89471
|
return map;
|
|
89292
89472
|
} catch (err) {
|
|
89293
89473
|
if (err.responseStatus === "NO") {
|
|
89294
|
-
let folders = await connection.run("LIST", "",
|
|
89474
|
+
let folders = await connection.run("LIST", "", path25, { listOnly: true });
|
|
89295
89475
|
if (folders && !folders.length) {
|
|
89296
|
-
let error2 = new Error(`Mailbox doesn't exist: ${
|
|
89476
|
+
let error2 = new Error(`Mailbox doesn't exist: ${path25}`);
|
|
89297
89477
|
error2.code = "NotFound";
|
|
89298
89478
|
error2.response = err;
|
|
89299
89479
|
throw error2;
|
|
@@ -89440,15 +89620,15 @@ var require_quota = __commonJS({
|
|
|
89440
89620
|
"node_modules/imapflow/lib/commands/quota.js"(exports, module) {
|
|
89441
89621
|
"use strict";
|
|
89442
89622
|
var { encodePath, normalizePath, enhanceCommandError, parseUintValue, isUnsafeKey } = require_tools2();
|
|
89443
|
-
module.exports = async (connection,
|
|
89444
|
-
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !
|
|
89623
|
+
module.exports = async (connection, path25) => {
|
|
89624
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path25) {
|
|
89445
89625
|
return;
|
|
89446
89626
|
}
|
|
89447
89627
|
if (!connection.capabilities.has("QUOTA")) {
|
|
89448
89628
|
return false;
|
|
89449
89629
|
}
|
|
89450
|
-
|
|
89451
|
-
let map = { path:
|
|
89630
|
+
path25 = normalizePath(connection, path25);
|
|
89631
|
+
let map = { path: path25 };
|
|
89452
89632
|
let processQuotaResponse = (untagged) => {
|
|
89453
89633
|
let attributes = untagged.attributes && untagged.attributes[1];
|
|
89454
89634
|
if (!attributes || !attributes.length) {
|
|
@@ -89488,7 +89668,7 @@ var require_quota = __commonJS({
|
|
|
89488
89668
|
let quotaFound = false;
|
|
89489
89669
|
let response;
|
|
89490
89670
|
try {
|
|
89491
|
-
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection,
|
|
89671
|
+
response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection, path25) }], {
|
|
89492
89672
|
untagged: {
|
|
89493
89673
|
// QUOTAROOT response tells us which quota root applies to this mailbox.
|
|
89494
89674
|
// A mailbox may have zero or one quota root.
|
|
@@ -89631,15 +89811,15 @@ var require_idle = __commonJS({
|
|
|
89631
89811
|
}
|
|
89632
89812
|
}
|
|
89633
89813
|
async function pollOnce2(connection, session) {
|
|
89634
|
-
let
|
|
89814
|
+
let path25 = connection.mailbox && connection.mailbox.path;
|
|
89635
89815
|
switch (connection.missingIdleCommand) {
|
|
89636
89816
|
case "SELECT":
|
|
89637
89817
|
connection.log.debug({ src: "c", msg: `Running SELECT to detect changes in folder`, cid: connection.id });
|
|
89638
|
-
await connection.runInternal("SELECT",
|
|
89818
|
+
await connection.runInternal("SELECT", path25, { readOnly: session.selectCommand.command === "EXAMINE" });
|
|
89639
89819
|
break;
|
|
89640
89820
|
case "STATUS": {
|
|
89641
89821
|
connection.log.debug({ src: "c", msg: `Running STATUS to detect changes in folder`, cid: connection.id });
|
|
89642
|
-
let status = await connection.runInternal("STATUS",
|
|
89822
|
+
let status = await connection.runInternal("STATUS", path25, {
|
|
89643
89823
|
messages: true,
|
|
89644
89824
|
uidNext: true,
|
|
89645
89825
|
uidValidity: true,
|
|
@@ -91326,12 +91506,12 @@ var require_imap_flow = __commonJS({
|
|
|
91326
91506
|
this.emit("flags", updateEvent);
|
|
91327
91507
|
}
|
|
91328
91508
|
}
|
|
91329
|
-
async ensureSelectedMailbox(
|
|
91330
|
-
if (!
|
|
91509
|
+
async ensureSelectedMailbox(path25) {
|
|
91510
|
+
if (!path25) {
|
|
91331
91511
|
return false;
|
|
91332
91512
|
}
|
|
91333
|
-
if (!this.mailbox || !comparePaths(this, this.mailbox.path,
|
|
91334
|
-
return await this.mailboxOpen(
|
|
91513
|
+
if (!this.mailbox || !comparePaths(this, this.mailbox.path, path25)) {
|
|
91514
|
+
return await this.mailboxOpen(path25);
|
|
91335
91515
|
}
|
|
91336
91516
|
return true;
|
|
91337
91517
|
}
|
|
@@ -91746,9 +91926,9 @@ var require_imap_flow = __commonJS({
|
|
|
91746
91926
|
* let quota = await client.getQuota();
|
|
91747
91927
|
* console.log(quota.storage.used, quota.storage.limit)
|
|
91748
91928
|
*/
|
|
91749
|
-
async getQuota(
|
|
91750
|
-
|
|
91751
|
-
return await this.run("QUOTA",
|
|
91929
|
+
async getQuota(path25) {
|
|
91930
|
+
path25 = path25 || "INBOX";
|
|
91931
|
+
return await this.run("QUOTA", path25);
|
|
91752
91932
|
}
|
|
91753
91933
|
/**
|
|
91754
91934
|
* @typedef {Object} ListResponse
|
|
@@ -91858,8 +92038,8 @@ var require_imap_flow = __commonJS({
|
|
|
91858
92038
|
* console.log(info.path);
|
|
91859
92039
|
* // "INBOX.parent.child" // assumes "INBOX." as namespace prefix and "." as delimiter
|
|
91860
92040
|
*/
|
|
91861
|
-
async mailboxCreate(
|
|
91862
|
-
return await this.run("CREATE",
|
|
92041
|
+
async mailboxCreate(path25) {
|
|
92042
|
+
return await this.run("CREATE", path25);
|
|
91863
92043
|
}
|
|
91864
92044
|
/**
|
|
91865
92045
|
* @typedef {Object} MailboxRenameResponse
|
|
@@ -91880,8 +92060,8 @@ var require_imap_flow = __commonJS({
|
|
|
91880
92060
|
* console.log(info.newPath);
|
|
91881
92061
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
91882
92062
|
*/
|
|
91883
|
-
async mailboxRename(
|
|
91884
|
-
return await this.run("RENAME",
|
|
92063
|
+
async mailboxRename(path25, newPath) {
|
|
92064
|
+
return await this.run("RENAME", path25, newPath);
|
|
91885
92065
|
}
|
|
91886
92066
|
/**
|
|
91887
92067
|
* @typedef {Object} MailboxDeleteResponse
|
|
@@ -91900,8 +92080,8 @@ var require_imap_flow = __commonJS({
|
|
|
91900
92080
|
* console.log(info.path);
|
|
91901
92081
|
* // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
|
|
91902
92082
|
*/
|
|
91903
|
-
async mailboxDelete(
|
|
91904
|
-
return await this.run("DELETE",
|
|
92083
|
+
async mailboxDelete(path25) {
|
|
92084
|
+
return await this.run("DELETE", path25);
|
|
91905
92085
|
}
|
|
91906
92086
|
/**
|
|
91907
92087
|
* Subscribes to a mailbox
|
|
@@ -91912,8 +92092,8 @@ var require_imap_flow = __commonJS({
|
|
|
91912
92092
|
* @example
|
|
91913
92093
|
* await client.mailboxSubscribe('Important stuff ❗️');
|
|
91914
92094
|
*/
|
|
91915
|
-
async mailboxSubscribe(
|
|
91916
|
-
return await this.run("SUBSCRIBE",
|
|
92095
|
+
async mailboxSubscribe(path25) {
|
|
92096
|
+
return await this.run("SUBSCRIBE", path25);
|
|
91917
92097
|
}
|
|
91918
92098
|
/**
|
|
91919
92099
|
* Unsubscribes from a mailbox
|
|
@@ -91924,8 +92104,8 @@ var require_imap_flow = __commonJS({
|
|
|
91924
92104
|
* @example
|
|
91925
92105
|
* await client.mailboxUnsubscribe('Important stuff ❗️');
|
|
91926
92106
|
*/
|
|
91927
|
-
async mailboxUnsubscribe(
|
|
91928
|
-
return await this.run("UNSUBSCRIBE",
|
|
92107
|
+
async mailboxUnsubscribe(path25) {
|
|
92108
|
+
return await this.run("UNSUBSCRIBE", path25);
|
|
91929
92109
|
}
|
|
91930
92110
|
/**
|
|
91931
92111
|
* Opens a mailbox to access messages. You can perform message operations only against an opened mailbox.
|
|
@@ -91943,8 +92123,8 @@ var require_imap_flow = __commonJS({
|
|
|
91943
92123
|
* console.log(mailbox.exists);
|
|
91944
92124
|
* // 125
|
|
91945
92125
|
*/
|
|
91946
|
-
async mailboxOpen(
|
|
91947
|
-
return await this.run("SELECT",
|
|
92126
|
+
async mailboxOpen(path25, options) {
|
|
92127
|
+
return await this.run("SELECT", path25, options);
|
|
91948
92128
|
}
|
|
91949
92129
|
/**
|
|
91950
92130
|
* Closes a previously opened mailbox
|
|
@@ -91991,8 +92171,8 @@ var require_imap_flow = __commonJS({
|
|
|
91991
92171
|
* console.log(status.unseen);
|
|
91992
92172
|
* // 123
|
|
91993
92173
|
*/
|
|
91994
|
-
async status(
|
|
91995
|
-
return await this.run("STATUS",
|
|
92174
|
+
async status(path25, query) {
|
|
92175
|
+
return await this.run("STATUS", path25, query);
|
|
91996
92176
|
}
|
|
91997
92177
|
/**
|
|
91998
92178
|
* Starts listening for new or deleted messages from the currently opened mailbox. Only required if {@link ImapFlow#disableAutoIdle} is set to `true`
|
|
@@ -92246,8 +92426,8 @@ var require_imap_flow = __commonJS({
|
|
|
92246
92426
|
* @example
|
|
92247
92427
|
* await client.append('INBOX', rawMessageBuffer, ['\\Seen'], new Date(2000, 1, 1));
|
|
92248
92428
|
*/
|
|
92249
|
-
async append(
|
|
92250
|
-
return await this.run("APPEND",
|
|
92429
|
+
async append(path25, content, flags, idate) {
|
|
92430
|
+
return await this.run("APPEND", path25, content, flags, idate) || false;
|
|
92251
92431
|
}
|
|
92252
92432
|
/**
|
|
92253
92433
|
* @typedef {Object} CopyResponseObject
|
|
@@ -93091,7 +93271,7 @@ var require_imap_flow = __commonJS({
|
|
|
93091
93271
|
await new Promise((resolve2) => setImmediate(resolve2));
|
|
93092
93272
|
}
|
|
93093
93273
|
const lock = this.locks.shift();
|
|
93094
|
-
const { resolve, reject, path:
|
|
93274
|
+
const { resolve, reject, path: path25, options, lockId } = lock;
|
|
93095
93275
|
if (lock.acquireTimer) {
|
|
93096
93276
|
clearTimeout(lock.acquireTimer);
|
|
93097
93277
|
lock.acquireTimer = null;
|
|
@@ -93107,7 +93287,7 @@ var require_imap_flow = __commonJS({
|
|
|
93107
93287
|
this.log.warn({
|
|
93108
93288
|
msg: "Mailbox lock held for a long time",
|
|
93109
93289
|
lockId: lock.lockId,
|
|
93110
|
-
path:
|
|
93290
|
+
path: path25,
|
|
93111
93291
|
heldFor: Date.now() - lock.heldAt,
|
|
93112
93292
|
/* c8 ignore next */
|
|
93113
93293
|
// the held-lock-warning diagnostic with a description set is a timing-dependent log detail
|
|
@@ -93143,52 +93323,52 @@ var require_imap_flow = __commonJS({
|
|
|
93143
93323
|
}
|
|
93144
93324
|
};
|
|
93145
93325
|
if (!this.usable || !this.socket || this.socket.destroyed) {
|
|
93146
|
-
this.log.trace({ msg: "Failed to acquire mailbox lock", path:
|
|
93326
|
+
this.log.trace({ msg: "Failed to acquire mailbox lock", path: path25, lockId, idling: this.idling });
|
|
93147
93327
|
let error2 = new Error("Connection not available");
|
|
93148
93328
|
error2.code = "NoConnection";
|
|
93149
93329
|
reject(error2);
|
|
93150
93330
|
continue;
|
|
93151
93331
|
}
|
|
93152
|
-
if (this.mailbox && this.mailbox.path ===
|
|
93332
|
+
if (this.mailbox && this.mailbox.path === path25 && !!this.mailbox.readOnly === !!options.readOnly) {
|
|
93153
93333
|
this.log.trace({
|
|
93154
93334
|
msg: "Mailbox lock acquired [existing]",
|
|
93155
|
-
path:
|
|
93335
|
+
path: path25,
|
|
93156
93336
|
lockId,
|
|
93157
93337
|
idling: this.idling,
|
|
93158
93338
|
...options.description && { description: options.description }
|
|
93159
93339
|
});
|
|
93160
93340
|
this.currentLock = lock;
|
|
93161
93341
|
armHeldTimer();
|
|
93162
|
-
resolve({ path:
|
|
93342
|
+
resolve({ path: path25, release });
|
|
93163
93343
|
break;
|
|
93164
93344
|
}
|
|
93165
93345
|
try {
|
|
93166
|
-
await this.mailboxOpen(
|
|
93346
|
+
await this.mailboxOpen(path25, options);
|
|
93167
93347
|
this.log.trace({
|
|
93168
93348
|
msg: "Mailbox lock acquired [selected]",
|
|
93169
|
-
path:
|
|
93349
|
+
path: path25,
|
|
93170
93350
|
lockId,
|
|
93171
93351
|
idling: this.idling,
|
|
93172
93352
|
...options.description && { description: options.description }
|
|
93173
93353
|
});
|
|
93174
93354
|
this.currentLock = lock;
|
|
93175
93355
|
armHeldTimer();
|
|
93176
|
-
resolve({ path:
|
|
93356
|
+
resolve({ path: path25, release });
|
|
93177
93357
|
break;
|
|
93178
93358
|
} catch (err) {
|
|
93179
93359
|
if (err.responseStatus === "NO") {
|
|
93180
93360
|
try {
|
|
93181
|
-
let folders = await this.run("LIST", "",
|
|
93361
|
+
let folders = await this.run("LIST", "", path25, { listOnly: true });
|
|
93182
93362
|
if (!folders || !folders.length) {
|
|
93183
93363
|
err.mailboxMissing = true;
|
|
93184
93364
|
}
|
|
93185
93365
|
} catch (E) {
|
|
93186
|
-
this.log.trace({ msg: "Failed to verify failed mailbox", path:
|
|
93366
|
+
this.log.trace({ msg: "Failed to verify failed mailbox", path: path25, err: E });
|
|
93187
93367
|
}
|
|
93188
93368
|
}
|
|
93189
93369
|
this.log.trace({
|
|
93190
93370
|
msg: "Failed to acquire mailbox lock",
|
|
93191
|
-
path:
|
|
93371
|
+
path: path25,
|
|
93192
93372
|
lockId,
|
|
93193
93373
|
idling: this.idling,
|
|
93194
93374
|
...options.description && { description: options.description },
|
|
@@ -93227,13 +93407,13 @@ var require_imap_flow = __commonJS({
|
|
|
93227
93407
|
* lock.release();
|
|
93228
93408
|
* }
|
|
93229
93409
|
*/
|
|
93230
|
-
getMailboxLock(
|
|
93410
|
+
getMailboxLock(path25, options) {
|
|
93231
93411
|
options = options || {};
|
|
93232
|
-
|
|
93412
|
+
path25 = normalizePath(this, path25);
|
|
93233
93413
|
let lockId = ++this.lockCounter;
|
|
93234
93414
|
this.log.trace({
|
|
93235
93415
|
msg: "Requesting lock",
|
|
93236
|
-
path:
|
|
93416
|
+
path: path25,
|
|
93237
93417
|
lockId,
|
|
93238
93418
|
...options.description && { description: options.description },
|
|
93239
93419
|
activeLock: this.currentLock ? {
|
|
@@ -93242,7 +93422,7 @@ var require_imap_flow = __commonJS({
|
|
|
93242
93422
|
} : null
|
|
93243
93423
|
});
|
|
93244
93424
|
let lockPromise = new Promise((resolve, reject) => {
|
|
93245
|
-
let lockEntry = { resolve, reject, path:
|
|
93425
|
+
let lockEntry = { resolve, reject, path: path25, options, lockId };
|
|
93246
93426
|
this.locks.push(lockEntry);
|
|
93247
93427
|
if (Number(options.acquireTimeout) > 0) {
|
|
93248
93428
|
lockEntry.acquireTimer = setTimeout(() => {
|
|
@@ -93331,16 +93511,16 @@ var require_imap_flow = __commonJS({
|
|
|
93331
93511
|
});
|
|
93332
93512
|
|
|
93333
93513
|
// src/mail/mail-fetcher.ts
|
|
93334
|
-
import
|
|
93335
|
-
import
|
|
93514
|
+
import fs22 from "node:fs/promises";
|
|
93515
|
+
import path23 from "node:path";
|
|
93336
93516
|
async function saveAttachments(attachments, downloadDir) {
|
|
93337
93517
|
if (attachments.length === 0) return [];
|
|
93338
|
-
await
|
|
93518
|
+
await fs22.mkdir(downloadDir, { recursive: true });
|
|
93339
93519
|
const saved = [];
|
|
93340
93520
|
for (const a of attachments) {
|
|
93341
|
-
const name =
|
|
93342
|
-
const savedPath =
|
|
93343
|
-
await
|
|
93521
|
+
const name = path23.basename(a.filename) || "attachment";
|
|
93522
|
+
const savedPath = path23.join(downloadDir, name);
|
|
93523
|
+
await fs22.writeFile(savedPath, a.content);
|
|
93344
93524
|
saved.push({ filename: name, savedPath, size: a.content.length });
|
|
93345
93525
|
}
|
|
93346
93526
|
return saved;
|
|
@@ -93471,7 +93651,7 @@ var init_mail_fetcher = __esm({
|
|
|
93471
93651
|
|
|
93472
93652
|
// src/tools/fetch-mail.ts
|
|
93473
93653
|
import os16 from "node:os";
|
|
93474
|
-
import
|
|
93654
|
+
import path24 from "node:path";
|
|
93475
93655
|
function registerFetchMailTool(server, deps = {}) {
|
|
93476
93656
|
const makeFetcher = deps.fetcherFactory ?? ((creds) => new ImapflowMailFetcher(creds));
|
|
93477
93657
|
server.registerTool(
|
|
@@ -93533,7 +93713,7 @@ var init_fetch_mail = __esm({
|
|
|
93533
93713
|
init_mail_fetcher();
|
|
93534
93714
|
init_auth_error();
|
|
93535
93715
|
init_validate();
|
|
93536
|
-
DEFAULT_DOWNLOAD_DIR =
|
|
93716
|
+
DEFAULT_DOWNLOAD_DIR = path24.join(os16.homedir(), ".cogent", "mail-downloads");
|
|
93537
93717
|
}
|
|
93538
93718
|
});
|
|
93539
93719
|
|