]>
Commit | Line | Data |
---|---|---|
5bdfa604 C |
1 | function getVerificationLink (email: { text: string }) { |
2 | const { text } = email | |
3 | ||
4 | const regexp = /\[(?<link>http:\/\/[^\]]+)\]/g | |
5 | const matched = text.matchAll(regexp) | |
6 | ||
7 | if (!matched) throw new Error('Could not find verification link in email') | |
8 | ||
9 | for (const match of matched) { | |
10 | const link = match.groups.link | |
11 | ||
12 | if (link.includes('/verify-account/')) return link | |
13 | } | |
14 | ||
15 | throw new Error('Could not find /verify-account/ link') | |
16 | } | |
17 | ||
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 | |
22 | } | |
23 | } | |
24 | ||
25 | return undefined | |
26 | } | |
27 | ||
28 | export { | |
29 | getVerificationLink, | |
30 | findEmailTo | |
31 | } |