Example usage for javax.mail URLName getPassword

List of usage examples for javax.mail URLName getPassword

Introduction

In this page you can find the example usage for javax.mail URLName getPassword.

Prototype

public String getPassword() 

Source Link

Document

Returns the password of this URLName.

Usage

From source file:com.adaptris.core.mail.MailHelper.java

static final URLName createURLName(String urlString, String username, String password)
        throws PasswordException {
    URLName url = new URLName(urlString);
    String realPassword = url.getPassword();
    String realUser = url.getUsername();
    if (realUser == null && !isEmpty(username)) {
        realUser = username;/*www.  ja  v a 2 s  . c  o m*/
    }
    if (url.getPassword() == null && password != null) {
        realPassword = Password.decode(password);
    }
    return new URLName(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), realUser, realPassword);
}

From source file:com.adaptris.mail.MailReceiverCase.java

protected static final URLName createURLName(String urlString, String uname, String pw)
        throws PasswordException {
    URLName url = new URLName(urlString);
    String password = url.getPassword();
    String username = url.getUsername();
    if (username == null && !isEmpty(uname)) {
        username = uname;//from  w w w.j a  va2 s. c  o  m
    }
    if (url.getPassword() == null && pw != null) {
        password = Password.decode(pw);
    }
    return new URLName(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), username, password);
}

From source file:com.adaptris.util.TestURLName.java

public void testUrl() throws Exception {
    URLName url = new URLName(testUrl);
    assertEquals(protocol, url.getProtocol());
    assertEquals(username, url.getUsername());
    assertEquals(password, url.getPassword());
    assertEquals(host, url.getHost());/*  w  ww .j  av  a 2  s  .co  m*/
    assertEquals(testUrl, url.toString());
}

From source file:org.springframework.integration.mail.MailTransportUtils.java

/**
 * Returns a string representation of the given {@link URLName}, where the
 * password has been protected./*from w w w.  j a va  2s .  c  om*/
 */
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();
    StringBuffer tempURL = new StringBuffer();
    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();
}

From source file:org.springframework.ws.transport.mail.support.MailTransportUtils.java

/** Returns a string representation of the given {@link URLName}, where the password has been protected. */
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();//  w  w  w.j  a  v a  2 s . c o  m
    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();
}