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'),
|
read: message.flags.has('\\Seen'),
|
||||||
starred: message.flags.has('\\Flagged'),
|
starred: message.flags.has('\\Flagged'),
|
||||||
flags: Array.from(message.flags),
|
flags: Array.from(message.flags),
|
||||||
hasAttachments: message.bodyStructure?.type === 'multipart')
|
hasAttachments: message.bodyStructure?.type === 'multipart'
|
||||||
};
|
};
|
||||||
|
|
||||||
// 9. Cache the email content
|
// 9. Cache the email content
|
||||||
|
|||||||
@ -4,24 +4,13 @@ import { getServerSession } from 'next-auth';
|
|||||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
|
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
|
||||||
import { prisma } from '@/lib/prisma';
|
import { prisma } from '@/lib/prisma';
|
||||||
|
|
||||||
// Add caching for better performance
|
// Simple email cache structure
|
||||||
const cache = new Map();
|
interface EmailCache {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
const getCachedEmail = (id: string) => cache.get(id);
|
// Simple in-memory cache
|
||||||
const setCachedEmail = (id: string, email: Email) => cache.set(id, email);
|
const cache: EmailCache = {};
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
@ -93,23 +82,21 @@ export async function GET(request: Request) {
|
|||||||
const adjustedEnd = Math.min(end, mailbox.exists);
|
const adjustedEnd = Math.min(end, mailbox.exists);
|
||||||
|
|
||||||
// Fetch both metadata and preview content
|
// Fetch both metadata and preview content
|
||||||
const messages = await client.fetch(`${adjustedStart}:${adjustedEnd}`, {
|
const fetchOptions: any = {
|
||||||
envelope: true,
|
envelope: true,
|
||||||
flags: true,
|
flags: true,
|
||||||
bodyStructure: true,
|
bodyStructure: true
|
||||||
// Only fetch preview content if requested
|
};
|
||||||
...(preview ? {
|
|
||||||
bodyParts: ['TEXT'],
|
// Only fetch preview content if requested
|
||||||
bodyPartsOptions: {
|
if (preview) {
|
||||||
TEXT: {
|
fetchOptions.bodyParts = ['TEXT'];
|
||||||
maxLength: 1000 // Limit preview length
|
}
|
||||||
}
|
|
||||||
}
|
const messages = await client.fetch(`${adjustedStart}:${adjustedEnd}`, fetchOptions);
|
||||||
} : {})
|
|
||||||
});
|
|
||||||
|
|
||||||
for await (const message of messages) {
|
for await (const message of messages) {
|
||||||
result.push({
|
const emailData: any = {
|
||||||
id: message.uid,
|
id: message.uid,
|
||||||
from: message.envelope.from?.[0]?.address || '',
|
from: message.envelope.from?.[0]?.address || '',
|
||||||
fromName: message.envelope.from?.[0]?.name || message.envelope.from?.[0]?.address?.split('@')[0] || '',
|
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'),
|
starred: message.flags.has('\\Flagged'),
|
||||||
folder: mailbox.path,
|
folder: mailbox.path,
|
||||||
hasAttachments: message.bodyStructure?.type === 'multipart',
|
hasAttachments: message.bodyStructure?.type === 'multipart',
|
||||||
flags: Array.from(message.flags),
|
flags: Array.from(message.flags)
|
||||||
// Include preview content if available
|
};
|
||||||
preview: preview ? message.bodyParts?.TEXT?.toString() : null
|
|
||||||
});
|
// 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