private MimeBodyPart getMainPart() throws MessagingException { MimeMultipart mimeMultipart = getMimeMultipart(); MimeBodyPart bodyPart = null; for (int i = 0; i < mimeMultipart.getCount(); i++) { BodyPart bp = mimeMultipart.getBodyPart(i); if (bp.getFileName() == null) { bodyPart = (MimeBodyPart) bp; } } if (bodyPart == null) { MimeBodyPart mimeBodyPart = new MimeBodyPart(); mimeMultipart.addBodyPart(mimeBodyPart); bodyPart = mimeBodyPart; } return bodyPart; }
private MimeBodyPart getMainPart() throws MessagingException { MimeMultipart mimeMultipart = getMimeMultipart(); MimeBodyPart bodyPart = null; for (int i = 0; i < mimeMultipart.getCount(); i++) { BodyPart bp = mimeMultipart.getBodyPart(i); if (bp.getFileName() == null) { bodyPart = (MimeBodyPart) bp; } } if (bodyPart == null) { MimeBodyPart mimeBodyPart = new MimeBodyPart(); mimeMultipart.addBodyPart(mimeBodyPart); bodyPart = mimeBodyPart; } return bodyPart; }
for(int i = 0; i < mp.getCount(); i++) { MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(i); String serializedVC = part.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0];
"multipart/mixed"); MimeMultipart mp = new MimeMultipart(ds); assertEquals("The number of body parts expected is not 1", 1, mp.getCount());
@Test void testHtmlAndOneAttachment() throws MessagingException, IOException { Email email = Email.create() .from("inf0@jodd.org") .to("ig0r@gmail.com") .subject("test6") .textMessage("Hello!") .attachment(EmailAttachment.with().content(BYTES_11_15, APPLICATION_ZIP)); Message message = createMessage(email); // wrapper final MimeMultipart multipart = (MimeMultipart) message.getContent(); assertEquals(2, multipart.getCount()); // inner content #1 MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(0); final MimeMultipart mimeMultipart = (MimeMultipart) mimeBodyPart.getContent(); assertEquals(1, mimeMultipart.getCount()); MimeBodyPart bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(0); assertEquals("Hello!", bodyPart.getContent()); }
@Test void testTextHtml() throws MessagingException, IOException { final Email email = Email.create() .from(FROM_EXAMPLE_COM) .to(TO_EXAMPLE_COM) .subject(SUB) .textMessage(HELLO) .htmlMessage("<html><body><h1>Hey!</h1></body></html>"); final Message message = createMessage(email); assertEquals(1, message.getFrom().length); assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString()); assertEquals(1, message.getRecipients(RecipientType.TO).length); assertEquals(TO_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString()); assertEquals(SUB, message.getSubject()); // wrapper final MimeMultipart multipart = (MimeMultipart) message.getContent(); assertEquals(1, multipart.getCount()); assertTrue(multipart.getContentType().contains("multipart/mixed")); // inner content final MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(0); final MimeMultipart mimeMultipart = (MimeMultipart) mimeBodyPart.getContent(); assertEquals(2, mimeMultipart.getCount()); assertTrue(mimeMultipart.getContentType().contains("multipart/alternative")); MimeBodyPart bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(0); assertEquals(HELLO, bodyPart.getContent()); assertTrue(bodyPart.getDataHandler().getContentType().contains(MimeTypes.MIME_TEXT_PLAIN)); bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(1); assertEquals("<html><body><h1>Hey!</h1></body></html>", bodyPart.getContent()); assertTrue(bodyPart.getDataHandler().getContentType().contains(MimeTypes.MIME_TEXT_HTML)); }
/** * Get the MimeBodyPart referred to by the given ContentID (CID). * Returns null if the part is not found. * * @param CID the ContentID of the desired part * @return the Part * @exception MessagingException for failures */ public synchronized BodyPart getBodyPart(String CID) throws MessagingException { parse(); int count = getCount(); for (int i = 0; i < count; i++) { MimeBodyPart part = (MimeBodyPart)getBodyPart(i); String s = part.getContentID(); if (s != null && s.equals(CID)) return part; } return null; }
/** * Get the MimeBodyPart referred to by the given ContentID (CID). * Returns null if the part is not found. * * @param CID the ContentID of the desired part * @return the Part * @exception MessagingException for failures */ public synchronized BodyPart getBodyPart(String CID) throws MessagingException { parse(); int count = getCount(); for (int i = 0; i < count; i++) { MimeBodyPart part = (MimeBodyPart)getBodyPart(i); String s = part.getContentID(); if (s != null && s.equals(CID)) return part; } return null; }
/** * Add a new part to the email. * * @param multipart The MimeMultipart. * @return An Email. * @throws EmailException see javax.mail.internet.MimeBodyPart * for definitions * @since 1.0 */ public Email addPart(final MimeMultipart multipart) throws EmailException { try { return addPart(multipart, getContainer().getCount()); } catch (final MessagingException me) { throw new EmailException(me); } }
int count = mp.getCount(); for (int i = 0; i < count; i++) { if (convertTo8Bit((MimePart)mp.getBodyPart(i)))
int count = mp.getCount(); for (int i = 0; i < count; i++) { if (convertTo8Bit((MimePart)mp.getBodyPart(i)))
MimeMultipart mp = new MimeMultipart(new ByteArrayDataSource(data, contentType)); int count = mp.getCount(); for (int i = 0; i < count; i++) { BodyPart bp = mp.getBodyPart(i); bp.saveFile(filepath + "_" + i); }
private String getCompleteContent(Message message) throws IOException, MessagingException { StringBuilder completeContent = new StringBuilder(); MimeMultipart contents = (MimeMultipart) message.getContent(); for (int i = 0; i < contents.getCount(); i++) { BodyPart part = contents.getBodyPart(i); String partText = getPartTextContent(part); completeContent.append(partText); } return completeContent.toString(); }
public static int IMAPMimeMultipart_getCount(MimeMultipart mmp) throws MessagingException { if (!Profiler.INSTANCE.isActive()) // only needed for better performance return mmp.getCount(); return (Integer)profileInvokeMExcep(mmp, "getCount"); }
Folder inbox = store.getFolder("Inbox"); inbox.open(Folder.READ_WRITE); DataHandler dataHandler = message.getDataHandler(); MimeMultipart mimeMultipart = (MimeMultipart) dataHandler.getContent(); for (int k = 0; k < mimeMultipart.getCount(); k++) { BodyPart bodyPart = mimeMultipart.getBodyPart(k); }
private void addMultiPart(MimeMultipart mp) throws MessagingException, IOException { for (int i = 0; i < mp.getCount(); i++) { BodyPart bp = mp.getBodyPart(i); if (bp.getContentType().toLowerCase().contains("multipart/")) { addMultiPart((MimeMultipart) bp.getContent()); } else { addPart(mp.getBodyPart(i)); } } }
private static String getMailTextFromMultiPart(MimeMultipart mm) throws MessagingException, IOException { for (int i = 0; i < mm.getCount(); i++) { BodyPart part = mm.getBodyPart(i); if (part.isMimeType("text/plain")) { return part.getContent().toString(); } else if (part.isMimeType("multipart/*")) { return getMailTextFromMultiPart((MimeMultipart) part.getContent()); } } return null; }
private void ensureResponse(String subject, String... contents) throws MessagingException, IOException { MimeMessage result = verifyHeaders(subject); MimeMultipart multipart = (MimeMultipart) result.getContent(); assertThat(multipart.getCount()).isEqualTo(contents.length); for (int i = 0; i < contents.length; i++) { if (multipart.getBodyPart(i).getContent() instanceof String) { assertThat(((String) multipart.getBodyPart(i).getContent()).trim()).isEqualTo(contents[i]); } else { assertThat(IOUtils.toString((ByteArrayInputStream) multipart.getBodyPart(i).getContent(), StandardCharsets.UTF_8).trim()).isEqualTo(contents[i]); } } }