diff --git a/back/abl/Account-abl.ts b/back/abl/Account-abl.ts index bc30bcf..7d49450 100644 --- a/back/abl/Account-abl.ts +++ b/back/abl/Account-abl.ts @@ -12,10 +12,10 @@ export default class Account { } static async register(body, res: Response) { - const { email, pwd, xoauth, xoauth2, host, port, tls } = body; + const { email, pwd, xoauth, xoauth2, imapHost, smtpHost, imapPort, smtpPort, tls } = body; getAddressId(email).then((addressId) => { - registerAccount(addressId, pwd, xoauth, xoauth2, host, port, tls) - .then((mailboxId) => { + registerAccount(addressId, pwd, xoauth, xoauth2, imapHost, smtpHost, imapPort, smtpPort, tls) + .then((mailboxId) => {0 res.status(statusCodes.OK).json({ id: mailboxId }); }) .catch(() => { diff --git a/back/db/api-db.ts b/back/db/api-db.ts index 08cba0c..b2afa21 100644 --- a/back/db/api-db.ts +++ b/back/db/api-db.ts @@ -1,12 +1,12 @@ import { execQueryAsync, execQueryAsyncWithId } from "./db"; import { queryCcId, queryToId, queryFromId } from "./utils/addressQueries"; -export async function registerAccount(userId, pwd, xoauth, xoauth2, host, port, tls) { +export async function registerAccount(userId, pwd, xoauth, xoauth2, imapHost, smtpHost, imapPort, smtpPort, tls) { const query = ` INSERT INTO app_account - (user_id, account_pwd, xoauth, xoauth2, host, port, tls) VALUES (?, ?, ?, ?, ?, ?, ?) + (user_id, account_pwd, xoauth, xoauth2, imap_host, smtp_host, imap_port, smtp_port, tls) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) `; - const values = [userId, pwd, xoauth, xoauth2, host, port, tls]; + const values = [userId, pwd, xoauth, xoauth2, imapHost, smtpHost, imapPort, smtpPort, tls]; return await execQueryAsyncWithId(query, values); } diff --git a/back/db/database.sql b/back/db/database.sql index 62da8ad..3376a7c 100644 --- a/back/db/database.sql +++ b/back/db/database.sql @@ -18,8 +18,10 @@ CREATE TABLE app_account ( account_pwd BINARY(22), xoauth VARCHAR(116), xoauth2 VARCHAR(116), - host VARCHAR(255) NOT NULL DEFAULT 'localhost', - port INT(5) NOT NULL DEFAULT 143, + imap_host VARCHAR(255) NOT NULL DEFAULT 'localhost', + imap_port INT(5) NOT NULL DEFAULT 993, + smtp_host VARCHAR(255) NOT NULL DEFAULT 'localhost', + smtp_port INT(5) NOT NULL DEFAULT 465, tls BOOLEAN NOT NULL DEFAULT true, PRIMARY KEY (account_id), FOREIGN KEY (user_id) REFERENCES address(address_id) ON DELETE CASCADE diff --git a/back/db/imap/imap-db.ts b/back/db/imap/imap-db.ts index c3c9a06..e28797d 100644 --- a/back/db/imap/imap-db.ts +++ b/back/db/imap/imap-db.ts @@ -6,9 +6,11 @@ export async function getAllAccounts() { app_account.account_id AS id, address.email AS user, app_account.account_pwd AS password, - app_account.host AS host, - app_account.port AS port, - app_account.tls AS tls + app_account.imap_host, + app_account.imap_port, + app_account.smtp_host, + app_account.smtp_port, + app_account.tls FROM app_account INNER JOIN address WHERE address.address_id = app_account.user_id `; diff --git a/back/mails/imap/ImapInstance.ts b/back/mails/imap/ImapInstance.ts index 7266930..cbb92e4 100644 --- a/back/mails/imap/ImapInstance.ts +++ b/back/mails/imap/ImapInstance.ts @@ -14,9 +14,9 @@ export class ImapInstance { this.imap = new Imap({ user: account.user, password: account.password, - tlsOptions: { servername: account.host }, - host: account.host, - port: account.port, + tlsOptions: { servername: account.imap_host }, + host: account.imap_host, + port: account.imap_port, tls: account.tls, }); this.account = account; diff --git a/back/mails/smtp/SmtpInstance.ts b/back/mails/smtp/SmtpInstance.ts index 1ffa839..0cbb727 100644 --- a/back/mails/smtp/SmtpInstance.ts +++ b/back/mails/smtp/SmtpInstance.ts @@ -5,12 +5,11 @@ export class SmtpInstance { transporter: Transporter; user: string; - constructor(account: { user: string; password: string }) { - // todo store other data + constructor(account: { user: string; password: string, smtp_host: string, smtp_port: number }) { this.user = account.user; this.transporter = nodemailer.createTransport({ - host: "smtp.gmail.com", - port: 465, + host: account.smtp_host, + port: account.smtp_port, secure: true, auth: { user: account.user, diff --git a/back/validator/schemas/createAccount-schema.json b/back/validator/schemas/createAccount-schema.json index 258630f..7b138a1 100644 --- a/back/validator/schemas/createAccount-schema.json +++ b/back/validator/schemas/createAccount-schema.json @@ -5,10 +5,12 @@ "pwd": { "type": "string" }, "xoauth": { "type": "string" }, "xoauth2": { "type": "string" }, - "host": { "type": "string", "format": "hostname" }, - "port": { "type": "number", "maximum": 65535 }, + "imapHost": { "type": "string", "format": "hostname" }, + "smtpHost": { "type": "string", "format": "hostname" }, + "imapPort": { "type": "number", "maximum": 65535 }, + "smtpPort": { "type": "number", "maximum": 65535 }, "tls": { "type": "boolean" } }, - "required": ["email", "host", "port", "tls"], + "required": ["email", "imapHost", "smtpHost", "imapPort", "smtpPort", "tls"], "additionalProperties": false } \ No newline at end of file diff --git a/front/src/components/modals/AddAccountModal.vue b/front/src/components/modals/AddAccountModal.vue index 7c679ec..cbcca4a 100644 --- a/front/src/components/modals/AddAccountModal.vue +++ b/front/src/components/modals/AddAccountModal.vue @@ -142,11 +142,11 @@ function mailChange() { /> +