/**
  * get user
  *
  * @param accountID String
  * @return all the info about the user and the related mail server MailServerAccount
  * @throws EntityException
  */
 public MailServerAccount getUserFromID(long accountID) throws EntityException {
   MailServerAccount msa = null;
   try {
     msa = cdao.getUserFromID(accountID);
   } catch (DBAccessException ee) {
     throw new EntityException("Error getting Account ", ee);
   }
   return msa;
 }
 /**
  * the UI cannot delete the entry. it will be marked as deleted. the push listener framework will
  * remove the entry.
  *
  * @param accountID String
  * @return int
  * @throws EntityException
  */
 public int markUserAsDelete(long accountID) throws EntityException {
   int result = 0;
   try {
     MailServerAccount msa = cdao.getUserFromID(accountID);
     if (msa == null) {
       return 0;
     }
     msa.setStatus(RegistryEntryStatus.DELETED);
     msa.setLastUpdate(System.currentTimeMillis());
     result = cdao.markUserAsDelete(msa);
   } catch (DBAccessException ee) {
     throw new EntityException("Error marking account as delete.", ee);
   }
   return result;
 }
  /**
   * 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;
  }