Package javax.mail.internet

Examples of javax.mail.internet.MimeMultipart$MimeBodyPartInputStream


                Assert.assertEquals(to.getPersonal(), "Gavin King");
                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
                Assert.assertEquals(from.getAddress(), "do-not-reply@jboss.com");
                Assert.assertEquals(from.getPersonal(), "Seam");
                Assert.assertEquals(renderedMessage.getSubject(), "Try out Seam!");
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();               
   
                Assert.assertEquals(body.getCount(), 4); //3 Attachments and 1 MimeMultipart               
               
                // The root multipart/related
                Assert.assertNotNull(body.getBodyPart(0));
                Assert.assertTrue(body.getBodyPart(0) instanceof MimeBodyPart);
                MimeBodyPart bodyPart = (MimeBodyPart) body.getBodyPart(0);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertTrue(bodyPart.getContent() instanceof MimeMultipart);
                Assert.assertTrue(bodyPart.isMimeType("multipart/related"));
               
                MimeMultipart attachments = (MimeMultipart) bodyPart.getContent();
               
                Assert.assertEquals(attachments.getCount(), 3); //2 Attachments and 1 MimeMultipart
               
                // Attachment 0 (the actual message)
                Assert.assertNotNull(attachments.getBodyPart(0));               
                Assert.assertTrue(attachments.getBodyPart(0) instanceof MimeBodyPart);
                bodyPart = (MimeBodyPart) attachments.getBodyPart(0);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertTrue(bodyPart.isMimeType("text/html"));
                Assert.assertEquals(bodyPart.getDisposition(), "inline");
               
                // Inline Attachment 1 // Attachment Jboss Logo
                Assert.assertNotNull(attachments.getBodyPart(1));               
                Assert.assertTrue(attachments.getBodyPart(1) instanceof MimeBodyPart);
                bodyPart = (MimeBodyPart) attachments.getBodyPart(1);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertTrue(bodyPart.getContent() instanceof InputStream);
                Assert.assertEquals(bodyPart.getFileName(), "jboss.jpg");
                Assert.assertTrue(bodyPart.isMimeType("image/jpeg"));
                Assert.assertEquals(bodyPart.getDisposition(), "inline");
                Assert.assertNotNull(bodyPart.getContentID());
               
                // Inline Attachment 1 // Attachment Gavin Pic
                Assert.assertNotNull(attachments.getBodyPart(2));               
                Assert.assertTrue(attachments.getBodyPart(2) instanceof MimeBodyPart);
                bodyPart = (MimeBodyPart) attachments.getBodyPart(2);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertTrue(bodyPart.getContent() instanceof InputStream);
                Assert.assertEquals(bodyPart.getFileName(), "Gavin_King.jpg");
                Assert.assertTrue(bodyPart.isMimeType("image/png"));
                Assert.assertEquals(bodyPart.getDisposition(), "inline");
View Full Code Here


                // m:header
                Assert.assertNotNull(renderedMessage.getHeader("X-Sent-From"));
                Assert.assertEquals(renderedMessage.getHeader("X-Sent-From").length, 1);
                Assert.assertEquals(renderedMessage.getHeader("X-Sent-From")[0], "Seam");
               
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();
               
                // Check the alternative facet
                Assert.assertTrue(renderedMessage.getContentType().startsWith("multipart/mixed"));
                Assert.assertEquals(body.getCount(), 1);
                MimeBodyPart bodyPart = (MimeBodyPart) body.getBodyPart(0);
                Assert.assertTrue(bodyPart.getContentType().startsWith("multipart/alternative"));
                Assert.assertTrue(bodyPart.getContent() instanceof MimeMultipart);
                MimeMultipart bodyParts = (MimeMultipart) bodyPart.getContent();
                Assert.assertEquals(bodyParts.getCount(), 2);
                Assert.assertTrue(bodyParts.getBodyPart(0) instanceof MimeBodyPart);
                Assert.assertTrue(bodyParts.getBodyPart(1) instanceof MimeBodyPart);
                MimeBodyPart alternative = (MimeBodyPart) bodyParts.getBodyPart(0);
                MimeBodyPart html = (MimeBodyPart) bodyParts.getBodyPart(1);
                Assert.assertTrue(alternative.isMimeType("text/plain"));
                Assert.assertEquals(alternative.getDisposition(), "inline");
                Assert.assertTrue(html.isMimeType("text/html"));
                Assert.assertEquals(html.getDisposition(), "inline");
View Full Code Here

                Assert.assertEquals(renderedMessage.getSubject(), "Plain text email sent by Seam");
               
                // Check the body
               
                Assert.assertNotNull(renderedMessage.getContent());
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();
                Assert.assertEquals(body.getCount(), 1);
                MimeBodyPart bodyPart = (MimeBodyPart) body.getBodyPart(0);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertEquals(bodyPart.getDisposition(), "inline");
                Assert.assertTrue(bodyPart.isMimeType("text/plain"));
            }
        }.run();
View Full Code Here

                Assert.assertNull(renderedMessage.getHeader("Priority"));
                Assert.assertNull(renderedMessage.getHeader("Importance"));
               
                // Check the body
               
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();
               
                // Check the alternative facet
                Assert.assertTrue(renderedMessage.getContentType().startsWith("multipart/mixed"));
                Assert.assertEquals(body.getCount(), 1);
                MimeBodyPart bodyPart = (MimeBodyPart) body.getBodyPart(0);
                Assert.assertTrue(bodyPart.getContentType().startsWith("multipart/alternative"));
                Assert.assertTrue(bodyPart.getContent() instanceof MimeMultipart);
                MimeMultipart bodyParts = (MimeMultipart) bodyPart.getContent();
                Assert.assertEquals(bodyParts.getCount(), 2);
                Assert.assertTrue(bodyParts.getBodyPart(0) instanceof MimeBodyPart);
                Assert.assertTrue(bodyParts.getBodyPart(1) instanceof MimeBodyPart);
                MimeBodyPart alternative = (MimeBodyPart) bodyParts.getBodyPart(0);
                MimeBodyPart html = (MimeBodyPart) bodyParts.getBodyPart(1);
                Assert.assertTrue(alternative.isMimeType("text/plain"));
                Assert.assertEquals(alternative.getDisposition(), "inline");
                Assert.assertTrue(html.isMimeType("text/html"));
                Assert.assertEquals(html.getDisposition(), "inline");
            }
View Full Code Here

      InputStream response = method.getResponseBodyAsStream();
      BufferedInputStream in = new BufferedInputStream(response);
      String contentType = method.getResponseHeader("content-type").getValue();
      System.out.println(contentType);
      ByteArrayDataSource ds = new ByteArrayDataSource(in, contentType);
      MimeMultipart mimeMultipart = new MimeMultipart(ds);
      Assert.assertEquals(mimeMultipart.getCount(), 3);
      method.releaseConnection();

   }
View Full Code Here

      Assert.assertEquals(HttpServletResponse.SC_OK, status);
      InputStream response = method.getResponseBodyAsStream();
      BufferedInputStream in = new BufferedInputStream(response);
      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());

View Full Code Here

      InputStream response = method.getResponseBodyAsStream();
      BufferedInputStream in = new BufferedInputStream(response);
      String contentType = method.getResponseHeader("content-type")
              .getValue();
      ByteArrayDataSource ds = new ByteArrayDataSource(in, contentType);
      MimeMultipart mimeMultipart = new MimeMultipart(ds);
      Assert.assertEquals(mimeMultipart.getCount(), 2);
      method.releaseConnection();
   }
View Full Code Here

      final String toAddress, final List<FileItem> files) {

    Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        try {
          Multipart mp = new MimeMultipart();
          MimeBodyPart htmlPart = new MimeBodyPart();
            htmlPart.setContent(htmlBody, "text/html");
            htmlPart.setHeader("Content-type", "text/html; charset=UTF-8");
            mp.addBodyPart(htmlPart);
            for (FileItem item : files) {
              MimeBodyPart attachment = new MimeBodyPart();
                attachment.setFileName(item.getFilename());
                String mimeType = MimeType.getContentTypeByExt(
                    FolderUtil.getFileExt(item.getFilename()));
                DataSource ds = new ByteArrayDataSource(item.getData(), mimeType);
                attachment.setDataHandler(new DataHandler(ds));
                mp.addBodyPart(attachment);
            }
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(fromAddress, fromText));
            msg.addRecipient(Message.RecipientType.TO,
                             new InternetAddress(toAddress, toAddress));
View Full Code Here

// Multipart nur bei Attachments!

           // send the body
          MimeBodyPart bodypart               = null;
          MimeBodyPart alternativeBodypart    = null;
          MimeMultipart multipart             = null;
          if (this.haveAlternative()){
            multipart = new MimeMultipart("alternative");
          }else{
            multipart = new MimeMultipart();
         }

           bodypart  = new MimeBodyPart();
           if (contentType.startsWith("text/")){
              bodypart.setContent( this.body,this.contentType + ";charset= " + this.charset);
           }else{
              bodypart.setContent( this.body,this.contentType);
           }          
       
           multipart.addBodyPart(bodypart);
          
//         Alternativer Body gesetzt? Nur wenn keine Attachments vorhanden!!!
          
           if (this.haveAlternative()){
            alternativeBodypart  = new MimeBodyPart();
            if (contentType.startsWith("text/")){
                alternativeBodypart.setContent( this.alternativeBody,this.alternativeContentType + ";charset= " + this.alternativeCharset);
            }else{
                alternativeBodypart.setContent( this.alternativeBody,this.alternativeContentType);
            }          
            multipart.addBodyPart(alternativeBodypart);
           }
          

          
           message.setContent(multipart);
View Full Code Here

      
//      Attachments entfernen
        MimeMessage mm = new MimeMessage(message);
        Object mmpo=mm.getContent();
        if (  ( mmpo instanceof MimeMultipart ) ){
          MimeMultipart mmp= (MimeMultipart) mmpo;
     
           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

Related Classes of javax.mail.internet.MimeMultipart$MimeBodyPartInputStream

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.