Merge pull request #349 from OpenSignLabs/mismatch_attach

feat: restrict emails
This commit is contained in:
prafull-opensignlabs
2025-03-03 17:57:33 +00:00
parent 5c06ff4242
commit 1b7f07a2c4
10 changed files with 68 additions and 9 deletions
@@ -35,7 +35,8 @@ const makeEmail = async (
bcc,
filename,
certificatePath,
replyto
replyto,
testPdf
) => {
const publicUrl = new URL(process.env.SERVER_URL);
const htmlContent = html;
@@ -46,7 +47,7 @@ const makeEmail = async (
let str;
if (url) {
let attachments;
let Pdf = fs.createWriteStream('test.pdf');
let Pdf = fs.createWriteStream(testPdf);
const writeToLocalDisk = () => {
return new Promise((resolve, reject) => {
const isSecure =
@@ -161,6 +162,8 @@ export default async function sendMailGmailProvider(_extRes, template) {
// Construct email message
const from = sender || _extRes.Email || 'me';
const to = receiver;
const randomNumber = Math.floor(Math.random() * 5000);
const testPdf = `test_${randomNumber}.pdf`;
const email = await makeEmail(
to,
from,
@@ -171,7 +174,8 @@ export default async function sendMailGmailProvider(_extRes, template) {
bcc,
filename,
certificatePath,
replyto
replyto,
testPdf
);
// Update Gmail client with new access token
const newGmail = createGmailClient(access_token);
@@ -189,6 +193,13 @@ export default async function sendMailGmailProvider(_extRes, template) {
console.log('Err in unlink certificate sendmailgmail provider');
}
}
if (fs.existsSync(testPdf)) {
try {
fs.unlinkSync(testPdf);
} catch (err) {
console.log('Err in unlink pdf sendmailv3');
}
}
return { code: 200, message: 'Email sent successfully' };
} catch (error) {
console.error('Error sending email:', error);
@@ -29,7 +29,9 @@ async function sendMailProvider(req, plan, monthchange) {
}
}
if (req.params.url) {
let Pdf = fs.createWriteStream('test.pdf');
const randomNumber = Math.floor(Math.random() * 5000);
const testPdf = `test_${randomNumber}.pdf`;
let Pdf = fs.createWriteStream(testPdf);
const writeToLocalDisk = () => {
return new Promise((resolve, reject) => {
const isSecure =
@@ -129,6 +131,13 @@ async function sendMailProvider(req, plan, monthchange) {
console.log('Err in unlink certificate sendmailv3');
}
}
if (fs.existsSync(testPdf)) {
try {
fs.unlinkSync(testPdf);
} catch (err) {
console.log('Err in unlink pdf sendmailv3');
}
}
return { status: 'success' };
}
} else {
@@ -146,6 +155,13 @@ async function sendMailProvider(req, plan, monthchange) {
console.log('Err in unlink certificate sendmailv3');
}
}
if (fs.existsSync(testPdf)) {
try {
fs.unlinkSync(testPdf);
} catch (err) {
console.log('Err in unlink pdf sendmailv3');
}
}
return { status: 'success' };
}
} else {
@@ -156,6 +172,13 @@ async function sendMailProvider(req, plan, monthchange) {
console.log('Err in unlink certificate sendmailv3');
}
}
if (fs.existsSync(testPdf)) {
try {
fs.unlinkSync(testPdf);
} catch (err) {
console.log('Err in unlink pdf sendmailv3');
}
}
return { status: 'error' };
}
}