mailparser updated
This commit is contained in:
30
ses-lambda/email2json1.js
Normal file
30
ses-lambda/email2json1.js
Normal file
@@ -0,0 +1,30 @@
|
||||
// simple-emailtojson.mjs
|
||||
import fs from 'fs/promises';
|
||||
import { simpleParser } from 'mailparser';
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.error('USAGE: node simple-emailtojson.mjs <emailfile.eml>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const mailpath = process.argv[2];
|
||||
|
||||
(async () => {
|
||||
const emlBuffer = await fs.readFile(mailpath);
|
||||
const mail = await simpleParser(emlBuffer);
|
||||
|
||||
// Optional: entferne Buffers, die du nicht serialisieren willst
|
||||
if (mail.attachments) {
|
||||
mail.attachments = mail.attachments.map(att => ({
|
||||
filename: att.filename,
|
||||
contentType: att.contentType,
|
||||
size: att.size,
|
||||
// evtl. att.content.toString('base64') oder weglassen
|
||||
}));
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(mail, null, 2));
|
||||
})().catch(err => {
|
||||
console.error('Fehler beim Parsen:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user