save message sync
This commit is contained in:
@@ -10,10 +10,9 @@ async function registerMessage(timestamp, rfc822size, messageId) {
|
||||
}
|
||||
|
||||
function registerMailbox_message(mailboxId, uid, messageId, modseq, seen, deleted) {
|
||||
const query = `INSERT IGNORE INTO mailbox_message (mailbox_id, uid, message_id, modseq, seen, deleted) VALUES ('${mailboxId}', '${uid}', '${messageId}', '${modseq}', '${seen}', '${deleted}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) DEBUG.log(err);
|
||||
});
|
||||
const query = `INSERT IGNORE INTO mailbox_message (mailbox_id, uid, message_id, modseq, seen, deleted) VALUES (?, ?, ?, ?, ?, ?)`;
|
||||
const values = [mailboxId, uid, messageId, modseq, seen, deleted];
|
||||
execQuery(query, values);
|
||||
}
|
||||
|
||||
function registerBodypart(messageId, part, bodypartId, bytes, nbLines) {
|
||||
@@ -23,27 +22,26 @@ function registerBodypart(messageId, part, bodypartId, bytes, nbLines) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function saveBodypart(bytes, hash, text, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT IGNORE INTO bodypart (bytes, hash, text, data) VALUES ('${bytes}', '${hash}', '${text}', '${data}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) reject(err);
|
||||
resolve(results.insertId);
|
||||
});
|
||||
});
|
||||
async function saveBodypart(bytes, hash, text, data) {
|
||||
const query = `INSERT IGNORE INTO bodypart (bytes, hash, text, data) VALUES (?, ?, ?,)`;
|
||||
const values = [bytes, hash, text, data];
|
||||
return await execQueryAsyncWithId(query, values);
|
||||
}
|
||||
|
||||
function saveHeader_fields(message, part, position, field, value) {
|
||||
const query = `INSERT INTO header_field (message_id, part, position, field_id, value) VALUES (?, ?, ?, ?, ?)`;
|
||||
const values = [message, part, position, field, value];
|
||||
execQuery(query, values);
|
||||
async function saveHeader_fields(messageId, fieldId, bodypartId, part, value) {
|
||||
const query = `INSERT IGNORE INTO header_field (message_id, field_id, bodypart_id, part, value) VALUES (?, ?, ?, ?, ?)`;
|
||||
const values = [messageId, fieldId, bodypartId, part, value];
|
||||
return await execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
function saveAddress_fields(message, part, position, field, number, address) {
|
||||
const query = `INSERT INTO address_field (message_id , part, position, field_id, number, address_id) VALUES (?, ?, ?, ?, ?, ?)`;
|
||||
const values = [message, part, position, field, number, address];
|
||||
execQuery(query, values);
|
||||
async function saveAddress_fields(messageId, fieldId, addressId, number) {
|
||||
const query = `INSERT IGNORE INTO address_field (message_id , field_id, address_id, number) VALUES (?, ?, ?, ?)`;
|
||||
const values = [messageId, fieldId, addressId, number];
|
||||
return execQueryAsync(query, values);
|
||||
}
|
||||
|
||||
function saveSource(messageId, content) {
|
||||
// todo
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
@@ -53,4 +51,5 @@ module.exports = {
|
||||
saveAddress_fields,
|
||||
registerBodypart,
|
||||
saveBodypart,
|
||||
saveSource
|
||||
}
|
||||
@@ -139,3 +139,19 @@ create table app_accounts (
|
||||
tls int(1) not null default 0,
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
create table app_rooms (
|
||||
id int not null auto_increment,
|
||||
name text not null,
|
||||
owner int not null,
|
||||
isGroup BIT(1) not null default 0,
|
||||
notSeen int not null default 0,
|
||||
lastUpdate timestamp not null,
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
create table app_room_messages (
|
||||
message int [not null]
|
||||
room int,
|
||||
primary key()
|
||||
)
|
||||
@@ -74,15 +74,11 @@ CREATE TABLE bodypart (
|
||||
);
|
||||
|
||||
-- 7
|
||||
CREATE TABLE part_number (
|
||||
CREATE TABLE source (
|
||||
message_id INT NOT NULL,
|
||||
part VARCHAR(128) NOT NULL,
|
||||
bodypart_id INT NOT NULL,
|
||||
bytes INT,
|
||||
nb_lines INT,
|
||||
PRIMARY KEY (message_id, part),
|
||||
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (bodypart_id) REFERENCES bodypart(bodypart_id) ON DELETE CASCADE
|
||||
content TEXT NOT NULL,
|
||||
PRIMARY KEY (message_id),
|
||||
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 8
|
||||
@@ -96,24 +92,24 @@ CREATE TABLE field_name (
|
||||
-- 9
|
||||
CREATE TABLE header_field (
|
||||
message_id INT NOT NULL,
|
||||
part VARCHAR(128) NOT NULL,
|
||||
position INT NOT NULL,
|
||||
field_id INT NOT NULL,
|
||||
bodypart_id INT,
|
||||
part VARCHAR(128),
|
||||
value TEXT NOT NULL,
|
||||
UNIQUE KEY (message_id, part, position, field_id),
|
||||
FOREIGN KEY (message_id, part) REFERENCES part_number(message_id, part) ON DELETE CASCADE,
|
||||
FOREIGN KEY (field_id) REFERENCES field_name(field_id)
|
||||
UNIQUE KEY (message_id, field_id, bodypart_id),
|
||||
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (field_id) REFERENCES field_name(field_id), -- todo on delete behavior
|
||||
FOREIGN KEY (bodypart_id) REFERENCES bodypart(bodypart_id)
|
||||
);
|
||||
|
||||
-- 10
|
||||
CREATE TABLE address_field (
|
||||
message_id INT NOT NULL,
|
||||
part VARCHAR(128) NOT NULL,
|
||||
position INT NOT NULL,
|
||||
field_id INT NOT NULL,
|
||||
number INT,
|
||||
address_id INT NOT NULL,
|
||||
FOREIGN KEY (message_id, part) REFERENCES part_number(message_id, part) ON DELETE CASCADE,
|
||||
number INT,
|
||||
UNIQUE KEY (message_id, field_id, address_id),
|
||||
FOREIGN KEY (message_id) REFERENCES message(message_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (field_id) REFERENCES field_name(field_id),
|
||||
FOREIGN KEY (address_id) REFERENCES address(address_id)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user