Search in sources :

Example 91 with ZMessage

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

the class TestBug89152 method testMessagesWithDifferentTimestamps.

@Test
public void testMessagesWithDifferentTimestamps() {
    try {
        int numMessages = 2207;
        int firstLimit = 100;
        int incLimit = 50;
        int offset = 0;
        Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT1);
        long timestamp = System.currentTimeMillis() - 3600 * 60 * 1000;
        byte[] msgBytes = Files.readAllBytes(FileSystems.getDefault().getPath(TEST_MESSAGE_FILE));
        for (int i = 0; i < numMessages; i++) {
            ParsedMessage pm = new ParsedMessage(msgBytes, timestamp, true);
            Message msg = TestUtil.addMessage(recieverMbox, pm);
            timestamp += 1001;
        //Thread.sleep(300);
        }
        Thread.sleep(150);
        ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT1);
        ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
        searchParams.setSortBy(SearchSortBy.dateDesc);
        searchParams.setLimit(firstLimit);
        searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
        List<ZMessage> resultSet = TestUtil.search(zmbx, searchParams);
        assertEquals(firstLimit, resultSet.size());
        int gotMessages = resultSet.size();
        List<String> seenIds = new ArrayList<String>();
        ZMessage lastHit = null;
        for (ZMessage m : resultSet) {
            seenIds.add(m.getId());
            lastHit = m;
        }
        int recCount = 1;
        offset += firstLimit;
        while (gotMessages > 0) {
            searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
            searchParams.setCursor((new Cursor(lastHit.getId(), Long.toString(lastHit.getReceivedDate()))));
            searchParams.setSortBy(SearchSortBy.dateDesc);
            searchParams.setLimit(incLimit);
            searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
            searchParams.setOffset(offset);
            resultSet = TestUtil.search(zmbx, searchParams);
            recCount++;
            gotMessages = resultSet.size();
            int resCount = 0;
            for (ZMessage m : resultSet) {
                assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, m.getId(), seenIds.indexOf(m.getId())), seenIds.contains(m.getId()));
                seenIds.add(m.getId());
                resCount++;
                lastHit = m;
            }
            Thread.sleep(300);
            offset += incLimit;
        }
        assertEquals("expecting " + numMessages + " messages. Got " + seenIds.size(), numMessages, seenIds.size());
    } catch (ServiceException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMessage(com.zimbra.client.ZMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ArrayList(java.util.ArrayList) Cursor(com.zimbra.client.ZSearchParams.Cursor) ServiceException(com.zimbra.common.service.ServiceException) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) ZSearchParams(com.zimbra.client.ZSearchParams) Test(org.junit.Test)

Example 92 with ZMessage

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

the class TestJaxb method testProposeNewTimeWorkflow.

/**
     * Bug 96748:
     * 1. user1 sends meeting invite to user2
     * 2. user2 proposes new time
     * 3. user1 accepts the proposed new time and new invite is sent to user2
     * 4. user2 accepts the new invite
     * At step 4, no acceptance message was being generated
     */
@Test
public void testProposeNewTimeWorkflow() throws Exception {
    TestUtil.createAccount(ORGANIZER);
    TestUtil.createAccount(ATTENDEE1);
    String subject = NAME_PREFIX + " attendee will cause time to change";
    ZMailbox organizerBox = TestUtil.getZMailbox(ORGANIZER);
    ZMailbox attendeeBox = TestUtil.getZMailbox(ATTENDEE1);
    String organizerEmail = organizerBox.getName();
    // Create and send the meeting request
    InviteComponent inviteComp = new InviteComponent();
    inviteComp.addAttendee(CalendarAttendee.createForAddressDisplaynameRolePartstatRsvp(attendeeBox.getName(), getCN(attendeeBox), "REQ", "NE", true));
    inviteComp.setStatus("CONF");
    inviteComp.setFreeBusy("B");
    inviteComp.setCalClass("PUB");
    inviteComp.setTransparency("O");
    inviteComp.setIsDraft(false);
    inviteComp.setIsAllDay(false);
    Date startDate = new Date(System.currentTimeMillis() + Constants.MILLIS_PER_DAY);
    ZDateTime start = new ZDateTime(startDate.getTime(), false, organizerBox.getPrefs().getTimeZone());
    Date endDate = new Date(startDate.getTime() + Constants.MILLIS_PER_HOUR);
    ZDateTime end = new ZDateTime(endDate.getTime(), false, organizerBox.getPrefs().getTimeZone());
    Date newStartDate = new Date(System.currentTimeMillis() + 2 * Constants.MILLIS_PER_DAY);
    ZDateTime newStart = new ZDateTime(newStartDate.getTime(), false, organizerBox.getPrefs().getTimeZone());
    Date newEndDate = new Date(newStartDate.getTime() + Constants.MILLIS_PER_HOUR);
    ZDateTime newEnd = new ZDateTime(newEndDate.getTime(), false, organizerBox.getPrefs().getTimeZone());
    inviteComp.setDtStart(DtTimeInfo.createForDatetimeAndZone(start.getDateTime(), start.getTimeZoneId()));
    inviteComp.setDtEnd(DtTimeInfo.createForDatetimeAndZone(end.getDateTime(), end.getTimeZoneId()));
    inviteComp.setName(subject);
    inviteComp.setLocation("room 101");
    inviteComp.setOrganizer(CalOrganizer.createForAddress(organizerEmail));
    InvitationInfo invite = new InvitationInfo();
    invite.setInviteComponent(inviteComp);
    EmailAddrInfo attendeeAddr = EmailAddrInfo.createForAddressPersonalAndAddressType(attendeeBox.getName(), getCN(attendeeBox), "t");
    MimePartInfo mimePart = MimePartInfo.createForContentType("multipart/alternative");
    mimePart.addMimePart(MimePartInfo.createForContentTypeAndContent("text/plain", "invite body"));
    mimePart.addMimePart(MimePartInfo.createForContentTypeAndContent("text/html", "<html><body><p><b>invite</b> body</p></body></html>"));
    Msg msg = new Msg();
    msg.setFolderId("10");
    msg.setInvite(invite);
    msg.addEmailAddress(attendeeAddr);
    msg.setSubject(subject);
    msg.setMimePart(mimePart);
    CreateAppointmentRequest createApptReq = CreateAppointmentRequest.create(msg);
    CreateAppointmentResponse caResp = organizerBox.invokeJaxb(createApptReq);
    Assert.assertNotNull("JAXB CreateAppointmentResponse object", caResp);
    Assert.assertNotNull("JAXB CreateAppointmentResponse calItemId", caResp.getCalItemId());
    Assert.assertNotNull("JAXB CreateAppointmentResponse invId", caResp.getCalInvId());
    Assert.assertNotNull("JAXB CreateAppointmentResponse modified sequence ms", caResp.getModifiedSequence());
    Assert.assertNotNull("JAXB CreateAppointmentResponse rev", caResp.getRevision());
    ZMessage seriesInviteMsg = TestUtil.waitForMessage(attendeeBox, subject);
    Assert.assertNotNull("ZMessage for series invite", seriesInviteMsg);
    ZInvite seriesInvite = seriesInviteMsg.getInvite();
    Assert.assertNotNull("ZInvite for series invite", seriesInvite);
    AppointmentHitInfo hit = findMatchingAppointment(attendeeBox, startDate, endDate, subject);
    // User 1 proposes new time for meeting
    ZMessage propNewTimeMsg = attendeeProposeNewTimeForMeeting(attendeeBox, organizerBox, newStart, newEnd, hit, subject);
    Assert.assertNotNull("ZMessage for propose new time", propNewTimeMsg);
    hit = findMatchingAppointment(organizerBox, startDate, endDate, subject);
    // Organizer changes the meeting to the new proposed time
    // easier to find unique inbox entry
    subject = NAME_PREFIX + " attendee CAUSED time to change";
    ZMessage attendee2ndInvite = organizerChangeTimeForMeeting(attendeeBox, organizerBox, newStart, newEnd, hit, subject);
    Assert.assertNotNull("attendee 2nd invite", attendee2ndInvite);
    hit = findMatchingAppointment(attendeeBox, newStartDate, newEndDate, "inid:10");
    acceptInvite(attendeeBox, organizerBox, attendee2ndInvite, subject);
}
Also used : Msg(com.zimbra.soap.mail.type.Msg) ZMessage(com.zimbra.client.ZMessage) CreateAppointmentRequest(com.zimbra.soap.mail.message.CreateAppointmentRequest) ZInvite(com.zimbra.client.ZInvite) InvitationInfo(com.zimbra.soap.mail.type.InvitationInfo) CreateAppointmentResponse(com.zimbra.soap.mail.message.CreateAppointmentResponse) AppointmentHitInfo(com.zimbra.soap.mail.type.AppointmentHitInfo) Date(java.util.Date) InviteComponent(com.zimbra.soap.mail.type.InviteComponent) ZDateTime(com.zimbra.client.ZDateTime) ZMailbox(com.zimbra.client.ZMailbox) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) MimePartInfo(com.zimbra.soap.mail.type.MimePartInfo) Test(org.junit.Test)

Example 93 with ZMessage

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

the class TestInvite method testBug86864DelegateInboxInviteLooksLikeInvite.

public void testBug86864DelegateInboxInviteLooksLikeInvite() throws Exception {
    TestUtil.createAccount(ORGANIZER);
    Account attendee = TestUtil.createAccount(ATTENDEE);
    Account delegate = TestUtil.createAccount(DELEGATE);
    ZMailbox mboxOrganizer = TestUtil.getZMailbox(ORGANIZER);
    ZMailbox mboxAttendee = TestUtil.getZMailbox(ATTENDEE);
    ZMailbox mboxDelegate = TestUtil.getZMailbox(DELEGATE);
    String subject = NAME_PREFIX + " for testing treatment at delegate inbox";
    Date startDate = new Date(System.currentTimeMillis() + Constants.MILLIS_PER_DAY);
    Date endDate = new Date(startDate.getTime() + Constants.MILLIS_PER_HOUR);
    String calendarId = Integer.valueOf(Mailbox.ID_FOLDER_CALENDAR).toString();
    FolderActionSelector action = new FolderActionSelector(calendarId, /* id */
    "grant");
    ActionGrantSelector grant = new ActionGrantSelector("rwidxa", /* perm */
    "usr");
    grant.setDisplayName(delegate.getName());
    grant.setPassword("");
    action.setGrant(grant);
    FolderActionRequest folderActionReq = new FolderActionRequest(action);
    FolderActionResponse folderActionResp = mboxAttendee.invokeJaxb(folderActionReq);
    assertNotNull("null FolderAction Response used to share folder", folderActionResp);
    ModifyPrefsRequest modPrefsReq = new ModifyPrefsRequest();
    Pref fwdInvitesPref = Pref.createPrefWithNameAndValue(ZAttrProvisioning.A_zimbraPrefCalendarForwardInvitesTo, delegate.getName());
    modPrefsReq.addPref(fwdInvitesPref);
    Pref noAutoAddPref = Pref.createPrefWithNameAndValue(ZAttrProvisioning.A_zimbraPrefCalendarAutoAddInvites, Boolean.FALSE.toString().toUpperCase());
    modPrefsReq.addPref(noAutoAddPref);
    ModifyPrefsResponse modPrefsResp = mboxAttendee.invokeJaxb(modPrefsReq);
    assertNotNull("null ModifyPrefs Response for forwarding calendar invites/no auto-add", modPrefsResp);
    NewMountpointSpec mpSpec = new NewMountpointSpec("Shared Calendar");
    mpSpec.setFlags("#");
    mpSpec.setRemoteId(Mailbox.ID_FOLDER_CALENDAR);
    mpSpec.setColor((byte) 4);
    mpSpec.setOwnerId(attendee.getId());
    mpSpec.setFolderId(Integer.valueOf(Mailbox.ID_FOLDER_USER_ROOT).toString());
    mpSpec.setDefaultView(MailItem.Type.APPOINTMENT.toString());
    CreateMountpointRequest createMpReq = new CreateMountpointRequest(mpSpec);
    CreateMountpointResponse createMpResp = mboxDelegate.invokeJaxb(createMpReq);
    assertNotNull("null ModifyPrefs Response for forwarding calendar invites", createMpResp);
    TestUtil.createAppointment(mboxOrganizer, subject, attendee.getName(), startDate, endDate);
    ZMessage inviteMsg = TestUtil.waitForMessage(mboxDelegate, "in:inbox " + subject);
    assertNotNull("null inviteMsg in delegate inbox", inviteMsg);
    MsgSpec msgSpec = new MsgSpec(inviteMsg.getId());
    msgSpec.setWantHtml(true);
    msgSpec.setNeedCanExpand(true);
    msgSpec.setMaxInlinedLength(250000);
    GetMsgRequest getMsgReq = new GetMsgRequest(msgSpec);
    GetMsgResponse getMsgResp = mboxDelegate.invokeJaxb(getMsgReq);
    assertNotNull("null GetMsgResponse in delegate inbox", getMsgResp);
    MsgWithGroupInfo msg = getMsgResp.getMsg();
    assertNotNull("null message in GetMsgResponse in delegate inbox", msg);
    InviteWithGroupInfo invite = msg.getInvite();
    assertNotNull("null invite in message in GetMsgResponse in delegate inbox regression to Bug 86864?", invite);
}
Also used : ZMessage(com.zimbra.client.ZMessage) Account(com.zimbra.cs.account.Account) CreateMountpointRequest(com.zimbra.soap.mail.message.CreateMountpointRequest) Pref(com.zimbra.soap.account.type.Pref) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse) GetMsgRequest(com.zimbra.soap.mail.message.GetMsgRequest) InviteWithGroupInfo(com.zimbra.soap.mail.type.InviteWithGroupInfo) ModifyPrefsRequest(com.zimbra.soap.account.message.ModifyPrefsRequest) MsgSpec(com.zimbra.soap.mail.type.MsgSpec) Date(java.util.Date) ActionGrantSelector(com.zimbra.soap.mail.type.ActionGrantSelector) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) CreateMountpointResponse(com.zimbra.soap.mail.message.CreateMountpointResponse) ZMailbox(com.zimbra.client.ZMailbox) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) MsgWithGroupInfo(com.zimbra.soap.mail.type.MsgWithGroupInfo) GetMsgResponse(com.zimbra.soap.mail.message.GetMsgResponse) ModifyPrefsResponse(com.zimbra.soap.account.message.ModifyPrefsResponse) NewMountpointSpec(com.zimbra.soap.mail.type.NewMountpointSpec)

Example 94 with ZMessage

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

the class TestLmtp method testSizeHint.

/**
     * Confirms that a message gets delivered regardless of what the size hint is set to.
     */
@Test
public void testSizeHint() throws Exception {
    // Send the same message 5 times with different size hints
    String address = TestUtil.getAddress(USER_NAME);
    String subject = NAME_PREFIX + " testIncorrectSizeHint";
    String messageString = TestUtil.getTestMessage(subject, address, address, null);
    String[] recipients = new String[] { address };
    LmtpClient lmtp = new LmtpClient("localhost", 7025);
    byte[] data = messageString.getBytes();
    lmtp.sendMessage(new ByteArrayInputStream(data), recipients, address, "TestLmtp", null);
    lmtp.sendMessage(new ByteArrayInputStream(data), recipients, address, "TestLmtp", 0L);
    lmtp.sendMessage(new ByteArrayInputStream(data), recipients, address, "TestLmtp", 10L);
    lmtp.sendMessage(new ByteArrayInputStream(data), recipients, address, "TestLmtp", (long) data.length);
    lmtp.sendMessage(new ByteArrayInputStream(data), recipients, address, "TestLmtp", (long) Integer.MAX_VALUE);
    lmtp.close();
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    List<ZMessage> messages = TestUtil.search(mbox, subject);
    Assert.assertEquals(5, messages.size());
    // Check message bodies
    ZGetMessageParams params = new ZGetMessageParams();
    params.setRawContent(true);
    for (ZMessage msg : messages) {
        String content = TestUtil.getContent(mbox, msg.getId());
        TestUtil.assertMessageContains(content, messageString);
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) LmtpClient(com.zimbra.common.lmtp.LmtpClient) ZMailbox(com.zimbra.client.ZMailbox) ZGetMessageParams(com.zimbra.client.ZGetMessageParams) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 95 with ZMessage

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

the class TestDataSource method testRss.

/**
     * Creates a folder that syncs to another folder via RSS, and verifies that an
     * RSS data source was implicitly created.
     */
@Test
public void testRss() throws Exception {
    // Create source folder, make it publicly readable, and add a message to it.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String parentId = Integer.toString(Mailbox.ID_FOLDER_USER_ROOT);
    ZFolder sourceFolder = TestUtil.createFolder(mbox, "/" + NAME_PREFIX + " testRss source");
    mbox.modifyFolderGrant(sourceFolder.getId(), GranteeType.pub, null, "r", null);
    String subject = NAME_PREFIX + " testRss";
    TestUtil.addMessage(mbox, subject, sourceFolder.getId());
    // Create destination folder that syncs to the source folder via RSS.
    String urlString = String.format("https://%s:%s/home/%s%s.rss", TestUtil.getServerAttr(Provisioning.A_zimbraServiceHostname), TestUtil.getServerAttr(Provisioning.A_zimbraMailSSLPort), USER_NAME, sourceFolder.getPath());
    urlString = HttpUtil.encodePath(urlString);
    ZFolder rssFolder = mbox.createFolder(parentId, NAME_PREFIX + " testRss destination", null, null, null, urlString);
    // Get the data source that was implicitly created.
    ZRssDataSource ds = (ZRssDataSource) getDataSource(mbox, rssFolder.getId());
    assertNotNull(ds);
    assertNull(mbox.testDataSource(ds));
    // Import data and validate the synced message.
    List<ZDataSource> list = new ArrayList<ZDataSource>();
    list.add(ds);
    mbox.importData(list);
    waitForData(mbox, rssFolder);
    ZMessage syncedMsg = TestUtil.getMessage(mbox, "in:\"" + rssFolder.getPath() + "\"");
    assertEquals(subject, syncedMsg.getSubject());
    /*
         *   Bug 102261 - simulate ZWC deleting an item from the folder
         */
    ConvActionSelector sel = ConvActionSelector.createForIdsAndOperation(syncedMsg.getConversationId(), "trash");
    sel.setConstraint("-dtjs");
    sel.setFolder(syncedMsg.getFolderId());
    try {
        mbox.invokeJaxb(new ConvActionRequest(sel));
    } catch (SoapFaultException sfe) {
        fail("SoapFaultException caught when deleting item from RSS datasource folder - " + sfe.getMessage());
    }
    // Delete folder, import data, and make sure that the data source was deleted.
    // Data source import runs asynchronously, so poll until the data source is gone.
    mbox.deleteFolder(rssFolder.getId());
//JBF - do not do the import; it will fail if DS is already deleted
//mbox.importData(list);
// XXX bburtin: disabled check to avoid false positives (bug 54816).  Some sort
// of race condition is causing this check to fail intermittently.  I was unable
// to consistently repro.
/*
        for (int i = 1; i <= 10; i++) {
            ds = (ZRssDataSource) getDataSource(mbox, rssFolder.getId());
            if (ds == null) {
                break;
            }
            Thread.sleep(500);
        }
        assertNull(ds);
        */
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ConvActionSelector(com.zimbra.soap.mail.type.ConvActionSelector) ConvActionRequest(com.zimbra.soap.mail.message.ConvActionRequest) ArrayList(java.util.ArrayList) ZRssDataSource(com.zimbra.client.ZRssDataSource) ZFolder(com.zimbra.client.ZFolder) ZDataSource(com.zimbra.client.ZDataSource) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Aggregations

ZMessage (com.zimbra.client.ZMessage)101 Test (org.junit.Test)63 ZMailbox (com.zimbra.client.ZMailbox)59 ArrayList (java.util.ArrayList)43 ZFilterRule (com.zimbra.client.ZFilterRule)29 ZFilterAction (com.zimbra.client.ZFilterAction)28 ZFilterCondition (com.zimbra.client.ZFilterCondition)28 ZFilterRules (com.zimbra.client.ZFilterRules)28 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)12 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)12 ZEmailAddress (com.zimbra.client.ZEmailAddress)11 ZTagAction (com.zimbra.client.ZFilterAction.ZTagAction)10 ZFolder (com.zimbra.client.ZFolder)10 ZMarkAction (com.zimbra.client.ZFilterAction.ZMarkAction)8 Account (com.zimbra.cs.account.Account)8 MessagePart (com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart)7 Date (java.util.Date)7 ZGetMessageParams (com.zimbra.client.ZGetMessageParams)5 ZMimePart (com.zimbra.client.ZMessage.ZMimePart)5 ZTag (com.zimbra.client.ZTag)5