diff --git a/back/db/api.js b/back/db/api.js index 09ea2a7..5a25060 100644 --- a/back/db/api.js +++ b/back/db/api.js @@ -1,6 +1,5 @@ -const { db, execQueryAsync, execQueryAsyncWithId } = require("./db.js"); +const { execQueryAsync, execQueryAsyncWithId } = require("./db.js"); const { queryCcId, queryToId, queryFromId } = require("./utils/addressQueries.js"); -const DEBUG = require("../utils/debug").DEBUG; async function registerAccount(userId, pwd, xoauth, xoauth2, host, port, tls) { const query = ` diff --git a/back/db/db.js b/back/db/db.js index 9f179dd..a245b7c 100644 --- a/back/db/db.js +++ b/back/db/db.js @@ -1,7 +1,6 @@ const mysql = require("mysql"); +const { logger } = require("../system/Logger"); const MYSQL = require("./config.json").mysql; -const DEBUG = require("../utils/debug.js").DEBUG; - const db = mysql.createConnection({ host: MYSQL.host, @@ -12,9 +11,9 @@ const db = mysql.createConnection({ db.connect(function (err) { if (err) { - DEBUG.log("Impossible de se connecter", err.code); + logger.error(`Unable to connect database ${err.code}`); } else { - DEBUG.log("Database successfully connected"); + logger.log("Database successfully connected"); } }); @@ -45,7 +44,7 @@ function execQueryAsyncWithId(query, values) { function execQuery(query, values) { db.query(query, values, (err, results, fields) => { if (err) { - DEBUG.log(err); + logger.err(err); throw (err); } return results; diff --git a/back/db/mail.js b/back/db/mail.js index 8e80a8c..bb034b3 100644 --- a/back/db/mail.js +++ b/back/db/mail.js @@ -1,6 +1,4 @@ const { execQueryAsync, execQueryAsyncWithId } = require("./db.js"); -const DEBUG = require("../utils/debug").DEBUG; - async function getAddresseId(email, name) { const localpart = email.split("@")[0]; diff --git a/back/db/saveMessage.js b/back/db/saveMessage.js index bf0a82f..4c673b6 100644 --- a/back/db/saveMessage.js +++ b/back/db/saveMessage.js @@ -1,6 +1,5 @@ const { transformEmojis } = require("../utils/string.js"); const { db, execQuery, execQueryAsync, execQueryAsyncWithId } = require("./db.js"); -const DEBUG = require("../utils/debug").DEBUG; async function registerMessage(timestamp, rfc822size, messageId) { const query = ` diff --git a/back/db/saveMessageApp.js b/back/db/saveMessageApp.js index e556f7b..7cc11e6 100644 --- a/back/db/saveMessageApp.js +++ b/back/db/saveMessageApp.js @@ -1,7 +1,6 @@ const { transformEmojis } = require("../utils/string.js"); const { db, execQueryAsync, execQueryAsyncWithId, execQuery } = require("./db.js"); const { queryFromId, queryToId, queryCcId } = require("./utils/addressQueries.js"); -const DEBUG = require("../utils/debug").DEBUG; async function createRoom(roomName, ownerId, messageId) { roomName = transformEmojis(roomName); diff --git a/back/mails/imap/Box.js b/back/mails/imap/Box.js index 9b3e592..3502593 100644 --- a/back/mails/imap/Box.js +++ b/back/mails/imap/Box.js @@ -1,5 +1,5 @@ const { getMailbox, updateMailbox } = require("../../db/imap/imap"); -const { DEBUG } = require("../../utils/debug"); +const { logger } = require("../../system/Logger"); const { registerMessageInApp } = require("../saveMessage"); const { saveMessage } = require("../storeMessage"); @@ -17,7 +17,7 @@ class Box { const readOnly = true; this.imap.openBox(this.boxName, readOnly, (err, box) => { - if (err) DEBUG.log(err); + if (err) logger.error(err); this.sync(this.box.uidnext, box.uidnext); }); } @@ -38,7 +38,7 @@ class Box { }); f.once("error", (err) => { - DEBUG.log("Fetch error: " + err); + logger.error("Fetch error: " + err); }); f.once("end", async () => { diff --git a/back/mails/imap/ImapInstance.js b/back/mails/imap/ImapInstance.js index e6526fb..f32e1bc 100644 --- a/back/mails/imap/ImapInstance.js +++ b/back/mails/imap/ImapInstance.js @@ -1,6 +1,6 @@ const Imap = require("imap"); const { getAllMailboxes, registerMailbox } = require("../../db/imap/imap"); -const { DEBUG } = require("../../utils/debug"); +const { logger } = require("../../system/Logger"); const { Box } = require("./Box"); class ImapInstance { @@ -13,7 +13,7 @@ class ImapInstance { port: account.port, tls: account.tls, }); - + this.account = account; this.boxes = []; @@ -21,16 +21,16 @@ class ImapInstance { * IMAP */ this.imap.once("ready", () => { - DEBUG.log("imap connected") + logger.log("Imap connected for " + this.account.user); this.imapReady(); }); this.imap.once("error", function (err) { - DEBUG.log(err); + logger.error("Imap error for " + this.account.user + ": " + err); }); - + this.imap.once("end", function () { - DEBUG.log("Connection ended"); + logger.log("Connection ended for " + this.account.user); }); this.imap.connect(); @@ -41,8 +41,8 @@ class ImapInstance { if (mailboxes.length > 0) { this.boxes.push(new Box(this.imap, mailboxes[0].mailbox_id, mailboxes[0].mailbox_name)); } else { - this.imap.getBoxes('', (err, boxes) => { - if (err) DEBUG.log(err); + this.imap.getBoxes("", (err, boxes) => { + if (err) logger.error(err); const allBoxName = this.getAllBox(boxes); registerMailbox(this.account.id, allBoxName).then((mailboxId) => { this.boxes.push(new Box(this.imap, mailboxId, allBoxName)); @@ -55,19 +55,21 @@ class ImapInstance { getAllBox(boxes) { // ideally we should get the all box to get all messages let allBox; - Object.keys(boxes).forEach(key => { - if (key === 'INBOX') return; + Object.keys(boxes).forEach((key) => { + if (key === "INBOX") return; + if (allBox.includes("/")) return; allBox = key; Object.keys(boxes[key].children).forEach((childBoxes) => { - if (boxes[key].children[childBoxes].attribs.includes('\\All')) { - allBox += '/' + childBoxes; + if (boxes[key].children[childBoxes].attribs.includes("\\All")) { + allBox += "/" + childBoxes; } }); }); + if (!allBox.includes("/")) logger.warn("Did not find 'All' mailbox"); return allBox; } } module.exports = { - ImapInstance -} \ No newline at end of file + ImapInstance, +}; diff --git a/back/mails/imap/ImapSync.js b/back/mails/imap/ImapSync.js index 71cbc7e..783e248 100644 --- a/back/mails/imap/ImapSync.js +++ b/back/mails/imap/ImapSync.js @@ -1,5 +1,5 @@ const { getAllAccounts } = require("../../db/imap/imap"); -const { DEBUG } = require("../../utils/debug"); +const { logger } = require("../../system/Logger"); const { ImapInstance } = require("./ImapInstance"); class ImapSync { @@ -14,7 +14,7 @@ class ImapSync { this.addInstance(accounts[i]); } }).catch((err) => { - DEBUG.log(err); + logger.error(err); }); } diff --git a/back/mails/storeMessage.js b/back/mails/storeMessage.js index fc18a56..4b46819 100644 --- a/back/mails/storeMessage.js +++ b/back/mails/storeMessage.js @@ -1,5 +1,4 @@ const { getAddresseId } = require("../db/mail"); -const { DEBUG } = require("../utils/debug"); const { simpleParser } = require("mailparser"); const moment = require("moment"); const { @@ -13,6 +12,7 @@ const { } = require("../db/saveMessage"); const { getFieldId } = require("../db/mail"); +const { logger } = require("../system/Logger"); function saveMessage(attrs, mailboxId, imap) { const envelope = attrs.envelope; @@ -54,14 +54,14 @@ function saveMessage(attrs, mailboxId, imap) { }); }); f.once("error", function (err) { - console.log("Fetch error: " + err); + logger.warn("Fetch error: " + err); }); f.once("end", function () { - DEBUG.log("Done fetching data of "+messageID); + logger.log("Done fetching data of " + messageID); }); }) .catch((err) => { - DEBUG.log("Unable to register message: " + err); + logger.warn("Unable to register message: " + err); reject(err); }); }); @@ -97,8 +97,8 @@ async function saveFromParsedData(parsed, messageId) { messageId, fieldId, bodypartId, - undefined, // todo ? - undefined + undefined, // todo ? + undefined, ); }); }); @@ -109,7 +109,7 @@ async function saveFromParsedData(parsed, messageId) { // other field are not important and can be retrieved in source return; } else { - DEBUG.log("doesn't know key: " + key); + logger.warn("doesn't know key: " + key); return; } }); @@ -121,8 +121,8 @@ module.exports = { saveMessage, }; -if (process.env['NODE_DEV'] == 'TEST') { +if (process.env["NODE_DEV"] == "TEST") { module.exports = { - saveFromParsedData + saveFromParsedData, }; -} \ No newline at end of file +} diff --git a/back/utils/debug.js b/back/utils/debug.js deleted file mode 100644 index ff14596..0000000 --- a/back/utils/debug.js +++ /dev/null @@ -1,9 +0,0 @@ -const DEBUG = (function () { - const timestamp = function () {}; - timestamp.toString = () => "[" + new Date().toLocaleString() + "]"; - return { log: console.log.bind(console, "%s", timestamp) }; -})(); - -module.exports = { - DEBUG, -}; diff --git a/front/src/store/models/Thread.js b/front/src/store/models/Thread.js index e69de29..df33e87 100644 --- a/front/src/store/models/Thread.js +++ b/front/src/store/models/Thread.js @@ -0,0 +1,5 @@ +export default class Thread { + constructor (roomId, name) { + + } +} \ No newline at end of file