From aacdd1203b721ae30b6ff84afc666c66262800e5 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Thu, 19 Dec 2024 08:22:11 -0500 Subject: [PATCH 1/2] Revert "Move cleanse to MailUtil" This reverts commit c166198d2a4cf9369ad7203c10e85a3edfa5ba05. --- .../org/eclipse/pass/deposit/service/MailUtil.java | 11 +++-------- .../pass/deposit/service/NihmsReceiveMailService.java | 8 +++++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/MailUtil.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/MailUtil.java index dc5641f3..30df01fc 100644 --- a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/MailUtil.java +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/MailUtil.java @@ -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 (rpoetke1@jh.edu) @@ -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")) { @@ -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); } @@ -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); - } } diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/NihmsReceiveMailService.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/NihmsReceiveMailService.java index 32e9ac65..0aeef643 100644 --- a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/NihmsReceiveMailService.java +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/NihmsReceiveMailService.java @@ -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; @@ -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); From 63d80d11ea165bc1fa2f6cc444061fbf5e0c50c4 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Thu, 19 Dec 2024 08:54:53 -0500 Subject: [PATCH 2/2] Use String.replaceAll --- .../deposit/service/NihmsReceiveMailService.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/NihmsReceiveMailService.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/NihmsReceiveMailService.java index 0aeef643..c0c644e1 100644 --- a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/NihmsReceiveMailService.java +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/NihmsReceiveMailService.java @@ -31,7 +31,6 @@ 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; @@ -94,21 +93,21 @@ public NihmsReceiveMailService(PassClient passClient, public void handleReceivedMail(MimeMessage receivedMessage) { try { - LOG.warn("Email received: " + receivedMessage.getSubject()); + LOG.warn("Email received: {}", receivedMessage.getSubject()); if (isEmailNotNihms(receivedMessage)) { return; } LOG.warn("Email is from Nihms"); String content = getHtmlText(receivedMessage); - 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()); + LOG.error("No HTML content found in nihms email: {}", receivedMessage.getSubject()); return; } - Elements messageElements = getMessageElements(cleansedContent); + String loggingContent = content.replaceAll("[\n\r]", " "); + LOG.warn("Nihms Email content: {}", loggingContent); + Elements messageElements = getMessageElements(content); if (messageElements.isEmpty()) { - LOG.error("No messages found in nihms email: " + cleansedContent); + LOG.error("No messages found in nihms email: {}", loggingContent); return; } processMessages(messageElements);