run server as typescript
This commit is contained in:
parent
a5d325818b
commit
7ba1ee083d
@ -43,4 +43,5 @@ export interface AttrsWithEnvelope {
|
||||
envelope: Envelope;
|
||||
/** The RFC822 message size (only set if requested with fetch()). */
|
||||
size?: number | undefined;
|
||||
modseq?: number;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Imap, { ImapMessageAttributes, MailBoxes } from "imap";
|
||||
import { getMailbox, updateMailbox } from "../../db/imap/imap";
|
||||
import { Attrs } from "../../interfaces/mail/attrs.interface";
|
||||
import { Attrs, AttrsWithEnvelope } from "../../interfaces/mail/attrs.interface";
|
||||
import logger from "../../system/Logger";
|
||||
import RegisterMessageInApp from "../saveMessage";
|
||||
import { saveMessage } from "../storeMessage";
|
||||
@ -31,7 +31,7 @@ export default class Box {
|
||||
|
||||
sync(savedUid, currentUid) {
|
||||
const promises: Promise<unknown>[] = [];
|
||||
const mails: ImapMessageAttributes[] = [];
|
||||
const mails: Attrs[] = [];
|
||||
logger.log(`Syncing from ${savedUid} to ${currentUid} uid`);
|
||||
const f = this.imap.seq.fetch(`${savedUid}:${currentUid}`, {
|
||||
// const f = this.imap.seq.fetch(`${savedUid}:${currentUid}`, {
|
||||
@ -40,7 +40,7 @@ export default class Box {
|
||||
});
|
||||
|
||||
f.on("message", (msg, seqno) => {
|
||||
msg.once("attributes", (attrs: Attrs) => {
|
||||
msg.once("attributes", (attrs: AttrsWithEnvelope) => {
|
||||
console.log(attrs.envelope)
|
||||
mails.push(attrs);
|
||||
promises.push(saveMessage(attrs, this.id, this.imap));
|
||||
@ -58,7 +58,7 @@ export default class Box {
|
||||
for (let j = i; j < (i + step && promises.length); j++) {
|
||||
await new Promise((resolve, reject) => {
|
||||
promises[j]
|
||||
.then(async (res) => {
|
||||
.then(async (res: number) => {
|
||||
const register = new RegisterMessageInApp(res, mails[j], this.id);
|
||||
await register.save();
|
||||
resolve("");
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { getAddresseId } from "../db/mail";
|
||||
import {simpleParser} from "mailparser";
|
||||
import moment from "moment";
|
||||
import Imap from "imap";
|
||||
import {
|
||||
registerMessage,
|
||||
registerMailbox_message,
|
||||
@ -13,8 +14,9 @@ import {
|
||||
|
||||
import { getFieldId } from "../db/mail";
|
||||
import logger from "../system/Logger";
|
||||
import { AttrsWithEnvelope } from "../interfaces/mail/attrs.interface";
|
||||
|
||||
export function saveMessage(attrs, mailboxId, imap) {
|
||||
export function saveMessage(attrs: AttrsWithEnvelope, mailboxId: number, imap: Imap): Promise<number> {
|
||||
const envelope = attrs.envelope;
|
||||
const ts = moment(new Date(envelope.date).getTime()).format("YYYY-MM-DD HH:mm:ss");
|
||||
const rfc822size = attrs.size;
|
||||
@ -26,7 +28,7 @@ export function saveMessage(attrs, mailboxId, imap) {
|
||||
const isSeen = attrs.flags.includes("\\Seen") ? 1 : 0; // todo verify
|
||||
const deleted = attrs.flags.includes("\\Deleted") ? 1 : 0; // todo verify
|
||||
|
||||
registerMailbox_message(mailboxId, attrs.uid, messageId, attrs.modseq, isSeen, deleted);
|
||||
registerMailbox_message(mailboxId, attrs.uid, messageId, attrs?.modseq, isSeen, deleted);
|
||||
const f = imap.fetch(attrs.uid, { bodies: "" });
|
||||
let buffer = "";
|
||||
|
||||
|
@ -36,9 +36,6 @@ export function generateAttrs(options: Options): AttrsWithEnvelope {
|
||||
"flags": options.flags ?? [],
|
||||
"uid": options.uid ?? randomInt(3),
|
||||
"modseq": options.modseq ?? randomInt(7),
|
||||
"x-gm-labels": ["\\Inbox"],
|
||||
"x-gm-msgid": "1760991478422670209",
|
||||
"x-gm-thrid": "1760991478422670209",
|
||||
};
|
||||
return attrs;
|
||||
}
|
||||
|
@ -8,10 +8,5 @@
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true,
|
||||
"types": ["node", "jest"],
|
||||
"paths": {
|
||||
"*": ["node_modules/*", "src/types/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user