display mail in iframe, add design for thread and unseen

This commit is contained in:
grimhilt
2023-03-27 01:04:43 +02:00
parent a9d15027aa
commit bffcdafe7a
22 changed files with 237 additions and 201 deletions

View File

@@ -25,7 +25,6 @@ class Box {
sync(savedUid, currentUid) {
const promises = [];
const mails = [];
console.log(savedUid, currentUid);
const f = this.imap.seq.fetch(`${savedUid}:${currentUid}`, {
size: true,
envelope: true,

View File

@@ -1,87 +0,0 @@
const Imap = require("imap");
const { simpleParser } = require("mailparser");
const inspect = require("util").inspect;
const saveMessage = require("./storeMessage").saveMessage;
const registerMessageInApp = require("./saveMessage").registerMessageInApp;
const imapConfig = require("./config.json").mail;
const fs = require("fs");
const { DEBUG } = require("../utils/debug");
const imap = new Imap({
user: imapConfig.user,
password: imapConfig.password,
tlsOptions: { servername: "imap.gmail.com" },
host: "imap.gmail.com",
port: 993,
tls: true,
});
// reset table;
let shouldReset = false;
// let shouldReset = true;
if (shouldReset) {
const { execQuery, execQueryAsync } = require("../db/db");
const query = "SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE table_schema = 'mail'";
execQueryAsync(query).then((results) => {
execQuery("SET FOREIGN_KEY_CHECKS=0");
results.map((table) => {
execQuery("DELETE FROM " + table.table_name);
// execQuery("DROP TABLE " + table.table_name);
});
});
return;
}
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]);
// });
// const f = imap.fetch(970, {
// size: true,
// envelope: true,
// });
const promises = [];
const mails = [];
const f = imap.seq.fetch('1:10', {
size: true,
envelope: true
});
f.on("message", function (msg, seqno) {
msg.once("attributes", (attrs) => {
// todo find boxId
const boxId = 1;
// mails.push(attrs);
// promises.push(saveMessage(attrs, boxId, imap));
});
});
f.once("error", function (err) {
DEBUG.log("Fetch error: " + err);
});
f.once("end", async function () {
Promise.all(promises).then(async (res) => {
DEBUG.log("Done fetching all messages!");
for (let i = 0; i < mails.length; i++) {
await registerMessageInApp(res[i], mails[i]);
}
});
});
// imap.end()
});
});
imap.once("error", function (err) {
console.log(err);
});
imap.once("end", function () {
console.log("Connection ended");
});
imap.connect();

View File

@@ -30,11 +30,11 @@ async function registerMessageInApp(messageId, attrs) {
if (res.length == 0) {
// first message of this sender
await createRoom(envelope.subject, ownerId, messageId).then(async (roomId) => {
await registerMessageInRoom(messageId, roomId, isSeen);
await registerMessageInRoom(messageId, roomId, isSeen, envelope.date);
});
} else {
// not a reply, add to the list of message if this sender
await registerMessageInRoom(messageId, res[0].room_id, isSeen);
await registerMessageInRoom(messageId, res[0].room_id, isSeen, envelope.date);
}
});
}
@@ -54,7 +54,7 @@ async function registerReplyMessage(envelope, messageId, isSeen, ownerId) {
if (isGroup) {
const hasSameMembers = await hasSameMembersAsParent(messageID, envelope.inReplyTo);
if (hasSameMembers) {
await registerMessageInRoom(messageId, rooms[0].room_id, isSeen);
await registerMessageInRoom(messageId, rooms[0].room_id, isSeen, envelope.date);
} else {
// is a group and has not the same member as the previous message
// some recipient has been removed create a thread

View File

@@ -2,7 +2,6 @@ const { getAddresseId } = require("../db/mail");
const { DEBUG } = require("../utils/debug");
const { simpleParser } = require("mailparser");
const moment = require("moment");
const fs = require("fs");
const {
registerMessage,
registerMailbox_message,