diff --git a/back/db/api.js b/back/db/api.js
index 7741109..09ea2a7 100644
--- a/back/db/api.js
+++ b/back/db/api.js
@@ -41,11 +41,12 @@ async function getRooms(mailboxId) {
INNER JOIN message
INNER JOIN mailbox_message
INNER JOIN address
- WHERE
- message.message_id = app_room.message_id AND
- mailbox_message.mailbox_id = ? AND
- mailbox_message.message_id = message.message_id AND
- address.address_id = app_room.owner_id
+ WHERE
+ message.message_id = app_room.message_id AND
+ mailbox_message.mailbox_id = ? AND
+ mailbox_message.message_id = message.message_id AND
+ address.address_id = app_room.owner_id
+ ORDER BY app_room.lastUpdate DESC
`;
const values = [mailboxId];
return await execQueryAsync(query, values);
diff --git a/back/db/mail.js b/back/db/mail.js
index f7434b4..8e80a8c 100644
--- a/back/db/mail.js
+++ b/back/db/mail.js
@@ -12,13 +12,6 @@ async function getAddresseId(email, name) {
return await execQueryAsyncWithId(query, values);
}
-function getMailboxId(email) {
- return new Promise((resolve, reject) => {
- resolve(0)
- });
- // todo
-}
-
async function getFieldId(field) {
const query = `INSERT INTO field_name (field_name) VALUES (?) ON DUPLICATE KEY UPDATE field_id=LAST_INSERT_ID(field_id)`;
const values = [field]
@@ -33,7 +26,6 @@ async function findRoomByOwner(ownerId) {
module.exports = {
getAddresseId,
- getMailboxId,
getFieldId,
findRoomByOwner,
};
diff --git a/back/db/saveMessage.js b/back/db/saveMessage.js
index d493dd0..bf0a82f 100644
--- a/back/db/saveMessage.js
+++ b/back/db/saveMessage.js
@@ -1,3 +1,4 @@
+const { transformEmojis } = require("../utils/string.js");
const { db, execQuery, execQueryAsync, execQueryAsyncWithId } = require("./db.js");
const DEBUG = require("../utils/debug").DEBUG;
@@ -30,12 +31,14 @@ function registerBodypart(messageId, part, bodypartId, bytes, nbLines) {
}
async function saveBodypart(bytes, hash, text, data) {
+ text = transformEmojis(text);
const query = `INSERT IGNORE INTO bodypart (bytes, hash, text, data) VALUES (?, ?, ?, ?)`;
const values = [bytes, hash, text, data];
return await execQueryAsyncWithId(query, values);
}
async function saveHeader_fields(messageId, fieldId, bodypartId, part, value) {
+ value = transformEmojis(value);
const query = `
INSERT IGNORE INTO header_field
(message_id, field_id, bodypart_id, part, value) VALUES (?, ?, ?, ?, ?)
@@ -54,7 +57,7 @@ async function saveAddress_fields(messageId, fieldId, addressId, number) {
}
function saveSource(messageId, content) {
- content = Buffer.from(content);
+ content = transformEmojis(content);
const query = `
INSERT INTO source (message_id, content) VALUES (?, ?)
ON DUPLICATE KEY UPDATE content = ?
diff --git a/back/db/saveMessageApp.js b/back/db/saveMessageApp.js
index ece6ab4..e556f7b 100644
--- a/back/db/saveMessageApp.js
+++ b/back/db/saveMessageApp.js
@@ -1,28 +1,32 @@
-const { db, execQueryAsync, execQueryAsyncWithId } = require("./db.js");
+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);
const query = `INSERT INTO app_room (room_name, owner_id, message_id) VALUES (?, ?, ?)`;
const values = [roomName.substring(0, 255), ownerId, messageId];
return await execQueryAsyncWithId(query, values);
// todo add members
}
-async function registerMessageInRoom(messageId, roomId, isSeen) {
+async function registerMessageInRoom(messageId, roomId, isSeen, idate) {
const query = `INSERT IGNORE INTO app_room_message (message_id, room_id) VALUES (?, ?)`;
const values = [messageId, roomId];
await execQueryAsync(query, values);
- updateLastUpdateRoom(roomId);
+ updateLastUpdateRoom(roomId, idate);
if (!isSeen) {
incrementNotSeenRoom(roomId);
}
}
-function updateLastUpdateRoom(roomId) {
- // todo
+function updateLastUpdateRoom(roomId, idate) {
+ const query = `UPDATE app_room SET lastUpdate = ? WHERE room_id = ?`;
+ const values = [idate, roomId];
+ execQuery(query, values);
}
function incrementNotSeenRoom(roomId) {
@@ -41,18 +45,10 @@ async function createThread(threadName, ownerId, messageId, parentRoomId, isDm)
async function registerMessageInThread(messageId, threadId, isSeen) {
// todo check if it is still a thread or should be a room
// todo isdm
- const query = `INSERT IGNORE INTO app_space_message
- (message_id, thread_id) VALUES (?, ?)`;
- const values = [messageId, threadId];
- await execQueryAsync(query, values);
- updateLastUpdateThread(threadId);
-
- if (!isSeen) {
- incrementNotSeenThread(threadId);
- }
+ console.log("register message in thread")
}
-function updateLastUpdateRoom(threadId) {
+function updateLastUpdateThread(threadId) {
// todo
// check for parent
}
diff --git a/back/db/structureV2.sql b/back/db/structureV2.sql
index 91333c1..11eb9fa 100644
--- a/back/db/structureV2.sql
+++ b/back/db/structureV2.sql
@@ -67,7 +67,7 @@ CREATE TABLE bodypart (
bodypart_id INT AUTO_INCREMENT,
bytes INT NOT NULL,
hash TEXT NOT NULL,
- text TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
+ text TEXT,
data BINARY,
PRIMARY KEY (bodypart_id)
);
@@ -75,10 +75,10 @@ CREATE TABLE bodypart (
-- 7
CREATE TABLE source (
message_id INT NOT NULL,
- content BLOB NOT NULL,
+ content TEXT NOT NULL,
PRIMARY KEY (message_id),
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE
-)
+);
-- 8
CREATE TABLE field_name (
@@ -94,7 +94,7 @@ CREATE TABLE header_field (
field_id INT NOT NULL,
bodypart_id INT,
part VARCHAR(128),
- value TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
+ value TEXT,
UNIQUE KEY (message_id, field_id, bodypart_id),
UNIQUE KEY (message_id, field_id, part),
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE,
diff --git a/back/mails/imap/Box.js b/back/mails/imap/Box.js
index 9329148..9b3e592 100644
--- a/back/mails/imap/Box.js
+++ b/back/mails/imap/Box.js
@@ -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,
diff --git a/back/mails/index.js b/back/mails/index.js
deleted file mode 100644
index f0ba06f..0000000
--- a/back/mails/index.js
+++ /dev/null
@@ -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();
diff --git a/back/mails/saveMessage.js b/back/mails/saveMessage.js
index 9e72ecb..ff6e687 100644
--- a/back/mails/saveMessage.js
+++ b/back/mails/saveMessage.js
@@ -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
diff --git a/back/mails/storeMessage.js b/back/mails/storeMessage.js
index f5d34b0..fc18a56 100644
--- a/back/mails/storeMessage.js
+++ b/back/mails/storeMessage.js
@@ -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,
diff --git a/back/utils/string.js b/back/utils/string.js
new file mode 100644
index 0000000..5683f89
--- /dev/null
+++ b/back/utils/string.js
@@ -0,0 +1,25 @@
+function transformEmojis(str) {
+ if (!str) return str;
+ // Use a regular expression to match emojis in the string
+ const regex =
+ /[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F900}-\u{1F9FF}\u{1F1E0}-\u{1F1FF}]/gu;
+
+ // Replace each matched emoji with its Unicode code point
+ const transformedStr = str.replace(regex, (match) => {
+ return "\\u{" + match.codePointAt(0).toString(16).toUpperCase() + "}";
+ });
+
+ return transformedStr;
+}
+
+function decodeEmojis(text) {
+ const regex = /\\u{([^}]+)}/g;
+ const decodedText = text.replace(regex, (_, hex) => String.fromCodePoint(parseInt(hex, 16)));
+ return decodedText;
+}
+
+
+module.exports = {
+ transformEmojis,
+ decodeEmojis
+}
\ No newline at end of file
diff --git a/front/package.json b/front/package.json
index 98804be..45ab08e 100644
--- a/front/package.json
+++ b/front/package.json
@@ -12,6 +12,7 @@
"@vueuse/core": "^9.13.0",
"axios": "^1.3.4",
"core-js": "^3.8.3",
+ "dompurify": "^3.0.1",
"vue": "^3.2.13",
"vue-router": "^4.1.6",
"vuex": "^4.0.2"
diff --git a/front/src/components/Badge.vue b/front/src/components/Badge.vue
new file mode 100644
index 0000000..1bedfd8
--- /dev/null
+++ b/front/src/components/Badge.vue
@@ -0,0 +1,28 @@
+
+