@ghostpaw/email 0.4.0 → 0.4.1

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/cli.js CHANGED
@@ -2350,7 +2350,7 @@ var init_dist2 = __esm({
2350
2350
  var emailVersion;
2351
2351
  var init_version = __esm({
2352
2352
  "src/version.ts"() {
2353
- emailVersion = "0.4.0";
2353
+ emailVersion = "0.4.1";
2354
2354
  }
2355
2355
  });
2356
2356
  function getConfigDir() {
@@ -4137,9 +4137,20 @@ var init_compress = __esm({
4137
4137
  "src/imap/compress.ts"() {
4138
4138
  }
4139
4139
  });
4140
+
4141
+ // src/lib/connection_error.ts
4142
+ function connectionError(error, host, port) {
4143
+ return error.code === "ECONNREFUSED" ? new EmailConnectionError(`Connection refused to ${host}:${port}`) : error;
4144
+ }
4145
+ var init_connection_error = __esm({
4146
+ "src/lib/connection_error.ts"() {
4147
+ init_errors();
4148
+ }
4149
+ });
4140
4150
  var ImapConnection;
4141
4151
  var init_connection = __esm({
4142
4152
  "src/imap/connection.ts"() {
4153
+ init_connection_error();
4143
4154
  init_defaults();
4144
4155
  ImapConnection = class extends EventEmitter {
4145
4156
  #config;
@@ -4163,8 +4174,9 @@ var init_connection = __esm({
4163
4174
  const useTls = this.#config.tls !== false;
4164
4175
  const onError = (err) => {
4165
4176
  this.#connected = false;
4166
- this.emit("error", err);
4167
- reject(err);
4177
+ const error = connectionError(err, this.#config.host, this.#config.port);
4178
+ if (this.listenerCount("error") > 0) this.emit("error", error);
4179
+ reject(error);
4168
4180
  };
4169
4181
  if (useTls) {
4170
4182
  const sock = tls.connect({
@@ -7663,10 +7675,11 @@ function createFts(db) {
7663
7675
  DELETE FROM messages_fts WHERE rowid = old.id;
7664
7676
  END;
7665
7677
 
7666
- CREATE TRIGGER IF NOT EXISTS messages_au AFTER UPDATE ON messages BEGIN
7667
- DELETE FROM messages_fts WHERE rowid = old.id;
7668
- INSERT INTO messages_fts(rowid, subject, body_text, sender, recipients)
7669
- VALUES (new.id, new.subject, '', new."from", new."to");
7678
+ DROP TRIGGER IF EXISTS messages_au;
7679
+
7680
+ CREATE TRIGGER messages_au AFTER UPDATE ON messages BEGIN
7681
+ UPDATE messages_fts SET subject = new.subject, sender = new."from", recipients = new."to"
7682
+ WHERE rowid = old.id;
7670
7683
  END;
7671
7684
  `);
7672
7685
  }
@@ -7993,6 +8006,10 @@ var init_encode_date = __esm({
7993
8006
  });
7994
8007
 
7995
8008
  // src/mime/compose_message.ts
8009
+ function bracketId(id) {
8010
+ const value = id.trim();
8011
+ return value.startsWith("<") && value.endsWith(">") ? value : `<${value}>`;
8012
+ }
7996
8013
  function composeMessage(input) {
7997
8014
  const lines = [];
7998
8015
  const from = input.from ?? { address: "unknown@local" };
@@ -8010,10 +8027,10 @@ function composeMessage(input) {
8010
8027
  }
8011
8028
  lines.push(encodeHeader("Subject", input.subject).trim());
8012
8029
  if (input.inReplyTo) {
8013
- lines.push(encodeHeader("In-Reply-To", input.inReplyTo).trim());
8030
+ lines.push(encodeHeader("In-Reply-To", bracketId(input.inReplyTo)).trim());
8014
8031
  }
8015
8032
  if (input.references?.length) {
8016
- lines.push(encodeHeader("References", input.references.join(" ")).trim());
8033
+ lines.push(encodeHeader("References", input.references.map(bracketId).join(" ")).trim());
8017
8034
  }
8018
8035
  if (input.headers) {
8019
8036
  for (const [k2, v2] of Object.entries(input.headers)) {
@@ -8075,7 +8092,6 @@ ${attBlocks}\r
8075
8092
  --${b2}--`;
8076
8093
  }
8077
8094
  const raw2 = `${lines.join("\r\n")}\r
8078
- \r
8079
8095
  ${body}`;
8080
8096
  return Buffer.from(raw2, "utf8");
8081
8097
  }
@@ -8226,6 +8242,7 @@ function parseEhloCapabilities(message) {
8226
8242
  var SmtpConnection;
8227
8243
  var init_connection2 = __esm({
8228
8244
  "src/smtp/connection.ts"() {
8245
+ init_connection_error();
8229
8246
  init_parse_response();
8230
8247
  SmtpConnection = class {
8231
8248
  #host;
@@ -8259,7 +8276,9 @@ var init_connection2 = __esm({
8259
8276
  reject(new Error("Plaintext port 25 requires allowInsecure: true"));
8260
8277
  return;
8261
8278
  }
8262
- this.#socket.once("error", reject);
8279
+ this.#socket.once("error", (error) => {
8280
+ reject(connectionError(error, this.#host, this.#port));
8281
+ });
8263
8282
  this.#socket.once(
8264
8283
  "secureConnect" in this.#socket ? "secureConnect" : "connect",
8265
8284
  async () => {
@@ -8702,7 +8721,13 @@ var init_mailbox = __esm({
8702
8721
  username: authUser2
8703
8722
  });
8704
8723
  const session = new ImapSession(this.#config);
8705
- await session.connect();
8724
+ try {
8725
+ await session.connect();
8726
+ } catch (error) {
8727
+ db.close();
8728
+ this.#db = null;
8729
+ throw error;
8730
+ }
8706
8731
  this.#session = session;
8707
8732
  this.#read = createReadSurface(db, account.id);
8708
8733
  this.#write = createWriteSurface(db, {
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, {
@@ -251,7 +251,7 @@ var init_mcp_stdio = __esm({
251
251
  var emailVersion;
252
252
  var init_version = __esm({
253
253
  "src/version.ts"() {
254
- emailVersion = "0.4.0";
254
+ emailVersion = "0.4.1";
255
255
  }
256
256
  });
257
257
 
@@ -2475,9 +2475,20 @@ var init_compress = __esm({
2475
2475
  "src/imap/compress.ts"() {
2476
2476
  }
2477
2477
  });
2478
+
2479
+ // src/lib/connection_error.ts
2480
+ function connectionError(error, host, port) {
2481
+ return error.code === "ECONNREFUSED" ? new EmailConnectionError(`Connection refused to ${host}:${port}`) : error;
2482
+ }
2483
+ var init_connection_error = __esm({
2484
+ "src/lib/connection_error.ts"() {
2485
+ init_errors();
2486
+ }
2487
+ });
2478
2488
  var ImapConnection;
2479
2489
  var init_connection = __esm({
2480
2490
  "src/imap/connection.ts"() {
2491
+ init_connection_error();
2481
2492
  init_defaults();
2482
2493
  ImapConnection = class extends EventEmitter {
2483
2494
  #config;
@@ -2501,8 +2512,9 @@ var init_connection = __esm({
2501
2512
  const useTls = this.#config.tls !== false;
2502
2513
  const onError = (err) => {
2503
2514
  this.#connected = false;
2504
- this.emit("error", err);
2505
- reject(err);
2515
+ const error = connectionError(err, this.#config.host, this.#config.port);
2516
+ if (this.listenerCount("error") > 0) this.emit("error", error);
2517
+ reject(error);
2506
2518
  };
2507
2519
  if (useTls) {
2508
2520
  const sock = tls.connect({
@@ -4110,6 +4122,10 @@ var init_encode_date = __esm({
4110
4122
  });
4111
4123
 
4112
4124
  // src/mime/compose_message.ts
4125
+ function bracketId(id) {
4126
+ const value = id.trim();
4127
+ return value.startsWith("<") && value.endsWith(">") ? value : `<${value}>`;
4128
+ }
4113
4129
  function composeMessage(input) {
4114
4130
  const lines = [];
4115
4131
  const from = input.from ?? { address: "unknown@local" };
@@ -4127,10 +4143,10 @@ function composeMessage(input) {
4127
4143
  }
4128
4144
  lines.push(encodeHeader("Subject", input.subject).trim());
4129
4145
  if (input.inReplyTo) {
4130
- lines.push(encodeHeader("In-Reply-To", input.inReplyTo).trim());
4146
+ lines.push(encodeHeader("In-Reply-To", bracketId(input.inReplyTo)).trim());
4131
4147
  }
4132
4148
  if (input.references?.length) {
4133
- lines.push(encodeHeader("References", input.references.join(" ")).trim());
4149
+ lines.push(encodeHeader("References", input.references.map(bracketId).join(" ")).trim());
4134
4150
  }
4135
4151
  if (input.headers) {
4136
4152
  for (const [k, v] of Object.entries(input.headers)) {
@@ -4192,7 +4208,6 @@ ${attBlocks}\r
4192
4208
  --${b}--`;
4193
4209
  }
4194
4210
  const raw2 = `${lines.join("\r\n")}\r
4195
- \r
4196
4211
  ${body}`;
4197
4212
  return Buffer.from(raw2, "utf8");
4198
4213
  }
@@ -4343,6 +4358,7 @@ function parseEhloCapabilities(message) {
4343
4358
  var SmtpConnection;
4344
4359
  var init_connection2 = __esm({
4345
4360
  "src/smtp/connection.ts"() {
4361
+ init_connection_error();
4346
4362
  init_parse_response();
4347
4363
  SmtpConnection = class {
4348
4364
  #host;
@@ -4376,7 +4392,9 @@ var init_connection2 = __esm({
4376
4392
  reject(new Error("Plaintext port 25 requires allowInsecure: true"));
4377
4393
  return;
4378
4394
  }
4379
- this.#socket.once("error", reject);
4395
+ this.#socket.once("error", (error) => {
4396
+ reject(connectionError(error, this.#host, this.#port));
4397
+ });
4380
4398
  this.#socket.once(
4381
4399
  "secureConnect" in this.#socket ? "secureConnect" : "connect",
4382
4400
  async () => {
@@ -6172,10 +6190,11 @@ function createFts(db) {
6172
6190
  DELETE FROM messages_fts WHERE rowid = old.id;
6173
6191
  END;
6174
6192
 
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");
6193
+ DROP TRIGGER IF EXISTS messages_au;
6194
+
6195
+ CREATE TRIGGER messages_au AFTER UPDATE ON messages BEGIN
6196
+ UPDATE messages_fts SET subject = new.subject, sender = new."from", recipients = new."to"
6197
+ WHERE rowid = old.id;
6179
6198
  END;
6180
6199
  `);
6181
6200
  }
package/dist/mcp.cjs CHANGED
@@ -1400,9 +1400,20 @@ var init_compress = __esm({
1400
1400
  "src/imap/compress.ts"() {
1401
1401
  }
1402
1402
  });
1403
+
1404
+ // src/lib/connection_error.ts
1405
+ function connectionError(error, host, port) {
1406
+ return error.code === "ECONNREFUSED" ? new EmailConnectionError(`Connection refused to ${host}:${port}`) : error;
1407
+ }
1408
+ var init_connection_error = __esm({
1409
+ "src/lib/connection_error.ts"() {
1410
+ init_errors();
1411
+ }
1412
+ });
1403
1413
  var ImapConnection;
1404
1414
  var init_connection = __esm({
1405
1415
  "src/imap/connection.ts"() {
1416
+ init_connection_error();
1406
1417
  init_defaults();
1407
1418
  ImapConnection = class extends node_events.EventEmitter {
1408
1419
  #config;
@@ -1426,8 +1437,9 @@ var init_connection = __esm({
1426
1437
  const useTls = this.#config.tls !== false;
1427
1438
  const onError = (err) => {
1428
1439
  this.#connected = false;
1429
- this.emit("error", err);
1430
- reject(err);
1440
+ const error = connectionError(err, this.#config.host, this.#config.port);
1441
+ if (this.listenerCount("error") > 0) this.emit("error", error);
1442
+ reject(error);
1431
1443
  };
1432
1444
  if (useTls) {
1433
1445
  const sock = tls__namespace.connect({
@@ -3035,6 +3047,10 @@ var init_encode_date = __esm({
3035
3047
  });
3036
3048
 
3037
3049
  // src/mime/compose_message.ts
3050
+ function bracketId(id) {
3051
+ const value = id.trim();
3052
+ return value.startsWith("<") && value.endsWith(">") ? value : `<${value}>`;
3053
+ }
3038
3054
  function composeMessage(input) {
3039
3055
  const lines = [];
3040
3056
  const from = input.from ?? { address: "unknown@local" };
@@ -3052,10 +3068,10 @@ function composeMessage(input) {
3052
3068
  }
3053
3069
  lines.push(encodeHeader("Subject", input.subject).trim());
3054
3070
  if (input.inReplyTo) {
3055
- lines.push(encodeHeader("In-Reply-To", input.inReplyTo).trim());
3071
+ lines.push(encodeHeader("In-Reply-To", bracketId(input.inReplyTo)).trim());
3056
3072
  }
3057
3073
  if (input.references?.length) {
3058
- lines.push(encodeHeader("References", input.references.join(" ")).trim());
3074
+ lines.push(encodeHeader("References", input.references.map(bracketId).join(" ")).trim());
3059
3075
  }
3060
3076
  if (input.headers) {
3061
3077
  for (const [k, v] of Object.entries(input.headers)) {
@@ -3117,7 +3133,6 @@ ${attBlocks}\r
3117
3133
  --${b}--`;
3118
3134
  }
3119
3135
  const raw2 = `${lines.join("\r\n")}\r
3120
- \r
3121
3136
  ${body}`;
3122
3137
  return Buffer.from(raw2, "utf8");
3123
3138
  }
@@ -3268,6 +3283,7 @@ function parseEhloCapabilities(message) {
3268
3283
  var SmtpConnection;
3269
3284
  var init_connection2 = __esm({
3270
3285
  "src/smtp/connection.ts"() {
3286
+ init_connection_error();
3271
3287
  init_parse_response();
3272
3288
  SmtpConnection = class {
3273
3289
  #host;
@@ -3301,7 +3317,9 @@ var init_connection2 = __esm({
3301
3317
  reject(new Error("Plaintext port 25 requires allowInsecure: true"));
3302
3318
  return;
3303
3319
  }
3304
- this.#socket.once("error", reject);
3320
+ this.#socket.once("error", (error) => {
3321
+ reject(connectionError(error, this.#host, this.#port));
3322
+ });
3305
3323
  this.#socket.once(
3306
3324
  "secureConnect" in this.#socket ? "secureConnect" : "connect",
3307
3325
  async () => {
@@ -4987,7 +5005,7 @@ var init_network = __esm({
4987
5005
  });
4988
5006
 
4989
5007
  // src/version.ts
4990
- var emailVersion = "0.4.0";
5008
+ var emailVersion = "0.4.1";
4991
5009
 
4992
5010
  // src/surface/email_mcp_instructions.ts
4993
5011
  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.";
@@ -5929,10 +5947,11 @@ function createFts(db) {
5929
5947
  DELETE FROM messages_fts WHERE rowid = old.id;
5930
5948
  END;
5931
5949
 
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");
5950
+ DROP TRIGGER IF EXISTS messages_au;
5951
+
5952
+ CREATE TRIGGER messages_au AFTER UPDATE ON messages BEGIN
5953
+ UPDATE messages_fts SET subject = new.subject, sender = new."from", recipients = new."to"
5954
+ WHERE rowid = old.id;
5936
5955
  END;
5937
5956
  `);
5938
5957
  }
package/dist/mcp.js CHANGED
@@ -1376,9 +1376,20 @@ var init_compress = __esm({
1376
1376
  "src/imap/compress.ts"() {
1377
1377
  }
1378
1378
  });
1379
+
1380
+ // src/lib/connection_error.ts
1381
+ function connectionError(error, host, port) {
1382
+ return error.code === "ECONNREFUSED" ? new EmailConnectionError(`Connection refused to ${host}:${port}`) : error;
1383
+ }
1384
+ var init_connection_error = __esm({
1385
+ "src/lib/connection_error.ts"() {
1386
+ init_errors();
1387
+ }
1388
+ });
1379
1389
  var ImapConnection;
1380
1390
  var init_connection = __esm({
1381
1391
  "src/imap/connection.ts"() {
1392
+ init_connection_error();
1382
1393
  init_defaults();
1383
1394
  ImapConnection = class extends EventEmitter {
1384
1395
  #config;
@@ -1402,8 +1413,9 @@ var init_connection = __esm({
1402
1413
  const useTls = this.#config.tls !== false;
1403
1414
  const onError = (err) => {
1404
1415
  this.#connected = false;
1405
- this.emit("error", err);
1406
- reject(err);
1416
+ const error = connectionError(err, this.#config.host, this.#config.port);
1417
+ if (this.listenerCount("error") > 0) this.emit("error", error);
1418
+ reject(error);
1407
1419
  };
1408
1420
  if (useTls) {
1409
1421
  const sock = tls.connect({
@@ -3011,6 +3023,10 @@ var init_encode_date = __esm({
3011
3023
  });
3012
3024
 
3013
3025
  // src/mime/compose_message.ts
3026
+ function bracketId(id) {
3027
+ const value = id.trim();
3028
+ return value.startsWith("<") && value.endsWith(">") ? value : `<${value}>`;
3029
+ }
3014
3030
  function composeMessage(input) {
3015
3031
  const lines = [];
3016
3032
  const from = input.from ?? { address: "unknown@local" };
@@ -3028,10 +3044,10 @@ function composeMessage(input) {
3028
3044
  }
3029
3045
  lines.push(encodeHeader("Subject", input.subject).trim());
3030
3046
  if (input.inReplyTo) {
3031
- lines.push(encodeHeader("In-Reply-To", input.inReplyTo).trim());
3047
+ lines.push(encodeHeader("In-Reply-To", bracketId(input.inReplyTo)).trim());
3032
3048
  }
3033
3049
  if (input.references?.length) {
3034
- lines.push(encodeHeader("References", input.references.join(" ")).trim());
3050
+ lines.push(encodeHeader("References", input.references.map(bracketId).join(" ")).trim());
3035
3051
  }
3036
3052
  if (input.headers) {
3037
3053
  for (const [k, v] of Object.entries(input.headers)) {
@@ -3093,7 +3109,6 @@ ${attBlocks}\r
3093
3109
  --${b}--`;
3094
3110
  }
3095
3111
  const raw2 = `${lines.join("\r\n")}\r
3096
- \r
3097
3112
  ${body}`;
3098
3113
  return Buffer.from(raw2, "utf8");
3099
3114
  }
@@ -3244,6 +3259,7 @@ function parseEhloCapabilities(message) {
3244
3259
  var SmtpConnection;
3245
3260
  var init_connection2 = __esm({
3246
3261
  "src/smtp/connection.ts"() {
3262
+ init_connection_error();
3247
3263
  init_parse_response();
3248
3264
  SmtpConnection = class {
3249
3265
  #host;
@@ -3277,7 +3293,9 @@ var init_connection2 = __esm({
3277
3293
  reject(new Error("Plaintext port 25 requires allowInsecure: true"));
3278
3294
  return;
3279
3295
  }
3280
- this.#socket.once("error", reject);
3296
+ this.#socket.once("error", (error) => {
3297
+ reject(connectionError(error, this.#host, this.#port));
3298
+ });
3281
3299
  this.#socket.once(
3282
3300
  "secureConnect" in this.#socket ? "secureConnect" : "connect",
3283
3301
  async () => {
@@ -4963,7 +4981,7 @@ var init_network = __esm({
4963
4981
  });
4964
4982
 
4965
4983
  // src/version.ts
4966
- var emailVersion = "0.4.0";
4984
+ var emailVersion = "0.4.1";
4967
4985
 
4968
4986
  // src/surface/email_mcp_instructions.ts
4969
4987
  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.";
@@ -5905,10 +5923,11 @@ function createFts(db) {
5905
5923
  DELETE FROM messages_fts WHERE rowid = old.id;
5906
5924
  END;
5907
5925
 
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");
5926
+ DROP TRIGGER IF EXISTS messages_au;
5927
+
5928
+ CREATE TRIGGER messages_au AFTER UPDATE ON messages BEGIN
5929
+ UPDATE messages_fts SET subject = new.subject, sender = new."from", recipients = new."to"
5930
+ WHERE rowid = old.id;
5912
5931
  END;
5913
5932
  `);
5914
5933
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghostpaw/email",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Standalone IMAP/SMTP email engine for Node.js — SQLite local cache, threading, sync, zero dependencies, with a built-in LLM tool facade",
5
5
  "type": "module",
6
6
  "exports": {
@@ -111,7 +111,7 @@
111
111
  "email": "max@anonyfox.com",
112
112
  "url": "https://anonyfox.com"
113
113
  },
114
- "homepage": "https://github.com/GhostPawJS/email",
114
+ "homepage": "https://email.ghostpaw.dev/",
115
115
  "bugs": {
116
116
  "url": "https://github.com/GhostPawJS/email/issues"
117
117
  },