Search in sources :

Example 1 with ZDocument

use of com.zimbra.client.ZDocument in project zm-mailbox by Zimbra.

the class ZDocumentTest method note.

@Test
public void note() throws Exception {
    String xml = "<doc f='' d='1300925565000' rev='2' ms='2' l='0-0-0:16' ver='1' ct='text/plain' id='0-0-0:257' cr='' " + "loid='' t='' s='18' md='1300925565000' leb='' name='doc.txt' descEnabled='1' cd='1300925565000'><meta/><fr>This is a document</fr></doc>";
    ZDocument doc = new ZDocument(Element.parseXML(xml));
    Assert.assertEquals(null, Strings.emptyToNull(doc.getFlags()));
    xml = "<doc f='t' d='1300925565000' rev='3' ms='4' l='0-0-0:16' ver='1' ct='text/plain' id='0-0-0:258' cr='' " + "loid='' t='' s='14' md='1300925565000' leb='' name='note.txt' descEnabled='1' cd='1300925565000'><meta/><fr>This is a note</fr></doc>";
    ZDocument note = new ZDocument(Element.parseXML(xml));
    Assert.assertEquals("t", note.getFlags());
}
Also used : ZDocument(com.zimbra.client.ZDocument) Test(org.junit.Test)

Example 2 with ZDocument

use of com.zimbra.client.ZDocument in project zm-mailbox by Zimbra.

the class TestDocument method testContentType.

/**
 * Tests the content-type based on file extension.
 */
@Test
public void testContentType() throws Exception {
    TestUtil.createAccount(USER_NAME);
    // Create two documents.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String folderId = Integer.toString(Mailbox.ID_FOLDER_BRIEFCASE);
    ZDocument doc1 = TestUtil.createDocument(mbox, folderId, NAME_PREFIX + "-docOne.doc", "application/octet-stream", "doc1".getBytes());
    ZDocument doc2 = TestUtil.createDocument(mbox, folderId, NAME_PREFIX + "-docTwo.xls", "application/ms-tnef", "doc2".getBytes());
    // Confirm that the content-type changed based on file extension
    Assert.assertEquals("application/msword", doc1.getContentType());
    Assert.assertEquals("application/vnd.ms-excel", doc2.getContentType());
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZDocument(com.zimbra.client.ZDocument) Test(org.junit.Test)

Example 3 with ZDocument

use of com.zimbra.client.ZDocument in project zm-mailbox by Zimbra.

the class TestUserServlet method testSanitizeHtmlContentType.

/**
 * Verifies that the value of {@code zimbraNotebookSanitizeHtml} does not
 * affect the {@code Content-Type} header (bug 67752).
 * @throws HttpException
 */
@Test
public void testSanitizeHtmlContentType() throws ServiceException, IOException, HttpException {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZDocument doc = TestUtil.createDocument(mbox, Integer.toString(Mailbox.ID_FOLDER_BRIEFCASE), NAME_PREFIX + " testSanitizeHtmlContentType.txt", "text/plain", "testSanitizeHtmlContentType".getBytes());
    Account account = TestUtil.getAccount(USER_NAME);
    account.setNotebookSanitizeHtml(false);
    checkContentType(mbox, doc);
    account.setNotebookSanitizeHtml(true);
    checkContentType(mbox, doc);
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) ZDocument(com.zimbra.client.ZDocument) Test(org.junit.Test)

Example 4 with ZDocument

use of com.zimbra.client.ZDocument in project zm-mailbox by Zimbra.

the class ZMailboxUtil method dumpSearch.

private void dumpSearch(ZSearchResult sr, boolean verbose) {
    if (verbose) {
        stdout.println(sr.dump());
        return;
    }
    int offset = mSearchPage * mSearchParams.getLimit();
    int first = offset + 1;
    int last = offset + sr.getHits().size();
    stdout.printf("num: %d, more: %s%n%n", sr.getHits().size(), sr.hasMore());
    int width = colWidth(last);
    if (sr.getHits().size() == 0) {
        return;
    }
    final int FROM_LEN = 20;
    int id_len = 4;
    for (ZSearchHit hit : sr.getHits()) {
        id_len = Math.max(id_len, hit.getId().length());
    }
    Calendar cal = Calendar.getInstance();
    String headerFormat = String.format("%%%d.%ds  %%%d.%ds  %%4s   %%-20.20s  %%-50.50s  %%s%%n", width, width, id_len, id_len);
    String itemFormat = String.format("%%%d.%ds. %%%d.%ds  %%4s   %%-20.20s  %%-50.50s  %%tD %%<tR%%n", width, width, id_len, id_len);
    stdout.format(headerFormat, "", "Id", "Type", "From", "Subject", "Date");
    stdout.format(headerFormat, "", "----------------------------------------------------------------------------------------------------", "----", "--------------------", "--------------------------------------------------", "--------------");
    int i = first;
    for (ZSearchHit hit : sr.getHits()) {
        if (hit instanceof ZConversationHit) {
            ZConversationHit ch = (ZConversationHit) hit;
            cal.setTimeInMillis(ch.getDate());
            String sub = ch.getSubject();
            String from = emailAddrs(ch.getRecipients());
            if (ch.getMessageCount() > 1) {
                String numMsg = " (" + ch.getMessageCount() + ")";
                int space = FROM_LEN - numMsg.length();
                from = ((from.length() < space) ? from : from.substring(0, space)) + numMsg;
            }
            // if (ch.getFragment() != null || ch.getFragment().length() > 0)
            // sub += " (" + ch.getFragment()+")";
            mIndexToId.put(i, ch.getId());
            stdout.format(itemFormat, i++, ch.getId(), "conv", from, sub, cal);
        } else if (hit instanceof ZContactHit) {
            ZContactHit ch = (ZContactHit) hit;
            cal.setTimeInMillis(ch.getDate());
            String from = getFirstEmail(ch);
            String sub = ch.getFileAsStr();
            mIndexToId.put(i, ch.getId());
            stdout.format(itemFormat, i++, ch.getId(), "cont", from, sub, cal);
        } else if (hit instanceof ZMessageHit) {
            ZMessageHit mh = (ZMessageHit) hit;
            cal.setTimeInMillis(mh.getDate());
            String sub = mh.getSubject();
            String from = mh.getSender() == null ? "<none>" : mh.getSender().getDisplay();
            mIndexToId.put(i, mh.getId());
            stdout.format(itemFormat, i++, mh.getId(), "mess", from, sub, cal);
        } else if (hit instanceof ZAppointmentHit) {
            ZAppointmentHit ah = (ZAppointmentHit) hit;
            if (ah.getInstanceExpanded()) {
                cal.setTimeInMillis(ah.getStartTime());
            } else {
                cal.setTimeInMillis(ah.getHitDate());
            }
            String sub = ah.getName();
            String from = "<na>";
            mIndexToId.put(i, ah.getId());
            stdout.format(itemFormat, i++, ah.getId(), ah.getIsTask() ? "task" : "appo", from, sub, cal);
        } else if (hit instanceof ZDocumentHit) {
            ZDocumentHit dh = (ZDocumentHit) hit;
            ZDocument doc = dh.getDocument();
            cal.setTimeInMillis(doc.getModifiedDate());
            String name = doc.getName();
            String editor = doc.getEditor();
            mIndexToId.put(i, dh.getId());
            stdout.format(itemFormat, i++, dh.getId(), doc.isWiki() ? "wiki" : "doc", editor, name, cal);
        }
    }
    stdout.println();
}
Also used : ZSearchHit(com.zimbra.client.ZSearchHit) ZAppointmentHit(com.zimbra.client.ZAppointmentHit) ZContactHit(com.zimbra.client.ZContactHit) ZDocument(com.zimbra.client.ZDocument) Calendar(java.util.Calendar) ZMessageHit(com.zimbra.client.ZMessageHit) ZConversationHit(com.zimbra.client.ZConversationHit) ZMountpoint(com.zimbra.client.ZMountpoint) ZDocumentHit(com.zimbra.client.ZDocumentHit)

Example 5 with ZDocument

use of com.zimbra.client.ZDocument in project zm-mailbox by Zimbra.

the class TestDocument method testNote.

/**
 * Tests documents created with the {@code Note} flag set.
 */
@Test
public void testNote() throws Exception {
    TestUtil.createAccount(USER_NAME);
    // Create a document and a note.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String folderId = Integer.toString(Mailbox.ID_FOLDER_BRIEFCASE);
    ZDocument doc = TestUtil.createDocument(mbox, folderId, NAME_PREFIX + "-doc.txt", "text/plain", "doc".getBytes());
    ZDocument note = TestUtil.createDocument(mbox, folderId, NAME_PREFIX + "-note.txt", "text/plain", "note".getBytes(), true);
    String flags = Character.toString(ZItem.Flag.NOTE.getFlagChar());
    mbox.updateItem(note.getId(), null, null, flags, null);
    // Confirm that the Note flag is set when getting the documents.
    doc = mbox.getDocument(doc.getId());
    Assert.assertEquals(null, doc.getFlags());
    Assert.assertEquals(flags, note.getFlags());
    // Test searching for notes.
    List<String> ids = TestUtil.search(mbox, "in:briefcase tag:\\note", ZSearchParams.TYPE_DOCUMENT);
    Assert.assertEquals(1, ids.size());
    Assert.assertEquals(note.getId(), ids.get(0));
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZDocument(com.zimbra.client.ZDocument) Test(org.junit.Test)

Aggregations

ZDocument (com.zimbra.client.ZDocument)6 Test (org.junit.Test)5 ZMailbox (com.zimbra.client.ZMailbox)4 Account (com.zimbra.cs.account.Account)2 ZAppointmentHit (com.zimbra.client.ZAppointmentHit)1 ZContactHit (com.zimbra.client.ZContactHit)1 ZConversationHit (com.zimbra.client.ZConversationHit)1 ZDocumentHit (com.zimbra.client.ZDocumentHit)1 ZMessageHit (com.zimbra.client.ZMessageHit)1 ZMountpoint (com.zimbra.client.ZMountpoint)1 ZSearchHit (com.zimbra.client.ZSearchHit)1 Document (com.zimbra.cs.mailbox.Document)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 Calendar (java.util.Calendar)1