The Unified and Autonomous Development Platform
Fix issue #967 - Service Desk email loop
Robin Shenfe37b76d99a0
diff --git a/server-core/src/main/java/io/onedev/server/mail/DefaultMailManager.java b/server-core/src/main/java/io/onedev/server/mail/DefaultMailManager.javaindex e1bc80d6a0..d2af9b42f1 100644--- a/server-core/src/main/java/io/onedev/server/mail/DefaultMailManager.java+++ b/server-core/src/main/java/io/onedev/server/mail/DefaultMailManager.java@@ -433,7 +433,7 @@ public class DefaultMailManager implements MailManager {throw new ExplicitException(errorMessage);}checkPermission(from, project, new AccessProject(), user, authorization);- issues.add(openIssue(message, project, from, user, authorization));+ issues.add(openIssue(message, project, from, user, authorization, parsedSystemAddress));} else {throw new ExplicitException("Unable to create issue from email as service desk is not enabled");}@@ -518,7 +518,7 @@ public class DefaultMailManager implements MailManager {if (serviceDeskSetting != null) {checkPermission(from, project, new AccessProject(), user, authorization);logger.debug("Creating issue via email (project: {})...", project.getPath());- issues.add(openIssue(message, project, from, user, authorization));+ issues.add(openIssue(message, project, from, user, authorization, parsedSystemAddress));} else {throw new ExplicitException("Unable to create issue from email as service desk is not enabled");}@@ -691,7 +691,8 @@ public class DefaultMailManager implements MailManager {}private Issue openIssue(Message message, Project project, InternetAddress submitter,- @Nullable User user, @Nullable SenderAuthorization authorization) throws MessagingException, IOException {+ @Nullable User user, @Nullable SenderAuthorization authorization,+ ParsedEmailAddress parsedSystemAddress) throws MessagingException, IOException {Issue issue = new Issue();issue.setProject(project);if (StringUtils.isNotBlank(message.getSubject()))@@ -725,14 +726,19 @@ public class DefaultMailManager implements MailManager {issueManager.open(issue);- String htmlBody = String.format("Issue <a href='%s'>%s</a> is created. You may reply this email to add more comments",- urlManager.urlFor(issue), issue.getFQN());- String textBody = String.format("Issue %s is created. You may reply this email to add more comments",- issue.getFQN());-- sendMailAsync(Lists.newArrayList(submitter.getAddress()), Lists.newArrayList(), Lists.newArrayList(),- "Re: " + issue.getTitle(), htmlBody, textBody, getReplyAddress(issue),- issue.getEffectiveThreadingReference());+ ParsedEmailAddress parsedSubmitterAddress = ParsedEmailAddress.parse(submitter.getAddress());+ if (!parsedSubmitterAddress.getDomain().equalsIgnoreCase(parsedSystemAddress.getDomain())+ || !parsedSubmitterAddress.getName().toLowerCase().startsWith(parsedSystemAddress.getName().toLowerCase() + "+")+ && !parsedSubmitterAddress.getName().equalsIgnoreCase(parsedSystemAddress.getName())) {+ String htmlBody = String.format("Issue <a href='%s'>%s</a> is created. You may reply this email to add more comments",+ urlManager.urlFor(issue), issue.getFQN());+ String textBody = String.format("Issue %s is created. You may reply this email to add more comments",+ issue.getFQN());++ sendMailAsync(Lists.newArrayList(submitter.getAddress()), Lists.newArrayList(), Lists.newArrayList(),+ "Re: " + issue.getTitle(), htmlBody, textBody, getReplyAddress(issue),+ issue.getEffectiveThreadingReference());+ }return issue;}