/** * {@inheritDoc} */ @Override protected boolean prove(String value) { if (value.isEmpty()) { return true; } return EMailUtils.isValidEmailAddress(value); }
/** * Adds a email address to the alerting definition. * * @param email * the email address to add * @return result of the adding (as specified by {@link Collection#add(Object)}) */ public boolean addNotificationEmailAddress(String email) { if (email == null) { throw new IllegalArgumentException("Adding email adress 'null'."); } else if (email.isEmpty()) { throw new IllegalArgumentException("Adding empty email address."); } else if (!EMailUtils.isValidEmailAddress(email)) { throw new IllegalArgumentException("Adding invalid email address '" + email + "'."); } else if (notificationEmailAddresses.contains(email)) { throw new IllegalArgumentException("Adding email address '" + email + "'."); } else { return notificationEmailAddresses.add(email); } }
/** * Unwrap the comma separated list string of default recipients into a real list. */ @PropertyUpdate(properties = { "mail.default.to" }) private void parseRecipientsString() { defaultRecipients.clear(); if (null != defaultRecipientString) { String[] strArray = defaultRecipientString.split(","); for (String element : strArray) { String address = element.trim(); if (EMailUtils.isValidEmailAddress(address)) { defaultRecipients.add(address); } } } }
/** * Checks whether the given comma separated list string contains an invalid e-mail address. * * @param commaSeparatedList * String to check. * @return Returns the first invalid e-mail address or null if all e-mail addresses are valid. */ private String getInvalidEmailAddress(String commaSeparatedList) { String[] strArray = StringUtils.splitPreserveAllTokens(commaSeparatedList, ','); for (int i = 0; i < strArray.length; i++) { if (!EMailUtils.isValidEmailAddress(strArray[i])) { return strArray[i]; } } return null; } }
/** * Validates the content of the email addresses input field checking whether the e-mails have a * correct syntax. * * @return Returns a integer-string pair indicating the line number and e-mail address that is * not correct. If all e-mail addresses have a correct syntax, then this method returns * <code>null</code>. */ private Pair<Integer, String> checkEmailText() { int i = 0; for (String address : getEmailAddresses()) { if (!address.isEmpty() && !EMailUtils.isValidEmailAddress(address)) { return new Pair<Integer, String>(i + 1, address); } i++; } return null; }
} else if (!EMailUtils.isValidEmailAddress(testMailRecipient)) { if (log.isWarnEnabled()) { log.warn("The specified recipient address for the test e-mail is not valid.");