-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
11 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import jakarta.mail.MessagingException; | ||
import jakarta.mail.Multipart; | ||
import jakarta.mail.Part; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** | ||
* @author Russ Poetker ([email protected]) | ||
|
@@ -31,7 +32,7 @@ private MailUtil() {} | |
|
||
static String getHtmlText(Part part) throws MessagingException, IOException { | ||
if (part.isMimeType("text/html")) { | ||
return part.getContent().toString(); | ||
return cleanseContent(part.getContent().toString()); | ||
} | ||
|
||
if (part.isMimeType("multipart/alternative")) { | ||
|
@@ -40,7 +41,7 @@ static String getHtmlText(Part part) throws MessagingException, IOException { | |
for (int i = 0; i < count; i++) { | ||
Part bodyPart = multipart.getBodyPart(i); | ||
if (bodyPart.isMimeType("text/html")) { | ||
return bodyPart.getContent().toString(); | ||
return cleanseContent(bodyPart.getContent().toString()); | ||
} else if (bodyPart.isMimeType("multipart/*")) { | ||
return getHtmlText(bodyPart); | ||
} | ||
|
@@ -52,11 +53,15 @@ static String getHtmlText(Part part) throws MessagingException, IOException { | |
Part bodyPart = multipart.getBodyPart(i); | ||
String content = getHtmlText(bodyPart); | ||
if (Objects.nonNull(content)) { | ||
return content; | ||
return cleanseContent(content); | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static String cleanseContent(String content) { | ||
return StringUtils.normalizeSpace(content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters