panel 2 courier api restore
This commit is contained in:
parent
fb12b916b8
commit
74f0a40139
@ -106,7 +106,7 @@ export async function GET(
|
||||
read: message.flags.has('\\Seen'),
|
||||
starred: message.flags.has('\\Flagged'),
|
||||
flags: Array.from(message.flags),
|
||||
hasAttachments: message.bodyStructure?.type === 'multipart')
|
||||
hasAttachments: message.bodyStructure?.type === 'multipart'
|
||||
};
|
||||
|
||||
// 9. Cache the email content
|
||||
|
||||
@ -4,24 +4,13 @@ import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
// Add caching for better performance
|
||||
const cache = new Map();
|
||||
// Simple email cache structure
|
||||
interface EmailCache {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
const getCachedEmail = (id: string) => cache.get(id);
|
||||
const setCachedEmail = (id: string, email: Email) => cache.set(id, email);
|
||||
|
||||
// Add debouncing for folder changes
|
||||
const debouncedLoadEmails = debounce((folder: string) => {
|
||||
loadEmails(folder);
|
||||
}, 300);
|
||||
|
||||
// Add infinite scroll
|
||||
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
||||
const { scrollTop, scrollHeight, clientHeight } = e.currentTarget;
|
||||
if (scrollHeight - scrollTop === clientHeight) {
|
||||
// Load more emails
|
||||
}
|
||||
};
|
||||
// Simple in-memory cache
|
||||
const cache: EmailCache = {};
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
@ -93,23 +82,21 @@ export async function GET(request: Request) {
|
||||
const adjustedEnd = Math.min(end, mailbox.exists);
|
||||
|
||||
// Fetch both metadata and preview content
|
||||
const messages = await client.fetch(`${adjustedStart}:${adjustedEnd}`, {
|
||||
const fetchOptions: any = {
|
||||
envelope: true,
|
||||
flags: true,
|
||||
bodyStructure: true,
|
||||
// Only fetch preview content if requested
|
||||
...(preview ? {
|
||||
bodyParts: ['TEXT'],
|
||||
bodyPartsOptions: {
|
||||
TEXT: {
|
||||
maxLength: 1000 // Limit preview length
|
||||
}
|
||||
}
|
||||
} : {})
|
||||
});
|
||||
bodyStructure: true
|
||||
};
|
||||
|
||||
// Only fetch preview content if requested
|
||||
if (preview) {
|
||||
fetchOptions.bodyParts = ['TEXT'];
|
||||
}
|
||||
|
||||
const messages = await client.fetch(`${adjustedStart}:${adjustedEnd}`, fetchOptions);
|
||||
|
||||
for await (const message of messages) {
|
||||
result.push({
|
||||
const emailData: any = {
|
||||
id: message.uid,
|
||||
from: message.envelope.from?.[0]?.address || '',
|
||||
fromName: message.envelope.from?.[0]?.name || message.envelope.from?.[0]?.address?.split('@')[0] || '',
|
||||
@ -120,10 +107,15 @@ export async function GET(request: Request) {
|
||||
starred: message.flags.has('\\Flagged'),
|
||||
folder: mailbox.path,
|
||||
hasAttachments: message.bodyStructure?.type === 'multipart',
|
||||
flags: Array.from(message.flags),
|
||||
// Include preview content if available
|
||||
preview: preview ? message.bodyParts?.TEXT?.toString() : null
|
||||
});
|
||||
flags: Array.from(message.flags)
|
||||
};
|
||||
|
||||
// Include preview content if available
|
||||
if (preview && message.bodyParts && message.bodyParts.has('TEXT')) {
|
||||
emailData.preview = message.bodyParts.get('TEXT')?.toString() || null;
|
||||
}
|
||||
|
||||
result.push(emailData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user