feat: fix backend some error;fix frontend display error

This commit is contained in:
2025-07-28 14:14:11 +08:00
parent eeb3b4b0df
commit f1b39d22a5
5 changed files with 470 additions and 241 deletions
+16 -2
View File
@@ -1,10 +1,24 @@
const { simpleParser } = require('mailparser');
const db = require('./db');
// Helper function to convert stream to buffer
function streamToBuffer(stream) {
return new Promise((resolve, reject) => {
const chunks = [];
stream.on('data', (chunk) => chunks.push(chunk));
stream.on('error', reject);
stream.on('end', () => resolve(Buffer.concat(chunks)));
});
}
async function saveEmail(stream) {
try {
const parsed = await simpleParser(stream);
const rawEmail = stream.toString(); // Or handle stream to buffer conversion appropriately
// First, buffer the entire stream
const emailBuffer = await streamToBuffer(stream);
// Now, parse the buffered email content
const parsed = await simpleParser(emailBuffer);
const rawEmail = emailBuffer.toString();
const recipient = parsed.to ? parsed.to.text : 'undisclosed-recipients';
const sender = parsed.from ? parsed.from.text : 'unknown-sender';