Skip to content

Commit d8d80f5

Browse files
committed
Integrate react-letter for improved email rendering
- Replace dangerouslySetInnerHTML with Letter component - Remove DOMPurify as react-letter handles sanitization
1 parent e9057e7 commit d8d80f5

File tree

3 files changed

+95
-263
lines changed

3 files changed

+95
-263
lines changed

react/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
"@emotion/styled": "^11.11.0",
88
"@mui/icons-material": "^5.11.16",
99
"@mui/material": "^5.13.6",
10-
"@testing-library/jest-dom": "^5.14.1",
11-
"@testing-library/react": "^13.0.0",
12-
"@testing-library/user-event": "^13.2.1",
10+
"@testing-library/jest-dom": "^6.4.6",
11+
"@testing-library/react": "^16.0.0",
12+
"@testing-library/user-event": "^14.5.2",
1313
"axios": "^1.4.0",
1414
"dompurify": "^3.0.5",
15-
"framer-motion": "^10.16.1",
15+
"framer-motion": "^11.2.12",
1616
"react": "^18.2.0",
1717
"react-dom": "^18.2.0",
18+
"react-letter": "^0.4.0",
1819
"react-router-dom": "^6.14.0",
19-
"react-scripts": "5.0.1",
20-
"web-vitals": "^2.1.0"
20+
"react-scripts": "^5.0.1",
21+
"web-vitals": "^4.2.0"
2122
},
2223
"scripts": {
2324
"start": "react-scripts start",

react/src/components/InboxEmail/index.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useEffect, useState, useContext } from "react";
22
import { Grid, Typography, Paper, Box, Chip, Tooltip, IconButton } from "@mui/material";
33
import { useParams } from "react-router-dom";
44
import axios from "axios";
5+
import { Letter } from "react-letter";
56
import ButtonSection from "../ButtonSection";
67
import InfoIcon from "@mui/icons-material/Info";
78
import { ThemeContext } from "../../context/ThemeContext";
8-
import { useContext } from "react";
99
import { motion } from "framer-motion";
10-
import DOMPurify from "dompurify";
1110
import { env } from "../../env";
1211

1312
const InboxEmail = () => {
14-
const { emailId } = useParams();
15-
const { email_id } = useParams();
13+
const { emailId, email_id } = useParams();
1614
const [emailData, setEmailData] = useState();
1715
const [emailAttachments, setEmailAttachments] = useState([]);
1816
const [emailHeaders, setEmailHeaders] = useState([]);
@@ -131,7 +129,7 @@ const InboxEmail = () => {
131129
wordBreak: "break-all",
132130
}}
133131
>
134-
{emailData ? emailData.subject : "No Subject"}
132+
{emailData?.subject || "No Subject"}
135133
</Typography>
136134
</motion.div>
137135
<motion.div variants={childVariants}>
@@ -149,30 +147,24 @@ const InboxEmail = () => {
149147
flexDirection: isMobile ? "column" : "row",
150148
}}
151149
>
152-
<Typography variant="subtitle1">From: {emailData ? emailData.from.text : "No From"}</Typography>
150+
<Typography variant="subtitle1">From: {emailData?.from.text || "No From"}</Typography>
153151
<Tooltip title="Click to copy to clipboard" placement="top">
154152
<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)}
157155
/>
158156
</Tooltip>
159157
</Box>
160158
</motion.div>
161159
<motion.div variants={childVariants}>
162160
<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"}
164162
</Typography>
165163
</motion.div>
166164
<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>
176168
</motion.div>
177169
<motion.div variants={childVariants}>
178170
<Typography variant="body1">Attachments: {emailData ? emailAttachments.length : "No Attachments"}</Typography>

0 commit comments

Comments
 (0)