solution clean not working

This commit is contained in:
grimhilt 2023-03-10 16:18:04 +01:00
parent 427ffba725
commit df69a7dbd9

View File

@ -18,46 +18,55 @@ imap.once("ready", function () {
const readOnly = true; const readOnly = true;
imap.openBox("INBOX", readOnly, (err, box) => { imap.openBox("INBOX", readOnly, (err, box) => {
// console.log(box); // uidvalidty uidnext, messages total and new // console.log(box); // uidvalidty uidnext, messages total and new
imap.search(["ALL"], function (err, results) { // imap.search(["ALL"], function (err, results) {
console.log(results[results.length - 1]); // console.log(results[results.length - 1]);
}); // });
const f = imap.fetch(969, { size: true, struct: true, envelope: true }); const fetchOptions = {
bodies: ["HEADER.FIELDS (FROM TO SUBJECT DATE)", "TEXT"],
struct: true,
};
const f = imap.fetch(969, fetchOptions);
// var f = imap.seq.fetch('1:3', { // var f = imap.seq.fetch('1:3', {
// bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)', // bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',
// struct: true // struct: true
// }); // });
f.on("message", function (msg, seqno) { f.on("message", function (msg, seqno) {
// console.log("Message #%d", seqno); const emailData = {};
// var prefix = "(#" + seqno + ") "; msg.on("body", (stream, info) => {
// msg.on("body", function (stream, info) { let buffer = "";
// simpleParser(stream, async (err, parsed) => { stream.on("data", (chunk) => {
// // find box id; buffer += chunk.toString("utf8");
// console.log(parsed) });
// const boxId = 1; stream.on("end", () => {
// // saveMessage(parsed, boxId); if (info.which === "TEXT") {
// console.log(parsed.subject); emailData.text = buffer;
// fs.writeFileSync("./test.json", JSON.stringify(parsed)); } else {
// }); const parsedHeader = Imap.parseHeader(buffer);
// // console.log(prefix + 'Body'); emailData.from = parsedHeader.from[0];
// // stream.pipe(fs.createWriteStream('msg-' + seqno + '-body.txt')); emailData.to = parsedHeader.to[0];
// }); emailData.subject = parsedHeader.subject[0];
msg.once('attributes', attrs => { emailData.date = parsedHeader.date[0];
// todo find boxId }
const boxId = 1; });
saveMessage(attrs, boxId, imap); });
msg.once("attributes", (attrs) => {
emailData.uid = attrs.uid;
emailData.flags = attrs.flags;
emailData.struct = attrs.struct;
});
msg.once("end", () => {
console.log("Email data:", inspect(emailData));
}); });
}); });
f.once("error", function (err) { f.once("error", function (err) {
console.log("Fetch error: " + err); console.log("Fetch error: " + err);
}); });
f.once("end", function () { f.once("end", function () {
console.log("Done fetching all messages!"); console.log("Done fetching all messages!");
// imap.end(); imap.end();
}); });
// }); // });
return; return;