示例#1
0
  /**
   * check the account on the mail server ok = 0 invalid protocol = 1 invalid username or password =
   * 2 cannection failed = 3
   *
   * @param msa MailServerAccount
   * @param timeoutStore timeout for the store
   * @param timeoutConnection timeout for connection
   * @return true if the user is a mail server account boolean
   * @throws com.funambol.email.exception.EntityException
   */
  public MailServerError guessAccount(
      MailServerAccount msa, int timeoutStore, int timeoutConnection) throws EntityException {

    MailServerError errorCode = MailServerError.ERR_OK;

    try {

      if (msa != null) {

        String login = msa.getMsLogin();
        String password = msa.getMsPassword();
        String protocol = msa.getMailServer().getProtocol();
        String outgoingServer = msa.getMailServer().getOutServer();
        int outgoingPort = msa.getMailServer().getOutPort();
        String incomingServer = msa.getMailServer().getInServer();
        int incomingPort = msa.getMailServer().getInPort();
        boolean isSSLIn = msa.getMailServer().getIsSSLIn();

        IMailServerWrapper mswf = MailServerWrapperFactory.getMailServerWrapper(protocol);

        if (mswf != null) {
          mswf.checkUser(
              outgoingServer,
              Integer.toString(outgoingPort),
              incomingServer,
              Integer.toString(incomingPort),
              login,
              password,
              isSSLIn,
              String.valueOf(timeoutStore),
              String.valueOf(timeoutConnection),
              sslSocketFactory);
        } else {
          errorCode = MailServerError.ERR_INVALID_PROTOCOL;
        }

      } else {
        errorCode = MailServerError.ERR_INVALID_INPUT;
      }

    } catch (EmailAccessException dae) {
      if (dae != null) {
        errorCode = MailServerErrorHandler.exceptionHandler(dae);
      } else {
        errorCode = MailServerError.ERR_GENERIC_MAILSERVER;
      }
    }

    return errorCode;
  }
示例#2
0
  /**
   * 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;
  }