本文整理了Java中javax.mail.Address.toString()
方法的一些代码示例,展示了Address.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.toString()
方法的具体详情如下:
包路径:javax.mail.Address
类名称:Address
方法名:toString
[英]Return a String representation of this address object.
[中]返回此地址对象的字符串表示形式。
代码示例来源:origin: oblac/jodd
/**
* Creates new email address from {@link InternetAddress}.
*
* @param address {@link Address} to convert.
*/
public static EmailAddress of(final Address address) {
return of(address.toString());
}
代码示例来源:origin: pentaho/pentaho-kettle
when( addrFrom1.toString() ).thenReturn( FROM1 );
Address addrFrom2 = mock( Address.class );
when( addrFrom2.toString() ).thenReturn( FROM2 );
Address addrRep1 = mock( Address.class );
when( addrRep1.toString() ).thenReturn( REP1 );
Address addrRep2 = mock( Address.class );
when( addrRep2.toString() ).thenReturn( REP2 );
Address allRec1 = mock( Address.class );
when( allRec1.toString() ).thenReturn( REC1 );
Address allRec2 = mock( Address.class );
when( allRec2.toString() ).thenReturn( REC2 );
代码示例来源:origin: spring-projects/spring-integration
private static String[] convertToStringArray(Address[] addresses) {
if (addresses != null) {
String[] addressStrings = new String[addresses.length];
for (int i = 0; i < addresses.length; i++) {
addressStrings[i] = addresses[i].toString();
}
return addressStrings;
}
return new String[0];
}
代码示例来源:origin: oblac/jodd
@Test
void testFromToBccCc() throws MessagingException {
final Email email = Email.create()
.from(FROM_EXAMPLE_COM)
.to(TO1_EXAMPLE_COM).to("Major Tom", "to2@example.com")
.cc(CC1_EXAMPLE_COM).cc("Major Carson", "cc2@example.com")
.bcc("Major Ben", "bcc1@example.com").bcc(BCC2_EXAMPLE_COM);
final Message message = createMessage(email);
assertEquals(1, message.getFrom().length);
assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString());
assertEquals(6, message.getAllRecipients().length);
assertEquals(2, message.getRecipients(RecipientType.TO).length);
assertEquals(TO1_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString());
assertEquals("Major Tom <to2@example.com>", message.getRecipients(RecipientType.TO)[1].toString());
assertEquals(2, message.getRecipients(RecipientType.CC).length);
assertEquals(CC1_EXAMPLE_COM, message.getRecipients(RecipientType.CC)[0].toString());
assertEquals("Major Carson <cc2@example.com>", message.getRecipients(RecipientType.CC)[1].toString());
assertEquals(2, message.getRecipients(RecipientType.BCC).length);
assertEquals("Major Ben <bcc1@example.com>", message.getRecipients(RecipientType.BCC)[0].toString());
assertEquals(BCC2_EXAMPLE_COM, message.getRecipients(RecipientType.BCC)[1].toString());
}
代码示例来源:origin: apache/nifi
assertEquals("test@apache.org", message.getFrom()[0].toString());
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());
assertEquals("recipientcc@apache.org", message.getRecipients(RecipientType.CC)[0].toString());
assertEquals("anothercc@apache.org", message.getRecipients(RecipientType.CC)[1].toString());
assertEquals("recipientbcc@apache.org", message.getRecipients(RecipientType.BCC)[0].toString());
assertEquals("anotherbcc@apache.org", message.getRecipients(RecipientType.BCC)[1].toString());
代码示例来源:origin: apache/nifi
session.getProvenanceReporter().send(flowFile, "mailto:" + message.getAllRecipients()[0].toString());
session.transfer(flowFile, REL_SUCCESS);
logger.info("Sent email as a result of receiving {}", new Object[]{flowFile});
代码示例来源:origin: spring-projects/spring-integration
private static String convertToString(Address[] addresses) {
if (addresses == null || addresses.length == 0) {
return null;
}
Assert.state(addresses.length == 1, "expected a single value but received an Array");
return addresses[0].toString();
}
代码示例来源: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/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());
assertEquals(1, message.getRecipients(RecipientType.BCC).length);
assertEquals("bcc@apache.org", message.getRecipients(RecipientType.BCC)[0].toString());
assertEquals(1, message.getRecipients(RecipientType.CC).length);
assertEquals("cc@apache.org",message.getRecipients(RecipientType.CC)[0].toString());
assertEquals("bulk", MimeUtility.decodeText(message.getHeader("Precedence")[0]));
assertEquals("búlk", MimeUtility.decodeText(message.getHeader("PrecedenceEncodeDecodeTest")[0]));
代码示例来源: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/nifi
assertEquals("test@apache.org", message.getFrom()[0].toString());
assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].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: oblac/jodd
assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString());
assertEquals(TO_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString());
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Set the RFC 822 "From" header field. Any existing values are
* replaced with the given address. If address is <code>null</code>,
* this header is removed.
*
* @param address the sender of this message
* @exception IllegalWriteException if the underlying
* implementation does not support modification
* of existing values
* @exception IllegalStateException if this message is
* obtained from a READ_ONLY folder.
* @exception MessagingException for other failures
*/
public void setFrom(Address address) throws MessagingException {
if (address == null)
removeHeader("From");
else
setHeader("From", MimeUtility.fold(6, address.toString()));
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Set the RFC 822 "Sender" header field. Any existing values are
* replaced with the given address. If address is <code>null</code>,
* this header is removed.
*
* @param address the sender of this message
* @exception IllegalWriteException if the underlying
* implementation does not support modification
* of existing values
* @exception IllegalStateException if this message is
* obtained from a READ_ONLY folder.
* @exception MessagingException for other failures
* @since JavaMail 1.3
*/
public void setSender(Address address) throws MessagingException {
if (address == null)
removeHeader("Sender");
else
setHeader("Sender", MimeUtility.fold(8, address.toString()));
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Set the RFC 822 "From" header field. Any existing values are
* replaced with the given address. If address is <code>null</code>,
* this header is removed.
*
* @param address the sender of this message
* @exception IllegalWriteException if the underlying
* implementation does not support modification
* of existing values
* @exception IllegalStateException if this message is
* obtained from a READ_ONLY folder.
* @exception MessagingException for other failures
*/
@Override
public void setFrom(Address address) throws MessagingException {
if (address == null)
removeHeader("From");
else
setHeader("From", MimeUtility.fold(6, address.toString()));
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Set the RFC 822 "Sender" header field. Any existing values are
* replaced with the given address. If address is <code>null</code>,
* this header is removed.
*
* @param address the sender of this message
* @exception IllegalWriteException if the underlying
* implementation does not support modification
* of existing values
* @exception IllegalStateException if this message is
* obtained from a READ_ONLY folder.
* @exception MessagingException for other failures
* @since JavaMail 1.3
*/
public void setSender(Address address) throws MessagingException {
if (address == null)
removeHeader("Sender");
else
setHeader("Sender", MimeUtility.fold(8, address.toString()));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testImap() throws Exception {
Message<?> message = this.imapChannel.receive(10000);
assertNotNull(message);
MimeMessage mm = (MimeMessage) message.getPayload();
assertEquals("Foo <foo@bar>", mm.getRecipients(RecipientType.TO)[0].toString());
assertEquals("Bar <bar@baz>", mm.getFrom()[0].toString());
assertEquals("Test Email", mm.getSubject());
assertThat(mm.getContent(), equalTo(TestMailServer.MailServer.MailHandler.BODY + "\r\n"));
}
代码示例来源:origin: pentaho/pentaho-kettle
.getMessage().getContentType() ) );
logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.EmailFrom.Label", Const.NVL( mailConn
.getMessage().getFrom()[0].toString(), "" ) ) );
logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.EmailSubject.Label", Const.NVL(
mailConn.getMessage().getSubject(), "" ) ) );
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Check if the "text" terms in the given SearchTerm contain
* non US-ASCII characters.
*
* @param term the search term
* @return true if only ASCII
*/
public static boolean isAscii(SearchTerm term) {
if (term instanceof AndTerm)
return isAscii(((AndTerm)term).getTerms());
else if (term instanceof OrTerm)
return isAscii(((OrTerm)term).getTerms());
else if (term instanceof NotTerm)
return isAscii(((NotTerm)term).getTerm());
else if (term instanceof StringTerm)
return isAscii(((StringTerm)term).getPattern());
else if (term instanceof AddressTerm)
return isAscii(((AddressTerm)term).getAddress().toString());
// Any other term returns true.
return true;
}
内容来源于网络,如有侵权,请联系作者删除!