Make use of HTML in outgoing emails optional

This will make it possible for gerrit-review.googlesource.com to turn
HTML off in the emails it sends until bugs in its EmailSender are
ironed out.

Bug: Issue 4589
Change-Id: Iadcfb5a38ac14044e0163a3f2db0c326ccda1f73
This commit is contained in:
Jonathan Nieder
2016-09-20 14:10:11 -07:00
parent 39727e98ab
commit dabd8c24db
11 changed files with 47 additions and 17 deletions

View File

@@ -3327,6 +3327,14 @@ and all other properties of section sendemail are ignored.
+
By default, true, allowing notifications to be sent.
[[sendemail.html]]sendemail.html::
+
If false, Gerrit will only send plain-text emails.
If true, Gerrit will send multi-part emails with an HTML and
plain text part.
+
By default, true, allowing HTML in the emails Gerrit sends.
[[sendemail.connectTimeout]]sendemail.connectTimeout::
+
The connection timeout of opening a socket connected to a

View File

@@ -51,11 +51,13 @@ public class AbandonedSender extends ReplyToChangeSender {
@Override
protected void formatChange() throws EmailException {
appendText(textTemplate("Abandoned"));
appendHtml(soyHtmlTemplate("AbandonedHtml"));
if (useHtml()) {
appendHtml(soyHtmlTemplate("AbandonedHtml"));
}
}
@Override
protected boolean useHtml() {
protected boolean supportsHtml() {
return true;
}
}

View File

@@ -81,7 +81,9 @@ public class AddKeySender extends OutgoingEmail {
@Override
protected void format() throws EmailException {
appendText(textTemplate("AddKey"));
appendHtml(soyHtmlTemplate("AddKeyHtml"));
if (useHtml()) {
appendHtml(soyHtmlTemplate("AddKeyHtml"));
}
}
public String getEmail() {
@@ -123,7 +125,7 @@ public class AddKeySender extends OutgoingEmail {
}
@Override
protected boolean useHtml() {
protected boolean supportsHtml() {
return true;
}
}

View File

@@ -66,7 +66,9 @@ public class DeleteReviewerSender extends ReplyToChangeSender {
@Override
protected void formatChange() throws EmailException {
appendText(textTemplate("DeleteReviewer"));
appendHtml(soyHtmlTemplate("DeleteReviewerHtml"));
if (useHtml()) {
appendHtml(soyHtmlTemplate("DeleteReviewerHtml"));
}
}
public List<String> getReviewerNames() {
@@ -87,7 +89,7 @@ public class DeleteReviewerSender extends ReplyToChangeSender {
}
@Override
protected boolean useHtml() {
protected boolean supportsHtml() {
return true;
}
}

View File

@@ -50,11 +50,13 @@ public class DeleteVoteSender extends ReplyToChangeSender {
@Override
protected void formatChange() throws EmailException {
appendText(textTemplate("DeleteVote"));
appendHtml(soyHtmlTemplate("DeleteVoteHtml"));
if (useHtml()) {
appendHtml(soyHtmlTemplate("DeleteVoteHtml"));
}
}
@Override
protected boolean useHtml() {
protected boolean supportsHtml() {
return true;
}
}

View File

@@ -22,11 +22,13 @@ import org.eclipse.jgit.lib.Config;
@Singleton
public class EmailSettings {
public final boolean html;
public final boolean includeDiff;
public final int maximumDiffSize;
@Inject
EmailSettings(@GerritServerConfig Config cfg) {
html = cfg.getBoolean("sendemail", "html", true);
includeDiff = cfg.getBoolean("sendemail", "includeDiff", false);
maximumDiffSize = cfg.getInt("sendemail", "maximumDiffSize", 256 << 10);
}

View File

@@ -68,7 +68,9 @@ public abstract class NewChangeSender extends ChangeEmail {
@Override
protected void formatChange() throws EmailException {
appendText(textTemplate("NewChange"));
appendHtml(soyHtmlTemplate("NewChangeHtml"));
if (useHtml()) {
appendHtml(soyHtmlTemplate("NewChangeHtml"));
}
}
public List<String> getReviewerNames() {
@@ -89,7 +91,7 @@ public abstract class NewChangeSender extends ChangeEmail {
}
@Override
protected boolean useHtml() {
protected boolean supportsHtml() {
return true;
}
}

View File

@@ -631,8 +631,12 @@ public abstract class OutgoingEmail {
return obj != null ? obj.toString() : "";
}
protected final boolean useHtml() {
return args.settings.html && supportsHtml();
}
/** Override this method to enable HTML in a subclass. */
protected boolean useHtml() {
protected boolean supportsHtml() {
return false;
}
}

View File

@@ -73,7 +73,9 @@ public class ReplacePatchSetSender extends ReplyToChangeSender {
@Override
protected void formatChange() throws EmailException {
appendText(textTemplate("ReplacePatchSet"));
appendHtml(soyHtmlTemplate("ReplacePatchSetHtml"));
if (useHtml()) {
appendHtml(soyHtmlTemplate("ReplacePatchSetHtml"));
}
}
public List<String> getReviewerNames() {
@@ -97,7 +99,7 @@ public class ReplacePatchSetSender extends ReplyToChangeSender {
}
@Override
protected boolean useHtml() {
protected boolean supportsHtml() {
return true;
}
}

View File

@@ -50,11 +50,13 @@ public class RestoredSender extends ReplyToChangeSender {
@Override
protected void formatChange() throws EmailException {
appendText(textTemplate("Restored"));
appendHtml(soyHtmlTemplate("RestoredHtml"));
if (useHtml()) {
appendHtml(soyHtmlTemplate("RestoredHtml"));
}
}
@Override
protected boolean useHtml() {
protected boolean supportsHtml() {
return true;
}
}

View File

@@ -48,11 +48,13 @@ public class RevertedSender extends ReplyToChangeSender {
@Override
protected void formatChange() throws EmailException {
appendText(textTemplate("Reverted"));
appendHtml(soyHtmlTemplate("RevertedHtml"));
if (useHtml()) {
appendHtml(soyHtmlTemplate("RevertedHtml"));
}
}
@Override
protected boolean useHtml() {
protected boolean supportsHtml() {
return true;
}
}