ensure autodiscover is only used if hostname is not set

This commit is contained in:
2018-10-16 12:34:05 +02:00
parent 530b6f500a
commit 4d79cbc35b
4 changed files with 92 additions and 77 deletions

View File

@ -5,7 +5,6 @@
package de.muehlencord.shared.network.mail;
import java.util.List;
import javax.mail.Folder;
/**
*

View File

@ -5,6 +5,7 @@ import de.muehlencord.shared.network.mail.MailReader;
import de.muehlencord.shared.network.mail.MailReaderConfiguration;
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
import de.muehlencord.shared.network.mail.MailReaderException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -34,7 +35,7 @@ import org.slf4j.LoggerFactory;
* @author Joern Muehlencord <joern at muehlencord.de>
*/
public class ExchangeMailReader implements MailReader {
private static final Logger LOGGER = LoggerFactory.getLogger(ExchangeMailReader.class);
private final MailReaderConfiguration configuration;
private ExchangeService service = null;
@ -55,8 +56,11 @@ public class ExchangeMailReader implements MailReader {
ExchangeCredentials credentials = new WebCredentials(userName, password);
service.setCredentials(credentials);
service.autodiscoverUrl(emailAddress, new RedirectionUrlCallback());
if (hostName == null) {
service.autodiscoverUrl(emailAddress, new RedirectionUrlCallback());
} else {
service.setUrl(new URI(hostName));
}
LOGGER.info("Connected to " + getConnectionShortCut());
} catch (Exception ex) {
throw new MailReaderConnectionException(ex.getMessage(), ex);
@ -241,9 +245,15 @@ public class ExchangeMailReader implements MailReader {
}
class RedirectionUrlCallback implements IAutodiscoverRedirectionUrl {
private static final Logger LOGGER = LoggerFactory.getLogger(RedirectionUrlCallback.class);
@Override
public boolean autodiscoverRedirectionUrlValidationCallback(String redirectionUrl) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("redirectUrl found: {}", redirectionUrl);
}
return redirectionUrl.toLowerCase().startsWith("https://");
}
}