提交 cb88b13b 编写于 作者: K kohsuke

[FIXED HUDSON-5164]

    Infer the default e-mail address more smartly with user IDs like "DOMAIN\user" (often seen in Windows)

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@25964 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b39cc4d5
......@@ -92,9 +92,15 @@ public abstract class MailAddressResolver implements ExtensionPoint {
return u.getFullName();
String ds = Mailer.descriptor().getDefaultSuffix();
if(ds!=null)
if(ds!=null) {
// another common pattern is "DOMAIN\person" in Windows. Only
// do this when this full name is not manually set. see HUDSON-5164
Matcher m = WINDOWS_DOMAIN_REGEXP.matcher(u.getFullName());
if (m.matches() && u.getFullName().replace('\\','_').equals(u.getId()))
return m.group(1)+ds; // user+defaultSuffix
return u.getId()+ds;
else
} else
return null;
}
......@@ -114,6 +120,10 @@ public abstract class MailAddressResolver implements ExtensionPoint {
*/
private static final Pattern EMAIL_ADDRESS_REGEXP = Pattern.compile("^.*<([^>]+)>.*$");
/**
* Matches something like "DOMAIN\person"
*/
private static final Pattern WINDOWS_DOMAIN_REGEXP = Pattern.compile("[^\\\\ ]+\\\\([^\\\\ ]+)");
/**
* All registered {@link MailAddressResolver} implementations.
......
package hudson.tasks;
import hudson.model.User;
import hudson.tasks.Mailer.UserProperty;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
/**
* @author Kohsuke Kawaguchi
*/
public class MailAddressResolverTest extends HudsonTestCase {
@Bug(5164)
public void test5164() {
Mailer.descriptor().setDefaultSuffix("@example.com");
String a = User.get("DOMAIN\\user").getProperty(UserProperty.class).getAddress();
assertEquals("user@example.com",a);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册