001package org.codemonkey.simplejavamail; 002 003/** 004 * Defines a set of restriction flags for email address validation. To remain completely true to RFC 2822, all flags should be set to 005 * <code>true</code>. 006 * 007 * @author Benny Bottema 008 * @see #EmailAddressValidationCriteria(boolean, boolean) 009 */ 010public class EmailAddressValidationCriteria { 011 012 private final boolean allowDomainLiterals; 013 private final boolean allowQuotedIdentifiers; 014 015 /** 016 * Criteria which is most RFC 2822 compliant and allows all compiant address forms, including the more exotic ones. 017 * 018 * @see #EmailAddressValidationCriteria(boolean, boolean) 019 */ 020 public static final EmailAddressValidationCriteria RFC_COMPLIANT = new EmailAddressValidationCriteria(true, true); 021 022 /** 023 * @param allowDomainLiterals <ul> 024 * <li>This flag states whether domain literals are allowed in the email address, e.g.: 025 * <p> 026 * <tt>someone@[192.168.1.100]</tt> or <br> 027 * <tt>john.doe@[23:33:A2:22:16:1F]</tt> or <br> 028 * <tt>me@[my computer]</tt> 029 * </p> 030 * <p> 031 * The RFC says these are valid email addresses, but most people don't like allowing them. If you don't want to allow them, 032 * and only want to allow valid domain names (<a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>, x.y.z.com, etc), 033 * change this constant to <tt>false</tt>. 034 * <p> 035 * Its default value is <tt>true</tt> to remain RFC 2822 compliant, but you should set it depending on what you need for your 036 * application.</li> 037 * </ul> 038 * @param allowQuotedIdentifiers <ul> 039 * <li>This flag states whether quoted identifiers are allowed (using quotes and angle brackets around the raw address) are 040 * allowed, e.g.: 041 * <p> 042 * <tt>"John Smith" <john.smith@somewhere.com></tt> 043 * <p> 044 * The RFC says this is a valid mailbox. If you don't want to allow this, because for example, you only want users to enter 045 * in a raw address (<tt>john.smith@somewhere.com</tt> - no quotes or angle brackets), then change this constant to 046 * <tt>false</tt>. 047 * <p> 048 * Its default value is <tt>true</tt> to remain RFC 2822 compliant, but you should set it depending on what you need for your 049 * application.</li> 050 * </ul> 051 */ 052 public EmailAddressValidationCriteria(boolean allowDomainLiterals, boolean allowQuotedIdentifiers) { 053 this.allowDomainLiterals = allowDomainLiterals; 054 this.allowQuotedIdentifiers = allowQuotedIdentifiers; 055 } 056 057 public final boolean isAllowDomainLiterals() { 058 return allowDomainLiterals; 059 } 060 061 public final boolean isAllowQuotedIdentifiers() { 062 return allowQuotedIdentifiers; 063 } 064}