Examples of Multipart


Examples of javax.mail.Multipart

          message.setFrom(new InternetAddress(from));
          message.setSubject(subject);
          BodyPart messageBodyPart        = new MimeBodyPart();
          String messageContext = "text/plain";
          messageBodyPart.setContent(body, messageContext);
          Multipart multipart             = new MimeMultipart();
          multipart.addBodyPart(messageBodyPart);
          messageBodyPart = new MimeBodyPart();
          message.setContent(multipart);
          Transport.send(message);
        }//end of try block
        catch (Exception e)
View Full Code Here

Examples of javax.mail.Multipart

        {
          mEmailMessage.setContent(o.toString());
        }
        else if (o instanceof Multipart)
        {
          Multipart mp = (Multipart) o;

          int count3 = mp.getCount();

          /*
           * This is for *.eml file j = 0 is for text, j = 1 is for
           * HTML.
           */
          for (int j = 0; j < count3; j++)
          {
            // Part are numbered starting at 0
            BodyPart b = mp.getBodyPart(j);

            Object o2 = b.getContent();
            if ((o2 instanceof String))
            {
              mEmailMessage.setContent(o2.toString());
            }
            else if (o2 instanceof Multipart)
            {
              // System.out.print("**This BodyPart is a nested
              // Multipart. ");
              Multipart mp2 = (Multipart) o2;

              int count2 = mp2.getCount();

              for (int k = 0; k < count2; k++)
              {
                b = mp2.getBodyPart(k);
                o2 = b.getContent();

                if ((o2 instanceof String))
                {
                  mEmailMessage.setContent(o2.toString());
View Full Code Here

Examples of javax.mail.Multipart

         mbp1.setDataHandler(new DataHandler(ds));
         mbp1.setFileName(attachmentName);
         // mbp1.getContentType(); "application/octet-stream"

         // create the Multipart and add its parts to it
         Multipart mp = new MimeMultipart();
         mp.addBodyPart(mbp1);

         if (attachmentName2 != null) {
            MimeBodyPart mbp2 = new MimeBodyPart(); // "text/plain"
            mbp2.setText(attachment2, encoding);
            mbp2.setFileName(attachmentName2);
            mp.addBodyPart(mbp2);
         }

         // add the Multipart to the message
         message.setContent(mp);
View Full Code Here

Examples of javax.mail.Multipart

         if (holder.length == 0 && emailData.getContent() != null && emailData.getContent().length() > 0) {
            message.setText(emailData.getContent(), Constants.UTF8_ENCODING);
         }
         else {
            // create the Multipart and add its parts to it
            Multipart multi = new MimeMultipart();
  
            if (emailData.getContent() != null && emailData.getContent().length() > 0) {
               MimeBodyPart mbp = new MimeBodyPart();
               mbp.setFileName("content.txt");
               mbp.setText(emailData.getContent(), Constants.UTF8_ENCODING);
               mbp.setDisposition(MimeBodyPart.INLINE);
               multi.addBodyPart(mbp);
            }
  
            for (int i=0; i<holder.length; i++) {
               MimeBodyPart mbp = new MimeBodyPart();
               // 'AA xmlBlasterMessage.xbf' will be automatically quoted to '"AA xmlBlasterMessage.xbf"' by javamail implementation
               // 'xx.xbf' names will be send unquoted
               mbp.setFileName(holder[i].getFileName());
               byte[] content = holder[i].getContent();
               if (this.messageIdForceBase64 && emailData.isMessageIdAttachment(holder[i], msgIdFileName)
                    || this.contentForceBase64 && emailData.isMsgUnitAttachment(holder[i])) {
                  //We don't need to do it, javamail does it for us
                  //content = Base64.encode(holder[i].getContent()).getBytes(Constants.UTF8_ENCODING);
                  //Buggy: is not accepted by javamail: (Why? and How?)
                  mbp.setHeader(Constants.EMAIL_TRANSFER_ENCODING, Constants.ENCODING_BASE64)// "Content-Transfer-Encoding", "base64");
               }
               else {
                  // http://www.ietf.org/rfc/rfc2045.txt
                  // The Quoted-Printable encoding REQUIRES that encoded lines be no more than 76
                  // characters long. (78 with CRLF), the line uses a trailing '=' as a soft line brake
                  mbp.setHeader(Constants.EMAIL_TRANSFER_ENCODING, Constants.ENCODING_QUOTED_PRINTABLE)// "Content-Transfer-Encoding", "quoted-printable");
                  if (holder[i].hasExtensionFromList(this.inlineExtension))
                     mbp.setDisposition(MimeBodyPart.INLINE);
               }
              
               // Encoding violates RFC 2231 but is very common to do so for non-ASCII character sets:
               //mbp.setFileName(MimeUtility.encodeText(holder[i].getFileName()));
               if (holder[i].getContentType().startsWith("text/")) {
                  //String tmp = MimeUtility.encodeText(new String(content, Constants.UTF8_ENCODING), Constants.UTF8_ENCODING, Constants.ENCODING_QUOTED_PRINTABLE);
                  //mbp.setText(tmp, Constants.UTF8_ENCODING);
                  String contentStr = new String(content, Constants.UTF8_ENCODING);
                  if (this.breakLongMessageIdLine && emailData.isMessageIdAttachment(holder[i], msgIdFileName)) {
                     // <messageId><sessionId>unknown</sessionId><requestId>1140597982821000000</requestId><methodName>update</methodName><expires>2006-02-23T08:46:22.821Z</expires></messageId>
                     contentStr = ReplaceVariable.replaceAll(contentStr, "<requestId>", "\r\n<requestId>");
                     contentStr = ReplaceVariable.replaceAll(contentStr, "<methodName>", "\r\n<methodName>");
                     contentStr = ReplaceVariable.replaceAll(contentStr, "<expires>", "\r\n<expires>");
                  }
                  mbp.setText(contentStr, Constants.UTF8_ENCODING);
               }
               else {
                  // "application/xmlBlaster-xbformat"
                  DataSource ds = new ByteArrayDataSource(
                        content,
                        holder[i].getContentType());
                  mbp.setDataHandler(new DataHandler(ds));
               }
               multi.addBodyPart(mbp);
            }
  
            // add the Multipart to the message
            message.setContent(multi);
         } // else multipart
View Full Code Here

Examples of javax.mail.Multipart

            else {
               a = new AttachmentHolder(fileName, ct, ((String)p.getContent()).getBytes(Constants.UTF8_ENCODING));
            }
            attachments.add(a);
         } else if (p.isMimeType("multipart/*")) { // Go one level deeper ...
            Multipart mp = (Multipart) p.getContent();
            level++;
            int count = mp.getCount();
            for (int i = 0; i < count; i++)
               level = accessPart(mp.getBodyPart(i), level, attachments);
            level--;
         } else if (p.isMimeType("message/rfc822")) {
            level++;
            level = accessPart((Part) p.getContent(), level, attachments);
            level--;
View Full Code Here

Examples of javax.mail.Multipart

         pr("=========This is plain text, level="+level+"===========", level);
         if (!showStructure && !saveAttachments)
            System.out.println((String) p.getContent());
      } else if (p.isMimeType("multipart/*")) {
         pr("=========This is a Multipart " + level + "==================", level);
         Multipart mp = (Multipart) p.getContent();
         level++;
         int count = mp.getCount();
         for (int i = 0; i < count; i++)
            level = dumpPart(mp.getBodyPart(i), level);
         level--;
      } else if (p.isMimeType("message/rfc822")) {
         pr("This is a Nested Message", level);
         pr("===========================", level);
         level++;
View Full Code Here

Examples of javax.mail.Multipart

      throw new NullPointerException("DBMimeMessage.getContent() : Folder for message cannot be null");
    }

    if (DebugFile.trace) DebugFile.writeln("Folder type " + oFolder.getClass().getName());

    Multipart oRetVal;

    if (oFolder.getClass().getName().equals("com.knowgate.hipermail.DBFolder")) {

      if (sGuid==null) {
        if (DebugFile.trace) DebugFile.decIdent();
        throw new NullPointerException("DBMimeMessage.getContent() : message GUID cannot be null");
      }

      PreparedStatement oStmt = null;
      ResultSet oRSet = null;
      DBMimeMultipart oMultiPart = new DBMimeMultipart((Part) this);

      try {
        if (DebugFile.trace) {
          DebugFile.writeln("Connection.prepareStatement(SELECT id_part,id_content,id_disposition,len_part,de_part,tx_md5,id_encoding,file_name,id_type FROM "+ DB.k_mime_parts + " WHERE " + DB.gu_mimemsg + "='"+sGuid+"')");
        }

    JDCConnection oJdcc = ((DBFolder)oFolder).getConnection();
        oStmt = oJdcc.prepareStatement("SELECT id_part,id_content,id_disposition,len_part,de_part,tx_md5,id_encoding,file_name,id_type FROM " + DB.k_mime_parts + " WHERE " + DB.gu_mimemsg + "=?",
                                        ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        oStmt.setString(1, sGuid);

        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();
        oRSet = null;
        oStmt.close();
        oStmt = null;

      } catch (SQLException sqle) {
        try { if (oRSet!=null) oRSet.close(); } catch (Exception e) {}
        try { if (oStmt!=null) oStmt.close(); } catch (Exception e) {}
        throw new MessagingException(sqle.getMessage(), sqle);
      }
      oRetVal = oMultiPart;
    }
    else {
      oRetVal = (MimeMultipart) super.getContent();
    }

    if (DebugFile.trace) {
      DebugFile.decIdent();
        DebugFile.writeln("End DBMimeMessage.getParts() : " + (oRetVal==null ? "null" : oRetVal.getClass().getName()));
    }

    return oRetVal;
  } // getParts
View Full Code Here

Examples of javax.mail.Multipart

      DebugFile.writeln("Begin DBMimeMessage.getText()");
      DebugFile.incIdent();
    }

    if (null==oFolder) {
      Multipart oParts = (Multipart) super.getContent();

      if (DebugFile.trace) DebugFile.writeln("MimeBodyPart = MimeMultipart.getBodyPart(0)");

      BodyPart oPart0 = oParts.getBodyPart(0);

      if (DebugFile.trace) {
        if (null==oPart0)
          DebugFile.writeln("part 0 is null");
        else
View Full Code Here

Examples of javax.mail.Multipart

      oBuffer.append(oStrBn.getStrings());
    }
    else {
      if (DebugFile.trace) DebugFile.writeln("Multipart = DBMimeMessage.getParts()");

      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")) {
          bHasPlainTextVersion = true;
          DBMimePart.parseMimePart (oBuffer, null,
                                    getFolder().getName(),
                                    getMessageID()!=null ? getMessageID() : getContentID(),
                                    oPart, p);
        }
      }

      if (DebugFile.trace) {
        if (bHasPlainTextVersion)
          DebugFile.writeln("MimeMultipart has plain text version at part " + String.valueOf(p));
        else
          DebugFile.writeln("MimeMultipart has no plain text version, converting part 0 from HTML");
      }

      if (!bHasPlainTextVersion) {
        oPart = (MimePart) oParts.getBodyPart(0);
        StringBuffer oHtml = new StringBuffer();
        DBMimePart.parseMimePart (oHtml, null, getFolder().getName(), getMessageID()!=null ? getMessageID() : getContentID(), oPart, 0);

        Parser oPrsr = Parser.createParser(oHtml.toString(), getEncoding());
        StringBean oStrBn = new StringBean();
View Full Code Here

Examples of javax.mail.Multipart

      oPipe.between(oInStrm, oOutStrm);
      oInStrm.close();
      oMBox.close();
    }
    else {
      Multipart oDBParts = getParts();
      MimeMultipart oMimeParts = new MimeMultipart();

      for (int p=0;p<oDBParts.getCount(); p++) {
        oMimeParts.addBodyPart(oDBParts.getBodyPart(p));
        super.setContent(oMimeParts);
      }
      super.writeTo(oOutStrm);
    }
    if (DebugFile.trace)  {
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.