diff --git a/src/mailer.ts b/src/mailer.ts
index 630c3e4..68d1646 100644
--- a/src/mailer.ts
+++ b/src/mailer.ts
@@ -99,15 +99,17 @@ export class CreateEmail {
}
// parses pnid name and links. set the plaintext bool (false by default) to use no html
- private parseReplacements(c: emailComponent, plainText: boolean = false): void {
+ private parseReplacements(c: emailComponent, plainText: boolean = false): string {
+ let tempText = c.text;
+
// for now only replaces the pnid for shoutouts. could easily be expanded to add more.
if (c?.replacements) {
Object.entries(c.replacements).forEach(([key, value]) => {
if (key === 'pnid') {
if (plainText) {
- c.text = c.text.replace(/{{pnid}}/g, value);
+ tempText = tempText.replace(/{{pnid}}/g, value);
} else {
- c.text = c.text.replace(/{{pnid}}/g, `${value}`);
+ tempText = tempText.replace(/{{pnid}}/g, `${value}`);
}
}
});
@@ -117,17 +119,19 @@ export class CreateEmail {
const bRegex = /.*?<\/b>|.*?<\/strong>/g;
if (!plainText) {
- c.text = c.text.replace(bRegex, el => `${el}`);
+ tempText = tempText.replace(bRegex, el => `${el}`);
}
// replace [links](https://example.com) with html anchor tags or a plaintext representation
const linkRegex = /\[(?.*?)\]\((?.*?)\)/g;
if (plainText) {
- c.text = c.text.replace(linkRegex, '$ ($)');
+ tempText = tempText.replace(linkRegex, '$ ($)');
} else {
- c.text = c.text.replace(linkRegex, '$');
+ tempText = tempText.replace(linkRegex, '$');
}
+
+ return tempText;
}
// generates the html version of the email
@@ -135,7 +139,7 @@ export class CreateEmail {
let innerHTML = '';
this.componentArray.map((c, i) => {
- let el = ' ';
+ let el = '';
/* double padding causes issues, and the signature already has padding, so if the last element
* is padding we just yeet it
@@ -143,20 +147,18 @@ export class CreateEmail {
if (i === this.componentArray.length - 1 && c.type === 'padding') {
return;
}
- if (c.type !== 'padding') {
- el = this.addGmailDarkModeFix(c.text);
- }
+
switch (c.type) {
case 'padding':
- innerHTML += `\n
${el}
`;
+ innerHTML += `\n
`;
break;
case 'header':
- this.parseReplacements(c);
- innerHTML += `\n
${el}
`;
+ el = this.parseReplacements(c);
+ innerHTML += `\n
${this.addGmailDarkModeFix(el)}
`;
break;
case 'paragraph':
- this.parseReplacements(c);
- innerHTML += `\n
${el}
`;
+ el = this.parseReplacements(c);
+ innerHTML += `\n
${this.addGmailDarkModeFix(el)}
`;
break;
case 'button':
if (c.link) {
@@ -164,7 +166,7 @@ export class CreateEmail {
} else {
el = `${el}`;
}
- innerHTML += `\n
${el}
`;
+ innerHTML += `\n
${this.addGmailDarkModeFix(el)}
`;
break;
}
});
@@ -179,16 +181,17 @@ export class CreateEmail {
let plainText = '';
this.componentArray.forEach((c) => {
+ let el = '';
switch (c.type) {
case 'padding':
break;
case 'header':
- this.parseReplacements(c, true);
- plainText += `\n${c.text}`;
+ el = this.parseReplacements(c, true);
+ plainText += `\n${el}`;
break;
case 'paragraph':
- this.parseReplacements(c, true);
- plainText += `\n${c.text}`;
+ el = this.parseReplacements(c, true);
+ plainText += `\n${el}`;
break;
case 'button':
if (c.link) {
diff --git a/src/util.ts b/src/util.ts
index 8f05d2d..41d90ae 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -281,9 +281,7 @@ export async function sendPNIDDeletedEmail(emailAddress: string, username: strin
const email = new CreateEmail()
.addHeader('Dear {{pnid}},', { pnid: username })
.addParagraph('your PNID has successfully been deleted.')
- .addParagraph('If you had a tier subscription, a separate cancellation email will be sent.')
- .addParagraph('If you do not receive this cancellation email, or your subscription is still being charged, please contact @jonbarrow on our Discord server.')
- .addButton('Join the Discord', 'https://discord.pretendo.network/');
+ .addParagraph('If you had a tier subscription, a separate cancellation email will be sent. If you do not receive this cancellation email, or you are still being charged for your subscription, please contact @jonbarrow on our [Discord server](https://discord.pretendo.network/).');
const options = {
to: emailAddress,