Пример #1
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();
  }
Пример #2
0
  /** Confirms that locator is not set for contacts. */
  @Test
  public void locator() throws Exception {
    // Create contact.
    Map<String, String> attrs = Maps.newHashMap();
    attrs.put(ContactConstants.A_fullName, "Volume Id");
    Mailbox mbox =
        MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    mbox.createContact(null, new ParsedContact(attrs), Mailbox.ID_FOLDER_CONTACTS, null);

    // Check volume id in database.
    String sql =
        String.format(
            "SELECT COUNT(*) FROM %s WHERE type = %d AND blob_digest IS NULL AND locator IS NOT NULL",
            DbMailItem.getMailItemTableName(mbox), MailItem.Type.CONTACT.toByte());
    DbResults results = DbUtil.executeQuery(sql);
    Assert.assertEquals("Found non-null locator values for contacts", 0, results.getInt(1));
  }
Пример #3
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);
  }