Skip to content

Instantly share code, notes, and snippets.

@bastengao
Forked from anonymous/EmailUtil.java
Created December 14, 2012 09:27
Show Gist options
  • Save bastengao/4284011 to your computer and use it in GitHub Desktop.
Save bastengao/4284011 to your computer and use it in GitHub Desktop.
163.com=http://mail.163.com
126.com=http://www.126.com
yeah.net=http://www.yeah.net/
188.com=http://www.188.com/
139.com=http://mail.10086.cn/
189.cn=http://mail.189.cn/
21cn.com=http://mail.21cn.com/
wo.com.cn=http://mail.wo.com.cn/
qq.com=http://mail.qq.com/
foxmail.com=http://www.foxmail.com/
sina.cn=http://mail.sina.com.cn/
sina.com=http://mail.sina.com.cn/
vip.sina.com=http://mail.sina.com.cn/
sogou.com=http://mail.sogou.com/
sohu.com=http://mail.sohu.com/
tom.com=http://mail.tom.com/
hotmail.com=http://www.hotmail.com/
gmail.com=https://mail.google.com/
outlook.com=http://www.outlook.com/
yahoo.com.cn=http://mail.cn.yahoo.com/
yahoo.cn=http://mail.cn.yahoo.com/
/**
* User: Administrator
* Date: 11-11-4
* Time: 下午11:32
*
* @author Basten Gao
*/
public class EmailUtil {
private static final Map<String, String> EMAILS = loadEmails();
private EmailUtil() {
}
private static Map<String, String> loadEmails() {
Properties emailProperties = new Properties();
try {
emailProperties.load(Resources.newInputStreamSupplier(Resources.getResource("mails.properties")).getInput());
Map<String, String> emailMap = new HashMap<String, String>(emailProperties.size());
for (Enumeration<String> enumeration = (Enumeration<String>) emailProperties.propertyNames(); enumeration.hasMoreElements(); ) {
String key = enumeration.nextElement();
emailMap.put(key, emailProperties.getProperty(key));
}
return emailMap;
} catch (IOException e) {
e.printStackTrace();
}
return Collections.emptyMap();
}
/**
* 返回邮箱地址的域名部分。(如 abc@163.com 则返回 163.com)
* 注意:如果无法解析了域名部分,则返回空字符串。
*
* @param email
* @return
*/
public static String parseDomain(String email) {
Preconditions.checkNotNull(email);
int index = email.lastIndexOf("@");
if (index == -1) {
return "";
}
return email.substring(index + 1, email.length());
}
/**
* 通过邮箱返回此邮箱的登录页面链接,如果找不到返回 null。
*
* @param email
* @return
*/
public static String getLoginUrl(String email) {
return EMAILS.get(parseDomain(email));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment