Skip to content

Commit

Permalink
Revert "Move cleanse to MailUtil"
Browse files Browse the repository at this point in the history
This reverts commit c166198.
  • Loading branch information
rpoet-jh committed Dec 19, 2024
1 parent c166198 commit aacdd12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import jakarta.mail.MessagingException;
import jakarta.mail.Multipart;
import jakarta.mail.Part;
import org.apache.commons.lang3.StringUtils;

/**
* @author Russ Poetker ([email protected])
Expand All @@ -32,7 +31,7 @@ private MailUtil() {}

static String getHtmlText(Part part) throws MessagingException, IOException {
if (part.isMimeType("text/html")) {
return cleanseContent(part.getContent().toString());
return part.getContent().toString();
}

if (part.isMimeType("multipart/alternative")) {
Expand All @@ -41,7 +40,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 cleanseContent(bodyPart.getContent().toString());
return bodyPart.getContent().toString();
} else if (bodyPart.isMimeType("multipart/*")) {
return getHtmlText(bodyPart);
}
Expand All @@ -53,15 +52,11 @@ static String getHtmlText(Part part) throws MessagingException, IOException {
Part bodyPart = multipart.getBodyPart(i);
String content = getHtmlText(bodyPart);
if (Objects.nonNull(content)) {
return cleanseContent(content);
return content;
}
}
}

return null;
}

private static String cleanseContent(String content) {
return StringUtils.normalizeSpace(content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import jakarta.mail.internet.AddressException;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.pass.deposit.provider.nihms.NihmsAssembler;
import org.eclipse.pass.support.client.PassClient;
import org.eclipse.pass.support.client.PassClientSelector;
Expand Down Expand Up @@ -99,14 +100,15 @@ public void handleReceivedMail(MimeMessage receivedMessage) {
}
LOG.warn("Email is from Nihms");
String content = getHtmlText(receivedMessage);
LOG.warn("Nihms Email content: {}", content);
String cleansedContent = StringUtils.normalizeSpace(content);
LOG.warn("Nihms Email content:" + cleansedContent);
if (Objects.isNull(content)) {
LOG.error("No HTML content found in nihms email: " + receivedMessage.getSubject());
return;
}
Elements messageElements = getMessageElements(content);
Elements messageElements = getMessageElements(cleansedContent);
if (messageElements.isEmpty()) {
LOG.error("No messages found in nihms email: {}", content);
LOG.error("No messages found in nihms email: " + cleansedContent);
return;
}
processMessages(messageElements);
Expand Down

0 comments on commit aacdd12

Please sign in to comment.