ensure autodiscover is only used if hostname is not set
This commit is contained in:
@ -5,7 +5,6 @@
|
||||
package de.muehlencord.shared.network.mail;
|
||||
|
||||
import java.util.List;
|
||||
import javax.mail.Folder;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@ -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://");
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public class ExchangeMailReaderTest {
|
||||
public void testConnect() {
|
||||
try {
|
||||
LOGGER.info("testConnect");
|
||||
String imapHost = null;
|
||||
String imapHost = null; // use autodiscover
|
||||
String smtpHost = null;
|
||||
String folder = null;
|
||||
String testFolder = null;
|
||||
@ -32,16 +32,15 @@ public class ExchangeMailReaderTest {
|
||||
String password = null;
|
||||
String emailaddress = null;
|
||||
|
||||
assumeNotNull(imapHost);
|
||||
// disable tests if not all values are set
|
||||
assumeNotNull(smtpHost);
|
||||
assumeNotNull(folder);
|
||||
assumeNotNull(testFolder);
|
||||
assumeNotNull(userName);
|
||||
assumeNotNull(emailaddress);
|
||||
assumeNotNull(password);
|
||||
|
||||
|
||||
MailReaderConfiguration config = new MailReaderConfiguration(smtpHost, imapHost, userName, password, emailaddress);
|
||||
MailReaderConfiguration config = new MailReaderConfiguration(smtpHost, imapHost, userName, password, emailaddress);
|
||||
MailReader instance = new ExchangeMailReader(config);
|
||||
|
||||
instance.connect();
|
||||
|
||||
Reference in New Issue
Block a user