routes of update flags with imap
This commit is contained in:
@@ -1,15 +1,54 @@
|
||||
import statusCode from "../utils/statusCodes";
|
||||
import { Response } from "express";
|
||||
import { getMessageUid, getUserOfMailbox } from "../db/utils/mail";
|
||||
import emailManager from "../mails/EmailManager";
|
||||
|
||||
export default class Message {
|
||||
|
||||
static async addFlag(body, res: Response) {
|
||||
console.log("hit")
|
||||
res.status(statusCode.OK).send();
|
||||
const { mailboxId, messageId, flag } = body;
|
||||
const uid = (await getMessageUid(messageId))[0]?.uid;
|
||||
if (!uid) {
|
||||
res.status(statusCode.NOT_FOUND).send({ error: "Message uid not found." });
|
||||
}
|
||||
|
||||
const user = (await getUserOfMailbox(mailboxId))[0]?.user;
|
||||
if (!user) {
|
||||
res.status(statusCode.NOT_FOUND).send({ error: "Not account for this mailbox." });
|
||||
}
|
||||
emailManager
|
||||
.getImap(user)
|
||||
.getMailbox(mailboxId)
|
||||
.addFlag(uid.toString(), [flag])
|
||||
.then(() => {
|
||||
res.status(statusCode.OK).send();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
res.status(statusCode.METHOD_FAILURE).send({ error: err });
|
||||
});
|
||||
}
|
||||
|
||||
static async removeFlag(body, res: Response) {
|
||||
console.log("hit")
|
||||
res.status(statusCode.OK).send();
|
||||
const { mailboxId, messageId, flag } = body;
|
||||
const uid = (await getMessageUid(messageId))[0]?.uid;
|
||||
if (!uid) {
|
||||
res.status(statusCode.NOT_FOUND).send({ error: "Message uid not found." });
|
||||
}
|
||||
|
||||
const user = (await getUserOfMailbox(mailboxId))[0]?.user;
|
||||
if (!user) {
|
||||
res.status(statusCode.NOT_FOUND).send({ error: "Not account for this mailbox." });
|
||||
}
|
||||
emailManager
|
||||
.getImap(user)
|
||||
.getMailbox(mailboxId)
|
||||
.removeFlag(uid.toString(), [flag])
|
||||
.then(() => {
|
||||
res.status(statusCode.OK).send();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
res.status(statusCode.METHOD_FAILURE).send({ error: err });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user