mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
feat: use postal mime parser
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user