update database structure
This commit is contained in:
@@ -22,7 +22,7 @@ imap.once("ready", function () {
|
||||
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', {
|
||||
// bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',
|
||||
// struct: true
|
||||
@@ -30,22 +30,23 @@ imap.once("ready", function () {
|
||||
f.on("message", function (msg, seqno) {
|
||||
// console.log("Message #%d", seqno);
|
||||
// var prefix = "(#" + seqno + ") ";
|
||||
// msg.on("body", function (stream, info) {
|
||||
// simpleParser(stream, async (err, parsed) => {
|
||||
// // find box id;
|
||||
// console.log(parsed)
|
||||
// const boxId = 1;
|
||||
// // saveMessage(parsed, boxId);
|
||||
// console.log(parsed.subject);
|
||||
// fs.writeFileSync("./test.json", JSON.stringify(parsed));
|
||||
// });
|
||||
// // console.log(prefix + 'Body');
|
||||
// // stream.pipe(fs.createWriteStream('msg-' + seqno + '-body.txt'));
|
||||
// });
|
||||
msg.on("body", function (stream, info) {
|
||||
simpleParser(stream, async (err, parsed) => {
|
||||
// find box id;
|
||||
console.log(parsed)
|
||||
const boxId = 1;
|
||||
// saveMessage(parsed, boxId);
|
||||
console.log(parsed.subject);
|
||||
fs.writeFileSync("./test.txt", JSON.stringify(parsed));
|
||||
});
|
||||
// console.log(prefix + 'Body');
|
||||
// stream.pipe(fs.createWriteStream('msg-' + seqno + '-body.txt'));
|
||||
});
|
||||
msg.once('attributes', attrs => {
|
||||
// todo find boxId
|
||||
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
|
||||
// message.headerLines.forEach(elt => {
|
||||
// const newKey = keyNormalizer(elt.key);
|
||||
// getFieldId(newKey).then((fieldId) => {
|
||||
// saveHeader_fields(messageId, part, 2, fieldId, elt[line]);
|
||||
// });
|
||||
// });
|
||||
// todo check for different provider
|
||||
if (envelope?.inReplyTo) {
|
||||
`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`;
|
||||
// parent message is in a thread, so register this message only in a thread
|
||||
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 express = require('express');
|
||||
const router = require('router');
|
||||
|
||||
/**
|
||||
* Return all mailboxes and folders for an user
|
||||
*/
|
||||
function getMailboxes(req, res) {
|
||||
router.get("/mailboxes", (req, res) => {
|
||||
const {token} = req.params;
|
||||
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 cors = require('cors')
|
||||
|
||||
@@ -25,6 +25,7 @@ Table "mailboxes" {
|
||||
|
||||
Table "messages" {
|
||||
"id" int [pk, not null, increment]
|
||||
"messageID" text [pk, not null]
|
||||
"idate" timestamp [not null]
|
||||
"rfc822size" int
|
||||
}
|
||||
@@ -103,3 +104,37 @@ Ref: address_fields.message > messages.id
|
||||
Ref: address_fields.part > part_numbers.part
|
||||
Ref: address_fields.field > field_names.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 |
Reference in New Issue
Block a user