E-Mail Aktionen und Anhang-Download ergänzen
KI-AGENT: Ergänzt IMAP-basierte Aktionen zum Verschieben, Archivieren und Löschen von E-Mails sowie den Download von Anhängen aus der Originalmail. Die E-Mail Oberfläche bietet dafür Zielordner-Auswahl, Aktionsbuttons und Anhang-Downloads.
This commit is contained in:
@@ -393,4 +393,86 @@ export default async function emailAsUserRoutes(server: FastifyInstance) {
|
||||
}
|
||||
})
|
||||
|
||||
server.post("/email/messages/:id/move", async (req, reply) => {
|
||||
try {
|
||||
if (!req.user?.tenant_id) {
|
||||
return reply.code(400).send({ error: "No tenant selected" })
|
||||
}
|
||||
|
||||
const { id } = req.params as { id: string }
|
||||
const body = (req.body || {}) as { mailbox?: string }
|
||||
|
||||
if (!body.mailbox) {
|
||||
return reply.code(400).send({ error: "Zielordner fehlt" })
|
||||
}
|
||||
|
||||
const result = await emailSync.moveMessage(
|
||||
req.user.tenant_id,
|
||||
req.user.user_id,
|
||||
id,
|
||||
body.mailbox,
|
||||
)
|
||||
|
||||
if (!result) return reply.code(404).send({ error: "E-Mail nicht gefunden" })
|
||||
return reply.send({ success: true, ...result })
|
||||
} catch (err: any) {
|
||||
req.log.error(err)
|
||||
return reply.code(500).send({ error: err.message || "E-Mail konnte nicht verschoben werden" })
|
||||
}
|
||||
})
|
||||
|
||||
server.post("/email/messages/:id/archive", async (req, reply) => {
|
||||
try {
|
||||
if (!req.user?.tenant_id) {
|
||||
return reply.code(400).send({ error: "No tenant selected" })
|
||||
}
|
||||
|
||||
const { id } = req.params as { id: string }
|
||||
const result = await emailSync.archiveMessage(req.user.tenant_id, req.user.user_id, id)
|
||||
|
||||
if (!result) return reply.code(404).send({ error: "E-Mail nicht gefunden" })
|
||||
return reply.send({ success: true, ...result })
|
||||
} catch (err: any) {
|
||||
req.log.error(err)
|
||||
return reply.code(500).send({ error: err.message || "E-Mail konnte nicht archiviert werden" })
|
||||
}
|
||||
})
|
||||
|
||||
server.delete("/email/messages/:id", async (req, reply) => {
|
||||
try {
|
||||
if (!req.user?.tenant_id) {
|
||||
return reply.code(400).send({ error: "No tenant selected" })
|
||||
}
|
||||
|
||||
const { id } = req.params as { id: string }
|
||||
const result = await emailSync.deleteMessage(req.user.tenant_id, req.user.user_id, id)
|
||||
|
||||
if (!result) return reply.code(404).send({ error: "E-Mail nicht gefunden" })
|
||||
return reply.send({ success: true })
|
||||
} catch (err: any) {
|
||||
req.log.error(err)
|
||||
return reply.code(500).send({ error: err.message || "E-Mail konnte nicht gelöscht werden" })
|
||||
}
|
||||
})
|
||||
|
||||
server.get("/email/attachments/:id/download", async (req, reply) => {
|
||||
try {
|
||||
if (!req.user?.tenant_id) {
|
||||
return reply.code(400).send({ error: "No tenant selected" })
|
||||
}
|
||||
|
||||
const { id } = req.params as { id: string }
|
||||
const attachment = await emailSync.getAttachmentContent(req.user.tenant_id, req.user.user_id, id)
|
||||
|
||||
if (!attachment) return reply.code(404).send({ error: "Anhang nicht gefunden" })
|
||||
|
||||
reply.header("Content-Type", attachment.contentType)
|
||||
reply.header("Content-Disposition", `attachment; filename="${attachment.filename.replace(/"/g, "")}"`)
|
||||
return reply.send(attachment.content)
|
||||
} catch (err: any) {
|
||||
req.log.error(err)
|
||||
return reply.code(500).send({ error: err.message || "Anhang konnte nicht geladen werden" })
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user