コード例 #1
0
  /**
   * Parse the headerValue and delegate to {@link #getDisplayAddress(Mailbox)}
   *
   * <p>If no display address is found an empty String is returned
   *
   * @param headerValue
   * @return display
   */
  public static String getDisplayAddress(String headerValue) {
    AddressList addressList =
        LenientAddressParser.DEFAULT.parseAddressList(MimeUtil.unfold(headerValue));
    if (addressList != null && addressList.isEmpty() == false) {
      Address address = addressList.get(0);
      if (address instanceof Mailbox) {
        return getDisplayAddress((Mailbox) address);
      } else if (address instanceof Group) {
        Group group = (Group) address;
        if (group != null) {
          MailboxList mList = group.getMailboxes();
          if (mList != null && mList.isEmpty() == false) {
            return getDisplayAddress(mList.get(0));
          }
        }
      }
    }

    return "";
  }
コード例 #2
0
 /**
  * Parse the headerValue and delegate to {@link #getMailboxAddress(Mailbox)}
  *
  * <p>If no mailbox name is found an empty String is returned
  *
  * @param headerValue
  * @return mailbox
  */
 public static String getMailboxAddress(String headerValue) {
   AddressList aList = LenientAddressParser.DEFAULT.parseAddressList(headerValue);
   for (Address address : aList) {
     if (address instanceof Mailbox) {
       Mailbox m = (Mailbox) address;
       String mailboxName = m.getLocalPart();
       if (mailboxName == null) {
         mailboxName = "";
       }
       return mailboxName;
     } else if (address instanceof Group) {
       MailboxList mList = ((Group) address).getMailboxes();
       for (int a = 0; a < mList.size(); ) {
         String mailboxName = mList.get(a).getLocalPart();
         if (mailboxName == null) {
           mailboxName = "";
         }
         return mailboxName;
       }
     }
   }
   return "";
 }