MCPcopy Index your code
hub / github.com/simstudioai/sim / stripQuotedReply

Function stripQuotedReply

apps/sim/lib/mothership/inbox/format.ts:67–86  ·  view source on GitHub ↗

* Strips quoted reply content from email body. * Email clients append the prior thread below a marker line like: * - "On [date] [person] wrote:" * - Lines starting with ">" * - Gmail's "---------- Forwarded message ----------" * * We keep only the new content above the first quote marker.

(text: string)

Source from the content-addressed store, hash-verified

65 * We keep only the new content above the first quote marker.
66 */
67function stripQuotedReply(text: string): string {
68 const lines = text.split('\n')
69 const cutIndex = lines.findIndex((line, i) => {
70 const trimmed = line.trim()
71
72 if (/^On .+ wrote:\s*$/i.test(trimmed)) return true
73
74 if (trimmed.startsWith('>') && i > 0) {
75 const prevTrimmed = lines[i - 1].trim()
76 if (prevTrimmed === '' || /^On .+ wrote:\s*$/i.test(prevTrimmed)) return true
77 }
78
79 return false
80 })
81
82 if (cutIndex < 0) return text
83 if (cutIndex === 0) return '(reply with no new content above the quote)'
84
85 return lines.slice(0, cutIndex).join('\n').trim()
86}
87
88/**
89 * Detects whether an email is a forwarded message based on subject/body patterns.

Callers 1

formatEmailAsMessageFunction · 0.85

Calls 2

testMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected