1
- import React , { useEffect , useState } from "react" ;
1
+ import React , { useEffect , useState , useContext } from "react" ;
2
2
import { Grid , Typography , Paper , Box , Chip , Tooltip , IconButton } from "@mui/material" ;
3
3
import { useParams } from "react-router-dom" ;
4
4
import axios from "axios" ;
5
+ import { Letter } from "react-letter" ;
5
6
import ButtonSection from "../ButtonSection" ;
6
7
import InfoIcon from "@mui/icons-material/Info" ;
7
8
import { ThemeContext } from "../../context/ThemeContext" ;
8
- import { useContext } from "react" ;
9
9
import { motion } from "framer-motion" ;
10
- import DOMPurify from "dompurify" ;
11
10
import { env } from "../../env" ;
12
11
13
12
const InboxEmail = ( ) => {
14
- const { emailId } = useParams ( ) ;
15
- const { email_id } = useParams ( ) ;
13
+ const { emailId, email_id } = useParams ( ) ;
16
14
const [ emailData , setEmailData ] = useState ( ) ;
17
15
const [ emailAttachments , setEmailAttachments ] = useState ( [ ] ) ;
18
16
const [ emailHeaders , setEmailHeaders ] = useState ( [ ] ) ;
@@ -131,7 +129,7 @@ const InboxEmail = () => {
131
129
wordBreak : "break-all" ,
132
130
} }
133
131
>
134
- { emailData ? emailData . subject : "No Subject" }
132
+ { emailData ? .subject || "No Subject" }
135
133
</ Typography >
136
134
</ motion . div >
137
135
< motion . div variants = { childVariants } >
@@ -149,30 +147,24 @@ const InboxEmail = () => {
149
147
flexDirection : isMobile ? "column" : "row" ,
150
148
} }
151
149
>
152
- < Typography variant = "subtitle1" > From: { emailData ? emailData . from . text : "No From" } </ Typography >
150
+ < Typography variant = "subtitle1" > From: { emailData ? .from . text || "No From" } </ Typography >
153
151
< Tooltip title = "Click to copy to clipboard" placement = "top" >
154
152
< Chip
155
- label = { `To: ${ emailData ? emailData . to . text : "No To" } ` }
156
- onClick = { ( ) => ( emailData ? navigator . clipboard . writeText ( emailData . to . text ) : null ) }
153
+ label = { `To: ${ emailData ? .to . text || "No To" } ` }
154
+ onClick = { ( ) => emailData ?. to . text && navigator . clipboard . writeText ( emailData . to . text ) }
157
155
/>
158
156
</ Tooltip >
159
157
</ Box >
160
158
</ motion . div >
161
159
< motion . div variants = { childVariants } >
162
160
< Typography variant = "body1" mb = { 2 } >
163
- Date: { emailData ? new Date ( emailData . date ) . toLocaleString ( ) : "No Date" }
161
+ Date: { emailData ?. date ? new Date ( emailData . date ) . toLocaleString ( ) : "No Date" }
164
162
</ Typography >
165
163
</ motion . div >
166
164
< motion . div variants = { childVariants } >
167
- < Typography
168
- variant = "body1"
169
- mb = { 2 }
170
- sx = { {
171
- justifyContent : "center" ,
172
- wordBreak : "break-all" ,
173
- } }
174
- dangerouslySetInnerHTML = { { __html : emailData ? DOMPurify . sanitize ( emailData . html ) : "No Message" } }
175
- />
165
+ < Box sx = { { maxWidth : "100%" , overflowX : "auto" } } >
166
+ < Letter html = { emailData ?. html || "<p>No Message</p>" } text = { emailData ?. text || "No Message" } />
167
+ </ Box >
176
168
</ motion . div >
177
169
< motion . div variants = { childVariants } >
178
170
< Typography variant = "body1" > Attachments: { emailData ? emailAttachments . length : "No Attachments" } </ Typography >
0 commit comments