Add sendemail.enable to disable email output

Some installations might be unable to connect to a SMTP relay,
but are still useful through the web page UI, provided that
reviewers check their dashboard periodically.  In such cases
we can't open a socket to a SMTP server, so we should bypass
any email sending code paths to prevent errors from filling
up the server logs.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-06-02 09:09:50 -07:00
parent f52f33d3e4
commit 2e4573b464
5 changed files with 42 additions and 3 deletions

View File

@@ -372,6 +372,13 @@ By default, false, as not all instances will deploy repo.
Section sendemail
~~~~~~~~~~~~~~~~~
sendemail.enable::
+
If false Gerrit will not send email messages, for any reason,
and all other properties of section sendemail are ignored.
+
By default, true, allowing notifications to be sent.
sendemail.smtpServer::
+
Hostname (or IP address) of a SMTP server that will relay

View File

@@ -137,7 +137,9 @@ class ContactPanel extends Composite {
});
final FlowPanel emailLine = new FlowPanel();
emailLine.add(emailPick);
emailLine.add(registerNewEmail);
if (Common.getGerritConfig().isAllowRegisterNewEmail()) {
emailLine.add(registerNewEmail);
}
row(infoPlainText, 0, Util.C.contactFieldFullName(), nameTxt);
row(infoPlainText, 1, Util.C.contactFieldEmail(), emailLine);
@@ -261,8 +263,10 @@ class ContactPanel extends Composite {
if (emailPick.getItemCount() > 0) {
emailPick.setVisible(true);
emailPick.setEnabled(true);
emailPick.addItem("... " + Util.C.buttonOpenRegisterNewEmail() + " ",
Util.C.buttonOpenRegisterNewEmail());
if (Common.getGerritConfig().isAllowRegisterNewEmail()) {
final String t = Util.C.buttonOpenRegisterNewEmail();
emailPick.addItem("... " + t + " ", t);
}
} else {
emailPick.setVisible(false);
}
@@ -299,6 +303,10 @@ class ContactPanel extends Composite {
}
private void doRegisterNewEmail() {
if (!Common.getGerritConfig().isAllowRegisterNewEmail()) {
return;
}
final AutoCenterDialogBox box = new AutoCenterDialogBox(true, true);
final VerticalPanel body = new VerticalPanel();

View File

@@ -29,6 +29,7 @@ public class GerritConfig implements Cloneable {
protected List<ApprovalType> actionTypes;
protected boolean useContributorAgreements;
protected boolean useContactInfo;
protected boolean allowRegisterNewEmail;
protected SystemConfig.LoginType loginType;
protected boolean useRepoDownload;
protected String gitDaemonUrl;
@@ -110,6 +111,14 @@ public class GerritConfig implements Cloneable {
useContactInfo = r;
}
public boolean isAllowRegisterNewEmail() {
return allowRegisterNewEmail;
}
public void setAllowRegisterNewEmail(final boolean r) {
allowRegisterNewEmail = r;
}
public ApprovalType getApprovalType(final ApprovalCategory.Id id) {
if (byCategoryId == null) {
byCategoryId = new HashMap<ApprovalCategory.Id, ApprovalType>();

View File

@@ -678,6 +678,7 @@ public class GerritServer {
r.setUseRepoDownload(getGerritConfig().getBoolean("repo", null,
"showdownloadcommand", false));
r.setUseContactInfo(getContactStoreURL() != null);
r.setAllowRegisterNewEmail(isOutgoingMailEnabled());
r.setLoginType(getLoginType());
final String gitwebUrl = getGerritConfig().getString("gitweb", null, "url");
@@ -693,7 +694,15 @@ public class GerritServer {
Common.setGerritConfig(r);
}
public boolean isOutgoingMailEnabled() {
return getGerritConfig().getBoolean("sendemail", null, "enable", true);
}
public SMTPClient createOutgoingMail() throws EmailException {
if (!isOutgoingMailEnabled()) {
throw new EmailException("Sending email is disabled");
}
final RepositoryConfig cfg = getGerritConfig();
String smtpHost = cfg.getString("sendemail", null, "smtpserver");
if (smtpHost == null) {

View File

@@ -112,6 +112,12 @@ public abstract class OutgoingEmail {
* @throws EmailException
*/
public void send() throws EmailException {
if (!server.isOutgoingMailEnabled()) {
// Server has explicitly disabled email sending.
//
return;
}
init();
format();
if (shouldSendMessage()) {