javax.mail.internet.MimeMultipart.getCount()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(197)

本文整理了Java中javax.mail.internet.MimeMultipart.getCount()方法的一些代码示例,展示了MimeMultipart.getCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeMultipart.getCount()方法的具体详情如下:
包路径:javax.mail.internet.MimeMultipart
类名称:MimeMultipart
方法名:getCount

MimeMultipart.getCount介绍

[英]Return the number of enclosed BodyPart objects.
[中]返回封闭身体部位对象的数量。

代码示例

代码示例来源:origin: spring-projects/spring-framework

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;
}

代码示例来源:origin: org.springframework/spring-context-support

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;
}

代码示例来源:origin: voldemort/voldemort

for(int i = 0; i < mp.getCount(); i++) {
  MimeMultipart valueParts = new MimeMultipart(nestedDS);
  for(int valueId = 0; valueId < valueParts.getCount(); valueId++) {

代码示例来源:origin: voldemort/voldemort

for(int i = 0; i < mp.getCount(); i++) {
  MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(i);
  String serializedVC = part.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0];

代码示例来源:origin: voldemort/voldemort

"multipart/mixed");
MimeMultipart mp = new MimeMultipart(ds);
assertEquals("The number of body parts expected is not 1", 1, mp.getCount());

代码示例来源:origin: oblac/jodd

@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());
}

代码示例来源:origin: oblac/jodd

@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));
}

代码示例来源:origin: oblac/jodd

assertEquals(2, multipart.getCount());
assertEquals(2, mimeMultipart.getCount());
final MimeMultipart htmlMessage = (MimeMultipart) bodyPart.getContent();
assertTrue(htmlMessage.getContentType().contains("multipart/related"));
assertEquals(2, htmlMessage.getCount());

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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;
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * 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;
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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);
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

int count = mp.getCount();
for (int i = 0; i < count; i++) {
  if (convertTo8Bit((MimePart)mp.getBodyPart(i)))

代码示例来源:origin: com.sun.mail/javax.mail

int count = mp.getCount();
for (int i = 0; i < count; i++) {
  if (convertTo8Bit((MimePart)mp.getBodyPart(i)))

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: rchodava/datamill

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();
}

代码示例来源:origin: org.evolvis.bsi/kolab-ws

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");
}

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: com.gitlab.jhonsapp/simple-email

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));
    }
  }
}

代码示例来源:origin: at.researchstudio.sat/won-bot

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;
}

代码示例来源:origin: org.apache.james/james-server-mailets

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]);
    }
  }
}

相关文章