panel 2 courier api restore
This commit is contained in:
parent
ce4d768182
commit
a158c99d26
@ -6,6 +6,7 @@ import { X, Paperclip, ChevronDown, ChevronUp, SendHorizontal, Loader2 } from 'l
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card';
|
||||||
|
import { decodeEmail } from '@/lib/mail-parser-wrapper';
|
||||||
|
|
||||||
interface ComposeEmailProps {
|
interface ComposeEmailProps {
|
||||||
initialEmail?: EmailMessage | null;
|
initialEmail?: EmailMessage | null;
|
||||||
@ -54,18 +55,24 @@ export default function ComposeEmail({
|
|||||||
// Initialize the form when replying to or forwarding an email
|
// Initialize the form when replying to or forwarding an email
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (initialEmail && type !== 'new') {
|
if (initialEmail && type !== 'new') {
|
||||||
const formattedEmail = formatEmailForReplyOrForward(initialEmail, type as 'reply' | 'reply-all' | 'forward');
|
// If it's a forward, use the same approach as Panel 3
|
||||||
|
if (type === 'forward') {
|
||||||
|
initializeForwardedEmail();
|
||||||
|
} else {
|
||||||
|
// For reply/reply-all, continue using formatEmailForReplyOrForward
|
||||||
|
const formattedEmail = formatEmailForReplyOrForward(initialEmail, type as 'reply' | 'reply-all');
|
||||||
|
|
||||||
setTo(formattedEmail.to);
|
setTo(formattedEmail.to);
|
||||||
|
|
||||||
if (formattedEmail.cc) {
|
if (formattedEmail.cc) {
|
||||||
setCc(formattedEmail.cc);
|
setCc(formattedEmail.cc);
|
||||||
setShowCc(true);
|
setShowCc(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSubject(formattedEmail.subject);
|
||||||
|
setBody(formattedEmail.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
setSubject(formattedEmail.subject);
|
|
||||||
setBody(formattedEmail.body);
|
|
||||||
|
|
||||||
// Focus editor after initializing
|
// Focus editor after initializing
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (editorRef.current) {
|
if (editorRef.current) {
|
||||||
@ -85,6 +92,69 @@ export default function ComposeEmail({
|
|||||||
}
|
}
|
||||||
}, [initialEmail, type]);
|
}, [initialEmail, type]);
|
||||||
|
|
||||||
|
// New function to initialize forwarded email using same approach as Panel 3
|
||||||
|
const initializeForwardedEmail = async () => {
|
||||||
|
if (!initialEmail || !initialEmail.content) {
|
||||||
|
console.error('No email content available for forwarding');
|
||||||
|
setBody('<div>No content available</div>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setSending(true); // Use sending state to show loading
|
||||||
|
|
||||||
|
// Use the same decoding approach as Panel 3
|
||||||
|
const decoded = await decodeEmail(initialEmail.content);
|
||||||
|
|
||||||
|
// Format subject with Fwd: prefix if needed
|
||||||
|
const cleanSubject = initialEmail.subject.replace(/^(Fwd|FW|Forward):\s*/i, '').trim();
|
||||||
|
const formattedSubject = initialEmail.subject.match(/^(Fwd|FW|Forward):/i)
|
||||||
|
? initialEmail.subject
|
||||||
|
: `Fwd: ${cleanSubject}`;
|
||||||
|
|
||||||
|
setSubject(formattedSubject);
|
||||||
|
|
||||||
|
// Format date for the forwarded message header
|
||||||
|
const formatDate = (date: Date | null): string => {
|
||||||
|
if (!date) return '';
|
||||||
|
|
||||||
|
return date.toLocaleString('en-US', {
|
||||||
|
weekday: 'short',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create the same forwarded message format as Panel 3
|
||||||
|
const formattedContent = `
|
||||||
|
<div>
|
||||||
|
<br>
|
||||||
|
---------- Forwarded message ---------<br>
|
||||||
|
<br>
|
||||||
|
From: ${decoded.from || ''}<br>
|
||||||
|
<br>
|
||||||
|
Date: ${formatDate(decoded.date)}<br>
|
||||||
|
<br>
|
||||||
|
Subject: ${decoded.subject || ''}<br>
|
||||||
|
<br>
|
||||||
|
To: ${decoded.to || ''}<br>
|
||||||
|
<br>
|
||||||
|
${decoded.html || `<pre>${decoded.text || ''}</pre>`}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
setBody(formattedContent);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error initializing forwarded email:', error);
|
||||||
|
setBody('<div>Error loading forwarded content</div>');
|
||||||
|
} finally {
|
||||||
|
setSending(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Handle attachment selection
|
// Handle attachment selection
|
||||||
const handleAttachmentClick = () => {
|
const handleAttachmentClick = () => {
|
||||||
attachmentInputRef.current?.click();
|
attachmentInputRef.current?.click();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user