@ghostpaw/email 0.4.0 → 0.5.0

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.cjs CHANGED
@@ -376,6 +376,11 @@ async function enableCompression(dispatcher) {
376
376
  }
377
377
  }
378
378
 
379
+ // src/lib/connection_error.ts
380
+ function connectionError(error, host, port) {
381
+ return error.code === "ECONNREFUSED" ? new EmailConnectionError(`Connection refused to ${host}:${port}`) : error;
382
+ }
383
+
379
384
  // src/types/defaults.ts
380
385
  var DEFAULT_CONNECTION_TIMEOUT = 3e4;
381
386
  var DEFAULT_SOCKET_TIMEOUT = 3e5;
@@ -420,8 +425,9 @@ var ImapConnection = class extends node_events.EventEmitter {
420
425
  const useTls = this.#config.tls !== false;
421
426
  const onError = (err) => {
422
427
  this.#connected = false;
423
- this.emit("error", err);
424
- reject(err);
428
+ const error = connectionError(err, this.#config.host, this.#config.port);
429
+ if (this.listenerCount("error") > 0) this.emit("error", error);
430
+ reject(error);
425
431
  };
426
432
  if (useTls) {
427
433
  const sock = tls__namespace.connect({
@@ -3748,10 +3754,11 @@ function createFts(db) {
3748
3754
  DELETE FROM messages_fts WHERE rowid = old.id;
3749
3755
  END;
3750
3756
 
3751
- CREATE TRIGGER IF NOT EXISTS messages_au AFTER UPDATE ON messages BEGIN
3752
- DELETE FROM messages_fts WHERE rowid = old.id;
3753
- INSERT INTO messages_fts(rowid, subject, body_text, sender, recipients)
3754
- VALUES (new.id, new.subject, '', new."from", new."to");
3757
+ DROP TRIGGER IF EXISTS messages_au;
3758
+
3759
+ CREATE TRIGGER messages_au AFTER UPDATE ON messages BEGIN
3760
+ UPDATE messages_fts SET subject = new.subject, sender = new."from", recipients = new."to"
3761
+ WHERE rowid = old.id;
3755
3762
  END;
3756
3763
  `);
3757
3764
  }
@@ -4020,6 +4027,10 @@ function encodeDate(date) {
4020
4027
  }
4021
4028
 
4022
4029
  // src/mime/compose_message.ts
4030
+ function bracketId(id) {
4031
+ const value = id.trim();
4032
+ return value.startsWith("<") && value.endsWith(">") ? value : `<${value}>`;
4033
+ }
4023
4034
  function composeMessage(input) {
4024
4035
  const lines = [];
4025
4036
  const from = input.from ?? { address: "unknown@local" };
@@ -4037,10 +4048,10 @@ function composeMessage(input) {
4037
4048
  }
4038
4049
  lines.push(encodeHeader("Subject", input.subject).trim());
4039
4050
  if (input.inReplyTo) {
4040
- lines.push(encodeHeader("In-Reply-To", input.inReplyTo).trim());
4051
+ lines.push(encodeHeader("In-Reply-To", bracketId(input.inReplyTo)).trim());
4041
4052
  }
4042
4053
  if (input.references?.length) {
4043
- lines.push(encodeHeader("References", input.references.join(" ")).trim());
4054
+ lines.push(encodeHeader("References", input.references.map(bracketId).join(" ")).trim());
4044
4055
  }
4045
4056
  if (input.headers) {
4046
4057
  for (const [k, v] of Object.entries(input.headers)) {
@@ -4102,7 +4113,6 @@ ${attBlocks}\r
4102
4113
  --${b}--`;
4103
4114
  }
4104
4115
  const raw2 = `${lines.join("\r\n")}\r
4105
- \r
4106
4116
  ${body}`;
4107
4117
  return Buffer.from(raw2, "utf8");
4108
4118
  }
@@ -4251,7 +4261,9 @@ var SmtpConnection = class {
4251
4261
  reject(new Error("Plaintext port 25 requires allowInsecure: true"));
4252
4262
  return;
4253
4263
  }
4254
- this.#socket.once("error", reject);
4264
+ this.#socket.once("error", (error) => {
4265
+ reject(connectionError(error, this.#host, this.#port));
4266
+ });
4255
4267
  this.#socket.once(
4256
4268
  "secureConnect" in this.#socket ? "secureConnect" : "connect",
4257
4269
  async () => {
@@ -4668,7 +4680,13 @@ var Mailbox = class {
4668
4680
  username: authUser
4669
4681
  });
4670
4682
  const session = new ImapSession(this.#config);
4671
- await session.connect();
4683
+ try {
4684
+ await session.connect();
4685
+ } catch (error) {
4686
+ db.close();
4687
+ this.#db = null;
4688
+ throw error;
4689
+ }
4672
4690
  this.#session = session;
4673
4691
  this.#read = createReadSurface(db, account.id);
4674
4692
  this.#write = createWriteSurface(db, {
package/dist/index.js CHANGED
@@ -352,6 +352,11 @@ async function enableCompression(dispatcher) {
352
352
  }
353
353
  }
354
354
 
355
+ // src/lib/connection_error.ts
356
+ function connectionError(error, host, port) {
357
+ return error.code === "ECONNREFUSED" ? new EmailConnectionError(`Connection refused to ${host}:${port}`) : error;
358
+ }
359
+
355
360
  // src/types/defaults.ts
356
361
  var DEFAULT_CONNECTION_TIMEOUT = 3e4;
357
362
  var DEFAULT_SOCKET_TIMEOUT = 3e5;
@@ -396,8 +401,9 @@ var ImapConnection = class extends EventEmitter {
396
401
  const useTls = this.#config.tls !== false;
397
402
  const onError = (err) => {
398
403
  this.#connected = false;
399
- this.emit("error", err);
400
- reject(err);
404
+ const error = connectionError(err, this.#config.host, this.#config.port);
405
+ if (this.listenerCount("error") > 0) this.emit("error", error);
406
+ reject(error);
401
407
  };
402
408
  if (useTls) {
403
409
  const sock = tls.connect({
@@ -3724,10 +3730,11 @@ function createFts(db) {
3724
3730
  DELETE FROM messages_fts WHERE rowid = old.id;
3725
3731
  END;
3726
3732
 
3727
- CREATE TRIGGER IF NOT EXISTS messages_au AFTER UPDATE ON messages BEGIN
3728
- DELETE FROM messages_fts WHERE rowid = old.id;
3729
- INSERT INTO messages_fts(rowid, subject, body_text, sender, recipients)
3730
- VALUES (new.id, new.subject, '', new."from", new."to");
3733
+ DROP TRIGGER IF EXISTS messages_au;
3734
+
3735
+ CREATE TRIGGER messages_au AFTER UPDATE ON messages BEGIN
3736
+ UPDATE messages_fts SET subject = new.subject, sender = new."from", recipients = new."to"
3737
+ WHERE rowid = old.id;
3731
3738
  END;
3732
3739
  `);
3733
3740
  }
@@ -3996,6 +4003,10 @@ function encodeDate(date) {
3996
4003
  }
3997
4004
 
3998
4005
  // src/mime/compose_message.ts
4006
+ function bracketId(id) {
4007
+ const value = id.trim();
4008
+ return value.startsWith("<") && value.endsWith(">") ? value : `<${value}>`;
4009
+ }
3999
4010
  function composeMessage(input) {
4000
4011
  const lines = [];
4001
4012
  const from = input.from ?? { address: "unknown@local" };
@@ -4013,10 +4024,10 @@ function composeMessage(input) {
4013
4024
  }
4014
4025
  lines.push(encodeHeader("Subject", input.subject).trim());
4015
4026
  if (input.inReplyTo) {
4016
- lines.push(encodeHeader("In-Reply-To", input.inReplyTo).trim());
4027
+ lines.push(encodeHeader("In-Reply-To", bracketId(input.inReplyTo)).trim());
4017
4028
  }
4018
4029
  if (input.references?.length) {
4019
- lines.push(encodeHeader("References", input.references.join(" ")).trim());
4030
+ lines.push(encodeHeader("References", input.references.map(bracketId).join(" ")).trim());
4020
4031
  }
4021
4032
  if (input.headers) {
4022
4033
  for (const [k, v] of Object.entries(input.headers)) {
@@ -4078,7 +4089,6 @@ ${attBlocks}\r
4078
4089
  --${b}--`;
4079
4090
  }
4080
4091
  const raw2 = `${lines.join("\r\n")}\r
4081
- \r
4082
4092
  ${body}`;
4083
4093
  return Buffer.from(raw2, "utf8");
4084
4094
  }
@@ -4227,7 +4237,9 @@ var SmtpConnection = class {
4227
4237
  reject(new Error("Plaintext port 25 requires allowInsecure: true"));
4228
4238
  return;
4229
4239
  }
4230
- this.#socket.once("error", reject);
4240
+ this.#socket.once("error", (error) => {
4241
+ reject(connectionError(error, this.#host, this.#port));
4242
+ });
4231
4243
  this.#socket.once(
4232
4244
  "secureConnect" in this.#socket ? "secureConnect" : "connect",
4233
4245
  async () => {
@@ -4644,7 +4656,13 @@ var Mailbox = class {
4644
4656
  username: authUser
4645
4657
  });
4646
4658
  const session = new ImapSession(this.#config);
4647
- await session.connect();
4659
+ try {
4660
+ await session.connect();
4661
+ } catch (error) {
4662
+ db.close();
4663
+ this.#db = null;
4664
+ throw error;
4665
+ }
4648
4666
  this.#session = session;
4649
4667
  this.#read = createReadSurface(db, account.id);
4650
4668
  this.#write = createWriteSurface(db, {
@@ -10,8 +10,13 @@ import { randomUUID } from 'node:crypto';
10
10
 
11
11
  var __defProp = Object.defineProperty;
12
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __esm = (fn, res) => function __init() {
14
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
13
+ var __esm = (fn, res, err) => function __init() {
14
+ if (err) throw err[0];
15
+ try {
16
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
17
+ } catch (e) {
18
+ throw err = [e], e;
19
+ }
15
20
  };
16
21
  var __export = (target, all) => {
17
22
  for (var name in all)
@@ -251,7 +256,7 @@ var init_mcp_stdio = __esm({
251
256
  var emailVersion;
252
257
  var init_version = __esm({
253
258
  "src/version.ts"() {
254
- emailVersion = "0.4.0";
259
+ emailVersion = "0.5.0";
255
260
  }
256
261
  });
257
262
 
@@ -2475,9 +2480,20 @@ var init_compress = __esm({
2475
2480
  "src/imap/compress.ts"() {
2476
2481
  }
2477
2482
  });
2483
+
2484
+ // src/lib/connection_error.ts
2485
+ function connectionError(error, host, port) {
2486
+ return error.code === "ECONNREFUSED" ? new EmailConnectionError(`Connection refused to ${host}:${port}`) : error;
2487
+ }
2488
+ var init_connection_error = __esm({
2489
+ "src/lib/connection_error.ts"() {
2490
+ init_errors();
2491
+ }
2492
+ });
2478
2493
  var ImapConnection;
2479
2494
  var init_connection = __esm({
2480
2495
  "src/imap/connection.ts"() {
2496
+ init_connection_error();
2481
2497
  init_defaults();
2482
2498
  ImapConnection = class extends EventEmitter {
2483
2499
  #config;
@@ -2501,8 +2517,9 @@ var init_connection = __esm({
2501
2517
  const useTls = this.#config.tls !== false;
2502
2518
  const onError = (err) => {
2503
2519
  this.#connected = false;
2504
- this.emit("error", err);
2505
- reject(err);
2520
+ const error = connectionError(err, this.#config.host, this.#config.port);
2521
+ if (this.listenerCount("error") > 0) this.emit("error", error);
2522
+ reject(error);
2506
2523
  };
2507
2524
  if (useTls) {
2508
2525
  const sock = tls.connect({
@@ -4110,6 +4127,10 @@ var init_encode_date = __esm({
4110
4127
  });
4111
4128
 
4112
4129
  // src/mime/compose_message.ts
4130
+ function bracketId(id) {
4131
+ const value = id.trim();
4132
+ return value.startsWith("<") && value.endsWith(">") ? value : `<${value}>`;
4133
+ }
4113
4134
  function composeMessage(input) {
4114
4135
  const lines = [];
4115
4136
  const from = input.from ?? { address: "unknown@local" };
@@ -4127,10 +4148,10 @@ function composeMessage(input) {
4127
4148
  }
4128
4149
  lines.push(encodeHeader("Subject", input.subject).trim());
4129
4150
  if (input.inReplyTo) {
4130
- lines.push(encodeHeader("In-Reply-To", input.inReplyTo).trim());
4151
+ lines.push(encodeHeader("In-Reply-To", bracketId(input.inReplyTo)).trim());
4131
4152
  }
4132
4153
  if (input.references?.length) {
4133
- lines.push(encodeHeader("References", input.references.join(" ")).trim());
4154
+ lines.push(encodeHeader("References", input.references.map(bracketId).join(" ")).trim());
4134
4155
  }
4135
4156
  if (input.headers) {
4136
4157
  for (const [k, v] of Object.entries(input.headers)) {
@@ -4192,7 +4213,6 @@ ${attBlocks}\r
4192
4213
  --${b}--`;
4193
4214
  }
4194
4215
  const raw2 = `${lines.join("\r\n")}\r
4195
- \r
4196
4216
  ${body}`;
4197
4217
  return Buffer.from(raw2, "utf8");
4198
4218
  }
@@ -4343,6 +4363,7 @@ function parseEhloCapabilities(message) {
4343
4363
  var SmtpConnection;
4344
4364
  var init_connection2 = __esm({
4345
4365
  "src/smtp/connection.ts"() {
4366
+ init_connection_error();
4346
4367
  init_parse_response();
4347
4368
  SmtpConnection = class {
4348
4369
  #host;
@@ -4376,7 +4397,9 @@ var init_connection2 = __esm({
4376
4397
  reject(new Error("Plaintext port 25 requires allowInsecure: true"));
4377
4398
  return;
4378
4399
  }
4379
- this.#socket.once("error", reject);
4400
+ this.#socket.once("error", (error) => {
4401
+ reject(connectionError(error, this.#host, this.#port));
4402
+ });
4380
4403
  this.#socket.once(
4381
4404
  "secureConnect" in this.#socket ? "secureConnect" : "connect",
4382
4405
  async () => {
@@ -6062,13 +6085,13 @@ var init_network = __esm({
6062
6085
  });
6063
6086
 
6064
6087
  // src/surface/email_surface_tools.ts
6065
- var emailSurfaceTools;
6088
+ var emailMcpTools;
6066
6089
  var init_email_surface_tools = __esm({
6067
6090
  "src/surface/email_surface_tools.ts"() {
6068
6091
  init_read();
6069
6092
  init_store();
6070
6093
  init_aligned();
6071
- emailSurfaceTools = emailTools2.map((tool) => ({
6094
+ emailMcpTools = emailTools2.map((tool) => ({
6072
6095
  ...tool,
6073
6096
  inputSchema: { ...tool.inputSchema, type: "object" },
6074
6097
  async handler(db, input) {
@@ -6134,7 +6157,7 @@ function emailMcpOptions(context) {
6134
6157
  version: emailVersion,
6135
6158
  title: "Email",
6136
6159
  instructions: emailMcpInstructions,
6137
- tools: emailSurfaceTools,
6160
+ tools: emailMcpTools,
6138
6161
  context,
6139
6162
  annotations: (tool) => ({
6140
6163
  readOnlyHint: tool.readOnly ?? false,
@@ -6172,10 +6195,11 @@ function createFts(db) {
6172
6195
  DELETE FROM messages_fts WHERE rowid = old.id;
6173
6196
  END;
6174
6197
 
6175
- CREATE TRIGGER IF NOT EXISTS messages_au AFTER UPDATE ON messages BEGIN
6176
- DELETE FROM messages_fts WHERE rowid = old.id;
6177
- INSERT INTO messages_fts(rowid, subject, body_text, sender, recipients)
6178
- VALUES (new.id, new.subject, '', new."from", new."to");
6198
+ DROP TRIGGER IF EXISTS messages_au;
6199
+
6200
+ CREATE TRIGGER messages_au AFTER UPDATE ON messages BEGIN
6201
+ UPDATE messages_fts SET subject = new.subject, sender = new."from", recipients = new."to"
6202
+ WHERE rowid = old.id;
6179
6203
  END;
6180
6204
  `);
6181
6205
  }
package/dist/mcp.cjs CHANGED
@@ -33,8 +33,13 @@ var zlib__namespace = /*#__PURE__*/_interopNamespace(zlib);
33
33
 
34
34
  var __defProp = Object.defineProperty;
35
35
  var __getOwnPropNames = Object.getOwnPropertyNames;
36
- var __esm = (fn, res) => function __init() {
37
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
36
+ var __esm = (fn, res, err) => function __init() {
37
+ if (err) throw err[0];
38
+ try {
39
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
40
+ } catch (e) {
41
+ throw err = [e], e;
42
+ }
38
43
  };
39
44
  var __export = (target, all) => {
40
45
  for (var name in all)
@@ -1400,9 +1405,20 @@ var init_compress = __esm({
1400
1405
  "src/imap/compress.ts"() {
1401
1406
  }
1402
1407
  });
1408
+
1409
+ // src/lib/connection_error.ts
1410
+ function connectionError(error, host, port) {
1411
+ return error.code === "ECONNREFUSED" ? new EmailConnectionError(`Connection refused to ${host}:${port}`) : error;
1412
+ }
1413
+ var init_connection_error = __esm({
1414
+ "src/lib/connection_error.ts"() {
1415
+ init_errors();
1416
+ }
1417
+ });
1403
1418
  var ImapConnection;
1404
1419
  var init_connection = __esm({
1405
1420
  "src/imap/connection.ts"() {
1421
+ init_connection_error();
1406
1422
  init_defaults();
1407
1423
  ImapConnection = class extends node_events.EventEmitter {
1408
1424
  #config;
@@ -1426,8 +1442,9 @@ var init_connection = __esm({
1426
1442
  const useTls = this.#config.tls !== false;
1427
1443
  const onError = (err) => {
1428
1444
  this.#connected = false;
1429
- this.emit("error", err);
1430
- reject(err);
1445
+ const error = connectionError(err, this.#config.host, this.#config.port);
1446
+ if (this.listenerCount("error") > 0) this.emit("error", error);
1447
+ reject(error);
1431
1448
  };
1432
1449
  if (useTls) {
1433
1450
  const sock = tls__namespace.connect({
@@ -3035,6 +3052,10 @@ var init_encode_date = __esm({
3035
3052
  });
3036
3053
 
3037
3054
  // src/mime/compose_message.ts
3055
+ function bracketId(id) {
3056
+ const value = id.trim();
3057
+ return value.startsWith("<") && value.endsWith(">") ? value : `<${value}>`;
3058
+ }
3038
3059
  function composeMessage(input) {
3039
3060
  const lines = [];
3040
3061
  const from = input.from ?? { address: "unknown@local" };
@@ -3052,10 +3073,10 @@ function composeMessage(input) {
3052
3073
  }
3053
3074
  lines.push(encodeHeader("Subject", input.subject).trim());
3054
3075
  if (input.inReplyTo) {
3055
- lines.push(encodeHeader("In-Reply-To", input.inReplyTo).trim());
3076
+ lines.push(encodeHeader("In-Reply-To", bracketId(input.inReplyTo)).trim());
3056
3077
  }
3057
3078
  if (input.references?.length) {
3058
- lines.push(encodeHeader("References", input.references.join(" ")).trim());
3079
+ lines.push(encodeHeader("References", input.references.map(bracketId).join(" ")).trim());
3059
3080
  }
3060
3081
  if (input.headers) {
3061
3082
  for (const [k, v] of Object.entries(input.headers)) {
@@ -3117,7 +3138,6 @@ ${attBlocks}\r
3117
3138
  --${b}--`;
3118
3139
  }
3119
3140
  const raw2 = `${lines.join("\r\n")}\r
3120
- \r
3121
3141
  ${body}`;
3122
3142
  return Buffer.from(raw2, "utf8");
3123
3143
  }
@@ -3268,6 +3288,7 @@ function parseEhloCapabilities(message) {
3268
3288
  var SmtpConnection;
3269
3289
  var init_connection2 = __esm({
3270
3290
  "src/smtp/connection.ts"() {
3291
+ init_connection_error();
3271
3292
  init_parse_response();
3272
3293
  SmtpConnection = class {
3273
3294
  #host;
@@ -3301,7 +3322,9 @@ var init_connection2 = __esm({
3301
3322
  reject(new Error("Plaintext port 25 requires allowInsecure: true"));
3302
3323
  return;
3303
3324
  }
3304
- this.#socket.once("error", reject);
3325
+ this.#socket.once("error", (error) => {
3326
+ reject(connectionError(error, this.#host, this.#port));
3327
+ });
3305
3328
  this.#socket.once(
3306
3329
  "secureConnect" in this.#socket ? "secureConnect" : "connect",
3307
3330
  async () => {
@@ -4987,7 +5010,7 @@ var init_network = __esm({
4987
5010
  });
4988
5011
 
4989
5012
  // src/version.ts
4990
- var emailVersion = "0.4.0";
5013
+ var emailVersion = "0.5.0";
4991
5014
 
4992
5015
  // src/surface/email_mcp_instructions.ts
4993
5016
  var emailMcpInstructions = "Read and search cached email offline. Configure live accounts with email account add before network operations. Inspect messages before replying or changing folders. Confirm recipients and content before sending; trash and folder deletion can remove mail. Credentials use the existing email CLI account configuration or EMAIL_* environment variables.";
@@ -5834,7 +5857,7 @@ var emailTools2 = emailTools.map((tool) => ({
5834
5857
  }));
5835
5858
 
5836
5859
  // src/surface/email_surface_tools.ts
5837
- var emailSurfaceTools = emailTools2.map((tool) => ({
5860
+ var emailMcpTools = emailTools2.map((tool) => ({
5838
5861
  ...tool,
5839
5862
  inputSchema: { ...tool.inputSchema, type: "object" },
5840
5863
  async handler(db, input) {
@@ -5898,7 +5921,7 @@ function emailMcpOptions(context) {
5898
5921
  version: emailVersion,
5899
5922
  title: "Email",
5900
5923
  instructions: emailMcpInstructions,
5901
- tools: emailSurfaceTools,
5924
+ tools: emailMcpTools,
5902
5925
  context,
5903
5926
  annotations: (tool) => ({
5904
5927
  readOnlyHint: tool.readOnly ?? false,
@@ -5929,10 +5952,11 @@ function createFts(db) {
5929
5952
  DELETE FROM messages_fts WHERE rowid = old.id;
5930
5953
  END;
5931
5954
 
5932
- CREATE TRIGGER IF NOT EXISTS messages_au AFTER UPDATE ON messages BEGIN
5933
- DELETE FROM messages_fts WHERE rowid = old.id;
5934
- INSERT INTO messages_fts(rowid, subject, body_text, sender, recipients)
5935
- VALUES (new.id, new.subject, '', new."from", new."to");
5955
+ DROP TRIGGER IF EXISTS messages_au;
5956
+
5957
+ CREATE TRIGGER messages_au AFTER UPDATE ON messages BEGIN
5958
+ UPDATE messages_fts SET subject = new.subject, sender = new."from", recipients = new."to"
5959
+ WHERE rowid = old.id;
5936
5960
  END;
5937
5961
  `);
5938
5962
  }
package/dist/mcp.d.cts CHANGED
@@ -19,6 +19,16 @@ interface JsonSchema {
19
19
  }
20
20
  interface SurfaceTool<TCtx> {
21
21
  name: string;
22
+ cli?: {
23
+ noun?: string;
24
+ verb: string;
25
+ positionals?: string[];
26
+ action?: {
27
+ property: string;
28
+ verbs?: Record<string, string>;
29
+ positionals?: Record<string, string[]>;
30
+ };
31
+ };
22
32
  title?: string;
23
33
  description: string;
24
34
  inputSchema: JsonSchema & {
package/dist/mcp.d.ts CHANGED
@@ -19,6 +19,16 @@ interface JsonSchema {
19
19
  }
20
20
  interface SurfaceTool<TCtx> {
21
21
  name: string;
22
+ cli?: {
23
+ noun?: string;
24
+ verb: string;
25
+ positionals?: string[];
26
+ action?: {
27
+ property: string;
28
+ verbs?: Record<string, string>;
29
+ positionals?: Record<string, string[]>;
30
+ };
31
+ };
22
32
  title?: string;
23
33
  description: string;
24
34
  inputSchema: JsonSchema & {
package/dist/mcp.js CHANGED
@@ -9,8 +9,13 @@ import { randomUUID } from 'node:crypto';
9
9
 
10
10
  var __defProp = Object.defineProperty;
11
11
  var __getOwnPropNames = Object.getOwnPropertyNames;
12
- var __esm = (fn, res) => function __init() {
13
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
+ var __esm = (fn, res, err) => function __init() {
13
+ if (err) throw err[0];
14
+ try {
15
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
16
+ } catch (e) {
17
+ throw err = [e], e;
18
+ }
14
19
  };
15
20
  var __export = (target, all) => {
16
21
  for (var name in all)
@@ -1376,9 +1381,20 @@ var init_compress = __esm({
1376
1381
  "src/imap/compress.ts"() {
1377
1382
  }
1378
1383
  });
1384
+
1385
+ // src/lib/connection_error.ts
1386
+ function connectionError(error, host, port) {
1387
+ return error.code === "ECONNREFUSED" ? new EmailConnectionError(`Connection refused to ${host}:${port}`) : error;
1388
+ }
1389
+ var init_connection_error = __esm({
1390
+ "src/lib/connection_error.ts"() {
1391
+ init_errors();
1392
+ }
1393
+ });
1379
1394
  var ImapConnection;
1380
1395
  var init_connection = __esm({
1381
1396
  "src/imap/connection.ts"() {
1397
+ init_connection_error();
1382
1398
  init_defaults();
1383
1399
  ImapConnection = class extends EventEmitter {
1384
1400
  #config;
@@ -1402,8 +1418,9 @@ var init_connection = __esm({
1402
1418
  const useTls = this.#config.tls !== false;
1403
1419
  const onError = (err) => {
1404
1420
  this.#connected = false;
1405
- this.emit("error", err);
1406
- reject(err);
1421
+ const error = connectionError(err, this.#config.host, this.#config.port);
1422
+ if (this.listenerCount("error") > 0) this.emit("error", error);
1423
+ reject(error);
1407
1424
  };
1408
1425
  if (useTls) {
1409
1426
  const sock = tls.connect({
@@ -3011,6 +3028,10 @@ var init_encode_date = __esm({
3011
3028
  });
3012
3029
 
3013
3030
  // src/mime/compose_message.ts
3031
+ function bracketId(id) {
3032
+ const value = id.trim();
3033
+ return value.startsWith("<") && value.endsWith(">") ? value : `<${value}>`;
3034
+ }
3014
3035
  function composeMessage(input) {
3015
3036
  const lines = [];
3016
3037
  const from = input.from ?? { address: "unknown@local" };
@@ -3028,10 +3049,10 @@ function composeMessage(input) {
3028
3049
  }
3029
3050
  lines.push(encodeHeader("Subject", input.subject).trim());
3030
3051
  if (input.inReplyTo) {
3031
- lines.push(encodeHeader("In-Reply-To", input.inReplyTo).trim());
3052
+ lines.push(encodeHeader("In-Reply-To", bracketId(input.inReplyTo)).trim());
3032
3053
  }
3033
3054
  if (input.references?.length) {
3034
- lines.push(encodeHeader("References", input.references.join(" ")).trim());
3055
+ lines.push(encodeHeader("References", input.references.map(bracketId).join(" ")).trim());
3035
3056
  }
3036
3057
  if (input.headers) {
3037
3058
  for (const [k, v] of Object.entries(input.headers)) {
@@ -3093,7 +3114,6 @@ ${attBlocks}\r
3093
3114
  --${b}--`;
3094
3115
  }
3095
3116
  const raw2 = `${lines.join("\r\n")}\r
3096
- \r
3097
3117
  ${body}`;
3098
3118
  return Buffer.from(raw2, "utf8");
3099
3119
  }
@@ -3244,6 +3264,7 @@ function parseEhloCapabilities(message) {
3244
3264
  var SmtpConnection;
3245
3265
  var init_connection2 = __esm({
3246
3266
  "src/smtp/connection.ts"() {
3267
+ init_connection_error();
3247
3268
  init_parse_response();
3248
3269
  SmtpConnection = class {
3249
3270
  #host;
@@ -3277,7 +3298,9 @@ var init_connection2 = __esm({
3277
3298
  reject(new Error("Plaintext port 25 requires allowInsecure: true"));
3278
3299
  return;
3279
3300
  }
3280
- this.#socket.once("error", reject);
3301
+ this.#socket.once("error", (error) => {
3302
+ reject(connectionError(error, this.#host, this.#port));
3303
+ });
3281
3304
  this.#socket.once(
3282
3305
  "secureConnect" in this.#socket ? "secureConnect" : "connect",
3283
3306
  async () => {
@@ -4963,7 +4986,7 @@ var init_network = __esm({
4963
4986
  });
4964
4987
 
4965
4988
  // src/version.ts
4966
- var emailVersion = "0.4.0";
4989
+ var emailVersion = "0.5.0";
4967
4990
 
4968
4991
  // src/surface/email_mcp_instructions.ts
4969
4992
  var emailMcpInstructions = "Read and search cached email offline. Configure live accounts with email account add before network operations. Inspect messages before replying or changing folders. Confirm recipients and content before sending; trash and folder deletion can remove mail. Credentials use the existing email CLI account configuration or EMAIL_* environment variables.";
@@ -5810,7 +5833,7 @@ var emailTools2 = emailTools.map((tool) => ({
5810
5833
  }));
5811
5834
 
5812
5835
  // src/surface/email_surface_tools.ts
5813
- var emailSurfaceTools = emailTools2.map((tool) => ({
5836
+ var emailMcpTools = emailTools2.map((tool) => ({
5814
5837
  ...tool,
5815
5838
  inputSchema: { ...tool.inputSchema, type: "object" },
5816
5839
  async handler(db, input) {
@@ -5874,7 +5897,7 @@ function emailMcpOptions(context) {
5874
5897
  version: emailVersion,
5875
5898
  title: "Email",
5876
5899
  instructions: emailMcpInstructions,
5877
- tools: emailSurfaceTools,
5900
+ tools: emailMcpTools,
5878
5901
  context,
5879
5902
  annotations: (tool) => ({
5880
5903
  readOnlyHint: tool.readOnly ?? false,
@@ -5905,10 +5928,11 @@ function createFts(db) {
5905
5928
  DELETE FROM messages_fts WHERE rowid = old.id;
5906
5929
  END;
5907
5930
 
5908
- CREATE TRIGGER IF NOT EXISTS messages_au AFTER UPDATE ON messages BEGIN
5909
- DELETE FROM messages_fts WHERE rowid = old.id;
5910
- INSERT INTO messages_fts(rowid, subject, body_text, sender, recipients)
5911
- VALUES (new.id, new.subject, '', new."from", new."to");
5931
+ DROP TRIGGER IF EXISTS messages_au;
5932
+
5933
+ CREATE TRIGGER messages_au AFTER UPDATE ON messages BEGIN
5934
+ UPDATE messages_fts SET subject = new.subject, sender = new."from", recipients = new."to"
5935
+ WHERE rowid = old.id;
5912
5936
  END;
5913
5937
  `);
5914
5938
  }