com.fsck.k9.mail.Address.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(227)

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

Address.<init>介绍

暂无

代码示例

代码示例来源:origin: k9mail/k-9

public Recipient(String name, String email, String addressLabel, long contactId, String lookupKey,
    int timesContacted, String sortKey) {
  this.address = new Address(email, name);
  this.contactId = contactId;
  this.addressLabel = addressLabel;
  this.cryptoStatus = RecipientCryptoStatus.UNDEFINED;
  this.contactLookupKey = lookupKey;
  this.timesContacted = timesContacted;
  this.sortKey = sortKey;
}

代码示例来源:origin: k9mail/k-9

private static Address[] stringArrayToAddressArray(String[] emails) {
    Address addresses[] = new Address[emails.length];
    for (int i = 0; i < emails.length; i++) {
      addresses[i] = new Address(emails[i]);
    }
    return addresses;
  }
}

代码示例来源:origin: k9mail/k-9

private static Address extractAddress(String headerValue) {
    if (headerValue == null || headerValue.isEmpty()) {
      return null;
    }

    Matcher matcher = MAILTO_CONTAINER_PATTERN.matcher(headerValue);
    if (!matcher.find()) {
      return null;
    }

    String mailToUri = matcher.group(1);
    String emailAddress = MailTo.parse(mailToUri).getTo();
    return new Address(emailAddress);
  }
}

代码示例来源:origin: k9mail/k-9

personal = addressList.substring(addressEndIndex + 2, pairEndIndex);
addresses.add(new Address(address, personal, false));
pairStartIndex = pairEndIndex + 2;

代码示例来源:origin: k9mail/k-9

/**
 * Parse a comma separated list of email addresses in human readable format and return an
 * array of Address objects, RFC-822 encoded.
 *
 * @param addressList
 * @return An array of 0 or more Addresses.
 */
public static Address[] parseUnencoded(String addressList) {
  List<Address> addresses = new ArrayList<>();
  if (!TextUtils.isEmpty(addressList)) {
    Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
    for (Rfc822Token token : tokens) {
      String address = token.getAddress();
      if (!TextUtils.isEmpty(address)) {
        addresses.add(new Address(token.getAddress(), token.getName(), false));
      }
    }
  }
  return addresses.toArray(EMPTY_ADDRESS_ARRAY);
}

代码示例来源:origin: k9mail/k-9

@Test
public void testToFriendlyArray() throws Exception {
  Address address1 = new Address("test@testor.com", "Tim Testor");
  Address address2 = new Address("foo@bar.com", "Foo Bar");
  Address[] addresses = new Address[] { address1, address2 };
  assertEquals("Tim Testor,Foo Bar", MessageHelper.toFriendly(addresses, contacts).toString());
}

代码示例来源:origin: k9mail/k-9

@Test
public void testToFriendlyWithChangeContactColor() throws Exception {
  Address address = new Address("test@testor.com");
  CharSequence friendly = MessageHelper.toFriendly(address, contactsWithFakeContact,
      true, true, Color.RED);
  assertTrue(friendly instanceof SpannableString);
  assertEquals("Tim Testor", friendly.toString());
}

代码示例来源:origin: k9mail/k-9

@Override
  public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
      case MENU_ITEM_EMAIL_SEND: {
        Uri uri = Uri.parse(WebView.SCHEME_MAILTO + email);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivityIfAvailable(getContext(), intent);
        break;
      }
      case MENU_ITEM_EMAIL_SAVE: {
        Contacts contacts = Contacts.getInstance(getContext());
        contacts.createContact(new Address(email));
        break;
      }
      case MENU_ITEM_EMAIL_COPY: {
        String label = getContext().getString(
            R.string.webview_contextmenu_email_clipboard_label);
        mClipboardManager.setText(label, email);
        break;
      }
    }
    return true;
  }
};

代码示例来源:origin: k9mail/k-9

@Test
public void testToFriendlyWithContactLookup() throws Exception {
  Address address = new Address("test@testor.com");
  assertEquals("Tim Testor", MessageHelper.toFriendly(address, contactsWithFakeContact).toString());
}

代码示例来源:origin: k9mail/k-9

private LocalMessage createFakeLocalMessage(MessageReference messageReference) {
    LocalMessage message = mock(LocalMessage.class);

    when(message.makeMessageReference()).thenReturn(messageReference);
    when(message.getPreviewType()).thenReturn(PreviewType.TEXT);
    when(message.getPreview()).thenReturn(PREVIEW);
    when(message.getSubject()).thenReturn(SUBJECT);
    when(message.getFrom()).thenReturn(new Address[] { new Address(SENDER_ADDRESS, SENDER_NAME) });
    when(message.getRecipients(RecipientType.TO))
        .thenReturn(new Address[] { new Address(RECIPIENT_ADDRESS, RECIPIENT_NAME) });

    return message;
  }
}

代码示例来源:origin: k9mail/k-9

@Test
public void toFriendly_spoofPreventionOverridesPersonal() {
  Address address = new Address("test@testor.com", "potus@whitehouse.gov");
  CharSequence friendly = MessageHelper.toFriendly(address, contacts);
  assertEquals("test@testor.com", friendly.toString());
}

代码示例来源:origin: k9mail/k-9

@Test
public void testToFriendlyWithoutCorrespondentNames() throws Exception {
  Address address = new Address("test@testor.com", "Tim Testor");
  CharSequence friendly = MessageHelper.toFriendly(address, contactsWithFakeContact,
      false, false, 0);
  assertEquals("test@testor.com", friendly.toString());
}

代码示例来源:origin: k9mail/k-9

@Test
  public void toFriendly_spoofPreventionDoesntOverrideContact() {
    Address address = new Address("test@testor.com", "Tim Testor");
    CharSequence friendly = MessageHelper.toFriendly(address, contactsWithFakeSpoofContact,
        true, false, 0);
    assertEquals("Tim@Testor", friendly.toString());
  }
}

代码示例来源:origin: k9mail/k-9

@Test
public void testToFriendlyShowsPersonalPartIfItExists() throws Exception {
  Address address = new Address("test@testor.com", "Tim Testor");
  assertEquals("Tim Testor", MessageHelper.toFriendly(address, contacts));
}

代码示例来源:origin: k9mail/k-9

@Test
public void testToFriendlyShowsEmailPartIfNoPersonalPartExists() throws Exception {
  Address address = new Address("test@testor.com");
  assertEquals("test@testor.com", MessageHelper.toFriendly(address, contacts));
}

代码示例来源:origin: k9mail/k-9

/**
 * Parse a comma separated list of addresses in RFC-822 format and return an
 * array of Address objects.
 *
 * @param addressList
 * @return An array of 0 or more Addresses.
 */
public static Address[] parse(String addressList) {
  if (TextUtils.isEmpty(addressList)) {
    return EMPTY_ADDRESS_ARRAY;
  }
  List<Address> addresses = new ArrayList<>();
  try {
    MailboxList parsedList =  DefaultAddressParser.DEFAULT.parseAddressList(addressList, DecodeMonitor.SILENT).flatten();
    for (int i = 0, count = parsedList.size(); i < count; i++) {
      Mailbox mailbox = parsedList.get(i);
      addresses.add(new Address(mailbox.getLocalPart() + "@" + mailbox.getDomain(), mailbox.getName(), false));
    }
  } catch (MimeException pe) {
    Timber.e(pe, "MimeException in Address.parse()");
    // broken addresses are never added to the resulting array
  }
  return addresses.toArray(EMPTY_ADDRESS_ARRAY);
}

代码示例来源:origin: k9mail/k-9

@Test
public void getRecipients_withXOriginalTo() throws Exception {
  MimeMessage msg = parseWithoutRecurse(toStream(
      "From: <adam@example.org>\r\n" +
          "To: <eva@example.org>\r\n" +
          "X-Original-To: <test@mail.com>\r\n" +
          "Subject: Testmail\r\n" +
          "MIME-Version: 1.0\r\n" +
          "Content-type: text/plain\r\n" +
          "Content-Transfer-Encoding: 7bit\r\n" +
          "\r\n" +
          "this is some test text."));
  Address[] xOriginalAddresses = msg.getRecipients(RecipientType.X_ORIGINAL_TO);
  assertEquals(1, xOriginalAddresses.length);
  assertEquals(new Address("<test@mail.com>"), xOriginalAddresses[0]);
}

代码示例来源:origin: k9mail/k-9

@Test
public void getRecipients_withDeliveredTo() throws Exception {
  MimeMessage msg = parseWithoutRecurse(toStream(
      "From: <adam@example.org>\r\n" +
          "To: <eva@example.org>\r\n" +
          "Delivered-To: <test@mail.com>\r\n" +
          "Subject: Testmail\r\n" +
          "MIME-Version: 1.0\r\n" +
          "Content-type: text/plain\r\n" +
          "Content-Transfer-Encoding: 7bit\r\n" +
          "\r\n" +
          "this is some test text."));
  Address[] deliveredToAddresses = msg.getRecipients(RecipientType.DELIVERED_TO);
  assertEquals(1, deliveredToAddresses.length);
  assertEquals(new Address("<test@mail.com>"), deliveredToAddresses[0]);
}

代码示例来源:origin: k9mail/k-9

@Test
public void getRecipients_withXEnvelopeTo() throws Exception {
  MimeMessage msg = parseWithoutRecurse(toStream(
      "From: <adam@example.org>\r\n" +
          "To: <eva@example.org>\r\n" +
          "X-Envelope-To: <test@mail.com>\r\n" +
          "Subject: Testmail\r\n" +
          "MIME-Version: 1.0\r\n" +
          "Content-type: text/plain\r\n" +
          "Content-Transfer-Encoding: 7bit\r\n" +
          "\r\n" +
          "this is some test text."));
  Address[] xEnvelopeToAddresses = msg.getRecipients(RecipientType.X_ENVELOPE_TO);
  assertEquals(1, xEnvelopeToAddresses.length);
  assertEquals(new Address("<test@mail.com>"), xEnvelopeToAddresses[0]);
}

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

相关文章