@bobfrankston/mailx-imap 0.1.84 → 0.1.85

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.
Files changed (2) hide show
  1. package/index.js +20 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -118,18 +118,30 @@ async function extractPreview(source) {
118
118
  // remaining base64 data: URIs (rare: text/plain copies generated
119
119
  // from a Quill compose pasted-image HTML) collapsed to [image] too.
120
120
  let raw;
121
- if (bodyHtml) {
122
- // Drop the CONTENTS of style/script/head blocks and HTML comments
123
- // first a plain tag-strip removes the <style> tags but leaves the
124
- // CSS rules between them, which then leak into the preview as
125
- // `*{box-sizing:border-box}` / `@media …{ }` garbage (Bob's
126
- // 2026-05-31 marketing-mail shot). Order matters: kill blocks, then
127
- // images [image], then any remaining tags.
121
+ // PREFER the plain-text rendering for the summary. The HTML→[image]
122
+ // path turns an image-heavy marketing/tracking email into a useless
123
+ // "[image] [image] [image]…" wall the "[no summary]" Bob hit
124
+ // 2026-06-04. mailparser's `text` is the text/plain alternative when
125
+ // present, otherwise a tags-and-images-stripped rendering of the HTML,
126
+ // i.e. the actual words. Only fall back to HTML when there's no usable
127
+ // text at all (genuinely image-only mail).
128
+ const textCandidate = (bodyText || "").replace(/\s+/g, " ").trim();
129
+ if (textCandidate.length >= 3) {
130
+ raw = bodyText;
131
+ }
132
+ else if (bodyHtml) {
133
+ // No usable text part. Strip style/script/head + comments (CSS would
134
+ // otherwise leak into the preview — Bob 2026-05-31), then prefer an
135
+ // <img alt="…"> caption over the bare "[image]" token, and collapse
136
+ // runs of placeholders so even this fallback isn't a wall.
128
137
  raw = bodyHtml
129
138
  .replace(/<!--[\s\S]*?-->/g, " ")
130
139
  .replace(/<(style|script|head)\b[^>]*>[\s\S]*?<\/\1>/gi, " ")
140
+ .replace(/<img\b[^>]*\balt\s*=\s*"([^"]+)"[^>]*>/gi, " $1 ")
141
+ .replace(/<img\b[^>]*\balt\s*=\s*'([^']+)'[^>]*>/gi, " $1 ")
131
142
  .replace(/<img\b[^>]*>/gi, " [image] ")
132
- .replace(/<[^>]+>/g, " ");
143
+ .replace(/<[^>]+>/g, " ")
144
+ .replace(/(\[image\]\s*){2,}/g, "[image] ");
133
145
  }
134
146
  else {
135
147
  raw = bodyText;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-imap",
3
- "version": "0.1.84",
3
+ "version": "0.1.85",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",