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());
}
}
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);
}
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);
}
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);
}
}
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);
*/
}
Aggregations