Skip to content

Commit

Permalink
Fix not working mail receiver (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
boavenn authored Nov 20, 2024
1 parent b0930fe commit d1ee31e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -133,7 +133,9 @@ private void keepInboxIdle() {

@Override
public void run() {
if (isEnabled){
if (!host.isBlank()){
log.info("Initializing MailReceiver");

// Configuring the inbox
performConfiguration();

Expand All @@ -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");
}
}

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit d1ee31e

Please sign in to comment.