panel 2 courier
This commit is contained in:
parent
90d9aaafd9
commit
5f17baf88e
@ -77,8 +77,10 @@ export async function GET(request: Request) {
|
|||||||
envelope: true,
|
envelope: true,
|
||||||
flags: true,
|
flags: true,
|
||||||
bodyStructure: true,
|
bodyStructure: true,
|
||||||
source: true, // Get the full email source
|
bodyParts: [
|
||||||
bodyParts: ['text/plain', 'text/html'] // Get both text and HTML content
|
'text/plain',
|
||||||
|
'text/html'
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
for await (const message of messages) {
|
for await (const message of messages) {
|
||||||
@ -86,7 +88,8 @@ export async function GET(request: Request) {
|
|||||||
let content = '';
|
let content = '';
|
||||||
if (message.bodyParts) {
|
if (message.bodyParts) {
|
||||||
// Prefer HTML content if available
|
// Prefer HTML content if available
|
||||||
content = message.bodyParts.get('text/html')?.toString() || message.bodyParts.get('text/plain')?.toString() || '';
|
content = message.bodyParts.get('text/html')?.toString() ||
|
||||||
|
message.bodyParts.get('text/plain')?.toString() || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
@ -101,8 +104,7 @@ export async function GET(request: Request) {
|
|||||||
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),
|
||||||
content: content,
|
content: content
|
||||||
source: message.source?.toString() || '' // Include full email source for parsing
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -500,22 +500,32 @@ export default function CourrierPage() {
|
|||||||
try {
|
try {
|
||||||
console.log('Checking for stored credentials...');
|
console.log('Checking for stored credentials...');
|
||||||
const response = await fetch('/api/courrier');
|
const response = await fetch('/api/courrier');
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json();
|
console.log('API response error:', data);
|
||||||
console.log('API response error:', errorData);
|
if (data.error === 'No mail credentials found. Please configure your email account.') {
|
||||||
if (errorData.error === 'No stored credentials found') {
|
|
||||||
console.log('No credentials found, redirecting to login...');
|
console.log('No credentials found, redirecting to login...');
|
||||||
router.push('/courrier/login');
|
router.push('/courrier/login');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error(errorData.error || 'Failed to check credentials');
|
if (data.error === 'Unauthorized') {
|
||||||
|
console.log('User not authenticated, redirecting to auth...');
|
||||||
|
router.push('/api/auth/signin');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setError(data.error || 'Failed to check credentials');
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we get here, credentials are valid and we have emails
|
||||||
console.log('Credentials verified, loading emails...');
|
console.log('Credentials verified, loading emails...');
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
loadEmails();
|
loadEmails();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error checking credentials:', err);
|
console.error('Error checking credentials:', err);
|
||||||
setError(err instanceof Error ? err.message : 'Failed to check credentials');
|
setError('Failed to connect to mail server. Please try again later.');
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user