}
try {
store.connect(server,port, username,password);
} catch (AuthenticationFailedException e) {
logger.error("cannot connect to mail server. authentication failed {"+props+"}");
throw new ArchivaException ("unable to connect to mail server. could not authenticate. {"+props+"}",e,logger);
} catch (IllegalStateException ise) {
throw new ArchivaException ("attempt to connect mail server when it already connected. {"+props+"}",ise,logger);
} catch (MessagingException me) {
if (me.getMessage().contains("sun.security.validator.ValidatorException")) {
throw new ArchivaException ("failed to authenticate TLS certificate. You must install the mail server's certificate as per the administration guide.",me,logger);
} else if (connection.getConnectionMode()==MailboxConnections.ConnectionMode.FALLBACK &&
me.getMessage().contains("javax.net.ssl.SSLHandshakeException")) {
logger.debug("cannot establish SSL handshake with mail server. falling back to insecure. {"+props+"}");
connection.setConnectionMode(MailboxConnections.ConnectionMode.INSECURE);
} else throw new ArchivaException ("failed to connect to mail server. "+me.getMessage()+". {"+props+"}",me,logger);
} catch (Throwable e) {
throw new ArchivaException ("unable to connect to mail server:"+e.getMessage(),e,logger);
}
try {
inboxFolder = store.getDefaultFolder();
} catch (Throwable e) {
throw new ArchivaException ("unable to get default folder. ",e,logger);
}
if (inboxFolder == null) {
throw new ArchivaException ("there was no default POP inbox folder found.",logger);
}
try {
inboxFolder = inboxFolder.getFolder("INBOX");
if (inboxFolder == null) {
throw new ArchivaException ("the inbox folder does not exist.",logger);
}
} catch (Throwable e) {
throw new ArchivaException ("unable to get INBOX folder. ",e,logger);
}
try {
inboxFolder.open(Folder.READ_WRITE);
} catch (Throwable e) {
throw new ArchivaException ("unable to open folder. ",e,logger);
}
return;
}