Package javax.mail.internet

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


        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

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

   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

      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

   * @throws MessagingException
   * @throws IOException
   */
  private static ByteArrayOutputStream getBodyAsStream(MimeMessage oMsg)
    throws MessagingException,IOException {
    MimePart oText = null;
    ByteArrayOutputStream byStrm;

    if (DebugFile.trace) {
      DebugFile.writeln("Begin DBFolder.getBodyAsStream([MimeMessage])");
      DebugFile.incIdent();
      if (null!=oMsg) DebugFile.writeln(oMsg.getClass().getName());
                 else DebugFile.writeln("MimeMessage is null");
    }

    if (oMsg.getClass().getName().equals("com.knowgate.hipermail.DBMimeMessage"))
      // If appended message is a DBMimeMessage then use DBMimeMessage.getBody()
      // for getting HTML text part or plain text part of the MULTIPART/ALTERNATIVE
      oText = ((DBMimeMessage) oMsg).getBody();
    else {
      // Else if the appended message is a MimeMessage use standard Java Mail getBody() method
      oText = new DBMimeMessage(oMsg).getBody();
    } // fi

    if (DebugFile.trace) {
      DebugFile.writeln("MimePart encoding is "+oText.getEncoding());
      DebugFile.writeln("MimePart size is "+String.valueOf(oText.getSize()));
    }

    // *************************************************************************
    // Initialize a byte array for containing the message body

    if (DebugFile.trace) DebugFile.writeln("ByteArrayOutputStream byOutStrm = new ByteArrayOutputStream("+String.valueOf(oText.getSize()>0 ? oText.getSize() : 8192)+")");

    byStrm = new ByteArrayOutputStream(oText.getSize()>0 ? oText.getSize() : 8192);
    oText.writeTo(byStrm);

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End DBFolder.getBodyAsStream() : " + Gadgets.left(new String(byStrm.toByteArray()),100));
    }
View Full Code Here

    private static void flattenMessageHelper
            (MimePart part, ContentTypePreference ctPref, List l) {
        try {
            if (part.isMimeType("multipart/alternative")) {
                MimeMultipart mp = (MimeMultipart) part.getContent();
                MimePart bestPart = null;
                int ctMax = 0;
                for (int i = 0; i < mp.getCount(); i++) {
                    MimePart p = (MimePart) mp.getBodyPart(i);
                    int ctPrefN = ctPref.preference(part);
                    if (ctPrefN > ctMax) {
                        ctMax = ctPrefN;
                        bestPart = p;
                    }
View Full Code Here

         */
        if (part.getContent() instanceof String && (part.isMimeType("text/plain"))) {
            characters((String) part.getContent());
        } else if (part.isMimeType("multipart/alternative")) {
            MimeMultipart mp = (MimeMultipart) part.getContent();
            MimePart bestPart = null;
            int ctMax = 0;
            for (int i = 0; i < mp.getCount(); i++) {
                MimePart p = (MimePart) mp.getBodyPart(i);
                int ctPrefN = alternativeMailCtPref.preference(p);
                if (ctPrefN > ctMax) {
                    ctMax = ctPrefN;
                    bestPart = p;
                }
View Full Code Here

         */
        if (part.getContent() instanceof String && (part.isMimeType("text/plain"))) {
            characters((String) part.getContent());
        } else if (part.isMimeType("multipart/alternative")) {
            MimeMultipart mp = (MimeMultipart) part.getContent();
            MimePart bestPart = null;
            int ctMax = 0;
            for (int i = 0; i < mp.getCount(); i++) {
                MimePart p = (MimePart) mp.getBodyPart(i);
                int ctPrefN = alternativeMailCtPref.preference(p);
                if (ctPrefN > ctMax) {
                    ctMax = ctPrefN;
                    bestPart = p;
                }
View Full Code Here

    }

    public AWResponseGenerating resourceResponse ()
    {
        String contentId = _resourceUrl.substring(4);
        MimePart part = _parsedMessage.partForId(contentId);
        return downloadPart(part, false);
    }
View Full Code Here

    private static void flattenMessageHelper
            (MimePart part, ContentTypePreference ctPref, List l) {
        try {
            if (part.isMimeType("multipart/alternative")) {
                MimeMultipart mp = (MimeMultipart) part.getContent();
                MimePart bestPart = null;
                int ctMax = 0;
                for (int i = 0; i < mp.getCount(); i++) {
                    MimePart p = (MimePart) mp.getBodyPart(i);
                    int ctPrefN = ctPref.preference(part);
                    if (ctPrefN > ctMax) {
                        ctMax = ctPrefN;
                        bestPart = p;
                    }
View Full Code Here

TOP

Related Classes of javax.mail.internet.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.