javax.mail.Message.getContent()方法的使用及代码示例

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

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

Message.getContent介绍

暂无

代码示例

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

content = mailMessage.getContent();
  subject = mailMessage.getSubject();
} catch (IOException e) {

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

@Override
protected AbstractIntegrationMessageBuilder<String> doTransform(javax.mail.Message mailMessage)
    throws Exception { // NOSONAR
  Object content = mailMessage.getContent();
  if (content instanceof String) {
    return this.getMessageBuilderFactory().withPayload((String) content);
  }
  if (content instanceof Multipart) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ((Multipart) content).writeTo(outputStream);
    return this.getMessageBuilderFactory().withPayload(
        new String(outputStream.toByteArray(), this.charset));
  }
  else if (content instanceof Part) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ((Part) content).writeTo(outputStream);
    return this.getMessageBuilderFactory().withPayload(
        new String(outputStream.toByteArray(), this.charset));
  }
  throw new IllegalArgumentException("failed to transform contentType ["
      + mailMessage.getContentType() + "] to String.");
}

代码示例来源:origin: apache/usergrid

private String getTokenFromMessage( Message msg ) throws IOException, MessagingException {
  String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
  // TODO better token extraction
  // this is going to get the wrong string if the first part is not
  // text/plain and the url isn't the last character in the email
  return StringUtils.substringAfterLast( body, "token=" );
}

代码示例来源:origin: pentaho/pentaho-kettle

@Before
public void before() throws IOException, KettleException, MessagingException {
 MockitoAnnotations.initMocks( this );
 Mockito.when( parentJob.getLogLevel() ).thenReturn( LogLevel.BASIC );
 entry.setParentJob( parentJob );
 entry.setSaveMessage( true );
 Mockito.when( message.getMessageNumber() ).thenReturn( 1 );
 Mockito.when( message.getContent() ).thenReturn( createMessageContent() );
 Mockito.when( mailConn.getMessage() ).thenReturn( message );
 Mockito.doNothing().when( mailConn ).openFolder( Mockito.anyBoolean() );
 Mockito.doNothing().when( mailConn ).openFolder( Mockito.anyString(), Mockito.anyBoolean() );
 Mockito.when( mailConn.getMessagesCount() ).thenReturn( 1 );
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Save attached files to a folder.
 *
 * @param foldername
 *          the target foldername
 * @param pattern
 *          regular expression to filter on files
 * @throws KettleException
 */
public void saveAttachedFiles( String foldername, Pattern pattern ) throws KettleException {
 Object content = null;
 try {
  content = getMessage().getContent();
  if ( content instanceof Multipart ) {
   handleMultipart( foldername, (Multipart) content, pattern );
  }
 } catch ( Exception e ) {
  throw new KettleException( BaseMessages.getString( PKG, "MailConnection.Error.SavingAttachedFiles", ""
   + this.message.getMessageNumber(), foldername ), e );
 } finally {
  if ( content != null ) {
   content = null;
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

int retval = 0;
try {
 content = message.getContent();
 if ( content instanceof Multipart ) {
  Multipart multipart = (Multipart) content;

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

@Test
void testSimpleText() throws MessagingException, IOException {
  final Email email = Email.create()
    .from(FROM_EXAMPLE_COM)
    .to(TO_EXAMPLE_COM)
    .subject(SUB)
    .textMessage(HELLO);
  final Message message = createMessage(email);
  final String content = (String) message.getContent();
  assertEquals(HELLO, content);
  assertTrue(message.getDataHandler().getContentType().contains("text/plain"));
}

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

@Test
void testSimpleTextWithCyrilic() throws MessagingException, IOException {
  final Email email = Email.create()
    .from("Тијана Милановић <t@gmail.com>")
    .to("Јодд <i@jodd.com>")
    .subject("Здраво!")
    .textMessage("шта радиш?");
  final Message message = createMessage(email);
  final String content = (String) message.getContent();
  assertEquals("шта радиш?", content);
  assertTrue(message.getDataHandler().getContentType().contains("text/plain"));
  assertEquals("=?UTF-8?B?0KLQuNGY0LDQvdCwINCc0LjQu9Cw0L3QvtCy0LjRmw==?= <t@gmail.com>", message.getFrom()[0].toString());
  assertEquals("=?UTF-8?B?0IjQvtC00LQ=?= <i@jodd.com>", message.getRecipients(RecipientType.TO)[0].toString());
}

代码示例来源:origin: apache/usergrid

String body = ( ( MimeMultipart ) confirmation.getContent() ).getBodyPart( 0 ).getContent().toString();
Boolean subbedEmailed = StringUtils.contains( body, "$" );

代码示例来源:origin: apache/nifi

assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
assertTrue(message.getContent() instanceof MimeMultipart);
final MimeMultipart multipart = (MimeMultipart) message.getContent();
final BodyPart part = multipart.getBodyPart(0);
final InputStream is = part.getDataHandler().getInputStream();

代码示例来源:origin: apache/nifi

assertEquals("\"test@apache.org\" <NiFi>", message.getFrom()[0].toString());
assertEquals("X-Mailer Header", "TestingNíFiNonASCII", MimeUtility.decodeText(message.getHeader("X-Mailer")[0]));
assertEquals("the message body", message.getContent());
assertEquals(1, message.getRecipients(RecipientType.TO).length);
assertEquals("to@apache.org", message.getRecipients(RecipientType.TO)[0].toString());

代码示例来源:origin: apache/nifi

@Test
public void testOutgoingMessage() throws Exception {
  // verifies that are set on the outgoing Message correctly
  runner.setProperty(PutEmail.SMTP_HOSTNAME, "smtp-host");
  runner.setProperty(PutEmail.HEADER_XMAILER, "TestingNiFi");
  runner.setProperty(PutEmail.FROM, "test@apache.org");
  runner.setProperty(PutEmail.MESSAGE, "Message Body");
  runner.setProperty(PutEmail.TO, "recipient@apache.org");
  runner.enqueue("Some Text".getBytes());
  runner.run();
  runner.assertQueueEmpty();
  runner.assertAllFlowFilesTransferred(PutEmail.REL_SUCCESS);
  // Verify that the Message was populated correctly
  assertEquals("Expected a single message to be sent", 1, processor.getMessages().size());
  Message message = processor.getMessages().get(0);
  assertEquals("test@apache.org", message.getFrom()[0].toString());
  assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
  assertEquals("Message Body", message.getContent());
  assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
  assertNull(message.getRecipients(RecipientType.BCC));
  assertNull(message.getRecipients(RecipientType.CC));
}

代码示例来源:origin: apache/usergrid

String mailContent = ( String ) ( ( MimeMultipart ) activation.getContent() ).getBodyPart( 1 ).getContent();
logger.info( mailContent );
assertTrue( StringUtils.contains( mailContent.toLowerCase(), activation_url.toLowerCase() ) );
mailContent = ( String ) ( ( MimeMultipart ) reset.getContent() ).getBodyPart( 1 ).getContent();
logger.info( mailContent );
assertTrue( StringUtils.contains( mailContent.toLowerCase(), reset_url.toLowerCase() ) );

代码示例来源:origin: apache/nifi

assertEquals("from@apache.org", message.getFrom()[1].toString());
assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
assertEquals("Some Text", message.getContent());
assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
assertEquals("another@apache.org", message.getRecipients(RecipientType.TO)[1].toString());

代码示例来源: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: apache/usergrid

String mailContent = ( String ) ( ( MimeMultipart ) confirmation.getContent() ).getBodyPart( 1 ).getContent();
logger.info( mailContent );
assertTrue( StringUtils.contains( mailContent.toLowerCase(), confirmation_url.toLowerCase() ) );

代码示例来源: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

final MimeMultipart multipart = (MimeMultipart) message.getContent();
assertEquals(2, multipart.getCount());

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

@Test
public void testAttachments() throws Exception {
  final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
  Folder folder = testAttachmentsGuts(receiver);
  Message[] messages = (Message[]) receiver.receive();
  Object content = messages[0].getContent();
  assertEquals("bar", ((Multipart) content).getBodyPart(0).getContent().toString().trim());
  assertEquals("foo", ((Multipart) content).getBodyPart(1).getContent().toString().trim());
  assertSame(folder, messages[0].getFolder());
}

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

private Stream<String> getMessageBodies(Message message) throws MessagingException, IOException {
  if (message != null) {
    return getMessageBodiesFromContent(message.getContent());
  }
  return Stream.of();
}

相关文章