Examples of MimePart


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

Examples of com.elasticinbox.core.model.MimePart

      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

Examples of com.elasticinbox.core.model.MimePart

      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

Examples of com.elasticinbox.core.model.MimePart

      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

Examples of com.sun.xml.internal.org.jvnet.mimepull.MIMEPart

     *
     * @return Map<String, StreamAttachment> for all attachment parts
     */
    public @NotNull Map<String, Attachment> getAttachmentParts() {
        if (!gotAll) {
            MIMEPart rootPart = (start != null) ? message.getPart(start) : message.getPart(0);
            List<MIMEPart> parts = message.getAttachments();
            for(MIMEPart part : parts) {
                if (part != rootPart) {
                    PartAttachment attach = new PartAttachment(part);
                    attachments.put(attach.getContentId(), attach);
View Full Code Here

Examples of helma.util.MimePart

                    body.write(b, 0, read);

                in.close();
            }

            MimePart mime = new MimePart(filename, body.toByteArray(), contentType);

            if (lastmod > 0) {
                mime.setLastModified(new Date(lastmod));
            }

            mime.setETag(etag);

            return Context.toObject(mime, this);
        } catch (Exception x) {
            app.logError("Error getting URL "+location, x);
        }
View Full Code Here

Examples of javax.mail.internet.MimePart

    throws MessagingException, IOException, UnsupportedEncodingException {

    MimeBodyPart oNext = null;
    MimeMultipart oAlt;
    String sType;
    MimePart oRetVal;

    sType = oPart.getContentType().toUpperCase();

    if (DebugFile.trace) DebugFile.writeln("Begin DBMimePart.getMessagePart("+String.valueOf(nPart)+", "+sType.replace('\n',' ').replace('\r',' ')+")");

    if (sType.startsWith("MESSAGE/RFC822")) {
      DBMimeMessage oAttachment = new  DBMimeMessage((MimeMessage) oPart.getContent());
      oRetVal = oAttachment.getBody ();
    }
    else if (sType.startsWith("MULTIPART/ALTERNATIVE") || sType.startsWith("MULTIPART/RELATED") || sType.startsWith("MULTIPART/SIGNED")) {
      oAlt = (MimeMultipart) oPart.getContent();

      int iAlt = 0;
      String[] aPreferred = {"TEXT/HTML","TEXT"};
      boolean bFound = false;

      while (iAlt<aPreferred.length && !bFound) {
        for (int q=0; q<oAlt.getCount(); q++) {
          oNext = (MimeBodyPart) oAlt.getBodyPart(q);
          if (DebugFile.trace && (iAlt==0)) DebugFile.writeln("  " + oNext.getContentType().toUpperCase().replace('\n',' ').replace('\r',' ') + " ID=" + oNext.getContentID());
          bFound = oNext.getContentType().toUpperCase().startsWith(aPreferred[iAlt]);
          if (bFound) break;
        } // next
        iAlt++;
      } // wend

      if (bFound)
        oRetVal = getMessagePart (oNext, -1);
      else
        oRetVal = getMessagePart ((MimeBodyPart) oAlt.getBodyPart(0), -1);
    }
    else {
      oRetVal = oPart;
    }

    if (DebugFile.trace) DebugFile.writeln("End DBMimePart.getMessagePart() : " + oRetVal.getContentType().replace('\n',' ').replace('\r',' '));

    return oRetVal;
  // getMessagePart
View Full Code Here

Examples of javax.mail.internet.MimePart

        oRSet = oStmt.executeQuery();

        while (oRSet.next()) {
          if (DebugFile.trace) DebugFile.writeln("DBMimeMultipart.addBodyPart("+sGuid+","+String.valueOf(oRSet.getInt(1))+","+oRSet.getString(2)+","+oRSet.getString(9)+","+oRSet.getString(6)+","+oRSet.getString(5)+","+oRSet.getString(3)+","+oRSet.getString(7)+","+oRSet.getString(8)+","+String.valueOf(oRSet.getInt(4)));

          MimePart oPart = new DBMimePart(oMultiPart, oRSet.getInt(1),oRSet.getString(2),oRSet.getString(9),oRSet.getString(6),oRSet.getString(5),oRSet.getString(3), oRSet.getString(7), oRSet.getString(8),oRSet.getInt(4));

          oMultiPart.addBodyPart(oPart );
        }

        oRSet.close();
View Full Code Here

Examples of javax.mail.internet.MimePart

  // ---------------------------------------------------------------------------

   public MimePart getBody ()
    throws ParseException, MessagingException, IOException {

    MimePart oRetVal = null;

    if (DebugFile.trace) {
      DebugFile.writeln("Begin DBMimeMessage.getBody([MimeMessage])");
      DebugFile.incIdent();
    }

     Object oContent = null;

     try {
       oContent = super.getContent();
     }
     catch (Exception xcpt) {
       DebugFile.decIdent();
       throw new ParseException("MimeMessage.getContent() ParseException cause " + xcpt.getClass().getName() + " " + (xcpt.getMessage()==null ? "" : xcpt.getMessage()));
     }

     if (DebugFile.trace) {
       if (null==oContent)
         DebugFile.writeln("message content is null");
       else
         DebugFile.writeln("message content class is " + oContent.getClass().getName());
     }

     String sContentClass = oContent.getClass().getName();

     if (sContentClass.equals("javax.mail.internet.MimeMultipart")) {

       MimeMultipart oParts = (MimeMultipart) oContent;
       int iParts = oParts.getCount();
       MimePart oPart;
       String sType, sPrevType, sNextType;

       for (int p=0; p<iParts; p++) {

         oPart = (MimePart) oParts.getBodyPart(0);

         sType = oPart.getContentType().toUpperCase();

         if (p<iParts-1)
           sNextType = ((MimeBodyPart) oParts.getBodyPart(p+1)).getContentType().toUpperCase();
         else
           sNextType = "";

         if (p>0 && iParts>1)
           sPrevType = ((MimeBodyPart) oParts.getBodyPart(p-1)).getContentType().toUpperCase();
         else
           sPrevType = "";

         // If a message has a dual content both text and html ignore the text and show only HTML
         if ((iParts<=1) && (sType.startsWith("TEXT/PLAIN") || sType.startsWith("TEXT/HTML"))) {
           if (DebugFile.trace) DebugFile.writeln("parts=" + String.valueOf(iParts) + ", content-type=" + oPart.getContentType());
           oRetVal = oPart;
           break;
         }
         else if (((p==0) && (iParts>1) && sType.startsWith("TEXT/PLAIN") && sNextType.startsWith("TEXT/HTML"))) {
           if (DebugFile.trace) DebugFile.writeln("parts=" + String.valueOf(iParts) + ", part=0, content-type=" + oPart.getContentType() + ", next-type=" + sNextType);
           oRetVal = ((MimeBodyPart) oParts.getBodyPart(p+1));
           break;
         }
         else if ((p==1) && sType.startsWith("TEXT/PLAIN") && sPrevType.startsWith("TEXT/HTML")) {
           if (DebugFile.trace) DebugFile.writeln("parts=" + String.valueOf(iParts) + ", part=1, content-type=" + oPart.getContentType() + ", prev-type=" + sPrevType);
           oRetVal = ((MimeBodyPart) oParts.getBodyPart(p-1));
           break;
         }
         else {
           oRetVal = DBMimePart.getMessagePart (oPart, p);
View Full Code Here

Examples of javax.mail.internet.MimePart

      Multipart oParts = getParts();

      final int iParts = oParts.getCount();

      MimePart oPart;

      int p;
      for (p=0; p<iParts && !bHasPlainTextVersion; p++) {
        oPart = (MimePart) oParts.getBodyPart(p);

        String sType = oPart.getContentType();
        if (null!=sType) sType=sType.toLowerCase();
        String sDisp = oPart.getDisposition();
        if (null==sDisp) sDisp="inline"; else if (sDisp.length()==0) sDisp="inline";

        if (DebugFile.trace) DebugFile.writeln("scanning part " + String.valueOf(p) + sDisp + " " + sType.replace('\r',' ').replace('\n', ' '));

        if (sType.startsWith("text/plain") && sDisp.equalsIgnoreCase("inline")) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.