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