ensure autodiscover is only used if hostname is not set
This commit is contained in:
@ -65,5 +65,12 @@
|
||||
<artifactId>commons-net</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.ws</groupId>
|
||||
<artifactId>jaxws-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -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;
|
||||
@ -55,8 +56,11 @@ public class ExchangeMailReader implements MailReader {
|
||||
|
||||
ExchangeCredentials credentials = new WebCredentials(userName, password);
|
||||
service.setCredentials(credentials);
|
||||
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);
|
||||
@ -242,8 +246,14 @@ 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,7 +32,7 @@ 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);
|
||||
@ -40,7 +40,6 @@ public class ExchangeMailReaderTest {
|
||||
assumeNotNull(emailaddress);
|
||||
assumeNotNull(password);
|
||||
|
||||
|
||||
MailReaderConfiguration config = new MailReaderConfiguration(smtpHost, imapHost, userName, password, emailaddress);
|
||||
MailReader instance = new ExchangeMailReader(config);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user