Examples of BodyPart


Examples of javax.mail.BodyPart

      // Set HTML text related inline images

      Iterator oImgs = oDocumentImages.keySet().iterator();

      while (oImgs.hasNext()) {
        BodyPart oImgBodyPart = new MimeBodyPart();

        sSrc = (String) oImgs.next();
        sCid = (String) oDocumentImages.get(sSrc);

        if (sSrc.startsWith("www."))
          sSrc = "http://" + sSrc;

        if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
          oImgBodyPart.setDataHandler(new DataHandler(new URL(Hosts.resolve(sSrc))));
        }
        else {
          oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource((sBasePath==null ? "" : sBasePath)+sSrc)));
        }

        oImgBodyPart.setDisposition("inline");
        oImgBodyPart.setHeader("Content-ID", sCid);
        oImgBodyPart.setFileName(sCid);

        // Add image to multi-part
        if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/related).addBodyPart("+sCid+")");
        oHtmlRelated.addBodyPart(oImgBodyPart);
      } // wend
View Full Code Here

Examples of javax.mail.BodyPart

           * 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.BodyPart

    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
          DebugFile.writeln("part 0 is " + oPart0.getClass().getName());
      }
      DBMimePart.parseMimePart (oBuffer, null, null, getMessageID()!=null ? getMessageID() : getContentID(), (MimePart) oPart0, 0);
    }
    else {
      InputStream oInStrm;
View Full Code Here

Examples of javax.mail.BodyPart

        // Set HTML text related inline images

        Iterator oImgs = oHtmBdy.getImagesCids().keySet().iterator();

        while (oImgs.hasNext()) {
          BodyPart oImgBodyPart = new MimeBodyPart();

          sSrc = (String) oImgs.next();
          sCid = (String) oHtmBdy.getImagesCids().get(sSrc);

          if (sSrc.startsWith("www."))
            sSrc = "http://" + sSrc;

          if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
            oImgBodyPart.setDataHandler(new DataHandler(new URL(Hosts.resolve(sSrc))));
          }
          else {
            oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource(sSrc)));
          }
     
      if (sSrc.endsWith(".png")) oImgBodyPart.setHeader("Content-Type", "image/png;name="+sCid);
          oImgBodyPart.setDisposition("inline");
          oImgBodyPart.setHeader("Content-ID", sCid);
          oImgBodyPart.setFileName(sCid);

          // Add image to multi-part
          if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/related).addBodyPart("+sCid+")");
          oHtmlRelated.addBodyPart(oImgBodyPart);
        } // wend
View Full Code Here

Examples of javax.mail.BodyPart

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

  public BodyPart getBodyPart(int index)
    throws MessagingException {
    BodyPart oRetVal = null;
    try {
      oRetVal = (BodyPart) aParts.get(index);
    }
    catch (ArrayIndexOutOfBoundsException aiob) {
      throw new MessagingException("Invalid message part index", aiob);
View Full Code Here

Examples of javax.mail.BodyPart

      if (message.getContent() instanceof Multipart) {
        //contentType = "multipart";
        Multipart mp = (Multipart) message.getContent();

        for (int i = 0; i < mp.getCount(); i++) {
          BodyPart bp = mp.getBodyPart(i);
          String disposition = bp.getDisposition();

          if ((disposition != null) && ((disposition.equals(Part.ATTACHMENT)))) {
            attachments.add("attachment: " + bp.getFileName());
            if (bp.isMimeType("text/*")) {
              textParts.add((String) bp.getContent());
              mLog.debug("added txt from attachment: " + bp.getFileName() + " : " + bp.getContentType());
            }

          } else if (disposition == null || disposition.equals(Part.INLINE)) {

            // Plain Text oder HTML
            if (bp.isMimeType("text/*")) {
              textParts.add((String) bp.getContent());

            } else if (bp.isMimeType("multipart/*")) {
              // another bodypart container
              // we process only depth = 1 and not deeper and only text.
              Multipart mpInner = (Multipart) bp.getContent();

              for (int k = 0; k < mpInner.getCount(); k++) {
                BodyPart bpInner = mpInner.getBodyPart(k);

                if (bpInner != null && (bpInner.getDisposition() == null ||
                        bpInner.getDisposition().equals(Part.INLINE))) {

                  if (bpInner.isMimeType("text/*")) {
                    textParts.add((String) bpInner.getContent());
                  }

                } // end of bodypart which are not attachments
              } // end of iterate over all inner bodyparts
            } // MultipartContainer in a MultipartContainer
View Full Code Here

Examples of javax.mail.BodyPart

            DebugFile.writeln("previous part at " + String.valueOf(iPrevPart));
            DebugFile.writeln("part boundary is " + sBoundary);
            if (null==sMsgCharSeq) DebugFile.writeln("characer sequence is null");
          }

          BodyPart oPart = oParts.getBodyPart(p);
          byOutPart = new ByteArrayOutputStream(oPart.getSize() > 0 ? oPart.getSize() : 131072);
          oPart.writeTo(byOutPart);

          if (sMsgCharSeq!=null && sBoundary!=null && iPrevPart>0) {
            iThisPart = sMsgCharSeq.indexOf(sBoundary, iPrevPart);
            if (iThisPart>0) {
              if (DebugFile.trace) DebugFile.writeln("found part " + String.valueOf(p+iOffset) + " boundary at " + String.valueOf(iThisPart));
              iPartStart = iThisPart + sBoundary.length();
              while (iPartStart<sMsgCharSeq.length()) {
                if (sMsgCharSeq.charAt(iPartStart)!=' ' && sMsgCharSeq.charAt(iPartStart)!='\r' && sMsgCharSeq.charAt(iPartStart)!='\n' && sMsgCharSeq.charAt(iPartStart)!='\t')
                  break;
                else
                  iPartStart++;
              } // wend
            }
            iNextPart = sMsgCharSeq.indexOf(sBoundary, iPartStart);
            if (iNextPart<0)  {
              if (DebugFile.trace) DebugFile.writeln("no next part found");
              iNextPart = sMsgCharSeq.length();
            }
            else {
              if (DebugFile.trace) DebugFile.writeln("next part boundary found at " + String.valueOf(iNextPart));
            }
          } // fi (sMsgCharSeq!=null && sBoundary!=null && iPrevPart>0)

          String sContentType = oPart.getContentType();
          if (sContentType!=null) sContentType = MimeUtility.decodeText(sContentType);

          boolean bForwardedAttachment = false;

          if ((null!=sContentType) && (null!=((DBStore) getStore()).getSession())) {
            if (DebugFile.trace) DebugFile.writeln("Part Content-Type: " + sContentType.replace('\r',' ').replace('\n',' '));

            if (sContentType.toUpperCase().startsWith("MULTIPART/ALTERNATIVE") ||
              sContentType.toUpperCase().startsWith("MULTIPART/RELATED") ||
              sContentType.toUpperCase().startsWith("MULTIPART/SIGNED")) {
              try {
                ByteArrayInputStream byInStrm = new ByteArrayInputStream(byOutPart.toByteArray());

                MimeMessage oForwarded = new MimeMessage (((DBStore) getStore()).getSession(), byInStrm);

                saveMimeParts (oForwarded, sMsgCharSeq, getPartsBoundary(oForwarded), sMsgGuid, sMsgId, iPgMessage, iOffset+iParts);

                byInStrm.close();
                byInStrm = null;

                bForwardedAttachment = true;
              }
              catch (Exception e) {
               if (DebugFile.trace) DebugFile.writeln(e.getClass().getName() + " " + e.getMessage());
              }
            } // fi (MULTIPART/ALTERNATIVE)
          } // fi (null!=sContentType && null!=getSession())

          if (!bForwardedAttachment) {
            if (DebugFile.trace) {
              if ((iOpenMode&MODE_MBOX)!=0) {
                DebugFile.writeln("MBOX mode");
                DebugFile.writeln("nu_offset=" + String.valueOf(iPartStart));
                DebugFile.writeln("nu_len=" + String.valueOf(iNextPart-iPartStart));
              } else if ((iOpenMode&MODE_BLOB)!=0) {
                DebugFile.writeln("BLOB mode");
                DebugFile.writeln("nu_offset=null");
                DebugFile.writeln("nu_len=" + String.valueOf(oPart.getSize() > 0 ? oPart.getSize() : byOutPart.size()));
              }
              DebugFile.writeln("id_message=" + sMsgId);
              DebugFile.writeln("id_part=" + String.valueOf(p+iOffset));
              DebugFile.writeln("pg_message=" + String.valueOf(iPgMessage));
            }

            oStmt.setString(1, sMsgId); // id_message
            oStmt.setBigDecimal(2, new BigDecimal(iPgMessage)); // pg_message

            if ((iPartStart>0) && ((iOpenMode&MODE_MBOX)!=0))
              oStmt.setBigDecimal(3, new BigDecimal(iPartStart)); // nu_offset
            else
              oStmt.setNull(3, oConn.getDataBaseProduct()==JDCConnection.DBMS_ORACLE ? Types.NUMERIC : Types.DECIMAL);

            oStmt.setInt(4, p+iOffset); // id_part
            oStmt.setString(5, ((javax.mail.internet.MimeBodyPart) oPart).getContentID()); // id_content
            oStmt.setString(6, Gadgets.left(sContentType, 254)); // id_type
            oStmt.setString(7, Gadgets.left(oPart.getDisposition(), 100));

            if ((iOpenMode&MODE_MBOX)!=0)
              oStmt.setInt(8, iNextPart-iPartStart);
            else
              oStmt.setInt(8, oPart.getSize() > 0 ? oPart.getSize() : byOutPart.size());

            if (oPart.getDescription()!=null)
              oStmt.setString(9, Gadgets.left(MimeUtility.decodeText(oPart.getDescription()), 254));
            else
              oStmt.setNull(9, Types.VARCHAR);

            if (DebugFile.trace) DebugFile.writeln("file name is " + oPart.getFileName());

            if (oPart.getFileName()!=null)
              oStmt.setString(10, Gadgets.left(MimeUtility.decodeText(oPart.getFileName()), 254));
            else
              oStmt.setNull(10, Types.VARCHAR);

            if ((iOpenMode&MODE_BLOB)!=0)
              oStmt.setBinaryStream(11, new ByteArrayInputStream(byOutPart.toByteArray()),byOutPart.size());
View Full Code Here

Examples of javax.mail.BodyPart

      if (attachments != null && attachments.length > 0) {
        // with attachment use multipart message
        Multipart multipart = new MimeMultipart();
        // 1) add body part
        BodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText(body);
        multipart.addBodyPart(messageBodyPart);
        // 2) add attachments
        for (File attachmentFile : attachments) {
          // abort if attachment does not exist
          if (attachmentFile == null || !attachmentFile.exists()) {
            result.setReturnCode(MailerResult.ATTACHMENT_INVALID);
            Tracing.logError("Tried to send mail wit attachment that does not exist::"
                + (attachmentFile == null ? null : attachmentFile.getAbsolutePath()), MailHelper.class);
            return msg;
          }
          messageBodyPart = new MimeBodyPart();
          DataSource source = new FileDataSource(attachmentFile);
          messageBodyPart.setDataHandler(new DataHandler(source));
          messageBodyPart.setFileName(attachmentFile.getName());
          multipart.addBodyPart(messageBodyPart);
        }
        // Put parts in message
        msg.setContent(multipart);
      } else {
View Full Code Here

Examples of javax.mail.BodyPart

      String contentType = method.getResponseHeader("content-type").getValue();
      ByteArrayDataSource ds = new ByteArrayDataSource(in, contentType);
      MimeMultipart mimeMultipart = new MimeMultipart(ds);
      Assert.assertEquals(mimeMultipart.getCount(), 1);

      BodyPart part = mimeMultipart.getBodyPart(0);
      InputStream is = part.getInputStream();

      Assert.assertEquals(3, part.getSize());


      char[] output = new char[3];
      output[0] = (char) is.read();
      output[1] = (char) is.read();
View Full Code Here

Examples of javax.mail.BodyPart

     
           if (mm.isMimeType("text/plain")) {
            } else if (mm.isMimeType("multipart/*")) {
              mmp=(MimeMultipart)mm.getContent();
             for (int i = 1; i < mmp.getCount(); i++) {
                BodyPart part = mmp.getBodyPart(i);
              mmp.removeBodyPart(i);
               i--;
              }
          
           } 
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.