fix cc and bcc
This commit is contained in:
@@ -8,7 +8,7 @@ import { useNavigate } from 'react-router-dom';
|
||||
import { useGetFavoriteMessages } from './hooks/useFavoriteData';
|
||||
import { FavoriteMessage } from './types/FavoriteTypes';
|
||||
import { useEmailActions } from '@/hooks/useEmailActions';
|
||||
import Favorite from '../received/Components/Favorite';
|
||||
import Favorite from '../received/components/Favorite';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import React from 'react';
|
||||
import { getIconColor } from '@/utils/colorUtils';
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { FC } from 'react'
|
||||
import { MessageDetail } from '../types/Types'
|
||||
import { MailboxEnum } from '../enum/Enum'
|
||||
|
||||
interface BccRecipientsProps {
|
||||
messageDetail: MessageDetail
|
||||
userEmail: string | null
|
||||
mailboxName: MailboxEnum
|
||||
}
|
||||
|
||||
const BccRecipients: FC<BccRecipientsProps> = ({ messageDetail, userEmail, mailboxName }) => {
|
||||
// If userEmail is not available, we can't determine BCC status
|
||||
if (!userEmail || userEmail.trim() === '') {
|
||||
return null
|
||||
}
|
||||
|
||||
// Check if current user was BCC recipient (for received messages)
|
||||
const isInTo = messageDetail.to?.some(recipient =>
|
||||
recipient.address.toLowerCase().trim() === userEmail.toLowerCase().trim()
|
||||
) || false
|
||||
const isInCc = messageDetail.cc?.some(recipient =>
|
||||
recipient.address.toLowerCase().trim() === userEmail.toLowerCase().trim()
|
||||
) || false
|
||||
|
||||
// Check if user is explicitly in BCC field OR implicitly (not in to/cc but received)
|
||||
const isExplicitlyInBcc = messageDetail.bcc?.some(recipient =>
|
||||
recipient.address.toLowerCase().trim() === userEmail.toLowerCase().trim()
|
||||
) || false
|
||||
const isInBcc = isExplicitlyInBcc || (!isInTo && !isInCc && mailboxName !== MailboxEnum.SENT)
|
||||
|
||||
console.log('BCC Debug:', {
|
||||
userEmail,
|
||||
to: messageDetail.to?.map(r => r.address),
|
||||
cc: messageDetail.cc?.map(r => r.address),
|
||||
bcc: messageDetail.bcc?.map(r => r.address),
|
||||
isInTo,
|
||||
isInCc,
|
||||
isExplicitlyInBcc,
|
||||
isInBcc,
|
||||
mailboxName
|
||||
});
|
||||
|
||||
|
||||
// Show BCC notice for received messages
|
||||
if (isInBcc) {
|
||||
return (
|
||||
<div className='mt-4 mr-14'>
|
||||
<div className='bg-accent border border-border rounded-lg px-4 py-2 text-xs text-muted-foreground'>
|
||||
شما به عنوان رونوشت مخفی (BCC) این پیام را دریافت کردهاید
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Show BCC recipients for sent messages
|
||||
if (mailboxName === MailboxEnum.SENT && messageDetail.envelope?.rcpt) {
|
||||
const toAddresses = messageDetail.to?.map(r => r.address.toLowerCase()) || []
|
||||
const ccAddresses = messageDetail.cc?.map(r => r.address.toLowerCase()) || []
|
||||
|
||||
const bccRecipients = messageDetail.envelope.rcpt.filter(rcpt => {
|
||||
const address = rcpt.value.toLowerCase()
|
||||
return !toAddresses.includes(address) && !ccAddresses.includes(address)
|
||||
})
|
||||
|
||||
if (bccRecipients.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='mt-4 mr-14'>
|
||||
<div className='text-xs text-description mb-2'>رونوشت مخفی (BCC):</div>
|
||||
<div className='flex flex-wrap gap-2'>
|
||||
{bccRecipients.map((recipient, index) => (
|
||||
<div key={index} className='bg-secondary rounded-full px-3 py-1 text-xs'>
|
||||
{recipient.formatted || recipient.value}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export default BccRecipients
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { FC } from 'react'
|
||||
import { EmailRecipient } from '../types/Types'
|
||||
|
||||
interface CcRecipientsProps {
|
||||
recipients: EmailRecipient[]
|
||||
}
|
||||
|
||||
const CcRecipients: FC<CcRecipientsProps> = ({ recipients }) => {
|
||||
if (!recipients || recipients.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='mt-4 mr-14'>
|
||||
<div className='text-xs text-description mb-2'>رونوشت (CC):</div>
|
||||
<div className='flex flex-wrap gap-2'>
|
||||
{recipients.map((recipient, index) => (
|
||||
<div key={index} className='bg-secondary rounded-full px-3 py-1 text-xs'>
|
||||
{recipient.name || recipient.address} {recipient.name && `<${recipient.address}>`}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default CcRecipients
|
||||
|
||||
@@ -4,25 +4,28 @@ import { useTranslation } from 'react-i18next'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import AvatarImage from '@/assets/images/avatar.svg'
|
||||
import { DocumentDownload } from 'iconsax-react'
|
||||
import Header from './Components/Header'
|
||||
import Header from './components/Header'
|
||||
import { useGetMessageDetail, useDownloadAttachment, useSendEmail } from './hooks/useEmailData'
|
||||
import { toast } from '@/components/Toast'
|
||||
import { formatDate, sanitizeEmailHTML, detectTextDirection } from '@/config/func'
|
||||
import SkeletonDetail from './Components/SkeletonDetail'
|
||||
import SkeletonDetail from './components/SkeletonDetail'
|
||||
import { useEmailActions } from '@/hooks/useEmailActions'
|
||||
import { MailboxEnum } from './enum/Enum'
|
||||
import Reply from '@/components/newMessage/Reply'
|
||||
import Forward from '@/components/newMessage/Forward'
|
||||
import EmojiReaction from '@/components/EmojiReaction'
|
||||
import { useAuthStore } from '@/pages/auth/store/AuthStore'
|
||||
import { SendEmailDto } from './types/Types'
|
||||
import { getIconColor } from '@/utils/colorUtils'
|
||||
import CcRecipients from './components/CcRecipients'
|
||||
import BccRecipients from './components/BccRecipients'
|
||||
import { useGetProfile } from '@/pages/profile/hooks/useProfileData'
|
||||
|
||||
const DetailEmail: FC = () => {
|
||||
|
||||
const { t } = useTranslation()
|
||||
const emailActions = useEmailActions()
|
||||
const { email: userEmail } = useAuthStore()
|
||||
const { data: profileData } = useGetProfile()
|
||||
const userEmail = profileData?.data?.user?.emailAddress || ''
|
||||
const { id, mailbox } = useParams<{ id: string, mailbox: string }>()
|
||||
const [activeAction, setActiveAction] = useState<'reply' | 'forward' | null>(null)
|
||||
|
||||
@@ -191,33 +194,13 @@ const DetailEmail: FC = () => {
|
||||
}
|
||||
</div>
|
||||
|
||||
{/* CC Recipients */}
|
||||
{messageDetail.cc && messageDetail.cc.length > 0 && (
|
||||
<div className='mt-4 mr-14'>
|
||||
<div className='text-xs text-description mb-2'>رونوشت (CC):</div>
|
||||
<div className='flex flex-wrap gap-2'>
|
||||
{messageDetail.cc.map((recipient, index) => (
|
||||
<div key={index} className='bg-secondary rounded-full px-3 py-1 text-xs'>
|
||||
{recipient.name || recipient.address} {recipient.name && `<${recipient.address}>`}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<CcRecipients recipients={messageDetail.cc || []} />
|
||||
|
||||
{/* BCC Recipients */}
|
||||
{messageDetail.bcc && messageDetail.bcc.length > 0 && (
|
||||
<div className='mt-4 mr-14'>
|
||||
<div className='text-xs text-description mb-2'>رونوشت مخفی (BCC):</div>
|
||||
<div className='flex flex-wrap gap-2'>
|
||||
{messageDetail.bcc.map((recipient, index) => (
|
||||
<div key={index} className='bg-secondary rounded-full px-3 py-1 text-xs'>
|
||||
{recipient.name || recipient.address} {recipient.name && `<${recipient.address}>`}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<BccRecipients
|
||||
messageDetail={messageDetail}
|
||||
userEmail={userEmail}
|
||||
mailboxName={messageDetail.mailboxName as MailboxEnum}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='xl:mt-8 mt-3 text-[13px] leading-7 font-light'>
|
||||
|
||||
@@ -11,10 +11,10 @@ import { InboxMessage } from './types/Types';
|
||||
|
||||
import MarkAsRead from '@/assets/images/mark_as_read.svg'
|
||||
import { useEmailActions } from '@/hooks/useEmailActions';
|
||||
import Favorite from './Components/Favorite';
|
||||
import Summerize from './Components/Summerize';
|
||||
import Favorite from './components/Favorite';
|
||||
import Summerize from './components/Summerize';
|
||||
import Intelligense from '@/assets/images/intelligense.svg'
|
||||
import SummarizeModal from './Components/SummarizeModal';
|
||||
import SummarizeModal from './components/SummarizeModal';
|
||||
import ModalConfrim from '@/components/ModalConfrim';
|
||||
import { ErrorType } from '@/helpers/types';
|
||||
import { toast } from '@/components/Toast';
|
||||
|
||||
@@ -198,6 +198,14 @@ export interface MessageDetailResponse {
|
||||
address: string;
|
||||
name: string;
|
||||
}>;
|
||||
cc?: Array<{
|
||||
address: string;
|
||||
name: string;
|
||||
}>;
|
||||
bcc?: Array<{
|
||||
address: string;
|
||||
name: string;
|
||||
}>;
|
||||
subject: string;
|
||||
messageId: string;
|
||||
date: string;
|
||||
@@ -214,7 +222,7 @@ export interface MessageDetailResponse {
|
||||
attachments: EmailAttachmentDto[];
|
||||
references: string[];
|
||||
metaData: Record<string, unknown>;
|
||||
verificationResults: {
|
||||
verificationResults?: {
|
||||
tls: {
|
||||
name: string;
|
||||
standardName: string;
|
||||
@@ -282,7 +290,7 @@ export interface MessageDetail {
|
||||
attachments: EmailAttachmentDto[];
|
||||
references: string[];
|
||||
metaData: Record<string, unknown>;
|
||||
verificationResults: {
|
||||
verificationResults?: {
|
||||
tls: {
|
||||
name: string;
|
||||
standardName: string;
|
||||
|
||||
Reference in New Issue
Block a user