 == K_OPEN_PAREN) {
        // comment
        ++idx;
        while (idx < len) {
          c = emailText.charAt(idx);
          if (c == K_CLOSE_PAREN) {
            ++idx;
            break;
          }
          if (c == K_ESCAPE) {
            ++idx;
            ++idx;
            continue;
          }
          // normal character...
          ++idx;
        }
      } else {
        // not whitespace -- return...
        break;
      }
    }
    return idx;
  }

  /**
   * RFC 5322 production 3.2.3 -- except it accepts epsilon transition and does
   * not consume pre/post FWS
   */
  private static final int advanceAtomText(String emailText, int idx, int len,
                                           boolean dotAtomAllowed) {
    boolean first = true;
    while (idx < len) {
      char c = emailText.charAt(idx);
      if (isWhitespace(c)) {
        // end of atom.
        break;
      } else if (K_SPECIAL_CHARS.indexOf(c)!= -1) {
        if (dotAtomAllowed &&!first && c == K_DOT) {
          // dot is allowed if it is embedded in the atom.
          if (idx + 1 >= len) {
            // this dot is not part of a dotAtom because it is terminal.
            break;
          }
          c = emailText.charAt(idx + 1);
          if (!isWhitespace(c) && K_SPECIAL_CHARS.indexOf(c) == -1) {
            // ok -- the character after the dot is not a terminator
            // so advance past the dot and this character
            // and continue consuming characters...
            ++idx;
            ++idx;
          } else {
            // dot is at end of atom, so consuming it wouldn't produce a
            // valid dot-atom. Leave it.
            break;
          }
        } else {
          // simple atom only or special character ending an atom.
          break;
        }
      } else {
        // ordinary character...
        first = false;
        ++idx;
      }
    }
    return idx;
  }

  /**
   * RFC 5322 production 3.2.4 -- except it accepts epsilon transition.
   */
  private static final int advanceQuotedText(String emailText, int idx, int len) {
    if (idx >= len)
      return idx;
    char c = emailText.charAt(idx);
    if (c!= K_DQ) {
      return idx;
    }
    if (idx + 1 >= len) {
      // orphan double quote -- not a valid quoted text.
      return idx;
    }

    ++idx;
    while (idx < len) {
      c = emailText.charAt(idx);
      if (c == K_DQ) {
        ++idx;
        return idx;
      } else if (c == K_ESCAPE) {
        ++idx;
        ++idx;
      } else {
        // ordinary character
        ++idx;
      }
    }
    throw new IllegalStateException("double-quoted string never ended");
  }

  /**
   * RFC 5322 PHRASE production -- except it accepts epsilon transition.
   */
  private static final int advancePhrase(String emailText, int idx, int len, boolean allowDotAtom) {
    if (idx >= len)
      return idx;
    char c = emailText.charAt(idx);
    if (c == K_DQ) {
      return advanceQuotedText(emailText, idx, len);
    } else {
      return advanceAtomText(emailText, idx, len, allowDotAtom);
    }
  }

  /**
   * Return a normalized domain string and the index of the next parse
   * character.
   */
  private static final PositionString advanceDomain(String emailText, int idx, int len) {
    char c = emailText.charAt(idx);
    if (c == K_OPEN_SQUARE) {
      ++idx;
      idx = advanceCFWS(emailText, idx, len);
      int idxStart = idx;
      int idxEnd = emailText.indexOf(K_CLOSE_SQUARE, idxStart);
      if (idxEnd == -1) {
        throw new IllegalStateException("Expecting close square bracket");
      }
      int idxEscape = emailText.indexOf(K_ESCAPE, idxStart);
      if (idxEscape!= -1 && idxEscape < idxEnd) {
        throw new IllegalStateException("escape sequence appears in domain expression");
      }
      int idxDone = idxStart;
      while (idxDone < len) {
        c = emailText.charAt(idxDone);
        if (isWhitespace(c) || c == K_OPEN_PAREN || c == K_CLOSE_SQUARE) {
          break;
        }
        ++idxDone;
      }
      idx = advanceCFWS(emailText, idxDone, len);
      if (idx!= idxEnd) {
        throw new IllegalStateException("more than just a domain string surround by whitespace");
      }
      PositionString ps = new PositionString(idxEnd + 1);
      ps.cleanString = K_OPEN_SQUARE + emailText.substring(idxStart, idxDone) + K_CLOSE_SQUARE;
      return ps;
    } else {
      int idxEnd = advancePhrase(emailText, idx, len, true);
      if (idxEnd == idx) {
        throw new IllegalStateException("Expected a domain name");
      }
      PositionString ps = new PositionString(idxEnd);
      ps.cleanString = emailText.substring(idx, idxEnd).toLowerCase();
      return ps;
    }
  }

  /**
   * Advance over an e-mail address specification (RFC 5322)
   */
  private static final PositionString advanceAddrSpec(String emailText, int idx, int len,
                                                      int idxStart, boolean expectCloseAngle) {
    // this had better get a dot-phrase
    int idxEnd = idx;
    if (idxStart == idxEnd) {
      throw new IllegalStateException("Missing local part (username) in e-mail address");
    }
    if (idxEnd >= len) {
      throw new IllegalStateException("Unexpected end to angle production");
    }
    char c = emailText.charAt(idx);
    if (c!= K_AT) {
      throw new IllegalStateException("Expected '@' sign in e-mail address");
    }
    ++idx;
    int idxStartDomain = idx;
    PositionString domain = advanceDomain(emailText, idx, len);
    if (idxStartDomain == domain.idxEnd) {
      throw new IllegalStateException("Missing domain in e-mail address");
    }
    idx = domain.idxEnd;
    idx = advanceCFWS(emailText, idx, len);
    if (expectCloseAngle) {
      c = emailText.charAt(idx);
      if (c!= K_CLOSE_ANGLE) {
        throw new IllegalStateException("Expecting close angle bracket");
      }
      ++idx;
    }
    PositionString ps = new PositionString(idx);
    ps.cleanString = emailText.substring(idxStart, idxEnd) + K_AT + domain.cleanString;
    return ps;
  }

  /**
   * Parses the &lt;user@domain.org&gt; portion of an email address per RFC
   * 5322.
   */
  private static final PositionString advanceAngleAddr(String emailText, int idx, int len) {
    char c = emailText.charAt(idx);
    if (c!= K_OPEN_ANGLE) {
      throw new IllegalStateException("Expected to be at angle production");
    }
    // e.g., embedded spaces '< foo@bar >'
    ++idx;
    idx = advanceCFWS(emailText, idx, len);

    boolean allowRouting = true;
    boolean expectColon = false;
    for (; idx < len; ) {
      c = emailText.charAt(idx);
      if (allowRouting && c == K_AT) {
        expectColon = true;
        ++idx;
        idx = advanceCFWS(emailText, idx, len);
        int idxDomainStart = idx;
        PositionString pd = advanceDomain(emailText, idx, len);
        idx = pd.idxEnd;
        if (idx == idx