Package javax.mail.internet

Examples of javax.mail.internet.MimeBodyPart$MimePartDataHandler


        try {
            if (message != null) {
                if (message.getContent() instanceof Multipart) {
                    Multipart multipart = (Multipart) message.getContent();
                    if (multipart.getCount() == 2) {
                        MimeBodyPart htmlPart = (MimeBodyPart) multipart.getBodyPart(1);
                        if (htmlPart.getContent() instanceof String) {
                            if (StringUtils.startsWith(htmlPart.getContentType(), "text/html")) {
                                return (String) htmlPart.getContent();
                            }
                        }
                    }
                }
            }
View Full Code Here


            if (StringUtils.isEmpty(plaintext) || StringUtils.isEmpty(html)) {
                throw new CedarRuntimeException("Must provide HTML and plaintext parts.");
            }

            MimeBodyPart plaintextPart = new MimeBodyPart();
            plaintextPart.setText(plaintext);
            plaintextPart.addHeaderLine("Content-Type: text/plain; charset=\"" + CHARSET + "\"");
            plaintextPart.addHeaderLine("Content-Transfer-Encoding: quoted-printable");

            MimeBodyPart htmlPart = new MimeBodyPart();
            htmlPart.setText(html);
            htmlPart.addHeaderLine("Content-Type: text/html; charset=\"" + CHARSET + "\"");
            htmlPart.addHeaderLine("Content-Transfer-Encoding: quoted-printable");

            Multipart content = new MimeMultipart("alternative");
            content.addBodyPart(plaintextPart);
            content.addBodyPart(htmlPart);
View Full Code Here

    String str = paramString2;
    if (paramString2 == null) {
      str = "text/html;charset=GBK";
    }

    MimeBodyPart localMimeBodyPart = new MimeBodyPart();

    localMimeBodyPart.setContent(paramString1, str);
    this.mm.setSubType("related");
    this.mm.addBodyPart(localMimeBodyPart);

    if (paramBoolean)
      for (int i = 0; i < this.IMGList.size(); ++i) {
        localMimeBodyPart = new MimeBodyPart();
        FileDataSource localFileDataSource = new FileDataSource(
            this.IMGList.get(i).toString());

        localMimeBodyPart.setDataHandler(new DataHandler(
            localFileDataSource));

        localMimeBodyPart.setFileName(this.IMGList.get(i).toString());
        localMimeBodyPart.setHeader("Content-ID", this.IMGList.get(i)
            .toString());

        this.mm.addBodyPart(localMimeBodyPart);
      }
  }
View Full Code Here

  public void setAttach(List paramList) throws MessagingException {
    if (paramList == null)
      return;
    for (int i = 0; i < paramList.size(); ++i) {
      MimeBodyPart localMimeBodyPart = new MimeBodyPart();
      localMimeBodyPart = new MimeBodyPart();
      FileDataSource localFileDataSource = new FileDataSource(paramList
          .get(i).toString());
      localMimeBodyPart.setDataHandler(new DataHandler(
          localFileDataSource));

      localMimeBodyPart.setFileName(localFileDataSource.getName());

      this.mm.addBodyPart(localMimeBodyPart);
    }
  }
View Full Code Here

                }
            } else {
                Multipart multipart = new MimeMultipart();
                BodyPart bodypart = null;
                if (this.body != null) {
                    bodypart = new MimeBodyPart();
                    bodypart.setText(this.body);
                    multipart.addBodyPart(bodypart);
                }
                this.message.setContent(multipart);

                for (Iterator i = this.attachmentList.iterator(); i.hasNext();) {
                    a = (Attachment) i.next();
                    DataSource ds = null;
                    if (a.isURL) {
                        String name = (String) a.getObject();
                        Source src = resolver.resolveURI(name);
                        sourcesList.add(src);
                        if (src.exists()) {
                            ds = new SourceDataSource(
                                    src,
                                    a.getType(src.getMimeType()),
                                    a.getName(name.substring(name.lastIndexOf('/') + 1)));
                        }
                    } else {
                        if (a.getObject() instanceof Part) {
                            Part part = (Part) a.getObject();
                            ds = new FilePartDataSource(
                                    part,
                                    a.getType(part.getMimeType()),
                                    a.getName(part.getUploadName()));
                        } else {
                            // TODO: other classes?
                            throw new AddressException("Not yet supported: " + a.getObject());
                        }
                    }

                    bodypart = new MimeBodyPart();
                    bodypart.setDataHandler(new DataHandler(ds));
                    bodypart.setFileName(ds.getName());
                    multipart.addBodyPart(bodypart);
                }
            }
View Full Code Here

                // BodyParts contain a list of Maps items containing content(String) and type(String) of the attachement
                MimeMultipart mp = new MimeMultipart();
                Debug.logInfo(bodyParts.size() + " multiparts found",module);
                for (Map<String, Object> bodyPart: bodyParts) {
                    Object bodyPartContent = bodyPart.get("content");
                    MimeBodyPart mbp = new MimeBodyPart();

                    if (bodyPartContent instanceof String) {
                        Debug.logInfo("part of type: " + bodyPart.get("type") + " and size: " + bodyPart.get("content").toString().length() , module);
                        mbp.setText((String) bodyPartContent, "UTF-8", ((String) bodyPart.get("type")).substring(5));
                    } else if (bodyPartContent instanceof byte[]) {
                        ByteArrayDataSource bads = new ByteArrayDataSource((byte[]) bodyPartContent, (String) bodyPart.get("type"));
                        Debug.logInfo("part of type: " + bodyPart.get("type") + " and size: " + ((byte[]) bodyPartContent).length , module);
                        mbp.setDataHandler(new DataHandler(bads));
                    } else if (bodyPartContent instanceof DataHandler) {
                        mbp.setDataHandler((DataHandler) bodyPartContent);
                    } else {
                        mbp.setDataHandler(new DataHandler(bodyPartContent, (String) bodyPart.get("type")));
                    }

                    String fileName = (String) bodyPart.get("filename");
                    if (fileName != null) {
                        mbp.setFileName(fileName);
                    }
                    mp.addBodyPart(mbp);
                }
                mail.setContent(mp);
                mail.saveChanges();
View Full Code Here

    /**
     * Lets encode a multipart mime message
     */
    protected void populateMimeMessageBody(MimeMessage message) throws MessagingException {
        MimeBodyPart plainPart = new MimeBodyPart();
        plainPart.setText(body);

        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setText("<html><body>" + body + "</body></html>");

        Multipart alt = new MimeMultipart("alternative");
        alt.addBodyPart(plainPart);
        alt.addBodyPart(htmlPart);

        Multipart mixed = new MimeMultipart("mixed");
        MimeBodyPart wrap = new MimeBodyPart();
        wrap.setContent(alt);
        mixed.addBodyPart(wrap);

        mixed.addBodyPart(plainPart);
        mixed.addBodyPart(htmlPart);

View Full Code Here

                Multipart mp = (Multipart) msg.getContent();
                for (int j = 0, n = mp.getCount(); i < n; i++) {
                  Part part = mp.getBodyPart(i);
                  String disposition = part.getDisposition();
                  if ((disposition == null)) {
                    MimeBodyPart mbp = (MimeBodyPart) part;
                    if (mbp.isMimeType(EmailConfig.MIMETYPE_TEXT_PLAIN)) {
                      rd.addField(EmailConfig.EMAIL_BODY, mbp.getContent().toString());
                    } else if (mbp.isMimeType(EmailConfig.MIMETYPE_HTML)) {
                      rd.addField(EmailConfig.EMAIL_BODY, mbp.getContent().toString()); //handle html accordingly. Returns content with html tags
                    }
                  }
                }
              } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_DATE)) {
                Date sentDate = msg.getSentDate();
View Full Code Here

   */
  protected void sendBuffer(LoggingEvent triggeringEvent) {
    // Note: this code already owns the monitor for this
    // appender. This frees us from needing to synchronize on 'cb'.
    try {
      MimeBodyPart part = new MimeBodyPart();
     
      String computedSubject = computeSubject(triggeringEvent);
      msg.setSubject(computedSubject, charset);
     
      StringBuffer sbuf = new StringBuffer();
      String t = layout.getHeader();

      if (t != null) {
        sbuf.append(t);
      }

      int len = cb.length();

      for (int i = 0; i < len; i++) {
        //sbuf.append(MimeUtility.encodeText(layout.format(cb.get())));
        LoggingEvent event = cb.get();
        sbuf.append(layout.format(event));

        if (layout.ignoresThrowable()) {
          String[] s = event.getThrowableStrRep();

          if (s != null) {
            for (int j = 0; j < s.length; j++) {
              sbuf.append(s[j]);
              sbuf.append(Layout.LINE_SEP);
            }
          }
        }
      }

      t = layout.getFooter();

      if (t != null) {
        sbuf.append(t);
      }

      part.setContent(sbuf.toString(), layout.getContentType() + ";charset=" + charset);

      Multipart mp = new MimeMultipart();
      mp.addBodyPart(part);
      msg.setContent(mp);

View Full Code Here

    throws SOAPException, MessagingException, IOException {
    SOAPContext respCtx = st.getResponseSOAPContext();
    BufferedReader in = null;
    String payloadStr = null;

    MimeBodyPart rootPart = respCtx.getRootPart();
    if (rootPart.isMimeType("text/*")) {
      // Get the input stream to read the response envelope from.
      in = st.receive();
      payloadStr = IOUtils.getStringFromReader(in);
    }

    // Check Content-Type of root part of response to see if it's
    // consistent with a SOAP envelope (text/xml).
    if (!rootPart.isMimeType(Constants.HEADERVAL_CONTENT_TYPE)) {
      throw new SOAPException(Constants.FAULT_CODE_PROTOCOL,
        "Unsupported response content type \"" +
        rootPart.getContentType() + "\", must be: \"" +
        Constants.HEADERVAL_CONTENT_TYPE + "\"." +
        (payloadStr == null ? "" : " Response was:\n" + payloadStr));
    }

    return payloadStr;
View Full Code Here

TOP

Related Classes of javax.mail.internet.MimeBodyPart$MimePartDataHandler

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.