Package javax.mail

Examples of javax.mail.Multipart


   * @param oMessage The message.
   * @throws MessagingException
   */
  private void addMessageContent(MimeMessage oMessage) throws MessagingException {
    BodyPart oBodyP = new MimeBodyPart();
    Multipart oMultiP = new MimeMultipart();

    oMultiP.addBodyPart(oBodyP);
    oMessage.setContent(oMultiP);
    if (null == this.message) {
            this.message = "";
    }
    oBodyP.setText(this.message + "\n");

       
        if (null != attachments) {
      for (int i1 = 0; i1 < this.attachments.length; i1++) {
              oMultiP.addBodyPart(oBodyP = new MimeBodyPart());
              String sFile = this.attachments[i1];
              oBodyP.setDataHandler(new DataHandler(new FileDataSource(sFile)));
              oBodyP.setFileName(sFile.substring(1 + sFile.lastIndexOf("\\")));
          }
        }
       
        for (MimeBodyPart part : attachmentParts) {
            oMultiP.addBodyPart(part);
        }
  }
View Full Code Here


  private void returnCerts(X509Certificate certs[], HttpServletResponse resp, String name) throws IOException, ServletException {
    if (certs==null) {
      resp.sendError(HttpServletResponse.SC_NO_CONTENT, "No certificates with issuer hash DN: "+name);
      return;
    }
    final Multipart mp = new MimeMultipart();// mixed is default
    try {
      resp.setContentType(mp.getContentType());
      for( int i=0; i<certs.length; i++ ) {
        final String filename = "cert" + name + '-' + i + ".der";
        if (log.isDebugEnabled()) {
          log.debug("Returning certificate with issuerDN '"+CertTools.getIssuerDN(certs[i])+"' and subjectDN '"+CertTools.getSubjectDN(certs[i])+"'. Filename="+filename);
        }
        final InternetHeaders headers = new InternetHeaders();
        headers.addHeader("Content-type", "application/pkix-cert");
        headers.addHeader("Content-disposition", "attachment; filename="+filename);
        mp.addBodyPart(new MimeBodyPart(headers,certs[i].getEncoded()));
      }
      if (log.isTraceEnabled()) {
        log.trace("content type: "+mp.getContentType());       
      }
      mp.writeTo(resp.getOutputStream());
      resp.flushBuffer();
    } catch (CertificateEncodingException e) {
      throw new ServletException(e);
    } catch (MessagingException e) {
      throw new ServletException(e);
View Full Code Here

            msg.setContent(content, MailConfiguration.getMailMimeType());
            if (log.isDebugEnabled()) {
              log.debug("content: " + content);
            }
          } else {
            Multipart multipart = new MimeMultipart();
            // Add the text message first
            MimeBodyPart msgBody = new MimeBodyPart();
            msgBody.setContent(content, MailConfiguration.getMailMimeType());
            multipart.addBodyPart(msgBody);
            // Attach all the requested files
        for (int i=0; i<attachments.size(); i++) {
          MailAttachment mailAttachment = (MailAttachment) attachments.get(i);
              MimeBodyPart msgAttachment = new MimeBodyPart();
              msgAttachment.setDataHandler(mailAttachment.getDataHandler());
              msgAttachment.setFileName(mailAttachment.getName());
              multipart.addBodyPart(msgAttachment);
            }
            msg.setContent(multipart);
          }
          msg.setHeader("X-Mailer", "JavaMailer");
          msg.setSentDate(new Date());
View Full Code Here

            sm.setText(messageString);
        }
        // add message as message body part
        else {
            messageBodyPart.setContent(messageString, this.bodyMimeType);
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messageBodyPart);

            // process attachments
            Iterator i = this.attachments.iterator();
            while (i.hasNext()) {
                AttachmentDescriptor aD = (AttachmentDescriptor) i.next();
                messageBodyPart = new MimeBodyPart();

                if (!aD.isTextContent()) {
                    Source inputSource = resolver.resolveURI(aD.isURLSource() ? aD.strAttrSrc : aD.strAttrFile);
                    this.usedSources.add(inputSource);

                    DataSource dataSource = new SourceDataSource(inputSource, aD.strAttrMimeType, aD.strAttrName);
                    ((SourceDataSource) dataSource).enableLogging(getLogger());

                    messageBodyPart.setDataHandler(new DataHandler(dataSource));
                } else {
                    messageBodyPart.setContent(aD.strContent, aD.strAttrMimeType);
                }

                messageBodyPart.setFileName(aD.strAttrName);
                multipart.addBodyPart(messageBodyPart);
            }
            sm.setContent(multipart);
        }

        //sm.setReturnOption(SMTPMessage.RETURN_FULL);
View Full Code Here

    final String sURI = RFC4387URL.iHash.appendQueryToURL(getURL(), subjectID);
    // remove keyID from list of CA keyIds to be checked.
    Assert.assertTrue("The certificate '"+theCert.getSubjectX500Principal().getName()+"' already tested.", setOfSubjectKeyIDs.remove(keyID.key));
    log.debug("URL: '"+sURI+"'.");
    final Multipart multipart;
    try {
      multipart = new MimeMultipart(new MyDataSource(new URI(sURI).toURL()));
    } catch (MyDataSource.NoData e1) {
      return; // no sub CAs to the this CA
    }
    final int nrOfCerts = multipart.getCount();
    for ( int i=0; i<nrOfCerts; i++ ) {
      final X509Certificate cert = (X509Certificate)this.cf.generateCertificate(multipart.getBodyPart(i).getInputStream());
      try {
        cert.verify(theCert.getPublicKey());
      } catch (GeneralSecurityException e) {
        // CA probably signed by an old not any longer existing CA. But this old CA certificate should still be in the DB. Let's check the chain.
        checkIssuer(cert);
View Full Code Here

        // System.out.println(response.getOutputStreamContent());
        // make sure we got a multipart
        assertTrue(response.getContentType().matches("multipart/related;\\s*boundary=\".*\""));

        // parse the multipart, check there are two parts
        Multipart multipart = getMultipart(response);
        assertEquals(2, multipart.getCount());

        // now check the first part is a proper description
        BodyPart coveragesPart = multipart.getBodyPart(0);
        assertEquals("text/xml", coveragesPart.getContentType());
//        System.out.println("Coverages part: " + coveragesPart.getContent());
        assertEquals("<urn:ogc:wcs:1.1:coverages>", coveragesPart.getHeader("Content-ID")[0]);
        // read the xml document into a dom
        Document dom = dom(coveragesPart.getDataHandler().getInputStream());
        checkValidationErrors(dom, WCS11_SCHEMA);
        assertXpathEvaluatesTo(TASMANIA_BM.getLocalPart(),
                "wcs:Coverages/wcs:Coverage/ows:Title", dom);

        // the second part is the actual coverage
        BodyPart coveragePart = multipart.getBodyPart(1);
        assertEquals("image/tiff", coveragePart.getContentType());
        assertEquals("<theCoverage>", coveragePart.getHeader("Content-ID")[0]);
    }
View Full Code Here

    }

    private Multipart getMultipart(MockHttpServletResponse response) throws MessagingException,
            IOException {
        MimeMessage body = new MimeMessage((Session) null, getBinaryInputStream(response));
        Multipart multipart = (Multipart) body.getContent();
        return multipart;
    }
View Full Code Here

                + "&BoundingBox=-90,-180,90,180,urn:ogc:def:crs:EPSG:4326"
                + "&GridBaseCRS=urn:ogc:def:crs:EPSG:4326" + "&format=image/tiff";
        MockHttpServletResponse response = getAsServletResponse(request);

        // parse the multipart, check there are two parts
        Multipart multipart = getMultipart(response);
        assertEquals(2, multipart.getCount());
        BodyPart coveragePart = multipart.getBodyPart(1);
        assertEquals("image/tiff", coveragePart.getContentType());
        assertEquals("<theCoverage>", coveragePart.getHeader("Content-ID")[0]);

        // make sure we can read the coverage back
        ImageReader reader = ImageIO.getImageReadersByFormatName("tiff").next();
View Full Code Here

                + "&BoundingBox=-90,-180,90,180,urn:ogc:def:crs:EPSG:4326"
                + "&GridBaseCRS=urn:ogc:def:crs:EPSG:4326" + "&format=image/png";
        MockHttpServletResponse response = getAsServletResponse(request);

        // parse the multipart, check there are two parts
        Multipart multipart = getMultipart(response);
        assertEquals(2, multipart.getCount());
        BodyPart coveragePart = multipart.getBodyPart(1);
        assertEquals("image/png", coveragePart.getContentType());
        assertEquals("<theCoverage>", coveragePart.getHeader("Content-ID")[0]);

        // make sure we can read the coverage back
        ImageReader reader = ImageIO.getImageReadersByFormatName("png").next();
View Full Code Here

        // make sure we got a multipart
        assertTrue("Content type not mulipart but " + response.getContentType(), response
                .getContentType().matches("multipart/related;\\s*boundary=\".*\""));

        // parse the multipart, check the second part is a geotiff
        Multipart multipart = getMultipart(response);
        BodyPart coveragePart = multipart.getBodyPart(1);
        assertEquals("image/tiff", coveragePart.getContentType());
    }
View Full Code Here

TOP

Related Classes of javax.mail.Multipart

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.