@Test
  public void testExpandMailbox() throws Exception {
    int customerID = m_user.getCustomerID();
    int userID = m_user.getUserID();
    String maildir = m_user.getMailDir();
    long messageId = 7890;

    EasyMock.reset(m_mockStoreManager);
    executeRequest(
        500, "uid", -1, "pid", 1, "cid", customerID, "mid", messageId, "private", "true");

    EasyMock.reset(m_mockStoreManager);
    EasyMock.expect(m_mockStoreManager.expandMessageToMeta(customerID, maildir, messageId, 1, true))
        .andReturn(true);
    executeRequest(200, "pid", 1, "uid", userID, "mid", messageId, "sender", "true");

    EasyMock.reset(m_mockStoreManager);
    EasyMock.expect(
            m_mockStoreManager.expandMessageToMeta(customerID, maildir, messageId, 1, false))
        .andReturn(true);
    executeRequest(
        200, "pid", 1, "cid", customerID, "uid", userID, "mid", messageId, "sender", "false");

    EasyMock.reset(m_mockStoreManager);
    EasyMock.expect(
            m_mockStoreManager.expandMessageToMeta(customerID, maildir, messageId, 1, false))
        .andReturn(false);
    executeRequest(
        500, "pid", 1, "cid", customerID, "uid", userID, "mid", messageId, "sender", "false");
  }
示例#2
0
  public CacheFileNames getCacheFileNames(final UserAccount user) {

    SecureHashKeyResult toRet =
        executeWithConnection(
            new ConnectionExecuteFunction<SecureHashKeyResult>() {
              public SecureHashKeyResult execute(Connection c) throws SQLException {
                return getSecureHashKey(user, c);
              }
            });

    if (toRet == null) {
      // A DB error should have been logged.
      return null;
    }

    // EMSDEV-7854.  Signal file manipulation is done outside of a DB transaction.
    String stateFile = null;
    String newmailFile = null;
    ClientHashSupport hash = null;
    byte[] key = toRet.getKey();
    if (key != null) {
      hash = new ClientHashSupport();
      hash.setCustomerId(user.getCustomerID());
      hash.setHashKey(key);
      hash.setUserId(user.getUserID());
      hash.getStateCachePath();
      hash.setLastActivationId(user.getLastActivationId());

      // Lines below don't hit the spindle.
      File stateFileF = new File(getCacheBase(), hash.getStateCachePath());
      stateFile = stateFileF.getAbsolutePath();

      File newmailFileF = new File(getCacheBase(), hash.getNewMailCachePath());
      newmailFile = newmailFileF.getAbsolutePath();

      if (toRet.isJustCreated()) {
        // If Webmail doesn't find the signal file, it polls the database,
        // so ensure the files are there.
        updateSignalFiles(hash, user.getUserState(), user.isDeleted());
      }
    }
    return new CacheFileNames(stateFile, newmailFile);
  }
示例#3
0
  // Use this to set headers that are required on all responses.
  protected void setResponseHeaders(
      ActionForm actionForm, HttpServletResponse response, UserAccount user, Device device)
      throws IOException {

    // The url is static across all devices in a customer.
    ICustomerManager customerManager = ManagementContainer.getInstance().getCustomerManager();
    Customer cust = customerManager.getCustomer(user.getCustomerID());
    IRimManager rimManager = ManagementContainer.getInstance().getRimManager();
    String cappUrl = cust.getCappUrl();
    if (m_devDebug) { // Our dev boxes use http and specifcy a port, this conflicts with the https
      // assumption of getCappUrl()
      cappUrl = "http://turbodog.austin.messageone.com:8080/";
    }

    URL url = null;
    try {
      url = new URL(cappUrl);
    } catch (MalformedURLException e) {

      LogMessageGen lmg = new LogMessageGen();
      lmg.setSubject("Bad URL");
      lmg.param(LoggingConsts.URL, cappUrl);
      lmg.param(LoggingConsts.USER_ID, device.getUserId());
      lmg.param(LoggingConsts.CUSTOMER_ID, device.getCustomerId());
      lmg.param(LoggingConsts.PIN, device.getPin());

      // This would come from the customer config, so it's bad.
      m_logCategory.error(lmg.toString(), e);
      response.setHeader(SUCCESS, "false");
      return;
    }
    int deviceCheckin =
        cust.getCapabilities().getIntCapability(Capabilities.CAP_RIM_DEVICE_PERIODIC_CHECKIN, 30);

    response.setHeader("rim-access-url-protocol", url.getProtocol());
    response.setHeader("rim-access-url-hostname", url.getHost());
    if (url.getPort() > 0) {
      response.setHeader("rim-access-url-port", Integer.toString(url.getPort()));
    }

    response.setHeader(EMS_RIM_DISPLAY_NAME, device.getDisplayName());
    response.setHeader("get-mail-path", "wfe/getRimMail.do");
    response.setHeader("send-mail-path", "wfe/sendRimMail.do");
    response.setHeader("get-display-name-path", "wfe/rimGetDisplayName.do");
    response.setHeader("checkin-path", "wfe/rimCheckin.do");

    response.setHeader("periodic-checkin", Integer.toString(deviceCheckin));

    CustomerState state = user.getUserState();
    String stateString = "ready";
    if (CustomerState.ACTIVE.equals(state) || CustomerState.TEST.equals(state)) {
      stateString = "active";

      String activationId = rimManager.getActivationId(device.getPin());
      if (StringUtils.isEmptyOrNull(activationId)) {
        // EMSDEV-4722
        // If an old agent is installed during activation, the dat_rim_user_connection_status
        // won't exist and thus no activation ID.  If needed, create one on the fly.
        // Incidently, this will fix most of the problems we've had with activationId's
        // disappearing for various reasons.
        LogMessageGen.log(
                "Old agent activationId not found; will create one on the fly", m_logCategory)
            .param(LoggingConsts.PIN, device.getPin())
            .param(LoggingConsts.USER_ID, device.getUserId())
            .info();

        activationId = rimManager.activateOldAgent(device.getPin(), device.getCustomerId());

        // Try again.
        if (StringUtils.isEmptyOrNull(activationId)) {

          LogMessageGen.log("Unable to create activationId for old agent", m_logCategory)
              .param(LoggingConsts.PIN, device.getPin())
              .param(LoggingConsts.USER_ID, device.getUserId())
              .error();
        }
      } // no activationId

      response.setHeader("activation-id", activationId);
    } // active.
    response.setHeader("application-state", stateString);

    response.setHeader(SUCCESS, "true");
  }