class urn_perun_vo_attribute_def_def_fromEmail extends VoAttributesModuleAbstract implements VoAttributesModuleImplApi {

	@Override
	public void checkAttributeSyntax(PerunSessionImpl sess, Vo vo, Attribute attribute) throws WrongAttributeValueException {
		// null attribute is ok for syntax check
		if (attribute.getValue() == null) return;

		String fromEmail = attribute.valueAsString();

		if (!(sess.getPerunBl().getModulesUtilsBl().isNameOfEmailValid(sess, fromEmail))){

			Matcher match = pattern.matcher(fromEmail);

			if (!match.matches()) {
				throw new WrongAttributeValueException(attribute, "Vo : " + vo.getName() + " has fromEmail " + fromEmail + " which is not valid. It has to be in form \"header\" <correct email> or just correct email.");
			}else{

				String[] emailParts = fromEmail.split("[<>]+");

				if (!(sess.getPerunBl().getModulesUtilsBl().isNameOfEmailValid(sess, emailParts[1]))){
					throw new WrongAttributeValueException(attribute, "Vo : " + vo.getName() +" has email in <> " + emailParts[1] +" which is not valid.");
				}
			}
		}
	}

}