Search in sources :

Example 1 with GetMsg

use of com.zimbra.cs.service.mail.GetMsg in project zm-mailbox by Zimbra.

the class GetMsgTest method testMsgHeaderN.

@Test
public void testMsgHeaderN() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    MimeMessage message = new JavaMailMimeMessage(JMSession.getSession(), new ZSharedFileInputStream("data/unittest/email/bug_75163.txt"));
    ParsedMessage pm = new ParsedMessage(message, false);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, pm, dopt, null);
    Element request = new Element.XMLElement(MailConstants.GET_MSG_REQUEST);
    Element action = request.addElement(MailConstants.E_MSG);
    action.addAttribute(MailConstants.A_ID, msg.getId());
    action.addElement(MailConstants.A_HEADER).addAttribute(MailConstants.A_ATTRIBUTE_NAME, "Return-Path");
    Element response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
    List<Element> headerN = response.listElements(MailConstants.A_HEADER);
    for (Element elt : headerN) {
        Assert.assertEquals(elt.getText(), "foo@example.com");
    }
}
Also used : ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) GetMsg(com.zimbra.cs.service.mail.GetMsg) Element(com.zimbra.common.soap.Element) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 2 with GetMsg

use of com.zimbra.cs.service.mail.GetMsg in project zm-mailbox by Zimbra.

the class GetMsgTest method testMsgMaxAttr.

@Test
public void testMsgMaxAttr() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    MimeMessage message = new JavaMailMimeMessage(JMSession.getSession(), new ZSharedFileInputStream("data/TestMailRaw/1"));
    ParsedMessage pm = new ParsedMessage(message, false);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, pm, dopt, null);
    Element request = new Element.XMLElement(MailConstants.GET_MSG_REQUEST);
    Element action = request.addElement(MailConstants.E_MSG);
    action.addAttribute(MailConstants.A_ID, msg.getId());
    action.addAttribute(MailConstants.A_MAX_INLINED_LENGTH, 10);
    Element response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
    Assert.assertEquals(response.getElement(MailConstants.E_MIMEPART).getElement(MailConstants.E_CONTENT).getText().length(), 10);
}
Also used : ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) GetMsg(com.zimbra.cs.service.mail.GetMsg) Element(com.zimbra.common.soap.Element) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 3 with GetMsg

use of com.zimbra.cs.service.mail.GetMsg in project zm-mailbox by Zimbra.

the class GetMsgTest method testMsgView.

@Test
public void testMsgView() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    MimeMessage message = new JavaMailMimeMessage(JMSession.getSession(), new ZSharedFileInputStream("data/unittest/email/bug_75163.txt"));
    ParsedMessage pm = new ParsedMessage(message, false);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, pm, dopt, null);
    Element request = new Element.XMLElement(MailConstants.GET_MSG_REQUEST);
    Element action = request.addElement(MailConstants.E_MSG);
    action.addAttribute(MailConstants.A_ID, msg.getId());
    Element response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
    List<Element> mimeParts = response.getElement(MailConstants.E_MIMEPART).listElements();
    // test plain text view
    for (Element elt : mimeParts) {
        if (elt.getAttribute(MailConstants.A_BODY, null) != null) {
            Assert.assertEquals(elt.getAttribute(MailConstants.A_CONTENT_TYPE), "text/plain");
            break;
        }
    }
    action.addAttribute(MailConstants.A_WANT_HTML, 1);
    response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
    mimeParts = response.getElement(MailConstants.E_MIMEPART).listElements();
    // test HTML view
    for (Element elt : mimeParts) {
        if (elt.getAttribute(MailConstants.A_BODY, null) != null) {
            Assert.assertEquals(elt.getAttribute(MailConstants.A_CONTENT_TYPE), "text/html");
            break;
        }
    }
}
Also used : ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) GetMsg(com.zimbra.cs.service.mail.GetMsg) Element(com.zimbra.common.soap.Element) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Aggregations

JavaMailMimeMessage (com.zimbra.common.mime.shim.JavaMailMimeMessage)3 Element (com.zimbra.common.soap.Element)3 ZSharedFileInputStream (com.zimbra.common.zmime.ZSharedFileInputStream)3 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 Message (com.zimbra.cs.mailbox.Message)3 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)3 GetMsg (com.zimbra.cs.service.mail.GetMsg)3 MimeMessage (javax.mail.internet.MimeMessage)3 Test (org.junit.Test)3