Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(google): forwarded emails keep their forwarded content in the brain

garrytan49bc500124b2
diff --git a/src/core/google/google-render.ts b/src/core/google/google-render.ts
index bc546666e1..0d35d9c719 100644
--- a/src/core/google/google-render.ts
+++ b/src/core/google/google-render.ts
@@ -171,15 +171,18 @@ export function htmlToText(html: string): string {
/**
* Trim quoted-reply tails: trailing '>'-quoted runs and the "On ... wrote:"
* marker line and everything after it. Conservative — only the TAIL is cut,
- * inline quotes mid-message survive.
+ * inline quotes mid-message survive. A forward separator (Gmail, Apple Mail)
+ * before any reply marker keeps the whole body (#8719): forwarded content is
+ * new to the brain, while a reply's quoted tail repeats a message of the thread.
*/
export function trimQuotedReply(text: string): string {
const lines = text.split('\n');
- // Find the "On <date>, <name> wrote:" marker (also matches forwarded-message separators).
+ // Find the "On <date>, <name> wrote:" or Original Message marker.
let cut = lines.length;
for (let i = 0; i < lines.length; i++) {
const l = lines[i].trim();
- if (/^On .{4,80} wrote:$/.test(l) || /^-{2,}\s*Original Message\s*-{2,}$/i.test(l) || /^-{2,}\s*Forwarded message\s*-{2,}$/i.test(l)) {
+ if (/^-{2,}\s*Forwarded message\s*-{2,}$/i.test(l) || /^Begin forwarded message:$/i.test(l)) return text.trim();
+ if (/^On .{4,80} wrote:$/.test(l) || /^-{2,}\s*Original Message\s*-{2,}$/i.test(l)) {
cut = i;
break;
}
diff --git a/test/google-render-forward-8719.test.ts b/test/google-render-forward-8719.test.ts
new file mode 100644
index 0000000000..a1d7d409e1
--- /dev/null
+++ b/test/google-render-forward-8719.test.ts
@@ -0,0 +1,31 @@
+/**
+ * #8719: a forwarded email's content is the message, not a quoted tail of
+ * this thread, so the Gmail renderer keeps it. Reply trimming is unchanged,
+ * including a forward quoted inside a reply.
+ *
+ * Synthetic bodies only: example.invalid addresses.
+ */
+import { describe, expect, test } from 'bun:test';
+import { trimQuotedReply } from '../src/core/google/google-render.ts';
+
+describe('#8719 trimQuotedReply keeps forwarded content', () => {
+ test('a Gmail forward keeps the note and the forwarded body', () => {
+ const text = 'FYI\n\n---------- Forwarded message ---------\nFrom: Alice Example <[email protected]>\nSubject: Launch\n\nThe launch moved to Friday.';
+ expect(trimQuotedReply(text)).toBe(text);
+ });
+
+ test('a forward with no note is not emptied', () => {
+ const text = '---------- Forwarded message ---------\nFrom: [email protected]\n\nThe launch moved to Friday.';
+ expect(trimQuotedReply(text)).toBe(text);
+ });
+
+ test('an Apple Mail forward keeps the reply chain quoted inside it', () => {
+ const text = 'See below.\n\nBegin forwarded message:\n\nFrom: [email protected]\nThe launch moved to Friday.\n\nOn Mon, Jan 5, 2026 at 9:00 AM Bob Example <[email protected]> wrote:\n> Is the launch still Thursday?';
+ expect(trimQuotedReply(text)).toBe(text);
+ });
+
+ test('a reply that quotes a forward is still cut at the reply marker', () => {
+ const text = 'Thanks, noted.\n\nOn Mon, Jan 5, 2026 at 9:00 AM Alice Example <[email protected]> wrote:\n> ---------- Forwarded message ---------\n> The launch moved to Friday.';
+ expect(trimQuotedReply(text)).toBe('Thanks, noted.');
+ });
+});