mail page rest
This commit is contained in:
parent
d3313abbde
commit
d8cab53806
@ -53,7 +53,7 @@ export async function GET() {
|
|||||||
envelope: true,
|
envelope: true,
|
||||||
flags: true,
|
flags: true,
|
||||||
bodyStructure: true,
|
bodyStructure: true,
|
||||||
bodyParts: ['TEXT']
|
bodyParts: ['HEADER', 'TEXT']
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
@ -63,12 +63,40 @@ export async function GET() {
|
|||||||
if (message.bodyParts && Array.isArray(message.bodyParts)) {
|
if (message.bodyParts && Array.isArray(message.bodyParts)) {
|
||||||
for (const [partType, content] of message.bodyParts) {
|
for (const [partType, content] of message.bodyParts) {
|
||||||
if (partType === 'text') {
|
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;
|
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({
|
result.push({
|
||||||
id: message.uid.toString(),
|
id: message.uid.toString(),
|
||||||
accountId: 1, // Default account ID
|
accountId: 1, // Default account ID
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user