org.bimserver.mail.MailSystem Maven / Gradle / Ivy
package org.bimserver.mail;
/******************************************************************************
* Copyright (C) 2009-2016 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see {@literal }.
*****************************************************************************/
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import org.bimserver.BimServer;
public class MailSystem {
private final BimServer bimServer;
public MailSystem(BimServer bimServer) {
this.bimServer = bimServer;
}
public static boolean isValidEmailAddress(String aEmailAddress) {
if (aEmailAddress == null) {
return false;
}
try {
new InternetAddress(aEmailAddress);
if (!hasNameAndDomain(aEmailAddress)) {
return false;
}
} catch (AddressException ex) {
return false;
}
return true;
}
private static boolean hasNameAndDomain(String aEmailAddress) {
String[] tokens = aEmailAddress.split("@");
return tokens.length == 2 && !tokens[0].isEmpty() && !tokens[1].isEmpty();
}
public EmailMessage createMessage() {
return new EmailMessage(bimServer);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy