@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.
- package/index.js +20 -8
- 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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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;
|