mail/back/db/imap/imap-db.ts
2023-04-17 13:08:54 +02:00

54 lines
1.9 KiB
TypeScript

import { execQueryAsyncWithId, execQueryAsync, execQuery } from "../db";
export async function getAllAccounts() {
const query = `
SELECT
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
FROM app_account INNER JOIN address
WHERE address.address_id = app_account.user_id
`;
const values = [];
return await execQueryAsync(query, values);
}
export async function getAllMailboxes(accountId: number) {
const query = "SELECT * FROM mailbox WHERE mailbox.account_id = ?";
const values = [accountId];
return await execQueryAsync(query, values);
}
export async function registerMailbox(accountId: number, mailboxName: string) {
const query = `INSERT INTO mailbox (account_id, mailbox_name) VALUES (?, ?)`;
const values = [accountId, mailboxName];
return await execQueryAsyncWithId(query, values);
}
export async function getMailbox(mailboxId: number) {
const query = `SELECT * FROM mailbox WHERE mailbox_id = ?`;
const values = [mailboxId];
return await execQueryAsync(query, values);
}
export function updateMailbox(mailboxId: number, uidnext: number) {
const query = `UPDATE mailbox SET uidnext = ? WHERE mailbox_id = ?`;
const values = [uidnext, mailboxId];
execQuery(query, values);
}
export async function updateMailboxModseq(mailboxId: number, modseq: number) {
const query = `UPDATE mailbox SET nextmodseq = ? WHERE mailbox_id = ?`;
const values = [modseq, mailboxId];
return await execQueryAsync(query, values);
}
export async function getMailboxModseq(mailboxId: number): Promise<{ modseq: number }[]> {
const query = `SELECT nextmodseq AS modseq FROM mailbox WHERE mailbox_id = ?`;
const values = [mailboxId];
return await execQueryAsync(query, values);
}