feat: fix backend some error;fix frontend display error
This commit is contained in:
@@ -20,7 +20,7 @@ app.get('/api/messages', async (req, res) => {
|
||||
|
||||
try {
|
||||
const [rows] = await db.execute(
|
||||
'SELECT id, sender, subject, body, received_at FROM emails WHERE recipient = ? ORDER BY received_at DESC',
|
||||
'SELECT id, sender, recipient, subject, body, received_at FROM emails WHERE recipient = ? ORDER BY received_at DESC',
|
||||
[recipient]
|
||||
);
|
||||
res.json(rows);
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user