use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class MailSenderTest method updateReferenceHeaders.
@Test
public void updateReferenceHeaders() throws Exception {
MailSender sender = new MailSender();
Provisioning prov = Provisioning.getInstance();
Account account = prov.getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
String from = "sender@example.com";
String to = "recipient@example.com";
String subject = "test subject";
MessageBuilder builder = new MessageBuilder().withFrom(from).withToRecipient(to).withSubject(subject).withBody("test body");
String content = builder.create();
MimeMessage msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
//default
Assert.assertNull(msg.getHeader("Thread-Index"));
Assert.assertNull(msg.getHeader("Thread-Topic"));
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
//technically the normalized subject, but our test message already had normalized subject
Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
//index set by sending agent (bg 96107)
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
String presetIndex = "1234";
msg.setHeader("Thread-Index", presetIndex);
Assert.assertNull(msg.getHeader("Thread-Topic"));
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
//topic set by sending agent (bug 96107)
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
Assert.assertNull(msg.getHeader("Thread-Index"));
String presetTopic = "mytopic";
msg.setHeader("Thread-Topic", presetTopic);
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
//both
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
msg.setHeader("Thread-Topic", presetTopic);
msg.setHeader("Thread-Index", presetIndex);
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
//subject changed from orig parent subject (bug 96954)
String parentSubject = "parent subject";
builder = new MessageBuilder().withFrom(from).withToRecipient(to).withSubject(parentSubject).withBody("parent body");
String parentContent = builder.create();
MimeMessage parentMsg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(parentContent.getBytes()));
sender.updateReferenceHeaders(parentMsg, null, account);
ParsedMessage pm = new ParsedMessage(parentMsg, false);
Message mboxMessage = mbox.addMessage(null, pm, MailboxTest.STANDARD_DELIVERY_OPTIONS, null);
sender = new MailSender();
sender.setOriginalMessageId(new ItemId(mboxMessage));
sender.setReplyType(MailSender.MSGTYPE_REPLY);
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
//keep agent specified topic and/or index even when parent specified
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
msg.setHeader("Thread-Topic", presetTopic);
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
msg.setHeader("Thread-Index", presetIndex);
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
msg.setHeader("Thread-Topic", presetTopic);
msg.setHeader("Thread-Index", presetIndex);
sender.updateReferenceHeaders(msg, null, account);
Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class SendShareNotificationTest method shareByAdmin.
@Test
public void shareByAdmin() 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");
Account acct3 = Provisioning.getInstance().get(Key.AccountBy.name, "test3@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_ADMIN, null);
mbox.grantAccess(null, f.getId(), acct3.getId(), ACL.GRANTEE_USER, ACL.RIGHT_ADMIN, null);
Element request = new Element.XMLElement(MailConstants.SEND_SHARE_NOTIFICATION_REQUEST);
request.addElement(MailConstants.E_ITEM).addAttribute(MailConstants.A_ID, new ItemId(acct.getId(), f.getId()).toString());
request.addElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS, "test3@zimbra.com");
handle(request, ServiceTestUtil.getRequestContext(acct));
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class ItemActionTest method deleteIncompleteConversation.
@Test
public void deleteIncompleteConversation() 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 one message in conversation
ItemActionHelper.MOVE(null, mbox, SoapProtocol.Soap12, Collections.singletonList(draft.getId()), MailItem.Type.MESSAGE, tcon, iid);
draft = mbox.getMessageById(null, draft.getId());
Assert.assertEquals(draft.getFolderId(), Mailbox.ID_FOLDER_TRASH);
ItemActionHelper.HARD_DELETE(null, mbox, SoapProtocol.Soap12, Collections.singletonList(draft.getConversationId()), MailItem.Type.CONVERSATION, tcon);
// the messages not in the trash should still exist and attached to the same conversation
parent = mbox.getMessageById(null, rootId);
Message m = mbox.getMessageById(null, draft2.getId());
Assert.assertEquals(parent.getConversationId(), m.getConversationId());
}
use of com.zimbra.cs.service.util.ItemId 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(e instanceof NoSuchItemException);
}
Assert.assertNotNull(ex);
ex = null;
try {
mbox.getMessageById(null, draft.getId());
} catch (Exception e) {
ex = e;
Assert.assertTrue(e instanceof NoSuchItemException);
}
Assert.assertNotNull(ex);
ex = null;
try {
mbox.getMessageById(null, draft2.getId());
} catch (Exception e) {
ex = e;
Assert.assertTrue(e instanceof NoSuchItemException);
}
Assert.assertNotNull(ex);
ex = null;
try {
mbox.getConversationById(null, draft2.getConversationId());
} catch (Exception e) {
ex = e;
Assert.assertTrue(e instanceof NoSuchItemException);
}
Assert.assertNotNull(ex);
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class ParseMimeMessage method handleAttachments.
private static void handleAttachments(Element attachElem, MimeMultipart mmp, ParseMessageContext ctxt, String contentID, String contentDisposition, boolean attachFromMessageCache) throws ServiceException, MessagingException, IOException {
if (contentID != null) {
contentID = '<' + contentID + '>';
}
String attachIds = attachElem.getAttribute(MailConstants.A_ATTACHMENT_ID, null);
if (attachIds != null) {
for (String uploadId : attachIds.split(FileUploadServlet.UPLOAD_DELIMITER)) {
Upload up = FileUploadServlet.fetchUpload(ctxt.zsc.getAuthtokenAccountId(), uploadId, ctxt.zsc.getAuthToken());
if (up == null) {
throw MailServiceException.NO_SUCH_UPLOAD(uploadId);
}
attachUpload(mmp, up, contentID, ctxt, null, null, contentDisposition);
ctxt.out.addUpload(up);
}
}
for (Element elem : attachElem.listElements()) {
String attachType = elem.getName();
boolean optional = elem.getAttributeBool(MailConstants.A_OPTIONAL, false);
try {
if (attachType.equals(MailConstants.E_MIMEPART)) {
ItemId iid = new ItemId(elem.getAttribute(MailConstants.A_MESSAGE_ID), ctxt.zsc);
String part = elem.getAttribute(MailConstants.A_PART);
attachPart(mmp, iid, part, contentID, ctxt, contentDisposition);
} else if (attachType.equals(MailConstants.E_MSG)) {
ItemId iid = new ItemId(elem.getAttribute(MailConstants.A_ID), ctxt.zsc);
attachMessage(mmp, iid, contentID, ctxt, attachFromMessageCache);
} else if (attachType.equals(MailConstants.E_CONTACT)) {
ItemId iid = new ItemId(elem.getAttribute(MailConstants.A_ID), ctxt.zsc);
attachContact(mmp, iid, contentID, ctxt);
} else if (attachType.equals(MailConstants.E_DOC)) {
String path = elem.getAttribute(MailConstants.A_PATH, null);
if (path != null) {
attachDocument(mmp, path, contentID, ctxt);
} else {
ItemId iid = new ItemId(elem.getAttribute(MailConstants.A_ID), ctxt.zsc);
int version = (int) elem.getAttributeLong(MailConstants.A_VERSION, 0);
attachDocument(mmp, iid, version, contentID, ctxt);
}
}
} catch (NoSuchItemException nsie) {
if (!optional)
throw nsie;
ZimbraLog.soap.info("skipping missing optional attachment: " + elem);
}
}
}
Aggregations