use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestCalDav method testAppleCaldavProxyFunctions.
/**
* http://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk/doc/Extensions/caldav-proxy.txt
* This is an Apple standard implemented by Apple Mac OSX at least up to Yosemite and offers a fairly simple
* sharing model for calendars. The model is simpler than Zimbra's native model and there are mismatches,
* for instance Zimbra requires the proposed delegate to accept shares.
*/
@Test
public void testAppleCaldavProxyFunctions() throws ServiceException, IOException {
Account sharer = users[3].create();
Account sharee1 = users[1].create();
Account sharee2 = users[2].create();
ZMailbox mboxSharer = TestUtil.getZMailbox(sharer.getName());
ZMailbox mboxSharee1 = TestUtil.getZMailbox(sharee1.getName());
ZMailbox mboxSharee2 = TestUtil.getZMailbox(sharee2.getName());
setZimbraPrefAppleIcalDelegationEnabled(mboxSharer, true);
setZimbraPrefAppleIcalDelegationEnabled(mboxSharee1, true);
setZimbraPrefAppleIcalDelegationEnabled(mboxSharee2, true);
// Test PROPPATCH to "calendar-proxy-read" URL
setGroupMemberSet(TestCalDav.getCalendarProxyReadUrl(sharer), sharer, sharee2);
// Test PROPPATCH to "calendar-proxy-write" URL
setGroupMemberSet(TestCalDav.getCalendarProxyWriteUrl(sharer), sharer, sharee1);
// verify that adding new members to groups triggered notification messages
List<ZMessage> msgs = TestUtil.waitForMessages(mboxSharee1, "in:inbox subject:\"Share Created: Calendar shared by \"", 1, 10000);
assertNotNull(String.format("Notification msgs for %s", sharee1.getName()), msgs);
assertEquals(String.format("num msgs for %s", sharee1.getName()), 1, msgs.size());
msgs = TestUtil.waitForMessages(mboxSharee2, "in:inbox subject:\"Share Created: Calendar shared by \"", 1, 10000);
assertNotNull(String.format("Notification msgs for %s", sharee2.getName()), msgs);
assertEquals(String.format("num msgs for %s", sharee2.getName()), 1, msgs.size());
// Simulate acceptance of the shares (would normally need to be done in ZWC
createCalendarMountPoint(mboxSharee1, sharer);
createCalendarMountPoint(mboxSharee2, sharer);
Document doc = delegateForExpandProperty(sharee1);
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(TestCalDav.NamespaceContextForXPath.forCalDAV());
XPathExpression xPathExpr;
try {
String xpathS = "/D:multistatus/D:response/D:href/text()";
xPathExpr = xpath.compile(xpathS);
NodeList result = (NodeList) xPathExpr.evaluate(doc, XPathConstants.NODESET);
assertEquals(String.format("num XPath nodes for %s for %s", xpathS, sharee1.getName()), 1, result.getLength());
String text = (String) xPathExpr.evaluate(doc, XPathConstants.STRING);
assertEquals("HREF for account owner", UrlNamespace.getPrincipalUrl(sharee1).replaceAll("@", "%40"), text);
xpathS = "/D:multistatus/D:response/D:propstat/D:prop/CS:calendar-proxy-write-for/D:response/D:href/text()";
xPathExpr = xpath.compile(xpathS);
result = (NodeList) xPathExpr.evaluate(doc, XPathConstants.NODESET);
assertEquals(String.format("num XPath nodes for %s for %s", xpathS, sharee1.getName()), 1, result.getLength());
text = (String) xPathExpr.evaluate(doc, XPathConstants.STRING);
assertEquals("HREF for sharer", UrlNamespace.getPrincipalUrl(sharer).replaceAll("@", "%40"), text);
} catch (XPathExpressionException e1) {
ZimbraLog.test.debug("xpath problem", e1);
}
// Check that proxy write has sharee1 in it
doc = groupMemberSetExpandProperty(sharer, sharee1, true);
// Check that proxy read has sharee2 in it
doc = groupMemberSetExpandProperty(sharer, sharee2, false);
String davBaseName = "notAllowed@There";
String url = String.format("%s%s", getFolderUrl(sharee1, "Shared Calendar").replaceAll(" ", "%20").replaceAll("@", "%40"), davBaseName);
HttpMethodExecutor exe = doIcalPut(url, sharee1, simpleEvent(sharer), HttpStatus.SC_MOVED_TEMPORARILY);
String location = null;
for (Header hdr : exe.respHeaders) {
if ("Location".equals(hdr.getName())) {
location = hdr.getValue();
}
}
assertNotNull("Location Header not returned when creating", location);
url = String.format("%s%s", getFolderUrl(sharee1, "Shared Calendar").replaceAll(" ", "%20").replaceAll("@", "%40"), location.substring(location.lastIndexOf('/') + 1));
doIcalPut(url, sharee1, simpleEvent(sharer), HttpStatus.SC_CREATED);
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestSaveDraft method testIdentityId.
/**
* Confirms that we update the identity id during a SaveDraft operation (bug 60066).
*/
@Test
public void testIdentityId() throws Exception {
TestUtil.createAccount(USER_NAME);
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
// Save initial draft.
ZOutgoingMessage outgoing = TestUtil.getOutgoingMessage(USER_NAME, NAME_PREFIX + " testIdentityId", "testIdentityId", null);
ZIdentity ident = TestUtil.getDefaultIdentity(mbox);
outgoing.setIdentityId(ident.getId());
ZMessage msg = mbox.saveDraft(outgoing, null, Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
Assert.assertEquals(ident.getId(), msg.getIdentityId());
// Save another draft with a new identity id.
outgoing.setIdentityId("xyz");
msg = mbox.saveDraft(outgoing, msg.getId(), Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
Assert.assertEquals("xyz", msg.getIdentityId());
// Unset identity id.
outgoing.setIdentityId("");
msg = mbox.saveDraft(outgoing, msg.getId(), Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
Assert.assertEquals(null, msg.getIdentityId());
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestNewMailNotification method testUtf8.
/**
* Confirms that the subject and body of the out of office and new mail
* notification can contain UTF-8 characters.
*
* @throws Exception
*/
public void testUtf8() throws Exception {
String NEW_MAIL_SUBJECT = // Krokodil
NAME_PREFIX + " Крокодил";
String NEW_MAIL_BODY = // Cherepaha
NAME_PREFIX + " Черепаха";
String OUT_OF_OFFICE_SUBJECT = // Obezyana
NAME_PREFIX + " Обезьяна";
String OUT_OF_OFFICE_BODY = // Jiraf
NAME_PREFIX + " Жираф";
// Turn on auto-reply and notification
Account recipientAcct = TestUtil.getAccount(MESSAGE_RECIPIENT);
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraPrefOutOfOfficeReplyEnabled, ProvisioningConstants.TRUE);
attrs.put(Provisioning.A_zimbraPrefOutOfOfficeReply, OUT_OF_OFFICE_BODY);
attrs.put(Provisioning.A_zimbraPrefNewMailNotificationEnabled, ProvisioningConstants.TRUE);
attrs.put(Provisioning.A_zimbraPrefNewMailNotificationAddress, TestUtil.getAddress(NOTIFICATION_RECIPIENT));
attrs.put(Provisioning.A_zimbraNewMailNotificationSubject, NEW_MAIL_SUBJECT);
attrs.put(Provisioning.A_zimbraNewMailNotificationBody, NEW_MAIL_BODY);
Provisioning.getInstance().modifyAttrs(recipientAcct, attrs);
ZMailbox notificationMbox = TestUtil.getZMailbox(NOTIFICATION_RECIPIENT);
ZMailbox recipientMbox = TestUtil.getZMailbox(MESSAGE_RECIPIENT);
ZMailbox senderMbox = TestUtil.getZMailbox(MESSAGE_SENDER);
// Send the message
TestUtil.sendMessage(senderMbox, MESSAGE_RECIPIENT, OUT_OF_OFFICE_SUBJECT, "testing");
// Make sure the recipient received it
TestUtil.waitForMessage(recipientMbox, "in:inbox subject:" + OUT_OF_OFFICE_SUBJECT);
// Check for out-of-office
TestUtil.waitForMessage(senderMbox, "in:inbox subject:" + OUT_OF_OFFICE_SUBJECT);
List<ZMessage> messages = TestUtil.search(senderMbox, "in:inbox content:" + OUT_OF_OFFICE_BODY);
assertEquals("Out-of-office body not found", 1, messages.size());
// Check for new mail notification
TestUtil.waitForMessage(notificationMbox, "in:inbox subject:" + NEW_MAIL_SUBJECT);
messages = TestUtil.search(notificationMbox, "in:inbox content:" + NEW_MAIL_BODY);
assertEquals("New mail notification body not found", 1, messages.size());
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestNewMailNotification method testNotificationSubjBodyFrom.
/**
* Verify that when zimbraNewMailNotificationMessage is set it overwrites
* zimbraNewMailNotificationBody, zimbraNewMailNotificationSubject and
* zimbraNewMailNotificationFrom
* @throws Exception
*/
public void testNotificationSubjBodyFrom() throws Exception {
String notificationSubject = "Even old New York was once New Amsterdam";
String notificationBody = "On ne passe pas";
String messageSubject = "Istanbul was Constantinople";
String messageBody = "Now it's Istanbul, not Constantinople";
String notifierAddress = "che@burashka.com";
Account recipientAcct = TestUtil.getAccount(MESSAGE_RECIPIENT);
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraPrefNewMailNotificationEnabled, ProvisioningConstants.TRUE);
attrs.put(Provisioning.A_zimbraPrefNewMailNotificationAddress, TestUtil.getAddress(NOTIFICATION_RECIPIENT));
attrs.put(Provisioning.A_zimbraNewMailNotificationSubject, notificationSubject);
attrs.put(Provisioning.A_zimbraNewMailNotificationBody, notificationBody);
attrs.put(Provisioning.A_zimbraNewMailNotificationFrom, notifierAddress);
Provisioning.getInstance().modifyAttrs(recipientAcct, attrs);
ZMailbox notificationMbox = TestUtil.getZMailbox(NOTIFICATION_RECIPIENT);
ZMailbox recipientMbox = TestUtil.getZMailbox(MESSAGE_RECIPIENT);
ZMailbox senderMbox = TestUtil.getZMailbox(MESSAGE_SENDER);
// Send the message
TestUtil.sendMessage(senderMbox, MESSAGE_RECIPIENT, messageSubject, messageBody);
// Make sure the recipient received it
TestUtil.waitForMessage(recipientMbox, "in:inbox subject:'" + messageSubject + "'");
// Check for new mail notification
TestUtil.waitForMessage(notificationMbox, "in:inbox subject:'" + notificationSubject + "'");
List<ZMessage> messages = TestUtil.search(notificationMbox, "in:inbox content:'" + notificationBody + "'");
assertEquals("found new mail notification with wrong body", 1, messages.size());
messages = TestUtil.search(notificationMbox, "in:inbox subject:'" + notificationSubject + "'");
assertEquals("found new mail notification with wrong subject", 1, messages.size());
messages = TestUtil.search(notificationMbox, "in:inbox from:" + notifierAddress);
assertEquals("found new mail notification with wrong sender", 1, messages.size());
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestNewMailNotification method testNotificationMessageOverwrite.
/**
* Verify that when zimbraNewMailNotificationMessage is set it overwrites
* zimbraNewMailNotificationBody, zimbraNewMailNotificationSubject and
* zimbraNewMailNotificationFrom
* @throws Exception
*/
public void testNotificationMessageOverwrite() throws Exception {
String notificationTemplate = "From: Postmaster <postmaster@${RECIPIENT_DOMAIN}>${NEWLINE}To: <${RECIPIENT_ADDRESS}>${NEWLINE}Subject: New message received at ${RECIPIENT_ADDRESS}${NEWLINE}Date: ${DATE}${NEWLINE}Content-Type: text/plain${NEWLINE}${NEWLINE}New message received at ${RECIPIENT_ADDRESS}.${NEWLINE}Sender: ${SENDER_ADDRESS}${NEWLINE}Subject: ${SUBJECT}";
String notificationSubject = "Even old New York was once New Amsterdam";
String notificationBody = "On ne passe pas";
String messageSubject = "Istanbul was Constantinople";
String messageBody = "Now it's Istanbul, not Constantinople";
String notifierAddress = "che@burashka.com";
Account recipientAcct = TestUtil.getAccount(MESSAGE_RECIPIENT);
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraPrefNewMailNotificationEnabled, ProvisioningConstants.TRUE);
attrs.put(Provisioning.A_zimbraPrefNewMailNotificationAddress, TestUtil.getAddress(NOTIFICATION_RECIPIENT));
attrs.put(Provisioning.A_zimbraNewMailNotificationSubject, notificationSubject);
attrs.put(Provisioning.A_zimbraNewMailNotificationBody, notificationBody);
attrs.put(Provisioning.A_zimbraNewMailNotificationMessage, notificationTemplate);
attrs.put(Provisioning.A_zimbraNewMailNotificationFrom, notifierAddress);
Provisioning.getInstance().modifyAttrs(recipientAcct, attrs);
ZMailbox notificationMbox = TestUtil.getZMailbox(NOTIFICATION_RECIPIENT);
ZMailbox recipientMbox = TestUtil.getZMailbox(MESSAGE_RECIPIENT);
ZMailbox senderMbox = TestUtil.getZMailbox(MESSAGE_SENDER);
// Send the message
TestUtil.sendMessage(senderMbox, MESSAGE_RECIPIENT, messageSubject, messageBody);
// Make sure the recipient received it
TestUtil.waitForMessage(recipientMbox, "in:inbox subject:'" + messageSubject + "'");
// Check for new mail notification
TestUtil.waitForMessage(notificationMbox, "in:inbox subject: New message received at " + TestUtil.getAddress(MESSAGE_RECIPIENT));
List<ZMessage> messages = TestUtil.search(notificationMbox, "in:inbox content: New message received at " + TestUtil.getAddress(MESSAGE_RECIPIENT));
assertEquals("New mail notification body not found", 1, messages.size());
messages = TestUtil.search(notificationMbox, "in:inbox content:'" + notificationBody + "'");
assertEquals("found new mail notification with wrong body", 0, messages.size());
messages = TestUtil.search(notificationMbox, "in:inbox subject:'" + notificationSubject + "'");
assertEquals("found new mail notification with wrong subject", 0, messages.size());
messages = TestUtil.search(notificationMbox, "in:inbox from:" + notifierAddress);
assertEquals("found new mail notification with wrong sender", 0, messages.size());
}
Aggregations