in server/src/main/java/org/apache/hupa/server/InMemoryIMAPStoreCache.java [208:274]
private Session createSession(final User user) {
Properties props = new Properties();
Settings settings = user.getSettings();
props.setProperty("mail.mime.decodetext.strict", "false");
if (settings.getImapSecure()) {
props.setProperty("mail.store.protocol", "imaps");
props.setProperty("mail.imaps.connectionpoolsize", connectionPoolSize + "");
props.setProperty("mail.imaps.connectionpooltimeout", timeout + "");
if (trustSSL) {
props.setProperty("mail.imaps.ssl.trust", settings.getImapServer());
}
} else {
props.setProperty("mail.imap.connectionpoolsize", connectionPoolSize + "");
props.setProperty("mail.imap.connectionpooltimeout", timeout + "");
}
if (settings.getSmtpSecure()) {
if (settings.getSmtpPort() == 587) {
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.transport.protocol.rfc822", "smtp");
} else {
props.setProperty("mail.transport.protocol.rfc822", "smtps");
props.setProperty("mail.smtps.ssl.enable", "true");
if (trustSSL) {
props.setProperty("mail.smtps.ssl.trust", settings.getSmtpServer());
}
}
} else {
props.setProperty("mail.transport.protocol.rfc822", "smtp");
}
props.setProperty("mail.smtp.host", settings.getSmtpServer());
props.setProperty("mail.smtps.host", settings.getSmtpServer());
props.setProperty("mail.smtp.port", settings.getSmtpPort() + "");
props.setProperty("mail.smtps.port", settings.getSmtpPort() + "");
Authenticator auth = null;
if (settings.getSmtpAuth() && user.getPassword() != null && user.getName() != null) {
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.smtps.auth", "true");
auth = new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
String userId = user.getId();
StackTraceElement[] sElms = Thread.currentThread().getStackTrace();
for (StackTraceElement e : sElms) {
if (e.getClassName().equals(InMemoryIMAPStoreCache.class.getName()) && e.getMethodName().equals("get")) {
// We try with the id part the second time (unix imap/smtp auth compatible)
if (userId.matches(".*@.*")) {
userId = userId.replaceFirst("@.*", "");
user.setId(userId);
break;
} else {
return null;
}
}
}
return new PasswordAuthentication(userId, user.getPassword());
}
};
}
Session ses = Session.getInstance(props, auth);
ses.setDebug(debug && logger.isDebugEnabled());
logger.debug("Created session " + user.getName() + "\n" + settings + "\n"+ props.toString().replaceAll(",", ",\n "));
return ses;
}