session.setAttribute(MailContext.SESSION_MAIL_CONTEXT, mailContext);
}
// assert mailSession is available
javax.mail.Session mailSession;
Store mailStore;
try {
try {
mailSession = (javax.mail.Session) mailContext.get(MailContext.MAIL_SESSION_ENTRY);
} catch (ContextException ce) {
// build session properties
Properties sessionProperties = new Properties();
String[] allParameterNames = par.getNames();
for (int i = 0; i < allParameterNames.length; i++) {
String parameterName = allParameterNames[i];
final String PARAMETER_NAME_PREFIX = "javax.mail.Session.props:";
if (parameterName.startsWith(PARAMETER_NAME_PREFIX)) {
String sessionPropName = parameterName.substring(PARAMETER_NAME_PREFIX.length());
String sessionPropValue = par.getParameter(parameterName, null);
if (sessionPropValue != null) {
getLogger().debug("Add session property " +
String.valueOf(sessionPropName) + ": " +
String.valueOf(sessionPropValue));
sessionProperties.put(sessionPropName, sessionPropValue);
}
}
}
mailSession = javax.mail.Session.getDefaultInstance(sessionProperties, null);
checkProviders(mailSession);
mailContext.put(MailContext.MAIL_SESSION_ENTRY, mailSession);
}
} catch (Exception e) {
String message = "Cannot create mail session";
getLogger().error(message, e);
throw new ProcessingException(message, e);
}
// assert mailStore is available
String storeURLNameExpanded = null;
String storeURLNameTemplate = par.getParameter("store-urlname", null);
try {
try {
mailStore = (Store) mailContext.get(MailContext.MAIL_STORE_ENTRY);
} catch (ContextException ce) {
// imap://{userid}:{password}@host:port/
storeURLNameExpanded = getURLNameExpanded(storeURLNameTemplate, userid, password);
URLName urlNameExpanded = new URLName(storeURLNameExpanded);
getLogger().info("get store using URLName " + String.valueOf(urlNameExpanded));
mailStore = mailSession.getStore(urlNameExpanded);
mailStore.connect();
mailContext.put(MailContext.MAIL_STORE_ENTRY, mailStore);
}
} catch (Exception e) {
String message = "Cannot get store, and connect " + String.valueOf(storeURLNameExpanded);
getLogger().error(message, e);