MCPcopy
hub / github.com/simstudioai/sim / decodePart

Function decodePart

apps/sim/tools/gmail/utils.test.ts:23–30  ·  view source on GitHub ↗

* Extract and base64-decode the body of a specific MIME part identified by its * Content-Type prefix (e.g. `text/plain`, `text/html`). Returns the decoded * UTF-8 string.

(mime: string, contentTypePrefix: string)

Source from the content-addressed store, hash-verified

21 * UTF-8 string.
22 */
23function decodePart(mime: string, contentTypePrefix: string): string {
24 const partRegex = new RegExp(
25 `Content-Type: ${contentTypePrefix}[^\\n]*\\nContent-Transfer-Encoding: base64\\n\\n([\\s\\S]*?)\\n\\n--`
26 )
27 const match = mime.match(partRegex)
28 if (!match) throw new Error(`No ${contentTypePrefix} part found`)
29 return Buffer.from(match[1].replace(/\n/g, ''), 'base64').toString('utf-8')
30}
31
32describe('encodeRfc2047', () => {
33 it('returns ASCII text unchanged', () => {

Callers 1

utils.test.tsFile · 0.85

Calls 2

replaceMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected