diff --git a/core/src/main/java/hudson/tasks/Mailer.java b/core/src/main/java/hudson/tasks/Mailer.java index bc97349472886629b9d5c05e16f5f34f1149f958..d84ab3437b061065bbc61c4029cf86444fc65ff7 100644 --- a/core/src/main/java/hudson/tasks/Mailer.java +++ b/core/src/main/java/hudson/tasks/Mailer.java @@ -27,6 +27,7 @@ import hudson.Launcher; import hudson.Functions; import hudson.Extension; import hudson.Util; +import static hudson.Util.fixEmptyAndTrim; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; import hudson.model.BuildListener; @@ -57,6 +58,8 @@ import java.util.Map; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; +import java.net.InetAddress; +import java.net.UnknownHostException; import net.sf.json.JSONObject; @@ -221,8 +224,11 @@ public class Mailer extends Notifier { return createSession(smtpHost,smtpPort,useSsl,smtpAuthUsername,smtpAuthPassword); } private static Session createSession(String smtpHost, String smtpPort, boolean useSsl, String smtpAuthUserName, Secret smtpAuthPassword) { + smtpPort = fixEmptyAndTrim(smtpPort); + smtpAuthUserName = fixEmptyAndTrim(smtpAuthUserName); + Properties props = new Properties(System.getProperties()); - if(smtpHost!=null) + if(fixEmptyAndTrim(smtpHost)!=null) props.put("mail.smtp.host",smtpHost); if (smtpPort!=null) { props.put("mail.smtp.port", smtpPort); @@ -251,7 +257,8 @@ public class Mailer extends Notifier { props.put("mail.smtp.timeout","60000"); props.put("mail.smtp.connectiontimeout","60000"); - return Session.getInstance(props,getAuthenticator(smtpAuthUserName,smtpAuthPassword.toString())); + return Session.getInstance(props,getAuthenticator(smtpAuthUserName, + smtpAuthPassword!=null ? smtpAuthPassword.toString() : null)); } private static Authenticator getAuthenticator(final String smtpAuthUserName, final String smtpAuthPassword) { @@ -314,7 +321,7 @@ public class Mailer extends Notifier { } public String getSmtpAuthPassword() { - return smtpAuthPassword.toString(); + return smtpAuthPassword!=null ? smtpAuthPassword.toString() : null; } public boolean getUseSsl() { @@ -392,12 +399,22 @@ public class Mailer extends Notifier { } } + public FormValidation doCheckSmtpServer(@QueryParameter String value) { + try { + if (fixEmptyAndTrim(value)!=null) + InetAddress.getByName(value); + return FormValidation.ok(); + } catch (UnknownHostException e) { + return FormValidation.error("Unknown host name: "+value); + } + } + public FormValidation doCheckAdminAddress(@QueryParameter String value) { return doAddressCheck(value); } public FormValidation doCheckDefaultSuffix(@QueryParameter String value) { - if (value.matches("@[A-Za-z0-9.\\-]+") || Util.fixEmptyAndTrim(value)==null) + if (value.matches("@[A-Za-z0-9.\\-]+") || fixEmptyAndTrim(value)==null) return FormValidation.ok(); else return FormValidation.error("This field should be '@' followed by a domain name."); diff --git a/test/src/test/java/hudson/tasks/MailerTest.java b/test/src/test/java/hudson/tasks/MailerTest.java index 1d787d7d5b9987c0d0177372592d61508278a195..dc35af992f97622b35498808d0c80b1498e5d067 100644 --- a/test/src/test/java/hudson/tasks/MailerTest.java +++ b/test/src/test/java/hudson/tasks/MailerTest.java @@ -119,7 +119,10 @@ public class MailerTest extends HudsonTestCase { assertEquals("pass",d.getSmtpAuthPassword()); d.setUseSsl(false); + d.setSmtpAuth(null,null); submit(new WebClient().goTo("configure").getFormByName("config")); assertEquals(false,d.getUseSsl()); + assertNull(d.getSmtpAuthUserName()); + assertNull(d.getSmtpAuthPassword()); } } diff --git a/war/resources/scripts/hudson-behavior.js b/war/resources/scripts/hudson-behavior.js index a35a6cce02a5f1e057a9b3071eb10a26eff3f9d7..255244913dd025da84d5f3bbefeb3e84c5417911 100644 --- a/war/resources/scripts/hudson-behavior.js +++ b/war/resources/scripts/hudson-behavior.js @@ -386,8 +386,8 @@ var hudsonRules = { var nameRef = tr.getAttribute("nameref"); while (container.lastChild != null) { var row = container.lastChild; - if(nameRef!=null) - row.setAttribute("nameref",nameRef); + if(nameRef!=null && row.getAttribute("nameref")==null) + row.setAttribute("nameref",nameRef); // to handle inner rowSets, don't override existing values tr.parentNode.insertBefore(row, tr.nextSibling); } });