start to save mail from imap
This commit is contained in:
23
back/sql/bdd.js
Normal file
23
back/sql/bdd.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const mysql = require("mysql");
|
||||
const MYSQL = require("./config.json").mysql;
|
||||
const DEBUG = require("../utils/debug.js").DEBUG;
|
||||
|
||||
|
||||
const bdd = mysql.createConnection({
|
||||
host: MYSQL.host,
|
||||
user: MYSQL.user,
|
||||
password: MYSQL.pwd,
|
||||
database: MYSQL.database,
|
||||
});
|
||||
|
||||
bdd.connect(function (err) {
|
||||
if (err) {
|
||||
DEBUG.log("Impossible de se connecter", err.code);
|
||||
} else {
|
||||
DEBUG.log("Database successfully connected");
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
bdd: bdd,
|
||||
};
|
||||
48
back/sql/saveMessage.js
Normal file
48
back/sql/saveMessage.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const bdd = require("./bdd.js").bdd;
|
||||
const DEBUG = require("../utils/debug").DEBUG;
|
||||
|
||||
function registerMessage(timestamp, rfc822size) {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(0);
|
||||
//todo
|
||||
const query = `INSERT INTO messages (idate, rfc822size) VALUES (UNIX_TIMESTAMP('${timestamp}'), '${rfc822size}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) reject(err);
|
||||
// resolve(results.insertId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function registerMailbox_message(mailboxId, uid, messageId, modseq, seen, deleted) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const query = `INSERT IGNORE INTO mailbox_messages (mailbox, uid, message, modseq, seen, deleted) VALUES ('${mailboxId}', '${uid}', '${messageId}', '${modseq}', '${seen}', '${deleted}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) reject(err);
|
||||
resolve();
|
||||
// resolve(results.insertId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function saveBodyparts() {}
|
||||
|
||||
function saveHeader_fields(message, part, position, field, value) {
|
||||
const query = `INSERT IGNORE INTO header_fields (message, part, position, field, value) VALUES ('${message}', '${part}', '${position}', '${field}', '${value}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
}
|
||||
|
||||
function saveAddress_fields(message, part, position, field, number, address) {
|
||||
const query = `INSERT IGNORE INTO address_fields (message, part, position, field, number, address) VALUES ('${message}', '${part}', '${position}', '${field}', '${number}', '${address}')`;
|
||||
bdd.query(query, (err, results, fields) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
registerMessage,
|
||||
registerMailbox_message,
|
||||
saveHeader_fields,
|
||||
saveAddress_fields,
|
||||
}
|
||||
141
back/sql/structure
Normal file
141
back/sql/structure
Normal file
@@ -0,0 +1,141 @@
|
||||
create table addresses (
|
||||
id int not null auto_increment,
|
||||
name text,
|
||||
localpart text not null,
|
||||
domain text not null,
|
||||
email text not null,
|
||||
primary key (id),
|
||||
unique key (email)
|
||||
);
|
||||
|
||||
create table mailboxes (
|
||||
-- Grant: select, insert, update
|
||||
id serial primary key,
|
||||
name text not null unique,
|
||||
-- owner int references users(id), todo
|
||||
|
||||
-- The UID that will be assigned to the next delivered message.
|
||||
-- Incremented after each successful delivery.
|
||||
uidnext int not null default 1,
|
||||
|
||||
-- The next modsequence value for this mailbox.
|
||||
nextmodseq bigint not null default 1,
|
||||
|
||||
-- The UID of the first message that should be marked \Recent.
|
||||
-- Set to uidnext when each new IMAP session is created.
|
||||
first_recent int not null default 1,
|
||||
|
||||
-- The IMAP mailbox UIDVALIDITY value, which, along with a message UID,
|
||||
-- is forever guaranteed to uniquely refer to a single message.
|
||||
uidvalidity int not null default 1,
|
||||
|
||||
-- When a mailbox is deleted, its entry is marked (not removed), so
|
||||
-- that its UIDVALIDITY can be incremented if it is ever re-created.
|
||||
deleted boolean not null default false
|
||||
);
|
||||
|
||||
/**
|
||||
* Store message
|
||||
*/
|
||||
|
||||
create table messages (
|
||||
-- Grant: select, insert
|
||||
id int primary key auto_increment,
|
||||
-- the time the message was added to the mailbox, as a unix time_t
|
||||
idate timestamp not null,
|
||||
-- the size of the message in RFC 822 format, in bytes
|
||||
rfc822size int
|
||||
);
|
||||
|
||||
-- todo make this work
|
||||
-- foreign key (mailbox) references mailboxes(id),
|
||||
-- foreign key (uid) references messages(id),
|
||||
create table mailbox_messages (
|
||||
-- Grant: select, insert, update
|
||||
mailbox int not null,
|
||||
-- the message's number in the mailbox
|
||||
uid int not null,
|
||||
message int not null,
|
||||
modseq bigint not null,
|
||||
seen boolean not null default false,
|
||||
deleted boolean not null default false,
|
||||
primary key (mailbox, uid)
|
||||
);
|
||||
|
||||
-- tood should not be auto increment but nextval('bodypart_ids')
|
||||
create table bodyparts (
|
||||
-- Grant: select, insert
|
||||
id int primary key auto_increment,
|
||||
-- the size of either text or data, whichever is used
|
||||
bytes int not null,
|
||||
-- MD5 hash of either text or data
|
||||
hash text not null,
|
||||
text text,
|
||||
data binary
|
||||
);
|
||||
|
||||
create table part_numbers (
|
||||
-- Grant: select, insert
|
||||
message int references messages(id) on delete cascade,
|
||||
part text not null,
|
||||
bodypart int references bodyparts(id),
|
||||
bytes int,
|
||||
nbLines int,
|
||||
primary key (message)
|
||||
);
|
||||
|
||||
create table field_names (
|
||||
-- Grant: select, insert
|
||||
id serial primary key,
|
||||
name text unique
|
||||
);
|
||||
|
||||
-- add foreign key (message, part)
|
||||
-- references part_numbers(message, part)
|
||||
--on delete cascade at the end
|
||||
-- references field_names(id) to field
|
||||
create table header_fields (
|
||||
-- Grant: select, insert
|
||||
id serial primary key,
|
||||
message int not null,
|
||||
part text not null,
|
||||
position int not null,
|
||||
field int not null,
|
||||
value text,
|
||||
unique (message, part, position, field)
|
||||
);
|
||||
|
||||
create table address_fields (
|
||||
-- Grant: select, insert
|
||||
message int not null,
|
||||
part text not null,
|
||||
position int not null,
|
||||
field int not null,
|
||||
number int,
|
||||
address int not null-- references addresses(id),
|
||||
-- foreign key (message, part)
|
||||
-- references part_numbers(message, part)
|
||||
-- on delete cascade
|
||||
);
|
||||
|
||||
create table date_fields (
|
||||
-- Grant: select, insert
|
||||
message int not null references messages(id)
|
||||
on delete cascade,
|
||||
value timestamp --with time zone
|
||||
);
|
||||
|
||||
/**
|
||||
* APP tables
|
||||
*/
|
||||
create table app_accounts (
|
||||
id int not null auto_increment,
|
||||
user varchar(255) not null,
|
||||
password binary(20),
|
||||
xoauth varchar(116),
|
||||
xoauth2 varchar(116),
|
||||
host varchar(255) not null default 'localhost',
|
||||
port int(5) not null default 143,
|
||||
tls int(1) not null default 0,
|
||||
primary key (id)
|
||||
);
|
||||
Reference in New Issue
Block a user