diff --git a/readme.md b/readme.md index fd9edd1..9bb4aa4 100644 --- a/readme.md +++ b/readme.md @@ -160,7 +160,6 @@ mails.bot= (Mail address of mailing bot) mails.storage= (Mail address of emails storage) mail.title.prefix = (Prefix for mail title - can be empty) mail.sender.enabled= (Boolean flag to set sending mail) -mail.receiver.enabled= (Boolean flag to set observing incoming mail) # slack slack.bot-token= slack.signing-secret= diff --git a/src/main/java/info/fingo/urlopia/config/mail/receive/MailDecider.java b/src/main/java/info/fingo/urlopia/config/mail/receive/MailDecider.java index 7263e98..5e562a7 100644 --- a/src/main/java/info/fingo/urlopia/config/mail/receive/MailDecider.java +++ b/src/main/java/info/fingo/urlopia/config/mail/receive/MailDecider.java @@ -86,8 +86,7 @@ private void parse(Mail mail){ private void updateAcceptance(Long deciderId) { var acceptanceId = mailParser.getId(); var decision = mailParser.getReply().toLowerCase(); - var loggerInfo = "Decision for acceptance with id: %d is: %s" - .formatted(acceptanceId, decision); + var loggerInfo = "Decision for acceptance with id: %d is: %s".formatted(acceptanceId, decision); log.info(loggerInfo); if (mailParser.isAcceptedByMail(decision)) { acceptanceService.accept(acceptanceId, deciderId); diff --git a/src/main/java/info/fingo/urlopia/config/mail/receive/MailParser.java b/src/main/java/info/fingo/urlopia/config/mail/receive/MailParser.java index dae5724..2b26172 100644 --- a/src/main/java/info/fingo/urlopia/config/mail/receive/MailParser.java +++ b/src/main/java/info/fingo/urlopia/config/mail/receive/MailParser.java @@ -81,7 +81,11 @@ public void parseSubject(Mail mail) { public void parseReply(Mail mail) { var emailLines = splitByLines(mail.getContent()); - reply = emailLines[0]; + reply = Arrays.stream(emailLines) + .map(String::trim) + .filter(line -> !line.isBlank() && !line.startsWith(">")) // Remove empty lines and quotes + .reduce((first, second) -> second) // Get last line + .orElse(""); } private void convertDate() { diff --git a/src/main/java/info/fingo/urlopia/config/mail/receive/MailReceiver.java b/src/main/java/info/fingo/urlopia/config/mail/receive/MailReceiver.java index 5763104..801ffba 100644 --- a/src/main/java/info/fingo/urlopia/config/mail/receive/MailReceiver.java +++ b/src/main/java/info/fingo/urlopia/config/mail/receive/MailReceiver.java @@ -9,7 +9,10 @@ import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; -import javax.mail.*; +import javax.mail.Folder; +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.Store; import javax.mail.event.MessageCountEvent; import javax.mail.event.MessageCountListener; import java.util.Properties; @@ -40,9 +43,6 @@ public class MailReceiver extends Thread { @Value("${mail.receiver.idle.time}") private int keepAliveFreq; //time unit: milliseconds - @Value("${mail.receiver.enabled}") - private boolean isEnabled; - private Store store; private IMAPFolder inbox; @@ -133,7 +133,9 @@ private void keepInboxIdle() { @Override public void run() { - if (isEnabled){ + if (!host.isBlank()){ + log.info("Initializing MailReceiver"); + // Configuring the inbox performConfiguration(); @@ -159,6 +161,8 @@ public void run() { } catch (MessagingException e) { log.error("MessagingException during closing the store", e); } + } else { + log.warn("MailReceiver has been disabled"); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 214a59c..9c78bde 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -45,7 +45,6 @@ mail.receiver.idle.time=300000 mails.bot= mails.storage= mail.sender.enabled=false -mail.receiver.enabled=false # slack slack.bot-token= slack.signing-secret=