Java Code Examples for javax.mail.internet.AddressException#toString()

The following examples show how to use javax.mail.internet.AddressException#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdateUserCommand.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Private helper method to validate the user's email address. Puts errors into the
 * errors list.
 */
private void validateEmail() {
    if (!emailChanged) {
        return; // nothing to verify
    }
    // Make sure user and email are not null
    if (email == null) {
        throw new IllegalArgumentException("Email address is null");
    }

    // Make email is not over the max length
    if (user.getEmail().length() > UserDefaults.get().getMaxEmailLength()) {
        throw new IllegalArgumentException(String.format(
                "Email address specified [%s] is too long", user.getEmail()));
    }

    // Make sure set email is valid
    try {
        new InternetAddress(email).validate();
    }
    catch (AddressException e) {
        throw new IllegalArgumentException(
                "Email address invalid. Cause: " + e.toString());
    }
}
 
Example 2
Source File: UpdateUserCommand.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Private helper method to validate the user's email address. Puts errors into the
 * errors list.
 */
private void validateEmail() {
    if (!emailChanged) {
        return; // nothing to verify
    }
    // Make sure user and email are not null
    if (email == null) {
        throw new IllegalArgumentException("Email address is null");
    }

    // Make email is not over the max length
    if (user.getEmail().length() > UserDefaults.get().getMaxEmailLength()) {
        throw new IllegalArgumentException(String.format(
                "Email address specified [%s] is too long", user.getEmail()));
    }

    // Make sure set email is valid
    try {
        new InternetAddress(email).validate();
    }
    catch (AddressException e) {
        throw new IllegalArgumentException(
                "Email address invalid. Cause: " + e.toString());
    }
}