class urn_perun_user_attribute_def_def_preferredMail extends UserAttributesModuleAbstract implements UserAttributesModuleImplApi {

	@Override
	public void checkAttributeSyntax(PerunSessionImpl sess, User user, Attribute attribute) throws WrongAttributeValueException {
		if(attribute.getValue() == null) return;
		String attributeValue = attribute.valueAsString();

		Matcher emailMatcher = Utils.emailPattern.matcher(attributeValue);
		if(!emailMatcher.find()) throw new WrongAttributeValueException(attribute, user, "Email is not in correct form.");

		/* User preferredMail now can be anything
		//user prefferedMail can be only one of memberMails if any
		List<Member> membersOfUser = sess.getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
		StringBuilder possiblePrefferedMailValues = new StringBuilder();
		for(Member m: membersOfUser) {
		Attribute memberMail = null;
		try {
		memberMail = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, m, A_M_mail);
		} catch (AttributeNotExistsException ex) {
		throw new ConsistencyErrorException(ex);
		} catch (WrongAttributeAssignmentException ex) {
		throw new InternalErrorException(ex);
		}

		if(attribute.getValue().equals(memberMail.getValue())) return;
		if(memberMail != null) {
		if(possiblePrefferedMailValues.length() != 0) possiblePrefferedMailValues.append(", ");
		possiblePrefferedMailValues.append("'" + memberMail.getValue() + "'");
		}
		}
		throw new WrongAttributeValueException("Attribute user preffered mail can be null (if no members mail exists) or one of the existing member's mails [" + possiblePrefferedMailValues.toString() + "]. " + attribute);
		*/
	}

}