Skip to content

Commit 7616aac

Browse files
Make email links clickable: linkify plain-text URLs, allow popups in HTML emails
Add linkify() helper to convert URLs in plain-text bodies into clickable links that open in new tabs. Update HTML email iframe sandbox to allow popups (for links). Style detail links with purple accent color.
1 parent bf45750 commit 7616aac

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎public/app.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ async function loadBox(box) {
144144
list.appendChild(div);
145145
}
146146
}
147+
// Turn URLs in plain-text bodies into links that open in a new tab.
148+
const linkify = (s) =>
149+
s.replace(
150+
/(https?:\/\/[^\s<]+)/g,
151+
'<a href="$1" target="_blank" rel="noopener">$1</a>',
152+
);
153+
147154
const joinAddrs = (j) => {
148155
try {
149156
return JSON.parse(j).join(", ");
@@ -189,8 +196,8 @@ async function openEmail(id, box) {
189196
</div>
190197
${
191198
email.body_html
192-
? `<iframe sandbox="" srcdoc="${esc(email.body_html)}"></iframe>`
193-
: `<pre>${esc(email.body_text || "(empty)")}</pre>`
199+
? `<iframe sandbox="allow-popups allow-popups-to-escape-sandbox" srcdoc="<base target='_blank'>${esc(email.body_html)}"></iframe>`
200+
: `<pre>${linkify(esc(email.body_text || "(empty)"))}</pre>`
194201
}
195202
`;
196203
detail.querySelectorAll("[data-rsvp]").forEach((b) =>

‎public/styles.css‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ main {
388388
font-family: var(--font);
389389
font-size: 14px;
390390
}
391+
.detail a {
392+
color: #a78db1;
393+
}
391394
.detail .actions {
392395
display: flex;
393396
gap: 8px;

0 commit comments

Comments
 (0)