mail page rest

This commit is contained in:
alma 2025-04-21 12:43:18 +02:00
parent d3313abbde
commit d8cab53806

View File

@ -53,7 +53,7 @@ export async function GET() {
envelope: true,
flags: true,
bodyStructure: true,
bodyParts: ['TEXT']
bodyParts: ['HEADER', 'TEXT']
});
const result = [];
@ -63,12 +63,40 @@ export async function GET() {
if (message.bodyParts && Array.isArray(message.bodyParts)) {
for (const [partType, content] of message.bodyParts) {
if (partType === 'text') {
body = content.toString('utf-8');
// Convert buffer to string and decode if needed
const contentStr = content.toString('utf-8');
// Check if content is base64 encoded
if (contentStr.includes('Content-Transfer-Encoding: base64')) {
const base64Content = contentStr.split('\r\n\r\n')[1];
body = Buffer.from(base64Content, 'base64').toString('utf-8');
} else {
body = contentStr;
}
break;
}
}
}
// If no body found, try to get it from the message structure
if (!body && message.bodyStructure) {
try {
const fetch = await client.fetchOne(message.uid.toString(), {
bodyStructure: true,
bodyParts: ['TEXT']
});
if (fetch?.bodyParts) {
for (const [partType, content] of fetch.bodyParts) {
if (partType === 'text') {
body = content.toString('utf-8');
break;
}
}
}
} catch (error) {
console.error('Error fetching message content:', error);
}
}
result.push({
id: message.uid.toString(),
accountId: 1, // Default account ID