//
// Copyright (c) 2011 Linkeos.
//
// This file is part of Elveos.org.
// Elveos.org is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// Elveos.org 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 General Public License for
// more details.
// You should have received a copy of the GNU General Public License along
// with Elveos.org. If not, see http://www.gnu.org/licenses/.
//
package com.bloatit.framework.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MailUtils {

    /**
     * <p>
     * Indicates wether a given string is a valid email address
     * </p>
     * <p>
     * Email format is :
     * <li>starts with A-Za-z or '-'</li>
     * <li>then has any number of A-Za-z (can be zero)</li>
     * <li>has any number of '.' followed by one of more characters</li>
     * <li>has an '@'</li>
     * <li>has any number of A-Za-z0-9</li>
     * <li>has a '.' then 2 to 4 A-Za-z</li>
     * </p>
     * 
     * @param email the string to validate
     * @return <code>true</code> if the string is a valid email address,
     *         <code>false</code> otherwise
     */
    public static boolean isValidEmail(final String email) {
        final String expression = "^[\\w\\-]+(\\.[\\w\\-]+)*@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$";
        final Pattern pattern = Pattern.compile(expression);

        final Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }
}

@@ -1275,10 +1275,9 @@
    *
- 
 %0A
+
     
@@ -1541,65 +1541,493 @@
 = %22%5E
-%5B%5C%5Cw%5C%5C-%5D+(
+(?:%5Ba-z0-9!#$%25&'*+/=?%5E_%60%7B%7C%7D~-%5D+(?:%5C%5C.%5Ba-z0-9!#$%25&'*+/=?%5E_%60%7B%7C%7D~-%5D+)*%7C%5C%22(?:%5B%5C%5Cx01-%5C%5Cx08%5C%5Cx0b%5C%5Cx0c%5C%5Cx0e-%5C%5Cx1f%5C%5Cx21%5C%5Cx23-%5C%5Cx5b%5C%5Cx5d-%5C%5Cx7f%5D%7C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