feat: use postal mime parser

This commit is contained in:
2024-08-15 20:32:34 +02:00
committed by Thea Schöbl
parent 7de16808fc
commit f81690e19f
28 changed files with 540 additions and 402 deletions

View File

@@ -77,22 +77,37 @@ app.get('/:id', async (request, response) => {
await client.logout();
});
app.get('/:id/attachment/:attachment', async (request, response) => {
app.get('/:id/attachment/:attachment?', async (request, response) => {
const client = response.locals.client as ImapFlow;
await client.connect();
const lock = await client.getMailboxLock('INBOX');
try {
const message = await client.download(request.params.id, request.params.attachment);
const body = await new Promise<string>(resolve => {
let body = '';
message.content.on('data', chunk => {
body += chunk.toString();
});
message.content.on('end', () => {
resolve(body);
});
message.content.on('data', chunk => {
response.write(chunk);
});
response.send(body);
message.content.on('end', () => {
response.end();
});
} finally {
lock.release();
}
await client.logout();
});
app.get('/:id/raw/:part', async (request, response) => {
const client = response.locals.client as ImapFlow;
await client.connect();
const lock = await client.getMailboxLock('INBOX');
try {
const message = await client.fetchOne(request.params.id, {
bodyParts: [`${request.params.part}.mime`, request.params.part],
});
response.write(message.bodyParts.get(`${request.params.part}.mime`));
response.write(message.bodyParts.get(request.params.part));
response.end();
} finally {
lock.release();
}