Compare commits
No commits in common. "4b2116854717060837d06f9766693921325bf56a" and "b9cc543b64839fb94f9c9edb342954fb5c0186e5" have entirely different histories.
4b21168547
...
b9cc543b64
@ -1,44 +0,0 @@
|
|||||||
import { ImapInstance } from "./imap/ImapInstance";
|
|
||||||
import { SmtpInstance } from "./smtp/SmtpInstance";
|
|
||||||
import logger from "../system/Logger";
|
|
||||||
import { getAllAccounts } from "../db/imap/imap-db";
|
|
||||||
|
|
||||||
export interface Account {
|
|
||||||
id: number;
|
|
||||||
user: string
|
|
||||||
password?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
class EmailManager {
|
|
||||||
imapInstances: ImapInstance[]
|
|
||||||
smtpInstances: SmtpInstance[]
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.imapInstances = [];
|
|
||||||
this.smtpInstances = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
init() {
|
|
||||||
getAllAccounts().then((accounts: Account[]) => {
|
|
||||||
for (let i = 0; i < accounts.length; i++) {
|
|
||||||
accounts[i].password = accounts[i]?.password?.toString().replace(/[\u{0080}-\u{FFFF}]/gu,"");
|
|
||||||
if (accounts[i].id == 2) continue; //debug_todo
|
|
||||||
this.addImapInstance(accounts[i]);
|
|
||||||
this.addSmtpInstance(accounts[i]);
|
|
||||||
}
|
|
||||||
}).catch((err) => {
|
|
||||||
logger.err(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
addImapInstance(config) {
|
|
||||||
this.imapInstances.push(new ImapInstance(config));
|
|
||||||
}
|
|
||||||
|
|
||||||
addSmtpInstance(config) {
|
|
||||||
this.smtpInstances.push(new SmtpInstance(config));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const emailManager = new EmailManager();
|
|
||||||
export default emailManager;
|
|
@ -1,4 +1,4 @@
|
|||||||
import { Account } from "../EmailManager";
|
import { Account } from "./ImapSync";
|
||||||
|
|
||||||
import Imap from "imap";
|
import Imap from "imap";
|
||||||
import { getAllMailboxes, registerMailbox } from "../../db/imap/imap-db";
|
import { getAllMailboxes, registerMailbox } from "../../db/imap/imap-db";
|
||||||
|
33
back/mails/imap/ImapSync.ts
Normal file
33
back/mails/imap/ImapSync.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { getAllAccounts } from "../../db/imap/imap-db";
|
||||||
|
import logger from "../../system/Logger";
|
||||||
|
import { ImapInstance } from "./ImapInstance";
|
||||||
|
|
||||||
|
export interface Account {
|
||||||
|
id: number;
|
||||||
|
user: string
|
||||||
|
password?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class ImapSync {
|
||||||
|
instances: ImapInstance[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.instances = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
getAllAccounts().then((accounts: Account[]) => {
|
||||||
|
for (let i = 0; i < accounts.length; i++) {
|
||||||
|
accounts[i].password = accounts[i]?.password?.toString().replace(/[\u{0080}-\u{FFFF}]/gu,"");
|
||||||
|
if (accounts[i].id == 2) continue; //debug_todo
|
||||||
|
this.addInstance(accounts[i]);
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
logger.err(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addInstance(config) {
|
||||||
|
this.instances.push(new ImapInstance(config));
|
||||||
|
}
|
||||||
|
}
|
@ -1,36 +0,0 @@
|
|||||||
import logger from "../../system/Logger";
|
|
||||||
import nodemailer, { Transporter } from "nodemailer";
|
|
||||||
|
|
||||||
export class SmtpInstance {
|
|
||||||
transporter: Transporter;
|
|
||||||
|
|
||||||
constructor(account: {user: string, password: string}) {
|
|
||||||
// todo store other data
|
|
||||||
this.transporter = nodemailer.createTransport({
|
|
||||||
host: "smtp.gmail.com",
|
|
||||||
port: 465,
|
|
||||||
secure: true,
|
|
||||||
auth: {
|
|
||||||
user: account.user,
|
|
||||||
pass: account.password,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
sendMail() {
|
|
||||||
const msg = {
|
|
||||||
from: "",
|
|
||||||
to: "",
|
|
||||||
subject: "Hello ✔",
|
|
||||||
text: "Hello world?",
|
|
||||||
html: "<b>Hello world?</b>",
|
|
||||||
};
|
|
||||||
this.transporter.sendMail(msg, (err, message) => {
|
|
||||||
if (err) {
|
|
||||||
logger.err(err);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
logger.log(message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
20
back/package-lock.json
generated
20
back/package-lock.json
generated
@ -26,7 +26,6 @@
|
|||||||
"@types/mailparser": "^3.0.2",
|
"@types/mailparser": "^3.0.2",
|
||||||
"@types/moment": "^2.13.0",
|
"@types/moment": "^2.13.0",
|
||||||
"@types/node": "^18.15.11",
|
"@types/node": "^18.15.11",
|
||||||
"@types/nodemailer": "^6.4.7",
|
|
||||||
"concurrently": "^8.0.1",
|
"concurrently": "^8.0.1",
|
||||||
"jest": "^29.5.0",
|
"jest": "^29.5.0",
|
||||||
"sql-mysql": "^1.2.0",
|
"sql-mysql": "^1.2.0",
|
||||||
@ -1628,16 +1627,6 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/nodemailer": {
|
|
||||||
"version": "6.4.7",
|
|
||||||
"resolved": "https://repo.plus4u.net/operatorGate/repository/public-javascript/@types/nodemailer/-/nodemailer-6.4.7.tgz",
|
|
||||||
"integrity": "sha512-f5qCBGAn/f0qtRcd4SEn88c8Fp3Swct1731X4ryPKqS61/A3LmmzN8zaEz7hneJvpjFbUUgY7lru/B/7ODTazg==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@types/prettier": {
|
"node_modules/@types/prettier": {
|
||||||
"version": "2.7.2",
|
"version": "2.7.2",
|
||||||
"resolved": "https://repo.plus4u.net/operatorGate/repository/public-javascript/@types/prettier/-/prettier-2.7.2.tgz",
|
"resolved": "https://repo.plus4u.net/operatorGate/repository/public-javascript/@types/prettier/-/prettier-2.7.2.tgz",
|
||||||
@ -8321,15 +8310,6 @@
|
|||||||
"integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==",
|
"integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/nodemailer": {
|
|
||||||
"version": "6.4.7",
|
|
||||||
"resolved": "https://repo.plus4u.net/operatorGate/repository/public-javascript/@types/nodemailer/-/nodemailer-6.4.7.tgz",
|
|
||||||
"integrity": "sha512-f5qCBGAn/f0qtRcd4SEn88c8Fp3Swct1731X4ryPKqS61/A3LmmzN8zaEz7hneJvpjFbUUgY7lru/B/7ODTazg==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"@types/node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"@types/prettier": {
|
"@types/prettier": {
|
||||||
"version": "2.7.2",
|
"version": "2.7.2",
|
||||||
"resolved": "https://repo.plus4u.net/operatorGate/repository/public-javascript/@types/prettier/-/prettier-2.7.2.tgz",
|
"resolved": "https://repo.plus4u.net/operatorGate/repository/public-javascript/@types/prettier/-/prettier-2.7.2.tgz",
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
"@types/mailparser": "^3.0.2",
|
"@types/mailparser": "^3.0.2",
|
||||||
"@types/moment": "^2.13.0",
|
"@types/moment": "^2.13.0",
|
||||||
"@types/node": "^18.15.11",
|
"@types/node": "^18.15.11",
|
||||||
"@types/nodemailer": "^6.4.7",
|
|
||||||
"concurrently": "^8.0.1",
|
"concurrently": "^8.0.1",
|
||||||
"jest": "^29.5.0",
|
"jest": "^29.5.0",
|
||||||
"sql-mysql": "^1.2.0",
|
"sql-mysql": "^1.2.0",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
const app = express();
|
const app = express();
|
||||||
import ImapSync from "./mails/EmailManager";
|
import ImapSync from "./mails/imap/ImapSync";
|
||||||
import { execQueryAsync, execQuery } from "./db/db";
|
import { execQueryAsync, execQuery } from "./db/db";
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
@ -14,12 +14,12 @@ app.use(cors());
|
|||||||
app.listen(process.env.PORT || 5500);
|
app.listen(process.env.PORT || 5500);
|
||||||
|
|
||||||
import mailRouter from "./routes/mail";
|
import mailRouter from "./routes/mail";
|
||||||
import emailManager from "./mails/EmailManager";
|
import logger from "./system/Logger";
|
||||||
app.use("/api/mail", mailRouter);
|
app.use("/api/mail", mailRouter);
|
||||||
|
|
||||||
emailManager.init();
|
const imapSync = new ImapSync();
|
||||||
|
imapSync.init();
|
||||||
|
|
||||||
// debug reset all tables
|
|
||||||
const shouldReset = false;
|
const shouldReset = false;
|
||||||
if (shouldReset) {
|
if (shouldReset) {
|
||||||
const query = "SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE table_schema = 'mail'";
|
const query = "SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE table_schema = 'mail'";
|
||||||
|
Loading…
Reference in New Issue
Block a user