Merge "Clean up disrespectful terms"

This commit is contained in:
Gal Paikin
2020-09-23 13:50:14 +00:00
committed by Gerrit Code Review
4 changed files with 57 additions and 25 deletions

View File

@@ -4423,19 +4423,25 @@ Defaults to false.
[[receiveemail.filter.mode]]receiveemail.filter.mode:: [[receiveemail.filter.mode]]receiveemail.filter.mode::
+ +
A black- and whitelist filter to filter incoming emails. An allow and block filter to filter incoming emails.
+ +
If `OFF`, emails are not filtered by the list filter. If `OFF`, emails are not filtered by the list filter.
+ +
If `WHITELIST`, only emails where a pattern from If `ALLOW`, only emails where a pattern from
<<receiveemail.filter.patterns,receiveemail.filter.patterns>> <<receiveemail.filter.patterns,receiveemail.filter.patterns>>
matches 'From' will be processed. matches 'From' will be processed.
+ +
If `BLACKLIST`, only emails where no pattern from If `BLOCK`, only emails where no pattern from
<<receiveemail.filter.patterns,receiveemail.filter.patterns>> <<receiveemail.filter.patterns,receiveemail.filter.patterns>>
matches 'From' will be processed. matches 'From' will be processed.
+ +
Defaults to `OFF`. Defaults to `OFF`.
+
The previous filter-names 'BLACKLIST' and 'WHITELIST' have been deprecated
since they may be considered disrespectful and there's no technical or
practical reason to use these exact terms for the filters.
For backwards compatibility they are still supported but support for these
deprecated terms will be removed in future releases.
[[receiveemail.filter.patterns]]receiveemail.filter.patterns:: [[receiveemail.filter.patterns]]receiveemail.filter.patterns::
+ +
@@ -4566,9 +4572,10 @@ Password for the account named by sendemail.smtpUser.
[[sendemail.allowrcpt]]sendemail.allowrcpt:: [[sendemail.allowrcpt]]sendemail.allowrcpt::
+ +
If present, each value adds one entry to the whitelist of email If present, each value adds one entry to the list of allowed email
addresses that Gerrit can send email to. If set to a complete addresses that Gerrit can send emails to. If set to a complete
email address, that one address is added to the white list. email address, that one address is added to the list of allowed
emails.
If set to a domain name, any address at that domain can receive If set to a domain name, any address at that domain can receive
email from Gerrit. email from Gerrit.
+ +
@@ -4579,9 +4586,10 @@ By default, unset, permitting delivery to any email address.
[[sendemail.denyrcpt]]sendemail.denyrcpt:: [[sendemail.denyrcpt]]sendemail.denyrcpt::
+ +
If present, each value adds one entry to the blacklist of email If present, each value adds one entry to the list of email
addresses that Gerrit can send email to. If set to a complete addresses that Gerrit can't send emails to. If set to a complete
email address, that one address is added to the blacklist. email address, that one address is added to the list of blocked
emails.
If set to a domain name, any address at that domain can *not* receive If set to a domain name, any address at that domain can *not* receive
email from Gerrit. email from Gerrit.
+ +

View File

@@ -35,7 +35,7 @@ public class HtmlParser {
"gmail_quote" // Used for quoting original content "gmail_quote" // Used for quoting original content
); );
private static final ImmutableSet<String> WHITELISTED_HTML_TAGS = private static final ImmutableSet<String> ALLOWED_HTML_TAGS =
ImmutableSet.of( ImmutableSet.of(
"div", // Most user-typed comments are contained in a <div> tag "div", // Most user-typed comments are contained in a <div> tag
"a", // We allow links to be contained in a comment "a", // We allow links to be contained in a comment
@@ -120,8 +120,8 @@ public class HtmlParser {
// There is no user-input in quoted text // There is no user-input in quoted text
continue; continue;
} }
if (!WHITELISTED_HTML_TAGS.contains(elementName)) { if (!ALLOWED_HTML_TAGS.contains(elementName)) {
// We only accept a set of whitelisted tags that can contain user input // We only accept a set of allowed tags that can contain user input
continue; continue;
} }
if (elementName.equals("a") && e.attr("href").startsWith("mailto:")) { if (elementName.equals("a") && e.attr("href").startsWith("mailto:")) {

View File

@@ -31,8 +31,8 @@ public class ListMailFilter implements MailFilter {
public enum ListFilterMode { public enum ListFilterMode {
OFF, OFF,
WHITELIST, ALLOW,
BLACKLIST BLOCK
} }
private final ListFilterMode mode; private final ListFilterMode mode;
@@ -40,12 +40,37 @@ public class ListMailFilter implements MailFilter {
@Inject @Inject
ListMailFilter(@GerritServerConfig Config cfg) { ListMailFilter(@GerritServerConfig Config cfg) {
this.mode = cfg.getEnum("receiveemail", "filter", "mode", ListFilterMode.OFF); mode = getListFilterMode(cfg);
String[] addresses = cfg.getStringList("receiveemail", "filter", "patterns"); String[] addresses = cfg.getStringList("receiveemail", "filter", "patterns");
String concat = Arrays.asList(addresses).stream().collect(joining("|")); String concat = Arrays.asList(addresses).stream().collect(joining("|"));
this.mailPattern = Pattern.compile(concat); this.mailPattern = Pattern.compile(concat);
} }
private static final String LEGACY_ALLOW = "WHITELIST";
private static final String LEGACY_BLOCK = "BLACKLIST";
/** Legacy names are supported, but should be removed in the future. */
private ListFilterMode getListFilterMode(Config cfg) {
ListFilterMode mode;
String modeString = cfg.getString("receiveemail", "filter", "mode");
if (modeString == null) {
modeString = "";
}
switch (modeString) {
case LEGACY_ALLOW:
case "ALLOW":
mode = ListFilterMode.ALLOW;
break;
case LEGACY_BLOCK:
case "BLOCK":
mode = ListFilterMode.BLOCK;
break;
default:
mode = ListFilterMode.OFF;
}
return mode;
}
@Override @Override
public boolean shouldProcessMessage(MailMessage message) { public boolean shouldProcessMessage(MailMessage message) {
if (mode == ListFilterMode.OFF) { if (mode == ListFilterMode.OFF) {
@@ -53,8 +78,7 @@ public class ListMailFilter implements MailFilter {
} }
boolean match = mailPattern.matcher(message.from().email()).find(); boolean match = mailPattern.matcher(message.from().email()).find();
if ((mode == ListFilterMode.WHITELIST && !match) if ((mode == ListFilterMode.ALLOW && !match) || (mode == ListFilterMode.BLOCK && match)) {
|| (mode == ListFilterMode.BLACKLIST && match)) {
logger.atInfo().log("Mail message from %s rejected by list filter", message.from()); logger.atInfo().log("Mail message from %s rejected by list filter", message.from());
return false; return false;
} }

View File

@@ -45,11 +45,11 @@ public class ListMailFilterIT extends AbstractMailIT {
} }
@Test @Test
@GerritConfig(name = "receiveemail.filter.mode", value = "WHITELIST") @GerritConfig(name = "receiveemail.filter.mode", value = "ALLOW")
@GerritConfig( @GerritConfig(
name = "receiveemail.filter.patterns", name = "receiveemail.filter.patterns",
values = {".+ser@example\\.com", "a@b\\.com"}) values = {".+ser@example\\.com", "a@b\\.com"})
public void listFilterWhitelistDoesNotFilterListedUser() throws Exception { public void listFilterAllowDoesNotFilterListedUser() throws Exception {
ChangeInfo changeInfo = createChangeAndReplyByEmail(); ChangeInfo changeInfo = createChangeAndReplyByEmail();
// Check that the comments from the email have been persisted // Check that the comments from the email have been persisted
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages; Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;
@@ -57,11 +57,11 @@ public class ListMailFilterIT extends AbstractMailIT {
} }
@Test @Test
@GerritConfig(name = "receiveemail.filter.mode", value = "WHITELIST") @GerritConfig(name = "receiveemail.filter.mode", value = "ALLOW")
@GerritConfig( @GerritConfig(
name = "receiveemail.filter.patterns", name = "receiveemail.filter.patterns",
values = {".+@gerritcodereview\\.com", "a@b\\.com"}) values = {".+@gerritcodereview\\.com", "a@b\\.com"})
public void listFilterWhitelistFiltersNotListedUser() throws Exception { public void listFilterAllowFiltersNotListedUser() throws Exception {
ChangeInfo changeInfo = createChangeAndReplyByEmail(); ChangeInfo changeInfo = createChangeAndReplyByEmail();
// Check that the comments from the email have NOT been persisted // Check that the comments from the email have NOT been persisted
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages; Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;
@@ -72,11 +72,11 @@ public class ListMailFilterIT extends AbstractMailIT {
} }
@Test @Test
@GerritConfig(name = "receiveemail.filter.mode", value = "BLACKLIST") @GerritConfig(name = "receiveemail.filter.mode", value = "BLOCK")
@GerritConfig( @GerritConfig(
name = "receiveemail.filter.patterns", name = "receiveemail.filter.patterns",
values = {".+@gerritcodereview\\.com", "a@b\\.com"}) values = {".+@gerritcodereview\\.com", "a@b\\.com"})
public void listFilterBlacklistDoesNotFilterNotListedUser() throws Exception { public void listFilterBlockDoesNotFilterNotListedUser() throws Exception {
ChangeInfo changeInfo = createChangeAndReplyByEmail(); ChangeInfo changeInfo = createChangeAndReplyByEmail();
// Check that the comments from the email have been persisted // Check that the comments from the email have been persisted
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages; Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;
@@ -84,11 +84,11 @@ public class ListMailFilterIT extends AbstractMailIT {
} }
@Test @Test
@GerritConfig(name = "receiveemail.filter.mode", value = "BLACKLIST") @GerritConfig(name = "receiveemail.filter.mode", value = "BLOCK")
@GerritConfig( @GerritConfig(
name = "receiveemail.filter.patterns", name = "receiveemail.filter.patterns",
values = {".+@example\\.com", "a@b\\.com"}) values = {".+@example\\.com", "a@b\\.com"})
public void listFilterBlacklistFiltersListedUser() throws Exception { public void listFilterBlockFiltersListedUser() throws Exception {
ChangeInfo changeInfo = createChangeAndReplyByEmail(); ChangeInfo changeInfo = createChangeAndReplyByEmail();
// Check that the comments from the email have been persisted // Check that the comments from the email have been persisted
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages; Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;