Search in sources :

Example 1 with ItemIdFormatter

use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.

the class GalSearchResultCallback method reset.

public void reset(GalSearchParams params) {
    if (params.getSoapContext() != null) {
        mResponse = params.getSoapContext().createElement(params.getResponseName());
        mFormatter = new ItemIdFormatter(params.getSoapContext());
    } else {
        mResponse = Element.XMLElement.mFactory.createElement(params.getResponseName());
        mFormatter = new ItemIdFormatter();
    }
    params.setGalResult(SearchGalResult.newSearchGalResult(this));
    mIdOnly = params.isIdOnly();
    try {
        mAuthAcct = params.getAuthAccount();
    } catch (ServiceException e) {
        ZimbraLog.gal.warn("unable to get authed account", e);
    }
    mNeedCanExpand = params.getNeedCanExpand();
    mNeedIsOwner = params.getNeedIsOwner();
    mNeedIsMember = params.getNeedIsMember();
    mNeedSMIMECerts = params.getNeedSMIMECerts();
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter)

Example 2 with ItemIdFormatter

use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.

the class DocumentTest method note.

/**
 * Verifies setting the {@code Note} flag on a document.
 */
@Test
public void note() throws Exception {
    // Create document and note.
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Document doc = createDocument(mbox, "doc.txt", "This is a document", false);
    Document note = createDocument(mbox, "note.txt", "This is a note", true);
    // Validate flag.
    doc = mbox.getDocumentById(null, doc.getId());
    note = mbox.getDocumentById(null, note.getId());
    assertTrue((note.getFlagBitmask() & Flag.FlagInfo.NOTE.toBitmask()) != 0);
    // Search by flag.
    List<Integer> ids = TestUtil.search(mbox, "tag:\\note", MailItem.Type.DOCUMENT);
    Assert.assertEquals(1, ids.size());
    Assert.assertEquals(note.getId(), ids.get(0).intValue());
    // Make sure that the note flag is serialized to XML.
    Element eDoc = ToXML.encodeDocument(new XMLElement("test"), new ItemIdFormatter(), null, doc);
    Assert.assertEquals(null, Strings.emptyToNull(eDoc.getAttribute(MailConstants.A_FLAGS, null)));
    Element eNote = ToXML.encodeDocument(new XMLElement("test"), new ItemIdFormatter(), null, note);
    Assert.assertEquals("t", eNote.getAttribute(MailConstants.A_FLAGS));
}
Also used : ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) XMLElement(com.zimbra.common.soap.Element.XMLElement) Test(org.junit.Test)

Example 3 with ItemIdFormatter

use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.

the class ContactTest method testEncodeContact.

@Test
public void testEncodeContact() throws Exception {
    Account account = Provisioning.getInstance().getAccountByName("testCont@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_userCertificate, "{\"ZMVAL\":[\"Cert1149638887753217\"]}");
    Contact contact = mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    Element response = new Element.XMLElement(MailConstants.MODIFY_CONTACT_RESPONSE);
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "testCont@zimbra.com");
    ToXML.encodeContact(response, new ItemIdFormatter(), new OperationContext(acct), contact, true, null);
    Assert.assertEquals(response.getElement("cn").getElement("a").getText(), "Cert1149638887753217");
}
Also used : Account(com.zimbra.cs.account.Account) ParsedContact(com.zimbra.cs.mime.ParsedContact) HashMap(java.util.HashMap) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Element(com.zimbra.common.soap.Element) ParsedContact(com.zimbra.cs.mime.ParsedContact) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with ItemIdFormatter

use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.

the class SaveDraftTest method updateRace.

@Test
public void updateRace() throws Exception {
    Account acct = Provisioning.getInstance().getAccountByName("test@zimbra.com");
    // create a draft via SOAP
    Element request = new Element.JSONElement(MailConstants.SAVE_DRAFT_REQUEST);
    Element m = request.addNonUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.E_SUBJECT, "dinner appt");
    m.addUniqueElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, ORIGINAL_CONTENT);
    Element response = new SaveDraft() {

        @Override
        protected Element generateResponse(ZimbraSoapContext zsc, ItemIdFormatter ifmt, OperationContext octxt, Mailbox mbox, Message msg, boolean wantImapUid, boolean wantModSeq) {
            // trigger the failure case by re-saving the draft before it's serialized out
            Message snapshotMsg = msg;
            try {
                snapshotMsg = (Message) msg.snapshotItem();
                MimeMessage mm = new MimeMessage(JMSession.getSession());
                mm.setText(MODIFIED_CONTENT);
                mm.saveChanges();
                mbox.saveDraft(null, new ParsedMessage(mm, false), snapshotMsg.getId());
            } catch (Exception e) {
                return null;
            }
            return super.generateResponse(zsc, ifmt, octxt, mbox, snapshotMsg, wantImapUid, wantModSeq);
        }
    }.handle(request, ServiceTestUtil.getRequestContext(acct));
    // make sure the response has the correct message content
    Assert.assertEquals("picked up modified content", MODIFIED_CONTENT, response.getElement(MailConstants.E_MSG).getElement(MailConstants.E_MIMEPART).getAttribute(MailConstants.E_CONTENT));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Element(com.zimbra.common.soap.Element) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Test(org.junit.Test)

Example 5 with ItemIdFormatter

use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.

the class CreateContact method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
    boolean verbose = request.getAttributeBool(MailConstants.A_VERBOSE, true);
    boolean wantImapUid = request.getAttributeBool(MailConstants.A_WANT_IMAP_UID, false);
    boolean wantModSeq = request.getAttributeBool(MailConstants.A_WANT_MODIFIED_SEQUENCE, false);
    Element cn = request.getElement(MailConstants.E_CONTACT);
    ItemId iidFolder = new ItemId(cn.getAttribute(MailConstants.A_FOLDER, DEFAULT_FOLDER), zsc);
    String[] tags = TagUtil.parseTags(cn, mbox, octxt);
    Element vcard = cn.getOptionalElement(MailConstants.E_VCARD);
    List<ParsedContact> pclist;
    if (vcard != null) {
        pclist = parseAttachedVCard(zsc, octxt, mbox, vcard);
    } else {
        pclist = new ArrayList<ParsedContact>(1);
        Pair<Map<String, Object>, List<Attachment>> cdata = parseContact(cn, zsc, octxt);
        pclist.add(new ParsedContact(cdata.getFirst(), cdata.getSecond()));
    }
    if (needToMigrateDlist(zsc)) {
        for (ParsedContact pc : pclist) {
            migrateFromDlist(pc);
        }
    }
    List<Contact> contacts = createContacts(octxt, mbox, iidFolder, pclist, tags);
    Contact con = null;
    if (contacts.size() > 0)
        con = contacts.get(0);
    Element response = zsc.createElement(MailConstants.CREATE_CONTACT_RESPONSE);
    if (con != null) {
        if (verbose) {
            int fields = ToXML.NOTIFY_FIELDS;
            if (wantImapUid) {
                fields |= Change.IMAP_UID;
            }
            if (wantModSeq) {
                fields |= Change.MODSEQ;
            }
            ToXML.encodeContact(response, ifmt, octxt, con, (ContactGroup) null, (Collection<String>) null, /* memberAttrFilter */
            true, /* summary */
            (Collection<String>) null, /* attrFilter */
            fields, (String) null, /* migratedDList */
            false, /* returnHiddenAttrs */
            GetContacts.NO_LIMIT_MAX_MEMBERS, true);
        } else {
            Element contct = response.addNonUniqueElement(MailConstants.E_CONTACT);
            contct.addAttribute(MailConstants.A_ID, con.getId());
            if (wantImapUid) {
                contct.addAttribute(MailConstants.A_IMAP_UID, con.getImapUid());
            }
            if (wantModSeq) {
                contct.addAttribute(MailConstants.A_MODIFIED_SEQUENCE, con.getModifiedSequence());
            }
        }
    }
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Element(com.zimbra.common.soap.Element) ItemId(com.zimbra.cs.service.util.ItemId) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact) ParsedContact(com.zimbra.cs.mime.ParsedContact) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)63 Element (com.zimbra.common.soap.Element)56 Mailbox (com.zimbra.cs.mailbox.Mailbox)47 OperationContext (com.zimbra.cs.mailbox.OperationContext)45 ItemId (com.zimbra.cs.service.util.ItemId)43 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)43 Account (com.zimbra.cs.account.Account)22 ServiceException (com.zimbra.common.service.ServiceException)16 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)14 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)11 Folder (com.zimbra.cs.mailbox.Folder)11 Message (com.zimbra.cs.mailbox.Message)11 MailItem (com.zimbra.cs.mailbox.MailItem)10 HashMap (java.util.HashMap)10 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)8 IOException (java.io.IOException)8 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)7 ArrayList (java.util.ArrayList)7 MessagingException (javax.mail.MessagingException)7 MimeMessage (javax.mail.internet.MimeMessage)7