in bindings/servicemix-mail/src/main/java/org/apache/servicemix/mail/utils/MailUtils.java [130:200]
public static MailConnectionConfiguration configure(String uriString) throws ParseException {
MailConnectionConfiguration config = new MailConnectionConfiguration();
if (uriString == null || uriString.length() <= 0) {
throw new ParseException("The given connection uri (" + uriString + ") is invalid.");
}
URI uri = URI.create(uriString);
String value = uri.getHost();
if (value != null) {
config.setHost(value);
}
String scheme = uri.getScheme();
if (scheme != null) {
config.setProtocol(scheme);
} else {
// set smtp as default
config.setProtocol(PROTOCOL_SMTP);
}
String userInfo = uri.getUserInfo();
if (userInfo != null) {
config.setUsername(userInfo);
}
int port = uri.getPort();
if (port >= 0) {
config.setPort(port);
} else {
config.setPort(getDefaultPortForProtocol(config.getProtocol()));
}
if (uri.getPath() != null && uri.getPath().length() > 0) {
if (uri.getPath().startsWith("/")) {
config.setFolderName(uri.getPath().substring(1));
} else {
config.setFolderName(uri.getPath());
}
} else {
config.setFolderName(DEFAULT_INBOX);
}
if (uri.getQuery() != null && uri.getQuery().indexOf(URI_PASSWORD_PART) != -1) {
// extract the password from query
int beginIndex = uri.getQuery().indexOf(URI_PASSWORD_PART) + URI_PASSWORD_PART.length();
int endIndex = uri.getQuery().indexOf(';', beginIndex + 1) != -1 ? uri.getQuery()
.indexOf(';', beginIndex + 1) : uri.getQuery().length();
config.setPassword(uri.getQuery().substring(beginIndex, endIndex));
} else {
// maybe no password required
config.setPassword("");
}
if (userInfo == null) {
// alternative way of specifying the user name
if (uri.getQuery() != null && uri.getQuery().indexOf(URI_USER_PART) != -1) {
// extract the password from query
int beginIndex = uri.getQuery().indexOf(URI_USER_PART) + URI_USER_PART.length();
int endIndex = uri.getQuery().indexOf(';', beginIndex + 1) != -1 ? uri.getQuery()
.indexOf(';', beginIndex + 1) : uri.getQuery().length();
config.setUsername(uri.getQuery().substring(beginIndex, endIndex));
} else {
// maybe no password required
config.setUsername("");
}
}
return config;
}