use of com.zimbra.cs.mailbox.Message 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.mailbox.Message in project zm-mailbox by Zimbra.
the class SearchActionTest method testSearchActionRead.
@Test
public void testSearchActionRead() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("testRead@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// Add two messages to inbox, one with search match and other with no match
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_MUTED);
Message message1 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Message message2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("unmatched subject"), dopt, null);
TypedIdList ids = mbox.getItemIds(null, 2);
Assert.assertEquals(2, ids.size());
Assert.assertEquals(true, message1.isUnread());
Assert.assertEquals(true, message2.isUnread());
SearchRequest sRequest = new SearchRequest();
sRequest.setSearchTypes("conversation");
// search with query 'test'
sRequest.setQuery("test");
BulkAction bAction = new BulkAction();
// search action - mark search result with 'read'
bAction.setOp(BulkAction.Operation.read);
Map<String, Object> context = ServiceTestUtil.getRequestContext(acct);
ZimbraSoapContext zsc = (ZimbraSoapContext) context.get(SoapEngine.ZIMBRA_CONTEXT);
Element searchResponse = new Search().handle(zsc.jaxbToElement(sRequest), ServiceTestUtil.getRequestContext(acct));
com.zimbra.soap.mail.message.SearchResponse sResponse = zsc.elementToJaxb(searchResponse);
List<SearchHit> searchHits = sResponse.getSearchHits();
ConvActionRequest req = SearchAction.getConvActionRequest(searchHits, "read");
ConvAction convAction = new ConvAction();
PowerMockito.stub(PowerMockito.method(SoapHttpTransport.class, "invokeWithoutSession")).toReturn(convAction.handle(zsc.jaxbToElement(req), ServiceTestUtil.getRequestContext(acct)));
SearchAction.performAction(bAction, sRequest, searchHits, mbox, null);
// check search result message is marked read
Assert.assertEquals(false, message1.isUnread());
Assert.assertEquals(true, message2.isUnread());
}
use of com.zimbra.cs.mailbox.Message in project zm-mailbox by Zimbra.
the class ParseMimeMessageTest method staleReference.
@Test
public void staleReference() throws Exception {
Account acct = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// first, create the original draft
OperationContext octxt = new OperationContext(acct);
Document doc = mbox.createDocument(octxt, Mailbox.ID_FOLDER_BRIEFCASE, "testdoc", MimeConstants.CT_TEXT_PLAIN, null, null, randomContent("test1", 8192));
Document doc2 = mbox.createDocument(octxt, Mailbox.ID_FOLDER_BRIEFCASE, "testdoc2", MimeConstants.CT_TEXT_PLAIN, null, null, randomContent("test2", 8192));
Element el = new Element.JSONElement(MailConstants.E_MSG), attach;
el.addAttribute(MailConstants.E_SUBJECT, "has attachment");
el.addElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS_TYPE, EmailType.TO.toString()).addAttribute(MailConstants.A_ADDRESS, "rcpt@zimbra.com");
el.addElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, "This is the content.");
attach = el.addElement(MailConstants.E_ATTACH);
attach.addElement(MailConstants.E_DOC).addAttribute(MailConstants.A_ID, doc.getId());
attach.addElement(MailConstants.E_DOC).addAttribute(MailConstants.A_ID, doc2.getId());
ZimbraSoapContext zsc = getMockSoapContext();
MimeMessage mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, null, el, null, new ParseMimeMessage.MimeMessageData());
Message draft = mbox.saveDraft(octxt, new ParsedMessage(mm, false), -1);
// then, create a new draft that references one of the original draft's attachments
attach.detach();
(attach = el.addElement(MailConstants.E_ATTACH)).addElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_MESSAGE_ID, draft.getId()).addAttribute(MailConstants.A_PART, "3");
mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, null, el, null, new ParseMimeMessage.MimeMessageData());
// delete the draft itself and then try to save the new draft
mbox.delete(octxt, draft.getId(), MailItem.Type.MESSAGE);
Message draft2 = mbox.saveDraft(octxt, new ParsedMessage(mm, false), -1);
// check that the attachment's content is present and correct
MimeMultipart multi = (MimeMultipart) (draft2.getMimeMessage().getContent());
Assert.assertEquals("2 parts in draft", 2, multi.getCount());
Assert.assertEquals("attached part content", "test2", firstLine((MimeBodyPart) multi.getBodyPart(1)));
}
use of com.zimbra.cs.mailbox.Message in project zm-mailbox by Zimbra.
the class AbstractBlobConsistencyCheckTest method wrongSize.
@Test
public void wrongSize() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg = mbox.addMessage(null, new ParsedMessage("From: test1-1@sub1.zimbra.com".getBytes(), false), dopt, null);
MailboxBlob blob = msg.getBlob();
String text = "some garbage";
appendText(blob, text);
BlobConsistencyChecker checker = getChecker();
Results results = checker.check(getVolumeIds(), mbox.getId(), true, false);
Assert.assertEquals(0, results.missingBlobs.size());
Assert.assertEquals(0, results.unexpectedBlobs.size());
Assert.assertEquals(0, results.usedBlobs.size());
Assert.assertEquals(1, results.incorrectSize.size());
BlobInfo info = results.incorrectSize.values().iterator().next();
Assert.assertEquals(blob.size + text.length(), (long) info.fileDataSize);
Assert.assertEquals(0, results.incorrectModContent.size());
}
use of com.zimbra.cs.mailbox.Message in project zm-mailbox by Zimbra.
the class UrlNamespace method getCalendarItemForMessage.
private static DavResource getCalendarItemForMessage(DavContext ctxt, Message msg) throws ServiceException {
Mailbox mbox = msg.getMailbox();
if (msg.isInvite() && msg.hasCalendarItemInfos()) {
Message.CalendarItemInfo calItemInfo = msg.getCalendarItemInfo(0);
try {
Invite invite = calItemInfo.getInvite();
if (invite == null && calItemInfo.calItemCreated()) {
// Pre-6.0 data
CalendarItem item = mbox.getCalendarItemById(ctxt.getOperationContext(), calItemInfo.getCalendarItemId());
invite = calItemInfo.getInvite();
int compNum = calItemInfo.getComponentNo();
invite = item.getInvite(msg.getId(), compNum);
}
if (invite != null) {
String path = CalendarObject.CalendarPath.generate(ctxt, msg.getPath(), invite.getUid(), mbox.getId(), msg.getId(), msg.getId());
return new CalendarObject.ScheduleMessage(ctxt, path, ctxt.getUser(), invite, msg);
}
} catch (MailServiceException.NoSuchItemException e) {
// the appt must have been cancelled or deleted.
// bug 26315
}
}
return null;
}
Aggregations