Skip to content
Permalink
Browse files

Merge pull request #63 from hajush/master

Fix for JENKINS-17503 by adding an excluded committer list to email-ext global config
  • Loading branch information
slide committed Apr 10, 2013
2 parents 4af57bf + 57c6b86 commit 519f012a2a59782e1fcccf6ab1de6aebff14b993
@@ -56,6 +56,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

@@ -518,7 +519,7 @@ private MimeMessage createMail(EmailType type, AbstractBuild<?, ?> build, BuildL

for (User user : users) {
String userAddress = EmailRecipientUtils.getUserConfiguredEmail(user);
if(userAddress != null){
if (userAddress != null && !isExcludedCommitter(user.getFullName())) {
addAddressesFromRecipientList(recipientAddresses, ccAddresses, userAddress, env, listener);
} else {
listener.getLogger().println("Failed to send e-mail to " + user.getFullName() + " because no e-mail address is known, and no default e-mail domain is configured");
@@ -600,6 +601,16 @@ private MimeMessage createMail(EmailType type, AbstractBuild<?, ?> build, BuildL
return msg;
}

private boolean isExcludedCommitter(String userName) {
StringTokenizer tokens = new StringTokenizer(DESCRIPTOR.getExcludedCommitters(), ",");
while (tokens.hasMoreTokens()) {
if (tokens.nextToken().trim().equalsIgnoreCase(userName)) {
return true;
}
}
return false;
}

private void addUserTriggeringTheBuild(AbstractBuild<?, ?> build, Set<InternetAddress> recipientAddresses, Set<InternetAddress> ccAddresses,
EnvVars env, BuildListener listener) {
User user = getByUserIdCause(build);
@@ -110,6 +110,12 @@
*/
private String defaultReplyTo = "";

/*
* This is a global excluded committers list for not sending commit emails.
*/
private String excludedCommitters = "";


private boolean overrideGlobalSettings;

/**
@@ -244,6 +250,10 @@ public String getDefaultRecipients() {
return recipientList;
}

public String getExcludedCommitters() {
return excludedCommitters;
}

public boolean getOverrideGlobalSettings() {
return overrideGlobalSettings;
}
@@ -393,6 +403,8 @@ public boolean configure(StaplerRequest req, JSONObject formData)
precedenceBulk = req.getParameter("extmailer.addPrecedenceBulk") != null;
enableSecurity = req.getParameter("ext_mailer_security_enabled") != null;

excludedCommitters = req.getParameter("ext_mailer_excluded_committers");

// specify List-ID information
if (req.getParameter("extmailer.useListID") != null) {
listId = nullify(req.getParameter("extmailer.ListID.id"));
@@ -62,6 +62,9 @@ f.section(title: _("Extended E-mail Notification")) {
f.entry(help: "/plugin/email-ext/help/globalConfig/emergencyReroute.html", title: _("Emergency reroute")) {
input(type: "text", class: "setting-input", value: descriptor.emergencyReroute, name: "ext_mailer_emergency_reroute")
}
f.entry(help: "/plugin/email-ext/help/globalConfig/excludedCommitters.html", title: _("Excluded Committers")) {
input(type: "text", class: "setting-input", value: descriptor.excludedCommitters, name: "ext_mailer_excluded_committers")
}
f.entry(help: "/plugin/email-ext/help/globalConfig/defaultSubject.html", title: _("Default Subject")) {
input(type: "text", class: "setting-input", value: descriptor.defaultSubject, name: "ext_mailer_default_subject")
}
@@ -0,0 +1,6 @@
<div>
Prevent system email account managers from being spammed
by commits by entering their account names here separated
by commas. They should just be the account names without
the "@domain.com" extension.
</div>

0 comments on commit 519f012

Please sign in to comment.
You can’t perform that action at this time.