# Member update emails can carry ONE header image (Marty, 2026-10-03: the Spooky Doors announcement with its share image). # An optional https image (+ link) adds a simple HTML part next to the plain text, never instead of it: the image on # top (linked), the same paragraphs, the same footer and unsubscribe link. No template, so deliverability stays plain. ROOT = 'D:/Projects/HighRisk/onchain-ad-membership/site/' def edit(path, pairs): b = open(ROOT + path, 'rb').read(); crlf = b.count(b'\r\n') > b.count(b'\n') // 2 s = b.decode('utf-8').replace('\r\n', '\n') for a, r in pairs: if s.count(a) != 1: raise SystemExit('%s anchor %d: %s' % (path, s.count(a), a[:70])) s = s.replace(a, r) if crlf: s = s.replace('\n', '\r\n') open(ROOT + path, 'wb').write(s.encode('utf-8')); print('patched', path) HTML = r"""// the optional HTML twin of the plain text: one linked header image, then the same paragraphs (URLs clickable) const escH = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); const okUrl = u => /^https:\/\/[^\s"'<>]+$/.test(String(u || '')); function toHtml(parts, image, link) { const para = t => '

' + escH(t).replace(/https:\/\/[^\s<]+/g, u => '' + u + '').replace(/\n/g, '
') + '

'; const img = ''; return '
' + (okUrl(link) ? '' + img + '' : img) + parts.map(para).join('') + '
'; } """ edit('updates.js', [ ("function compose({ subject, intro, noteIds, closing }, acct) {", HTML + "function compose({ subject, intro, noteIds, closing, image, imageLink }, acct) {"), (" return { subject: String(subject || '').trim().slice(0, 150) || 'What is new on InstantAdPay', text: parts.join('\\n\\n') };", " return { subject: String(subject || '').trim().slice(0, 150) || 'What is new on InstantAdPay', text: parts.join('\\n\\n'), html: okUrl(image) ? toHtml(parts, image, imageLink) : null };"), (" await R.mailer.send(to, '[TEST] ' + m.subject, m.text);", " await R.mailer.send(to, '[TEST] ' + m.subject, m.text, m.html);"), (" await R.mailer.send(acct.email, m.subject, m.text); rec.sent += 1;", " await R.mailer.send(acct.email, m.subject, m.text, m.html); rec.sent += 1;"), ]) edit('server.js', [ ("const r = await updates.send({ subject: b.subject, intro: b.intro, closing: b.closing, noteIds: (b.noteIds || []).map(String), audience: b.audience,", "const r = await updates.send({ subject: b.subject, intro: b.intro, closing: b.closing, image: b.image, imageLink: b.imageLink, noteIds: (b.noteIds || []).map(String), audience: b.audience,"), ]) print('ok')