use of com.zimbra.cs.mailbox.Message in project zm-mailbox by Zimbra.
the class NotifyMailtoTest method testPercentEncodingVariable_WithEncodeurl.
@Test
public void testPercentEncodingVariable_WithEncodeurl() {
String sampleMsg = "Auto-Submitted: \"no\"\n" + "from: xyz@example.com\n" + "Subject: [acme-users] [fwd] version 1.0 is out\n" + "to: foo@example.com, baz@example.com\n" + "cc: qux@example.com\n";
String filterScript_PercentEncodingVariable = "require [\"enotify\", \"variables\"];\n" + "set :encodeurl \"body_param\" \"Safe body&evil=evilbody\";\n" + "notify \"mailto:test2@zimbra.com?body=${body_param}\";";
try {
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
acct1.setMail("test1@zimbra.com");
RuleManager.clearCachedRules(acct1);
acct1.setMailSieveScript(filterScript_PercentEncodingVariable);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleMsg.getBytes(), false), 0, acct1.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
// The triggered message should be delivered to the target mailbox
Assert.assertEquals(1, ids.size());
// Notification message should be delivered to mailto and to= addresses
Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message notifyMsg = mbox2.getMessageById(null, item);
Assert.assertEquals("Safe body&evil=evilbody", notifyMsg.getFragment());
String[] headers = notifyMsg.getMimeMessage().getHeader("evil");
Assert.assertFalse(notifyMsg.getSender() == null);
RuleManager.clearCachedRules(acct1);
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.mailbox.Message in project zm-mailbox by Zimbra.
the class SendShareNotificationTest method testShareFolderNotificationEmailNotes.
@Test
public void testShareFolderNotificationEmailNotes() throws Exception {
revoke = false;
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
Folder f = mbox.createFolder(null, "f1", Mailbox.ID_FOLDER_BRIEFCASE, new Folder.FolderOptions().setDefaultView(MailItem.Type.DOCUMENT));
mbox.grantAccess(null, f.getId(), acct2.getId(), ACL.GRANTEE_USER, ACL.RIGHT_READ, null);
Element request = new Element.XMLElement(MailConstants.SEND_SHARE_NOTIFICATION_REQUEST);
request.addElement(MailConstants.E_ITEM).addAttribute(MailConstants.A_ID, f.getId());
request.addElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS, "test2@zimbra.com");
request.addElement(MailConstants.E_NOTES).setText("this\n is\n a\nstandard\nmessage.");
handle(request, ServiceTestUtil.getRequestContext(acct));
MailItem sent = mbox.getItemById(null, 258, MailItem.Type.MESSAGE);
Message zMsg = (Message) sent;
String body = new String(zMsg.getContent());
String expected = "this<br> is<br> a<br>standard<br>message.<br>";
assertTrue(body.indexOf(expected) != -1);
}
use of com.zimbra.cs.mailbox.Message in project zm-mailbox by Zimbra.
the class SyncTest method msgConversationsCutoff.
@Test
public void msgConversationsCutoff() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test1@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
mbox.beginTrackingSync();
acct.setMailThreadingAlgorithm(MailThreadingAlgorithm.subject);
int currTime = (int) (System.currentTimeMillis() / 1000);
long before60min = currTime - (60 * Constants.SECONDS_PER_MINUTE);
long before45min = currTime - (45 * Constants.SECONDS_PER_MINUTE);
long before30min = currTime - (30 * Constants.SECONDS_PER_MINUTE);
long before15min = currTime - (15 * Constants.SECONDS_PER_MINUTE);
Message msg60minbefore = TestUtil.addMessage(mbox, Mailbox.ID_FOLDER_INBOX, "test1 x", before60min * 1000);
Message msg45minbefore = TestUtil.addMessage(mbox, Mailbox.ID_FOLDER_INBOX, "Re: test1 x", before45min * 1000);
Message msg30minbefore = TestUtil.addMessage(mbox, Mailbox.ID_FOLDER_INBOX, "test2 x", before30min * 1000);
Message msg15minbefore = TestUtil.addMessage(mbox, Mailbox.ID_FOLDER_INBOX, "Re: test2 x", before15min * 1000);
int convId1 = msg60minbefore.getConversationId();
int convId2 = msg30minbefore.getConversationId();
List<Integer> expectedConvIds = new ArrayList<Integer>();
List<Integer> expectedMsgIds = new ArrayList<Integer>();
// No message no conversation should be returned if msgCutOff is current time.
SyncRequest request = new SyncRequest();
request.setMsgCutoff(currTime);
request.setFolderId("" + Mailbox.ID_FOLDER_ROOT);
Map<String, Object> context = new HashMap<String, Object>();
context.put(SoapEngine.ZIMBRA_CONTEXT, new ZimbraSoapContext(AuthProvider.getAuthToken(acct), acct.getId(), SoapProtocol.Soap12, SoapProtocol.Soap12));
Element response = new Sync().handle(JaxbUtil.jaxbToElement(request), context);
Pair<Integer, Element> pairFolderIdElement = new Pair<Integer, Element>(Mailbox.ID_FOLDER_CONVERSATIONS, null);
getFolderElement(response, pairFolderIdElement);
Assert.assertNotNull(pairFolderIdElement.getSecond());
Assert.assertNull(pairFolderIdElement.getSecond().getOptionalElement(MailConstants.E_CONV));
pairFolderIdElement = new Pair<Integer, Element>(Mailbox.ID_FOLDER_INBOX, null);
getFolderElement(response, pairFolderIdElement);
Assert.assertNotNull(pairFolderIdElement.getSecond());
Assert.assertNull(pairFolderIdElement.getSecond().getOptionalElement(MailConstants.E_MSG));
// 4 messages 2 conversation should be returned if msgCutOff is current time - 61 mins.
request = new SyncRequest();
request.setMsgCutoff(currTime - 61 * Constants.SECONDS_PER_MINUTE);
request.setFolderId("" + Mailbox.ID_FOLDER_ROOT);
response = new Sync().handle(JaxbUtil.jaxbToElement(request), context);
expectedConvIds.add(convId1);
expectedConvIds.add(convId2);
Assert.assertTrue(verifyItemsPresentInResponse(response, Mailbox.ID_FOLDER_CONVERSATIONS, expectedConvIds, Type.CONVERSATION));
expectedConvIds.clear();
expectedMsgIds.add(msg60minbefore.getId());
expectedMsgIds.add(msg45minbefore.getId());
expectedMsgIds.add(msg30minbefore.getId());
expectedMsgIds.add(msg15minbefore.getId());
Assert.assertTrue(verifyItemsPresentInResponse(response, Mailbox.ID_FOLDER_INBOX, expectedMsgIds, Type.MESSAGE));
expectedMsgIds.clear();
// 2 messages 1 conversation should be returned if msgCutOff is current time - 31 mins.
request = new SyncRequest();
request.setMsgCutoff(currTime - 31 * Constants.SECONDS_PER_MINUTE);
request.setFolderId("" + Mailbox.ID_FOLDER_ROOT);
response = new Sync().handle(JaxbUtil.jaxbToElement(request), context);
expectedConvIds.add(convId2);
Assert.assertTrue(verifyItemsPresentInResponse(response, Mailbox.ID_FOLDER_CONVERSATIONS, expectedConvIds, Type.CONVERSATION));
expectedConvIds.clear();
expectedMsgIds.add(msg30minbefore.getId());
expectedMsgIds.add(msg15minbefore.getId());
Assert.assertTrue(verifyItemsPresentInResponse(response, Mailbox.ID_FOLDER_INBOX, expectedMsgIds, Type.MESSAGE));
expectedMsgIds.clear();
// 1 messages 1 conversation should be returned if msgCutOff is current time - 16 mins.
request = new SyncRequest();
request.setMsgCutoff(currTime - 16 * Constants.SECONDS_PER_MINUTE);
request.setFolderId("" + Mailbox.ID_FOLDER_ROOT);
response = new Sync().handle(JaxbUtil.jaxbToElement(request), context);
expectedConvIds.add(convId2);
Assert.assertTrue(verifyItemsPresentInResponse(response, Mailbox.ID_FOLDER_CONVERSATIONS, expectedConvIds, Type.CONVERSATION));
expectedConvIds.clear();
expectedMsgIds.add(msg15minbefore.getId());
Assert.assertTrue(verifyItemsPresentInResponse(response, Mailbox.ID_FOLDER_INBOX, expectedMsgIds, Type.MESSAGE));
expectedMsgIds.clear();
// Delete message before 15mins no messages no conversation should be returned if msgCutOff is current time - 16 mins.
mbox.delete(null, msg15minbefore.getId(), Type.MESSAGE);
request = new SyncRequest();
request.setMsgCutoff(currTime - 16 * Constants.SECONDS_PER_MINUTE);
request.setFolderId("" + Mailbox.ID_FOLDER_ROOT);
response = new Sync().handle(JaxbUtil.jaxbToElement(request), context);
pairFolderIdElement = new Pair<Integer, Element>(Mailbox.ID_FOLDER_CONVERSATIONS, null);
getFolderElement(response, pairFolderIdElement);
Assert.assertNotNull(pairFolderIdElement.getSecond());
Assert.assertNull(pairFolderIdElement.getSecond().getOptionalElement(MailConstants.E_CONV));
pairFolderIdElement = new Pair<Integer, Element>(Mailbox.ID_FOLDER_INBOX, null);
getFolderElement(response, pairFolderIdElement);
Assert.assertNotNull(pairFolderIdElement.getSecond());
Assert.assertNull(pairFolderIdElement.getSecond().getOptionalElement(MailConstants.E_MSG));
}
use of com.zimbra.cs.mailbox.Message 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));
}
use of com.zimbra.cs.mailbox.Message in project zm-mailbox by Zimbra.
the class ItemActionTest method deleteConversation.
@Test
public void deleteConversation() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
acct.setMailThreadingAlgorithm(MailThreadingAlgorithm.subject);
// setup: add the root message
ParsedMessage pm = MailboxTestUtil.generateMessage("test subject");
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
int rootId = mbox.addMessage(null, pm, dopt, null).getId();
// add additional messages
pm = MailboxTestUtil.generateMessage("Re: test subject");
Message draft = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT, rootId + "", MailSender.MSGTYPE_REPLY, null, null, 0);
Message parent = mbox.getMessageById(null, rootId);
Assert.assertEquals(parent.getConversationId(), draft.getConversationId());
pm = MailboxTestUtil.generateMessage("Re: test subject");
Message draft2 = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT);
parent = mbox.getMessageById(null, rootId);
Assert.assertEquals(parent.getConversationId(), draft2.getConversationId());
MailItem.TargetConstraint tcon = new MailItem.TargetConstraint(mbox, MailItem.TargetConstraint.INCLUDE_TRASH);
ItemId iid = new ItemId(mbox, Mailbox.ID_FOLDER_TRASH);
// trash the conversation
ItemActionHelper.MOVE(null, mbox, SoapProtocol.Soap12, Arrays.asList(parent.getId(), draft.getId(), draft2.getId()), MailItem.Type.MESSAGE, tcon, iid);
parent = mbox.getMessageById(null, parent.getId());
draft = mbox.getMessageById(null, draft.getId());
draft2 = mbox.getMessageById(null, draft2.getId());
Assert.assertEquals(parent.getFolderId(), Mailbox.ID_FOLDER_TRASH);
Assert.assertEquals(draft.getFolderId(), Mailbox.ID_FOLDER_TRASH);
Assert.assertEquals(draft2.getFolderId(), Mailbox.ID_FOLDER_TRASH);
ItemActionHelper.HARD_DELETE(null, mbox, SoapProtocol.Soap12, Collections.singletonList(parent.getConversationId()), MailItem.Type.CONVERSATION, tcon);
Exception ex = null;
try {
mbox.getMessageById(null, parent.getId());
} catch (Exception e) {
ex = e;
}
Assert.assertTrue("test NoSuchItemException (parent/id)", ex instanceof NoSuchItemException);
ex = null;
try {
mbox.getMessageById(null, draft.getId());
} catch (Exception e) {
ex = e;
}
Assert.assertTrue("test NoSuchItemException (draft/id)", ex instanceof NoSuchItemException);
ex = null;
try {
mbox.getMessageById(null, draft2.getId());
} catch (Exception e) {
ex = e;
}
Assert.assertTrue("test NoSuchItemException (draft2/id)", ex instanceof NoSuchItemException);
ex = null;
try {
mbox.getConversationById(null, draft2.getConversationId());
} catch (Exception e) {
ex = e;
}
Assert.assertTrue("test NoSuchItemException (draft2/conversation)", ex instanceof NoSuchItemException);
}
Aggregations