MailTransportUtils { public static String toPasswordProtectedString(URLName name) { String protocol = name.getProtocol(); String username = name.getUsername(); String password = name.getPassword(); String host = name.getHost(); int port = name.getPort(); String file = name.getFile(); String ref = name.getRef(); StringBuilder tempURL = new StringBuilder(); if (protocol != null) { tempURL.append(protocol).append(':'); } if (StringUtils.hasLength(username) || StringUtils.hasLength(host)) { tempURL.append(" if (StringUtils.hasLength(username)) { tempURL.append(username); if (StringUtils.hasLength(password)) { tempURL.append(":*****"); } tempURL.append("@"); } if (StringUtils.hasLength(host)) { tempURL.append(host); } if (port != -1) { tempURL.append(':').append(Integer.toString(port)); } if (StringUtils.hasLength(file)) { tempURL.append('/'); } } if (StringUtils.hasLength(file)) { tempURL.append(file); } if (StringUtils.hasLength(ref)) { tempURL.append('#').append(ref); } return tempURL.toString(); } private  MailTransportUtils(); static InternetAddress getTo(URI uri); static String getSubject(URI uri); static void closeService(Service service); static void closeFolder(Folder folder); static void closeFolder(Folder folder, boolean expunge); static String toPasswordProtectedString(URLName name); static URI toUri(InternetAddress to, String subject);  }
@Test public void testToPasswordProtectedString() throws Exception { URLName name = new URLName("imap: String result = MailTransportUtils.toPasswordProtectedString(name); Assert.assertEquals("Password found in string", -1, result.indexOf("secret")); }