@zaclinley/dsh-mailharbor 0.22.1 → 0.22.2

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/lib/index.js CHANGED
@@ -1609,6 +1609,20 @@ var MailDatabase = class {
1609
1609
  return 0;
1610
1610
  }
1611
1611
  }
1612
+ /** Recover To/Cc from raw headers when the stored summary is empty. */
1613
+ recipientsFromRaw(raw) {
1614
+ const text2 = Buffer.from(raw.subarray(0, Math.min(raw.byteLength, 3e5))).toString("utf8");
1615
+ const separator = text2.search(/\r?\n\r?\n/);
1616
+ const head = (separator >= 0 ? text2.slice(0, separator) : text2).replace(/\r?\n[ \t]+/g, " ");
1617
+ const value = (name2) => {
1618
+ const match = new RegExp(`^${name2}:\\s*(.*)$`, "im").exec(head);
1619
+ return match === null ? "" : String(match[1] ?? "");
1620
+ };
1621
+ const to = parseAddressList(
1622
+ value("to") || value("delivered-to") || value("x-original-to") || value("apparently-to")
1623
+ );
1624
+ return { to, cc: parseAddressList(value("cc")) };
1625
+ }
1612
1626
  get(localId) {
1613
1627
  const db = this.open();
1614
1628
  const row = db.prepare(
@@ -1642,6 +1656,19 @@ var MailDatabase = class {
1642
1656
  size: Number(item.size ?? 0)
1643
1657
  }));
1644
1658
  const max = this.options.maxBodyChars ?? 4e5;
1659
+ let to = parseAddressList(String(row.to_addr ?? ""));
1660
+ let cc = parseAddressList(String(row.cc ?? ""));
1661
+ if (to.length === 0) {
1662
+ try {
1663
+ const raw = db.prepare("SELECT raw_eml FROM emails WHERE id = ?").get(localId)?.raw_eml;
1664
+ if (raw instanceof Uint8Array) {
1665
+ const recovered = this.recipientsFromRaw(raw);
1666
+ to = recovered.to;
1667
+ if (cc.length === 0) cc = recovered.cc;
1668
+ }
1669
+ } catch {
1670
+ }
1671
+ }
1645
1672
  const bodyText2 = String(row.body_text ?? "");
1646
1673
  const inlineImages = wantsInline ? rows.filter(
1647
1674
  (item) => String(item.content_type ?? "").toLowerCase().startsWith("image/")
@@ -1653,7 +1680,8 @@ var MailDatabase = class {
1653
1680
  })).filter((item) => item.data !== void 0) : [];
1654
1681
  return {
1655
1682
  ...rowToSummary(row),
1656
- cc: parseAddressList(String(row.cc ?? "")),
1683
+ to,
1684
+ cc,
1657
1685
  replyTo: [],
1658
1686
  text: truncate(bodyText2, max),
1659
1687
  html: bodyHtml === "" ? null : truncate(inlineCidImages(bodyHtml, inlineImages), max * 2),
@@ -3124,7 +3152,7 @@ ${conversation.trim()}
3124
3152
  }
3125
3153
 
3126
3154
  // src/host/version.ts
3127
- var VERSION = "0.22.1";
3155
+ var VERSION = "0.22.2";
3128
3156
 
3129
3157
  // src/host/api.ts
3130
3158
  init_smtp();