Skip to content

The Unified and Autonomous Development Platform

More robust logic to remove quoted content when creating comment from mail message

Robin Shen74ee5b0eaec4
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.java
index 72db572e1e..dec067cafe 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
@@ -583,20 +583,43 @@ public class DefaultMailManager implements MailManager {
@Nullable
private String stripQuotation(MailSendSetting sendSetting, String content) {
- String quotedSender = sendSetting.getSenderAddress();
- Pattern pattern = Pattern.compile("(^|\\W)" + quotedSender.replace(".", "\\.") + "($|\\W)");
+ String senderAddress = sendSetting.getSenderAddress();
+ Pattern senderAddressPattern = Pattern.compile(
+ "(^|\\W)" + senderAddress.replace(".", "\\.") + "($|\\W)",
+ Pattern.CASE_INSENSITIVE);
+
+ String smtpUser = sendSetting.getSmtpUser();
+
+ Pattern smtpUserPattern;
+ if (smtpUser != null && smtpUser.contains("@") && !smtpUser.equalsIgnoreCase(senderAddress)) {
+ smtpUserPattern = Pattern.compile(
+ "(^|\\W)" + smtpUser.replace(".", "\\.") + "($|\\W)",
+ Pattern.CASE_INSENSITIVE);
+ } else {
+ smtpUserPattern = null;
+ }
Document document = HtmlUtils.parse(content);
document.select(".gmail_quote").remove();
document.outputSettings().prettyPrint(false);
Element quotedSenderElement = null;
- for (Element element: document.getElementsContainingOwnText(quotedSender)) {
- if (pattern.matcher(element.text()).find()) {
+ for (Element element: document.getElementsContainingOwnText(senderAddress)) {
+ if (senderAddressPattern.matcher(element.text()).find()) {
quotedSenderElement = element;
break;
}
}
+
+ if (quotedSenderElement == null && smtpUserPattern != null) {
+ for (Element element: document.getElementsContainingOwnText(smtpUser)) {
+ if (smtpUserPattern.matcher(element.text()).find()) {
+ quotedSenderElement = element;
+ break;
+ }
+ }
+ }
+
if (quotedSenderElement != null) {
Element quotedSenderBlockElement = quotedSenderElement.parent();
while (quotedSenderBlockElement != null
diff --git a/server-core/src/main/java/io/onedev/server/model/support/administration/mailsetting/Office365Setting.java b/server-core/src/main/java/io/onedev/server/model/support/administration/mailsetting/Office365Setting.java
index e2bc160a07..a2da1503e4 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/administration/mailsetting/Office365Setting.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/administration/mailsetting/Office365Setting.java
@@ -96,8 +96,8 @@ public class Office365Setting extends MailSetting {
}
@Editable(order=410, description="Primary or alias email address of above account to be used as sender address "
- + "of various notifications. Emails targeting this address will also be checked in inbox of above user "
- + "if <code>Check Incoming Email</code> option is enabled below")
+ + "of various notifications. Emails targeting this address will also be checked to post various "
+ + "comments if <code>Check Incoming Email</code> option is enabled below")
@NotEmpty
public String getEmailAddress() {
return emailAddress;