/*
 * $Id: Validator.java 1001 2009-03-19 02:38:47Z lhoriman $
 * $Source: /cvsroot/Similarity4/src/java/com/similarity/util/Geometry.java,v $
 */

package org.subethamail.entity.i;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * For validating data at all tiers.  These constants also define
 * the length of columns in the database.
 *
 * @author Jeff Schnitzer
 */
public class Validator
{
	/** */
	private final static Logger log = LoggerFactory.getLogger(Validator.class);

	// Config
	public static final int MAX_CONFIG_ID = 80;
	public static final int MAX_CONFIG_VALUE = 4096;
	
	// Person
	public static final int MAX_PERSON_PASSWORD = 80;
	public static final int MIN_PERSON_PASSWORD = 3;
	public static final int MAX_PERSON_NAME = 80;
	
	// EmailAddress
	public static final int MAX_EMAIL_ADDRESS = 255;
	
	// MailingList
	public static final int MAX_LIST_EMAIL = 255;
	public static final int MAX_LIST_NAME = 255;
	public static final int MAX_LIST_URL = 255;
	public static final int MAX_LIST_DESCRIPTION = 4096;
	public static final int MAX_LIST_WELCOME_MESSAGE = 4096;
	
	// Role
	public static final int MAX_ROLE_NAME = 50;
	
	// EnabledFilter
	public static final int MAX_FILTER_CLASSNAME = 255;
	
	// FilterArgument
	public static final int MAX_FILTER_ARGUMENT_NAME = 255;
	public static final int MAX_FILTER_ARGUMENT_VALUE = 4096;
	
	// Subscription
	public static final int MAX_SUBSCRIPTION_NOTE = 4096;
	
	// Mail
	public static final int MAX_MAIL_CONTENT = 1024 * 1024 * 1024;	// 1G
	public static final int MAX_MAIL_MESSAGE_ID = 255;
	public static final int MAX_MAIL_SUBJECT = 4096;
	public static final int MAX_MAIL_SENDER = 4096;
	
	// Attachment
	public static final int MAX_ATTACHMENT_CONTENT_TYPE = 255;
	public static final int MAX_ATTACHMENT_CONTENT = 1024 * 1024 * 1024;	// 1G

	/** default constructor prevents util class from being created. */
	private Validator() {}

	/**
	 * Normalizes an email address to a canonical form - the domain
	 * name is lowercased but the user part is left case sensitive.
	 * It's just a good idea to always work with addresses this way.
	 */
	public static String normalizeEmail(String email)
	{
		int atIndex = email.indexOf('@');
		
		StringBuffer buf = new StringBuffer(email.length());
		buf.append(email, 0, atIndex + 1);
		
		for (int i=atIndex+1; i<email.length(); i++)
			buf.append(Character.toLowerCase(email.charAt(i)));
		
		return buf.toString();
	}

	/**
	 * This method does its best to identify invalid internet email addresses.
	 * It just checks syntax structure and can be useful to catch really
	 * blatant typos or garbage data.
	 *
	 * @return whether or not the specified email address is valid.
	 */
	public static boolean validEmail(String email)
	{
		if (email == null || email.length() == 0)
			return false;
		
		if (email.length() > MAX_EMAIL_ADDRESS)
		{
			if (log.isDebugEnabled()) log.debug("Email too long: " + email);
			return false;
		}
		
		int indexOfAt = email.indexOf('@');

		if (indexOfAt < 1)
		{ 
			// must have @ and must not be 1st char
			if (log.isDebugEnabled()) log.debug("@ is first char: " + email);
			return false;
		}

		String site = email.substring(indexOfAt + 1);

		if (site.indexOf('@') >= 0)
		{
			if (log.isDebugEnabled()) log.debug("@ missing: " + email);
			return false;
		}

		if (site.startsWith(".") || site.endsWith("."))
		{
			if (log.isDebugEnabled()) log.debug("cannot start or end with '.': " + email);
			return false;
		}

		// Make sure we don't have a one-letter TLD
		if (site.length() - 2 > 0 && site.charAt(site.length() - 2) == '.')
		{
			if (log.isDebugEnabled()) log.debug("TLD too short:" + email);
			return false;
		}
		
		return true;
	}
}

@@ -194,57 +194,65 @@
 ort 
-org.slf4j.Logger;%0D%0Aimport org.slf4j.LoggerFactory
+java.util.logging.Level;%0D%0A%0D%0Aimport lombok.extern.java.Log
 ;%0D%0A%0D
@@ -403,16 +403,22 @@
 r%0D%0A */%0D%0A
+@Log%0D%0A
 public c
@@ -437,100 +437,11 @@
 or%0D%0A
+
 %7B%0D%0A
-%09/** */%0D%0A%09private final static Logger log = LoggerFactory.getLogger(Validator.class);%0D%0A%0D%0A
 %09// 
@@ -2891,45 +2891,31 @@
 %0D%0A%09%09
-%09if (log.isDebugEnabled()) log.debug(
+    log.log(Level.FINE,
 %22Ema
@@ -2923,27 +2923,29 @@
 l too long: 
-%22 +
+%7B0%7D%22,
  email);%0D%0A%09%09
@@ -3088,45 +3088,31 @@
 %0D%0A%09%09
-%09if (log.isDebugEnabled()) log.debug(
+    log.log(Level.FINE,
 %22@ i
@@ -3125,19 +3125,21 @@
 t char: 
-%22 +
+%7B0%7D%22,
  email);
@@ -3258,45 +3258,31 @@
 %0D%0A%09%09
-%09if (log.isDebugEnabled()) log.debug(
+    log.log(Level.FINE,
 %22@ m
@@ -3289,19 +3289,21 @@
 issing: 
-%22 +
+%7B0%7D%22,
  email);
@@ -3391,45 +3391,31 @@
 %0D%0A%09%09
-%09if (log.isDebugEnabled()) log.debug(
+    log.log(Level.FINE,
 %22can
@@ -3441,15 +3441,19 @@
 th '
-.': %22 +
+'.'': %7B0%7D%22,
  ema
@@ -3612,45 +3612,31 @@
 %0D%0A%09%09
-%09if (log.isDebugEnabled()) log.debug(
+    log.log(Level.FINE,
 %22TLD
@@ -3650,11 +3650,13 @@
 ort:
-%22 +
+%7B0%7D%22,
  ema

switch logging framework