update database structure
This commit is contained in:
parent
61d7eb386c
commit
749127ac19
4
.gitignore
vendored
4
.gitignore
vendored
@ -28,4 +28,6 @@ pnpm-debug.log*
|
|||||||
log*
|
log*
|
||||||
config.json
|
config.json
|
||||||
.direnv
|
.direnv
|
||||||
.envrc
|
.envrc
|
||||||
|
*.txt
|
||||||
|
*.json
|
@ -22,7 +22,7 @@ imap.once("ready", function () {
|
|||||||
console.log(results[results.length - 1]);
|
console.log(results[results.length - 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
const f = imap.fetch(969, { size: true, struct: true, envelope: true });
|
const f = imap.fetch(970, { bodies: ['TEXT'], size: true, struct: true, envelope: true });
|
||||||
// var f = imap.seq.fetch('1:3', {
|
// var f = imap.seq.fetch('1:3', {
|
||||||
// bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',
|
// bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',
|
||||||
// struct: true
|
// struct: true
|
||||||
@ -30,22 +30,23 @@ imap.once("ready", function () {
|
|||||||
f.on("message", function (msg, seqno) {
|
f.on("message", function (msg, seqno) {
|
||||||
// console.log("Message #%d", seqno);
|
// console.log("Message #%d", seqno);
|
||||||
// var prefix = "(#" + seqno + ") ";
|
// var prefix = "(#" + seqno + ") ";
|
||||||
// msg.on("body", function (stream, info) {
|
msg.on("body", function (stream, info) {
|
||||||
// simpleParser(stream, async (err, parsed) => {
|
simpleParser(stream, async (err, parsed) => {
|
||||||
// // find box id;
|
// find box id;
|
||||||
// console.log(parsed)
|
console.log(parsed)
|
||||||
// const boxId = 1;
|
const boxId = 1;
|
||||||
// // saveMessage(parsed, boxId);
|
// saveMessage(parsed, boxId);
|
||||||
// console.log(parsed.subject);
|
console.log(parsed.subject);
|
||||||
// fs.writeFileSync("./test.json", JSON.stringify(parsed));
|
fs.writeFileSync("./test.txt", JSON.stringify(parsed));
|
||||||
// });
|
});
|
||||||
// // console.log(prefix + 'Body');
|
// console.log(prefix + 'Body');
|
||||||
// // stream.pipe(fs.createWriteStream('msg-' + seqno + '-body.txt'));
|
// stream.pipe(fs.createWriteStream('msg-' + seqno + '-body.txt'));
|
||||||
// });
|
});
|
||||||
msg.once('attributes', attrs => {
|
msg.once('attributes', attrs => {
|
||||||
// todo find boxId
|
// todo find boxId
|
||||||
const boxId = 1;
|
const boxId = 1;
|
||||||
saveMessage(attrs, boxId, imap);
|
console.log(attrs)
|
||||||
|
// saveMessage(attrs, boxId, imap);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -95,15 +95,30 @@ function saveMessage(attrs, mailboxId, imap) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// save more header
|
// todo check for different provider
|
||||||
// message.headerLines.forEach(elt => {
|
if (envelope?.inReplyTo) {
|
||||||
// const newKey = keyNormalizer(elt.key);
|
`SELECT app_room_messages.room, app_room_messages.thread FROM app_room_messages INNER JOIN messages WHERE messages.messageID = '${envelope.inReplyTo}' AND app_room_messages.message = messages.id`;
|
||||||
// getFieldId(newKey).then((fieldId) => {
|
// parent message is in a thread, so register this message only in a thread
|
||||||
// saveHeader_fields(messageId, part, 2, fieldId, elt[line]);
|
if (thread) {
|
||||||
// });
|
`INSERT IGNORE INTO app_room_messages (thread, message) VALUES('${thread}', '${messageId}')`;
|
||||||
// });
|
// increment not read counter and lastUpdate is not read (both)
|
||||||
|
} else if (room) {
|
||||||
|
|
||||||
|
if (!isGroup) {
|
||||||
|
// check if create thread
|
||||||
|
} else {
|
||||||
|
// check if create new group and delete thread
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* if reply to then add to same group as previous and update type if necessary
|
||||||
|
* else add to sender group
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
// // todo add date field
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,30 @@
|
|||||||
const statusCodes = require("../utils/statusCodes.js").statusCodes;
|
const statusCodes = require("../utils/statusCodes.js").statusCodes;
|
||||||
|
const express = require('express');
|
||||||
|
const router = require('router');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all mailboxes and folders for an user
|
* Return all mailboxes and folders for an user
|
||||||
*/
|
*/
|
||||||
function getMailboxes(req, res) {
|
router.get("/mailboxes", (req, res) => {
|
||||||
const {token} = req.params;
|
const {token} = req.params;
|
||||||
const query = ``;
|
const query = ``;
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
});
|
||||||
getFolders,
|
|
||||||
}
|
/**
|
||||||
|
* @param {number} mailboxId the id of the mailbox from which to fetch the messages, 0 if from all
|
||||||
|
* @param {number} offset the offset of the query
|
||||||
|
* @param {number} limit the number of message to return
|
||||||
|
* @param {string} token the token of the user
|
||||||
|
* @return {object} a list of room and their preview
|
||||||
|
*/
|
||||||
|
router.get("/{mailboxId}/messages", (req, res) => {
|
||||||
|
const {token, mailboxId, offset, limit} = req.params;
|
||||||
|
// todo check token
|
||||||
|
// todo use offset
|
||||||
|
const query = ``;
|
||||||
|
SELECT header_fields.value FROM header_fields INNER JOIN field_names WHERE header_fields.field = field_names.id AND (field_names.name = "subject" OR field_names.name = "date"); ORDER BY messages.idate
|
||||||
|
// number of message missed in the room
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const mails = require("./api/mails.js");
|
const mails = require("./routers/mail.js");
|
||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const cors = require('cors')
|
const cors = require('cors')
|
||||||
|
@ -25,6 +25,7 @@ Table "mailboxes" {
|
|||||||
|
|
||||||
Table "messages" {
|
Table "messages" {
|
||||||
"id" int [pk, not null, increment]
|
"id" int [pk, not null, increment]
|
||||||
|
"messageID" text [pk, not null]
|
||||||
"idate" timestamp [not null]
|
"idate" timestamp [not null]
|
||||||
"rfc822size" int
|
"rfc822size" int
|
||||||
}
|
}
|
||||||
@ -103,3 +104,37 @@ Ref: address_fields.message > messages.id
|
|||||||
Ref: address_fields.part > part_numbers.part
|
Ref: address_fields.part > part_numbers.part
|
||||||
Ref: address_fields.field > field_names.id
|
Ref: address_fields.field > field_names.id
|
||||||
Ref: address_fields.address > addresses.id
|
Ref: address_fields.address > addresses.id
|
||||||
|
|
||||||
|
// app table
|
||||||
|
Table "front_threads" {
|
||||||
|
"id" int [pk, not null, increment]
|
||||||
|
"room" int [not null]
|
||||||
|
"name" text
|
||||||
|
"notSeen" int [not null, default: true]
|
||||||
|
"lastUpdate" timestamp [not null]
|
||||||
|
"isDm" bool [not null, default: true]
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref: front_threads.room > front_rooms.id
|
||||||
|
|
||||||
|
Table "front_rooms" {
|
||||||
|
"id" int [pk, not null, increment]
|
||||||
|
"name" text
|
||||||
|
"isGroup" bool [not null, default: false]
|
||||||
|
"notSeen" int [not null]
|
||||||
|
"lastUpdate" timestamp [not null]
|
||||||
|
}
|
||||||
|
|
||||||
|
Table "front_room_messages" {
|
||||||
|
"room" int [not null]
|
||||||
|
"thread" int [not null]
|
||||||
|
"message" int [not null]
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref: front_room_messages.room > front_rooms.id
|
||||||
|
Ref: front_room_messages.message - messages.id
|
||||||
|
Ref: front_room_messages.thread > front_threads.id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 141 KiB |
@ -1,3 +0,0 @@
|
|||||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path d="M21.2756 4.69628C21.8922 4.07969 21.8922 3.08 21.2756 2.46342C20.659 1.84683 19.6593 1.84683 19.0427 2.46342L11.8917 9.61447L4.74063 2.46342C4.12404 1.84683 3.12436 1.84683 2.50777 2.46342C1.89118 3.08 1.89118 4.07969 2.50777 4.69628L9.65882 11.8473L2.20145 19.3047C1.58487 19.9213 1.58487 20.921 2.20145 21.5376C2.81804 22.1541 3.81773 22.1541 4.43431 21.5376L11.8917 14.0802L19.349 21.5375C19.9656 22.1541 20.9653 22.1541 21.5819 21.5375C22.1985 20.921 22.1985 19.9213 21.5819 19.3047L14.1245 11.8473L21.2756 4.69628Z" fill="#737D8C"/>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 650 B After Width: | Height: | Size: 0 B |
Loading…
Reference in New Issue
Block a user