/**
   * check if the fnbl_email_inbox must be refreshed for the given user
   *
   * @param currMsa
   * @throws com.funambol.email.exception.EntityException
   * @return true if the table must be refreshed
   */
  private boolean needCacheRefreshing(MailServerAccount currMsa) throws EntityException {

    boolean check = false;

    MailServerAccount prevMsa = null;
    String prevMailServerID = null;
    String prevProtocol = null;
    String currMailServerID = null;
    String currProtocol = null;
    try {

      // get all info from DB
      prevMsa = cdao.getUserFromID(currMsa.getId());

      prevMailServerID = prevMsa.getMailServer().getMailServerId();
      prevProtocol = prevMsa.getMailServer().getProtocol();

      currMailServerID = currMsa.getMailServer().getMailServerId();
      currProtocol = currMsa.getMailServer().getProtocol();

      if (currMailServerID != null && prevMailServerID != null) {
        if (!currMailServerID.equals(prevMailServerID)) {
          check = true;
        }
      }

      // same mail server but differt protocol
      if (currProtocol != null && prevProtocol != null) {
        if (!currProtocol.equals(prevProtocol)) {
          check = true;
        }
      }

      // different login or mail address
      String currMsLogin = currMsa.getMsLogin();
      String prevMsLogin = prevMsa.getMsLogin();

      if (currMsLogin != null && prevMsLogin != null) {
        if (!currMsLogin.equals(prevMsLogin)) {
          check = true;
        }
      }

      String currMsAddress = currMsa.getMsAddress();
      String prevMsAddress = prevMsa.getMsAddress();

      if (currMsAddress != null && prevMsAddress != null) {
        if (!currMsAddress.equals(prevMsAddress)) {
          check = true;
        }
      }

    } catch (DBAccessException ee) {
      throw new EntityException(
          "Error checking if the cache for the "
              + "account "
              + currMsa.getId()
              + " must be freshed",
          ee);
    }
    return check;
  }