Ejemplo n.º 1
0
  private void handleOutOfOffice(Account account) {
    try {
      Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);

      synchronized (DbMailbox.getZimbraSynchronizer(mbox)) {
        Connection conn = null;
        try {
          // clear the OOF database for this account
          conn = DbPool.getConnection(mbox);
          DbOutOfOffice.clear(conn, mbox);
          conn.commit();
          ZimbraLog.misc.info("reset vacation info");

          // Convenient place to prune old data, until we determine that this
          //  needs to be a separate scheduled process.
          // TODO: only prune once a day?
          long interval =
              account.getTimeInterval(
                  Provisioning.A_zimbraPrefOutOfOfficeCacheDuration,
                  Notification.DEFAULT_OUT_OF_OFFICE_CACHE_DURATION_MILLIS);
          DbOutOfOffice.prune(conn, interval);
          conn.commit();
        } catch (ServiceException e) {
          DbPool.quietRollback(conn);
        } finally {
          DbPool.quietClose(conn);
        }
      }
    } catch (ServiceException e) {
      ZimbraLog.misc.warn("error handling out-of-office", e);
    }
  }
Ejemplo n.º 2
0
 private void useMVCC(Mailbox mbox) throws ServiceException, SQLException {
   // tell HSQLDB to use multiversion so our asserts can read while write is open
   PreparedStatement stmt = null;
   ResultSet rs = null;
   DbConnection conn = DbPool.getConnection(mbox);
   try {
     stmt = conn.prepareStatement("SET DATABASE TRANSACTION CONTROL MVCC");
     stmt.executeUpdate();
   } finally {
     DbPool.closeResults(rs);
     DbPool.quietCloseStatement(stmt);
     DbPool.quietClose(conn);
   }
 }
Ejemplo n.º 3
0
  @Test
  public void tooLongSender() throws Exception {
    Mailbox mbox =
        MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_firstName, Strings.repeat("F", 129));
    Contact contact =
        mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);

    DbConnection conn = DbPool.getConnection(mbox);

    Assert.assertEquals(
        Strings.repeat("F", 128),
        DbUtil.executeQuery(
                conn,
                "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?",
                mbox.getId(),
                contact.getId())
            .getString(1));

    fields.put(ContactConstants.A_firstName, null);
    fields.put(ContactConstants.A_lastName, Strings.repeat("L", 129));
    mbox.modifyContact(null, contact.getId(), new ParsedContact(fields));

    Assert.assertEquals(
        Strings.repeat("L", 128),
        DbUtil.executeQuery(
                conn,
                "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?",
                mbox.getId(),
                contact.getId())
            .getString(1));

    conn.closeQuietly();
  }
Ejemplo n.º 4
0
 private int countInboxMessages(Mailbox mbox) throws ServiceException, SQLException {
   PreparedStatement stmt = null;
   ResultSet rs = null;
   DbConnection conn = DbPool.getConnection(mbox);
   try {
     stmt =
         conn.prepareStatement(
             "SELECT COUNT(*) FROM mboxgroup1.mail_item WHERE mailbox_id = ? and folder_id = ?");
     stmt.setInt(1, mbox.getId());
     stmt.setInt(2, Mailbox.ID_FOLDER_INBOX);
     rs = stmt.executeQuery();
     if (rs.next()) {
       return rs.getInt(1);
     }
     return 0;
   } finally {
     DbPool.closeResults(rs);
     DbPool.quietCloseStatement(stmt);
     DbPool.quietClose(conn);
   }
 }
Ejemplo n.º 5
0
  @Test
  public void mdate() throws Exception {
    Mailbox mbox =
        MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);

    DbConnection conn = DbPool.getConnection();
    DbUtil.executeUpdate(
        conn,
        "INSERT INTO mboxgroup1.mail_item "
            + "(mailbox_id, id, folder_id, type, flags, date, change_date, size, tags, mod_metadata, mod_content) "
            + "VALUES(?, ?, ?, ?, 0, ?, ?, 0, 0, 0, 0)",
        mbox.getId(),
        101,
        Mailbox.ID_FOLDER_INBOX,
        MailItem.Type.MESSAGE.toByte(),
        100,
        1000);
    DbUtil.executeUpdate(
        conn,
        "INSERT INTO mboxgroup1.mail_item "
            + "(mailbox_id, id, folder_id, type, flags, date, change_date, size, tags, mod_metadata, mod_content) "
            + "VALUES(?, ?, ?, ?, 0, ?, ?, 0, 0, 0, 0)",
        mbox.getId(),
        102,
        Mailbox.ID_FOLDER_INBOX,
        MailItem.Type.MESSAGE.toByte(),
        200,
        2000);
    DbUtil.executeUpdate(
        conn,
        "INSERT INTO mboxgroup1.mail_item "
            + "(mailbox_id, id, folder_id, type, flags, date, change_date, size, tags, mod_metadata, mod_content) "
            + "VALUES(?, ?, ?, ?, 0, ?, ?, 0, 0, 0, 0)",
        mbox.getId(),
        103,
        Mailbox.ID_FOLDER_INBOX,
        MailItem.Type.MESSAGE.toByte(),
        300,
        3000);
    DbUtil.executeUpdate(
        conn,
        "INSERT INTO mboxgroup1.mail_item "
            + "(mailbox_id, id, folder_id, type, flags, date, change_date, size, tags, mod_metadata, mod_content) "
            + "VALUES(?, ?, ?, ?, 0, ?, ?, 0, 0, 0, 0)",
        mbox.getId(),
        104,
        Mailbox.ID_FOLDER_INBOX,
        MailItem.Type.MESSAGE.toByte(),
        400,
        4000);
    DbUtil.executeUpdate(
        conn,
        "INSERT INTO mboxgroup1.mail_item "
            + "(mailbox_id, id, folder_id, type, flags, date, change_date, size, tags, mod_metadata, mod_content) "
            + "VALUES(?, ?, ?, ?, 0, ?, ?, 0, 0, 0, 0)",
        mbox.getId(),
        105,
        Mailbox.ID_FOLDER_INBOX,
        MailItem.Type.MESSAGE.toByte(),
        500,
        5000);
    conn.commit();
    conn.closeQuietly();

    SearchParams params = new SearchParams();
    params.setQueryString("mdate:>3000000");
    params.setSortBy(SortBy.DATE_ASC);
    params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
    params.setFetchMode(SearchParams.Fetch.IDS);

    ZimbraQuery query =
        new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
    Assert.assertEquals("ZQ: Q(DATE:MDATE,197001010050-196912312359)", query.toString());
    ZimbraQueryResults result = query.execute();
    Assert.assertEquals(104, result.getNext().getItemId());
    Assert.assertEquals(105, result.getNext().getItemId());
    Assert.assertEquals(null, result.getNext());
    Closeables.closeQuietly(result);
  }
 @Override
 public Results check(
     Collection<Short> volumeIds, int mboxId, boolean checkSize, boolean reportUsedBlobs)
     throws ServiceException {
   mailboxId = mboxId;
   this.checkSize = checkSize;
   this.reportUsedBlobs = reportUsedBlobs;
   results = new Results();
   Mailbox mbox = MailboxManager.getInstance().getMailboxById(mailboxId);
   DbConnection conn = null;
   assert (StoreManager.getInstance() instanceof ExternalStoreManager);
   ExternalStoreManager sm = (ExternalStoreManager) StoreManager.getInstance();
   try {
     unexpectedBlobPaths = sm.getAllBlobPaths(mbox);
   } catch (IOException ioe) {
     log.error("IOException getting remote blob list", ioe);
   }
   try {
     conn = DbPool.getConnection();
     int mailboxMaxId = DbBlobConsistency.getMaxId(conn, mbox);
     int minId = 0;
     int maxId = CHUNK_SIZE;
     while (minId <= mailboxMaxId) {
       for (BlobInfo blobInfo :
           DbBlobConsistency.getExternalMailItemBlobInfo(conn, mbox, minId, maxId)) {
         checkExternalBlob(mbox, checkSize, blobInfo, sm);
       }
       for (BlobInfo blobInfo :
           DbBlobConsistency.getExternalMailItemDumpsterBlobInfo(conn, mbox, minId, maxId)) {
         checkExternalBlob(mbox, checkSize, blobInfo, sm);
       }
       for (BlobInfo blobInfo :
           DbBlobConsistency.getExternalRevisionBlobInfo(conn, mbox, minId, maxId)) {
         checkExternalBlob(mbox, checkSize, blobInfo, sm);
       }
       for (BlobInfo blobInfo :
           DbBlobConsistency.getExternalRevisionDumpsterBlobInfo(conn, mbox, minId, maxId)) {
         checkExternalBlob(mbox, checkSize, blobInfo, sm);
       }
       minId = maxId + 1;
       maxId += CHUNK_SIZE;
     }
   } finally {
     DbPool.quietClose(conn);
   }
   for (String unexpected : unexpectedBlobPaths) {
     BlobInfo bi = new BlobInfo();
     bi.external = true;
     bi.locator = unexpected;
     bi.path = unexpected;
     results.unexpectedBlobs.put(0, bi);
     try {
       Blob blob = sm.getLocalBlob(mbox, unexpected, false);
       bi.fileSize = blob.getFile().length();
     } catch (IOException ioe) {
       // log this?
       bi.fileSize = 0L;
       bi.fetchException = ioe;
     }
   }
   return results;
 }