link imap sync to server and show email on front
This commit is contained in:
@@ -2,7 +2,7 @@ const { db, execQueryAsync, execQueryAsyncWithId } = require("./db.js");
|
||||
const { queryCcId, queryToId, queryFromId } = require("./utils/addressQueries.js");
|
||||
const DEBUG = require("../utils/debug").DEBUG;
|
||||
|
||||
async function registerMailbox(userId, pwd, xoauth, xoauth2, host, port, tls) {
|
||||
async function registerAccount(userId, pwd, xoauth, xoauth2, host, port, tls) {
|
||||
const query = `
|
||||
INSERT INTO app_account
|
||||
(user_id, account_pwd, xoauth, xoauth2, host, port, tls) VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
@@ -11,13 +11,18 @@ async function registerMailbox(userId, pwd, xoauth, xoauth2, host, port, tls) {
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
async function getMailboxes() {
|
||||
async function getAccounts() {
|
||||
// todo mailbox or account id ?
|
||||
const query = `
|
||||
SELECT
|
||||
app_account.account_id AS id,
|
||||
mailbox.mailbox_id AS id,
|
||||
address.email
|
||||
FROM app_account INNER JOIN address
|
||||
WHERE address.address_id = app_account.user_id
|
||||
FROM app_account
|
||||
INNER JOIN address
|
||||
INNER JOIN mailbox
|
||||
WHERE
|
||||
address.address_id = app_account.user_id AND
|
||||
mailbox.account_id = app_account.account_id
|
||||
`;
|
||||
const values = [];
|
||||
return await execQueryAsync(query, values);
|
||||
@@ -38,12 +43,11 @@ async function getRooms(mailboxId) {
|
||||
INNER JOIN address
|
||||
WHERE
|
||||
message.message_id = app_room.message_id AND
|
||||
mailbox_message.mailbox_id = 1 AND
|
||||
mailbox_message.mailbox_id = ? AND
|
||||
mailbox_message.message_id = message.message_id AND
|
||||
address.address_id = app_room.owner_id
|
||||
`;
|
||||
// todo mailboxId
|
||||
const values = [];
|
||||
const values = [mailboxId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
@@ -92,8 +96,8 @@ async function getMessages(roomId) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
registerMailbox,
|
||||
getMailboxes,
|
||||
registerAccount,
|
||||
getAccounts,
|
||||
getRooms,
|
||||
getMessages
|
||||
};
|
||||
|
||||
49
back/db/imap/imap.js
Normal file
49
back/db/imap/imap.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const { execQueryAsyncWithId, execQueryAsync, execQuery } = require("../db");
|
||||
|
||||
async function getAllAccounts() {
|
||||
const query = `
|
||||
SELECT
|
||||
app_account.account_id AS id,
|
||||
address.email AS user,
|
||||
app_account.account_pwd AS password,
|
||||
app_account.host AS host,
|
||||
app_account.port AS port,
|
||||
app_account.tls AS tls
|
||||
FROM app_account INNER JOIN address
|
||||
WHERE address.address_id = app_account.user_id
|
||||
`;
|
||||
const values = [];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
async function getAllMailboxes(accountId) {
|
||||
const query = 'SELECT * FROM mailbox WHERE mailbox.account_id = ?';
|
||||
const values = [accountId];
|
||||
return await execQueryAsync(query, values)
|
||||
}
|
||||
|
||||
async function registerMailbox(accountId, mailboxName) {
|
||||
const query = `INSERT INTO mailbox (account_id, mailbox_name) VALUES (?, ?)`;
|
||||
const values = [accountId, mailboxName];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
async function getMailbox(mailboxId) {
|
||||
const query = `SELECT * FROM mailbox WHERE mailbox_id = ?`;
|
||||
const values = [mailboxId];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
function updateMailbox(mailboxId, uidnext) {
|
||||
const query = `UPDATE mailbox SET uidnext = ? WHERE mailbox_id = ?`;
|
||||
const values = [uidnext, mailboxId];
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAllAccounts,
|
||||
getAllMailboxes,
|
||||
registerMailbox,
|
||||
getMailbox,
|
||||
updateMailbox
|
||||
}
|
||||
@@ -1,19 +1,14 @@
|
||||
const { db, execQueryAsync, execQueryAsyncWithId } = require("./db.js");
|
||||
const { execQueryAsync, execQueryAsyncWithId } = require("./db.js");
|
||||
const DEBUG = require("../utils/debug").DEBUG;
|
||||
|
||||
function isValidEmail(email) {
|
||||
// todo
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
async function getAddresseId(email, name) {
|
||||
const localpart = email.split("@")[0];
|
||||
const domain = email.split("@")[1];
|
||||
const query = `INSERT INTO address
|
||||
(address_name, localpart, domain, email) VALUES (?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE email = ?, address_id = LAST_INSERT_ID(address_id)`;
|
||||
const values = [name, localpart, domain, email, email];
|
||||
ON DUPLICATE KEY UPDATE address_name = ?, address_id = LAST_INSERT_ID(address_id)`;
|
||||
const values = [name, localpart, domain, email, name];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ function registerMailbox_message(mailboxId, uid, messageId, modseq, seen, delete
|
||||
(mailbox_id, uid, message_id, modseq, seen, deleted) VALUES (?, ?, ?, ?, ?, ?)
|
||||
`;
|
||||
const values = [mailboxId, uid, messageId, modseq, seen, deleted];
|
||||
console.log(values)
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
@@ -55,6 +54,7 @@ async function saveAddress_fields(messageId, fieldId, addressId, number) {
|
||||
}
|
||||
|
||||
function saveSource(messageId, content) {
|
||||
content = Buffer.from(content);
|
||||
const query = `
|
||||
INSERT INTO source (message_id, content) VALUES (?, ?)
|
||||
ON DUPLICATE KEY UPDATE content = ?
|
||||
|
||||
@@ -67,7 +67,7 @@ CREATE TABLE bodypart (
|
||||
bodypart_id INT AUTO_INCREMENT,
|
||||
bytes INT NOT NULL,
|
||||
hash TEXT NOT NULL,
|
||||
text TEXT,
|
||||
text TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
|
||||
data BINARY,
|
||||
PRIMARY KEY (bodypart_id)
|
||||
);
|
||||
@@ -75,10 +75,10 @@ CREATE TABLE bodypart (
|
||||
-- 7
|
||||
CREATE TABLE source (
|
||||
message_id INT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
content BLOB NOT NULL,
|
||||
PRIMARY KEY (message_id),
|
||||
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE
|
||||
);
|
||||
)
|
||||
|
||||
-- 8
|
||||
CREATE TABLE field_name (
|
||||
@@ -94,8 +94,9 @@ CREATE TABLE header_field (
|
||||
field_id INT NOT NULL,
|
||||
bodypart_id INT,
|
||||
part VARCHAR(128),
|
||||
value TEXT,
|
||||
UNIQUE KEY (message_id, field_id, bodypart_id),-- todo multiple raws
|
||||
value TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
|
||||
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,
|
||||
FOREIGN KEY (field_id) REFERENCES field_name(field_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (bodypart_id) REFERENCES bodypart(bodypart_id)
|
||||
|
||||
Reference in New Issue
Block a user