Search in sources :

Example 6 with InputStreamWithSize

use of com.zimbra.common.util.InputStreamWithSize in project zm-mailbox by Zimbra.

the class ImapPartSpecifierTest method checkPartial.

private void checkPartial(MimeMessage mm, String part, String modifier, int start, int count, String startsWith, String endsWith) throws IOException, BinaryDecodingException, ServiceException {
    ImapPartSpecifier pspec = new ImapPartSpecifier("BODY", part, modifier, start, count);
    InputStreamWithSize content = pspec.getContentOctetRange(mm);
    if (startsWith == null) {
        Assert.assertNull(pspec.getSectionSpec() + " is null", content);
    } else {
        Assert.assertNotNull(pspec.getSectionSpec() + " is not null", content.stream);
        String data = new String(ByteUtil.getContent(content.stream, content.size.intValue())).trim();
        if (startsWith.length() > 0) {
            Assert.assertTrue(pspec.getSectionSpec() + " start matches", data.startsWith(startsWith));
        } else {
            Assert.assertTrue(pspec.getSectionSpec() + " start empty", data.length() == 0);
        }
        if (endsWith.length() > 0) {
            Assert.assertTrue(pspec.getSectionSpec() + " end matches", data.endsWith(endsWith));
        } else {
            Assert.assertTrue(pspec.getSectionSpec() + " end empty", data.length() == 0);
        }
    }
}
Also used : InputStreamWithSize(com.zimbra.common.util.InputStreamWithSize)

Aggregations

InputStreamWithSize (com.zimbra.common.util.InputStreamWithSize)6 IOException (java.io.IOException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 MessagingException (javax.mail.MessagingException)2 MimeMessage (javax.mail.internet.MimeMessage)2 MailboxStore (com.zimbra.common.mailbox.MailboxStore)1 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)1 ServiceException (com.zimbra.common.service.ServiceException)1 StartOutOfBoundsException (com.zimbra.common.util.StartOutOfBoundsException)1 Account (com.zimbra.cs.account.Account)1 AuthToken (com.zimbra.cs.account.AuthToken)1 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 BinaryDecodingException (com.zimbra.cs.imap.ImapPartSpecifier.BinaryDecodingException)1 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 Mime (com.zimbra.cs.mime.Mime)1 UserServlet (com.zimbra.cs.service.UserServlet)1 Enumeration (java.util.Enumeration)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1