Package javax.mail

Examples of javax.mail.Multipart


      }
      else if (content instanceof javax.mail.Message)  {
        handleMessage(directory, (javax.mail.Message) content, emailFragments);
      }
      else if (content instanceof Multipart) {
        final Multipart mp2 = (Multipart) content;
        handleMultipart(directory, mp2, mailMessage, emailFragments);
      }
      else {
        throw new IllegalStateException("Content type not handled: " + content.getClass().getSimpleName());
      }
View Full Code Here


    if (content instanceof String) {
      emailFragments.add(new EmailFragment(new File(subject), "message.txt", content));
    }
    else if (content instanceof Multipart) {
      Multipart multipart = (Multipart) content;
      handleMultipart(directoryToUse, multipart, mailMessage, emailFragments);
    }
    else {
      throw new IllegalStateException("This content type is not handled - " + content.getClass().getSimpleName());
    }
View Full Code Here

    private void assertOnMailResult(User user, VerificationToken token) throws MessagingException, IOException {
        List<MimeMessage> messages = mailSender.getMessages();
        assertThat(messages.size(), is(1));
        MimeMessage message = messages.get(0);
        assertThat(message.getAllRecipients()[0].toString(), is((user.getEmailAddress())));
        Multipart multipart = (Multipart)message.getContent();
        String content = (String)multipart.getBodyPart(0).getContent();
        assertThat(content, containsString(new String(Base64.encodeBase64(token.getToken().getBytes()))));
    }
View Full Code Here

        addresses[toIndex++] = new InternetAddress(t);
      }
      msg.setRecipients(Message.RecipientType.TO, addresses);
      msg.setSubject(subject);
      msg.setSentDate(new Date());
      final Multipart mp = new MimeMultipart();
      final MimeBodyPart mbp1 = new MimeBodyPart();
      mbp1.setText(message);
      mp.addBodyPart(mbp1);
      if (paths != null && paths.length > 0) {
        for (final Path path : paths) {
          final MimeBodyPart mbp = new MimeBodyPart();
          final FileDataSource fds = new FileDataSource(path.toFile());
          mbp.setDataHandler(new DataHandler(fds));
          mbp.setFileName(fds.getName());
          mp.addBodyPart(mbp);
        }
      }
      // text attachment
      // MimeBodyPart mbp2 = new MimeBodyPart();
      // mbp2.setText("some text in an attachment form");
View Full Code Here

      log.debug("Checking message body for commands");
      String msgRawContent = null;
      if (msg.getContentType().toLowerCase().indexOf("text") > -1) {
        msgRawContent = (String) msg.getContent();
      } else if (msg.getContentType().toLowerCase().indexOf("multipart") > -1) {
        final Multipart multipart = (Multipart) msg.getContent();
        BodyPart bodyPart = multipart.getBodyPart(0);
        msgRawContent = bodyPart.getContent().toString();
      } else {
        log.warn("Commands being ignored for content type: " + msg.getContentType());
      }
      if (msgRawContent != null) {
View Full Code Here

        assertNull(message.getRecipients(RecipientType.CC));
        assertNull(message.getRecipients(RecipientType.BCC));
        assertEquals(1, message.getRecipients(RecipientType.TO).length);
        assertEquals(recipient, message.getRecipients(RecipientType.TO)[0]);
        assertTrue(message.getContent() instanceof Multipart);
        Multipart multipart = (Multipart) message.getContent();
        assertEquals(2, multipart.getCount());
        assertEquals("text/plain; charset=\"iso-8859-1\"", multipart.getBodyPart(0).getContentType());
        assertEquals(plaintext, multipart.getBodyPart(0).getContent());
        assertEquals(plaintext, new GaeEmailUtils().getTextPart(message));
        assertEquals("text/html; charset=\"iso-8859-1\"", multipart.getBodyPart(1).getContentType())// seems like this ought to be text/html ???
        assertEquals(html, multipart.getBodyPart(1).getContent());
        assertEquals(html, new GaeEmailUtils().getHtmlPart(message));
    }
View Full Code Here

        assertNull(message.getRecipients(RecipientType.CC));
        assertNull(message.getRecipients(RecipientType.BCC));
        assertEquals(1, message.getRecipients(RecipientType.TO).length);
        assertEquals(recipient, message.getRecipients(RecipientType.TO)[0]);
        assertTrue(message.getContent() instanceof Multipart);
        Multipart multipart = (Multipart) message.getContent();
        assertEquals(2, multipart.getCount());
        assertEquals("text/plain; charset=\"iso-8859-1\"", multipart.getBodyPart(0).getContentType());
        assertEquals(plaintext, multipart.getBodyPart(0).getContent());
        assertEquals(plaintext, new GaeEmailUtils().getTextPart(message));
        assertEquals("text/html; charset=\"iso-8859-1\"", multipart.getBodyPart(1).getContentType())// seems like this ought to be text/html ???
        assertEquals(html, multipart.getBodyPart(1).getContent());
        assertEquals(html, new GaeEmailUtils().getHtmlPart(message));
    }
View Full Code Here

        assertNull(message.getRecipients(RecipientType.CC));
        assertNull(message.getRecipients(RecipientType.BCC));
        assertEquals(1, message.getRecipients(RecipientType.TO).length);
        assertEquals(recipient, message.getRecipients(RecipientType.TO)[0]);
        assertTrue(message.getContent() instanceof Multipart);
        Multipart multipart = (Multipart) message.getContent();
        assertEquals(2, multipart.getCount());
        assertEquals("text/plain; charset=\"iso-8859-1\"", multipart.getBodyPart(0).getContentType());
        assertEquals(plaintext, multipart.getBodyPart(0).getContent());
        assertEquals(plaintext, new GaeEmailUtils().getTextPart(message));
        assertEquals("text/html; charset=\"iso-8859-1\"", multipart.getBodyPart(1).getContentType())// seems like this ought to be text/html ???
        assertEquals(html, multipart.getBodyPart(1).getContent());
        assertEquals(html, new GaeEmailUtils().getHtmlPart(message));
    }
View Full Code Here

                if (message.getContent() instanceof String) {
                    if ("text/plain".equals(message.getContentType())) {
                        return (String) message.getContent();
                    }
                } else if (message.getContent() instanceof Multipart) {
                    Multipart multipart = (Multipart) message.getContent();
                    if (multipart.getCount() == 2) {
                        MimeBodyPart textPart = (MimeBodyPart) multipart.getBodyPart(0);
                        if (textPart.getContent() instanceof String) {
                            if (StringUtils.startsWith(textPart.getContentType(), "text/plain")) {
                                return (String) textPart.getContent();
                            }
                        }
View Full Code Here

     */
    public String getHtmlPart(Message message) {
        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

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.