private String parseAddress ( String address ) { try { StringBuilder buf = new StringBuilder ( ) ; InternetAddress [ ] netAddrs = InternetAddress . parseHeader ( address , false ) ; for ( InternetAddress netAddr : netAddrs ) { if ( buf . length ( ) > 0 ) { buf . append ( SP ) ; } buf . append ( LB ) ; String personal = netAddr . getPersonal ( ) ; if ( personal != null && ( personal . length ( ) != 0 ) ) { buf . append ( Q ) . append ( personal ) . append ( Q ) ; } else { buf . append ( NIL ) ; } buf . append ( SP ) ; buf . append ( NIL ) ; // should add route-addr buf . append ( SP ) ; try { // Remove quotes to avoid double quoting MailAddress mailAddr = new MailAddress ( netAddr . getAddress ( ) . replaceAll ( "\"" , "\\\\\"" ) ) ; buf . append ( Q ) . append ( mailAddr . getUser ( ) ) . append ( Q ) ; buf . append ( SP ) ; buf . append ( Q ) . append ( mailAddr . getHost ( ) ) . append ( Q ) ; } catch ( Exception pe ) { buf . append ( NIL + SP + NIL ) ; } buf . append ( RB ) ; } return buf . toString ( ) ; } catch ( AddressException e ) { throw new RuntimeException ( "Failed to parse address: " + address , e ) ; } }
Parses a String email address to an IMAP address string .