update database structure

This commit is contained in:
grimhilt
2023-03-11 14:52:08 +01:00
parent 29bf4bbdbd
commit 9046ccf137
6 changed files with 64 additions and 32 deletions

View File

@@ -22,7 +22,7 @@ imap.once("ready", function () {
console.log(results[results.length - 1]);
});
const f = imap.fetch(969, { size: true, struct: true, envelope: true });
const f = imap.fetch(970, { bodies: ['TEXT'], size: true, struct: true, envelope: true });
// var f = imap.seq.fetch('1:3', {
// bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',
// struct: true
@@ -30,22 +30,23 @@ imap.once("ready", function () {
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.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.txt", 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);
console.log(attrs)
// saveMessage(attrs, boxId, imap);
});
});

View File

@@ -95,15 +95,30 @@ function saveMessage(attrs, mailboxId, imap) {
}
});
// save more header
// message.headerLines.forEach(elt => {
// const newKey = keyNormalizer(elt.key);
// getFieldId(newKey).then((fieldId) => {
// saveHeader_fields(messageId, part, 2, fieldId, elt[line]);
// });
// });
// todo check for different provider
if (envelope?.inReplyTo) {
`SELECT app_room_messages.room, app_room_messages.thread FROM app_room_messages INNER JOIN messages WHERE messages.messageID = '${envelope.inReplyTo}' AND app_room_messages.message = messages.id`;
// parent message is in a thread, so register this message only in a thread
if (thread) {
`INSERT IGNORE INTO app_room_messages (thread, message) VALUES('${thread}', '${messageId}')`;
// increment not read counter and lastUpdate is not read (both)
} else if (room) {
if (!isGroup) {
// check if create thread
} else {
// check if create new group and delete thread
}
} else {
}
}
/**
* if reply to then add to same group as previous and update type if necessary
* else add to sender group
*
*/
// // todo add date field
}
);
}