Package com.elasticinbox.core.model

Examples of com.elasticinbox.core.model.MimePart


   
    Map<String, MimePart> parts = message.getParts();
   
    for (String partId : parts.keySet())
    {
      MimePart part = parts.get(partId);
      InputStream attachmentContentByPartId = mp.getInputStreamByPartId(partId);
      String attachmentHashByPartId = DigestUtils.md5Hex(attachmentContentByPartId);
     
      InputStream attachmentContentByContentId = mp.getInputStreamByContentId(part.getContentId());
      String attachmentHashByContentId = DigestUtils.md5Hex(attachmentContentByContentId);
     
      assertEquals(attachmentHashByPartId, attachmentHashByContentId);
    }
  }
View Full Code Here


      logger.trace("MIME parser extracted TEXT part: {}", (String) content);

      if ((dis != null) && dis.equals(Part.ATTACHMENT)) {
        // add text part as attachment
        message.addPart(partId, new MimePart(part));
      } else {
        // if no disposition, then add to message body
        if(part.isMimeType("text/html")) {
          htmlBody.append((String) content);
        } else {
          textBody.append((String) content);
        }
      }
    } else if (content instanceof MimeMultipart) {
      MimeMultipart multipart = (MimeMultipart) content;

      for (int i = 0; i <  multipart.getCount(); i++)
      {
        // build next part id
        StringBuilder nextPartId = new StringBuilder(partId);

        // add period if not at root level
        if (!partId.isEmpty())
          nextPartId.append(".");

        int localPartId = i+1; // IMAPv4 MIME part counter starts from 1
        nextPartId.append(localPartId);

        Part nextPart = multipart.getBodyPart(i);
        parseMessagePart(nextPart, nextPartId.toString());
      }
    } else if ((content instanceof InputStream)
        || (content instanceof MimeMessage)) {
      // binary, message/rfc822 or text attachment
      message.addPart(partId, new MimePart(part));
    } else {
      throw new MessagingException("Unkonwn message part type " + content.getClass().getName());
    }
  }
View Full Code Here

      throws IOException
  {
    Mailbox mailbox = new Mailbox(user, domain);
    InputStream rawIn = null;
    InputStream partIn = null;
    MimePart part = null;

    try {
      rawIn = messageDAO.getRaw(mailbox, messageId).getUncompressedInputStream();
      MimeParser mimeParser = new MimeParser();
      mimeParser.parse(rawIn);
      part = mimeParser.getMessage().getPart(partId);
      partIn = mimeParser.getInputStreamByPartId(partId);
      rawIn.close();
    } catch (IllegalArgumentException iae) {
      throw new BadRequestException(iae.getMessage());
    } catch (Exception e) {
      logger.warn("Internal Server Error: ", e);
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } finally {
      if (rawIn != null) rawIn.close();
    }

    return Response
        .ok(partIn, part.getMimeType())
        .header("Content-Disposition", filenameToContentDisposition(part.getFileName()))
        .build();
  }
View Full Code Here

      throws IOException
  {
    Mailbox mailbox = new Mailbox(user, domain);
    InputStream rawIn = null;
    InputStream partIn = null;
    MimePart part = null;

    try {
      rawIn = messageDAO.getRaw(mailbox, messageId).getUncompressedInputStream();
      MimeParser mimeParser = new MimeParser();
      mimeParser.parse(rawIn);
      part = mimeParser.getMessage().getPartByContentId(contentId);
      partIn = mimeParser.getInputStreamByContentId(contentId);
      rawIn.close();
    } catch (IllegalArgumentException iae) {
      throw new BadRequestException(iae.getMessage());
    } catch (Exception e) {
      logger.info("Internal Server Error: ", e);
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } finally {
      if (rawIn != null) rawIn.close();
    }

    return Response
        .ok(partIn, part.getMimeType())
        .header("Content-Disposition", filenameToContentDisposition(part.getFileName()))
        .build();
    }
View Full Code Here

TOP

Related Classes of com.elasticinbox.core.model.MimePart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.