1 function getVerificationLink (email: { text: string }) {
4 const regexp = /\[(?<link>http:\/\/[^\]]+)\]/g
5 const matched = text.matchAll(regexp)
7 if (!matched) throw new Error('Could not find verification link in email')
9 for (const match of matched) {
10 const link = match.groups.link
12 if (link.includes('/verify-account/')) return link
15 throw new Error('Could not find /verify-account/ link')
18 function findEmailTo (emails: { text: string, to: { address: string }[] }[], to: string) {
19 for (const email of emails) {
20 for (const { address } of email.to) {
21 if (address === to) return email