本文整理了Java中com.fsck.k9.mail.Address.parse()
方法的一些代码示例,展示了Address.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.parse()
方法的具体详情如下:
包路径:com.fsck.k9.mail.Address
类名称:Address
方法名:parse
[英]Parse a comma separated list of addresses in RFC-822 format and return an array of Address objects.
[中]解析RFC-822格式的以逗号分隔的地址列表,并返回地址对象数组。
代码示例来源:origin: k9mail/k-9
public void initFromTrustIdAction(String trustId) {
addToAddresses(Address.parse(trustId));
currentCryptoMode = CryptoMode.CHOICE_ENABLED;
}
代码示例来源:origin: k9mail/k-9
private static Address[] toAddressArray(List<String> recipients) {
if (recipients.isEmpty()) {
return EMPTY_ADDRESS_LIST;
}
String addressList = toCommaSeparatedString(recipients);
return Address.parse(addressList);
}
代码示例来源:origin: k9mail/k-9
@Override
public Address[] getReplyTo() {
if (mReplyTo == null) {
mReplyTo = Address.parse(MimeUtility.unfold(getFirstHeader("Reply-to")));
}
return mReplyTo;
}
代码示例来源:origin: k9mail/k-9
@Override
public Address[] getSender() {
return Address.parse(MimeUtility.unfold(getFirstHeader("Sender")));
}
代码示例来源:origin: k9mail/k-9
@Override
public Address[] getFrom() {
if (mFrom == null) {
String list = MimeUtility.unfold(getFirstHeader("From"));
if (list == null || list.length() == 0) {
list = MimeUtility.unfold(getFirstHeader("Sender"));
}
mFrom = Address.parse(list);
}
return mFrom;
}
代码示例来源:origin: k9mail/k-9
@Test
public void equals_withoutPersonal_doesNotMatchWithAddress() throws Exception {
Address address = Address.parse("alice@example.org")[0];
Address address2 = Address.parse("Alice <alice@example.org>")[0];
boolean result = address.equals(address2);
assertFalse(result);
}
代码示例来源:origin: k9mail/k-9
@Override
protected Recipient defaultObject(String completionText) {
Address[] parsedAddresses = Address.parse(completionText);
if (!CharsetUtil.isASCII(completionText)) {
setError(getContext().getString(R.string.recipient_error_non_ascii));
return null;
}
if (parsedAddresses.length == 0 || parsedAddresses[0].getAddress() == null) {
setError(getContext().getString(R.string.recipient_error_parse_failed));
return null;
}
return new Recipient(parsedAddresses[0]);
}
代码示例来源:origin: k9mail/k-9
@Test
public void hashCode_withoutAddress() throws Exception {
Address[] addresses = Address.parse("name only");
assertEquals(0, addresses.length);
}
代码示例来源:origin: k9mail/k-9
/**
* test the possibility to parse "From:" fields with no email.
* for example: From: News for Vector Limited - Google Finance
* http://code.google.com/p/k9mail/issues/detail?id=3814
*/
@Test
public void parse_withMissingEmail__shouldSetPersonal() {
Address[] addresses = Address.parse("NAME ONLY");
assertEquals(0, addresses.length);
}
代码示例来源:origin: k9mail/k-9
@Test
public void equals_withoutPersonal_matchesSame() throws Exception {
Address address = Address.parse("alice@example.org")[0];
Address address2 = Address.parse("alice@example.org")[0];
assertNull(address.getPersonal());
boolean result = address.equals(address2);
assertTrue(result);
}
代码示例来源:origin: k9mail/k-9
@Test
public void multipartSigned__shouldCallOpenPgpApiAsync() throws Exception {
BodyPart signedBodyPart = spy(bodypart("text/plain", "content"));
Message message = messageFromBody(
multipart("signed", "protocol=\"application/pgp-signature\"",
signedBodyPart,
bodypart("application/pgp-signature", "content")
)
);
message.setFrom(Address.parse("Test <test@example.org>")[0]);
OutputStream outputStream = mock(OutputStream.class);
processSignedMessageAndCaptureMocks(message, signedBodyPart, outputStream);
assertEquals(OpenPgpApi.ACTION_DECRYPT_VERIFY, capturedApiIntent.getAction());
assertEquals("test@example.org", capturedApiIntent.getStringExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS));
verify(autocryptOperations).addAutocryptPeerUpdateToIntentIfPresent(message, capturedApiIntent);
verifyNoMoreInteractions(autocryptOperations);
}
代码示例来源:origin: k9mail/k-9
@Test
public void handlesInvalidBase64Encoding() throws Exception {
Address address = Address.parse("=?utf-8?b?invalid#?= <oops@example.com>")[0];
assertEquals("oops@example.com", address.getAddress());
}
}
代码示例来源:origin: k9mail/k-9
@Test
public void hashCode_withoutPersonal() throws Exception {
Address address = Address.parse("alice@example.org")[0];
assertNull(address.getPersonal());
address.hashCode();
}
代码示例来源:origin: k9mail/k-9
@Test
public void parse_withQuotedEncodedPersonal_shouldDecode() {
Address[] addresses = Address.parse(
"\"=?UTF-8?B?WWFob28h44OA44Kk44Os44Kv44OI44Kq44OV44Kh44O8?= \"<directoffer-master@mail.yahoo.co.jp>");
assertEquals("Yahoo!ダイレクトオファー ", addresses[0].getPersonal());
assertEquals("directoffer-master@mail.yahoo.co.jp", addresses[0].getAddress());
}
代码示例来源:origin: k9mail/k-9
@Test
public void generateMessageId_withReplyToAddress() throws Exception {
Message message = new MimeMessage();
message.setReplyTo(Address.parse("bob@example.com"));
String result = messageIdGenerator.generateMessageId(message);
assertEquals("<00000000-0000-4000-0000-000000000000@example.com>", result);
}
代码示例来源:origin: k9mail/k-9
@Test
public void parse_withEncodedPersonal_shouldDecode() {
Address[] addresses = Address.parse(
"=?UTF-8?B?WWFob28h44OA44Kk44Os44Kv44OI44Kq44OV44Kh44O8?= <directoffer-master@mail.yahoo.co.jp>");
assertEquals("Yahoo!ダイレクトオファー", addresses[0].getPersonal());
assertEquals("directoffer-master@mail.yahoo.co.jp", addresses[0].getAddress());
}
代码示例来源:origin: k9mail/k-9
@Test
public void parse_withUnusualEmails_shouldSetAddress() {
String[] testEmails = new String [] {
"prettyandsimple@example.com",
"very.common@example.com",
"disposable.style.email.with+symbol@example.com",
"other.email-with-dash@example.com",
//TODO: Handle addresses with quotes
/*
"\"much.more unusual\"@example.com",
"\"very.unusual.@.unusual.com\"@example.com",
//"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
"\"very.(),:;<>[]\\\".VERY.\\\"very@\\\\ \\\"very\\\".unusual\"@strange.example.com",
"\"()<>[]:,;@\\\\\\\"!#$%&'*+-/=?^_`{}| ~.a\"@example.org",
"\" \"@example.org",
*/
"admin@mailserver1",
"#!$%&'*+-/=?^_`{}|~@example.org",
"example@localhost",
"example@s.solutions",
"user@com",
"user@localserver",
"user@[IPv6:2001:db8::1]"
};
for(String testEmail: testEmails) {
Address[] addresses = Address.parse("Anonymous <"+testEmail+">");
assertEquals(1, addresses.length);
assertEquals(testEmail, addresses[0].getAddress());
}
}
代码示例来源:origin: k9mail/k-9
/**
* test name + valid email
*/
@Test
public void parse_withValidEmailAndPersonal_shouldSetBoth() {
Address[] addresses = Address.parse("Max Mustermann <maxmuster@mann.com>");
assertEquals(1, addresses.length);
assertEquals("maxmuster@mann.com", addresses[0].getAddress());
assertEquals("Max Mustermann", addresses[0].getPersonal());
}
代码示例来源:origin: k9mail/k-9
@Test
public void generateMessageId_withFromAndReplyToAddress() throws Exception {
Message message = new MimeMessage();
message.setFrom(new Address("alice@example.org"));
message.setReplyTo(Address.parse("bob@example.com"));
String result = messageIdGenerator.generateMessageId(message);
assertEquals("<00000000-0000-4000-0000-000000000000@example.org>", result);
}
代码示例来源:origin: k9mail/k-9
/**
* test with multi email addresses
*/
@Test
public void parse_withMultipleEmails_shouldDecodeBoth() {
Address[] addresses = Address.parse("lorem@ipsum.us,mark@twain.com");
assertEquals(2, addresses.length);
assertEquals("lorem@ipsum.us", addresses[0].getAddress());
assertEquals(null, addresses[0].getPersonal());
assertEquals("mark@twain.com", addresses[1].getAddress());
assertEquals(null, addresses[1].getPersonal());
}
内容来源于网络,如有侵权,请联系作者删除!