deploy success - first version successed

This commit is contained in:
2025-07-28 13:17:54 +08:00
parent 2999e562c7
commit eeb3b4b0df
9 changed files with 172 additions and 358 deletions
+9 -24
View File
@@ -1,16 +1,11 @@
#!/usr/bin/env node
const { simpleParser } = require('mailparser');
const db = require('./db');
// Using require for get-stream v5 as it's CommonJS
const getStream = require('get-stream');
async function saveEmail(rawEmail) {
async function saveEmail(stream) {
try {
const parsed = await simpleParser(rawEmail);
const parsed = await simpleParser(stream);
const rawEmail = stream.toString(); // Or handle stream to buffer conversion appropriately
// Ensure 'to' and 'from' objects exist before accessing 'text'
const recipient = parsed.to ? parsed.to.text : 'undisclosed-recipients';
const sender = parsed.from ? parsed.from.text : 'unknown-sender';
const subject = parsed.subject;
@@ -21,7 +16,7 @@ async function saveEmail(rawEmail) {
[recipient, sender, subject, body, rawEmail]
);
console.log(`Email saved with ID: ${result.insertId}`);
console.log(`Email from <${sender}> to <${recipient}> saved with ID: ${result.insertId}`);
if (parsed.attachments && parsed.attachments.length > 0) {
for (const attachment of parsed.attachments) {
@@ -34,21 +29,11 @@ async function saveEmail(rawEmail) {
}
} catch (error) {
console.error('Failed to save email:', error);
// Exit with an error code to signal failure to the calling process (e.g., Mailu)
process.exit(1);
// We should not exit the process here, but maybe throw the error
// so the caller (SMTPServer) can handle it.
throw error;
}
}
(async () => {
try {
const rawEmail = await getStream(process.stdin);
if (rawEmail && rawEmail.length > 0) {
await saveEmail(rawEmail);
} else {
console.log('Received empty input, no email to save.');
}
} catch (error) {
console.error('Error reading from stdin:', error);
process.exit(1);
}
})();
module.exports = { saveEmail };