mail page fix
This commit is contained in:
parent
dbe55757be
commit
6444f67555
@ -64,14 +64,21 @@ export async function GET(request: Request) {
|
||||
// Open the requested mailbox
|
||||
const mailbox = await client.mailboxOpen(folder);
|
||||
|
||||
const result = [];
|
||||
|
||||
// Only try to fetch if the mailbox has messages
|
||||
if (mailbox.exists > 0) {
|
||||
// Adjust start and end to be within bounds
|
||||
const adjustedStart = Math.min(start, mailbox.exists);
|
||||
const adjustedEnd = Math.min(end, mailbox.exists);
|
||||
|
||||
// Fetch messages from the current folder
|
||||
const messages = await client.fetch(`${start}:${end}`, {
|
||||
const messages = await client.fetch(`${adjustedStart}:${adjustedEnd}`, {
|
||||
envelope: true,
|
||||
flags: true,
|
||||
bodyStructure: true
|
||||
});
|
||||
|
||||
const result = [];
|
||||
for await (const message of messages) {
|
||||
result.push({
|
||||
id: message.uid,
|
||||
@ -87,6 +94,7 @@ export async function GET(request: Request) {
|
||||
flags: Array.from(message.flags)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
emails: result,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user