ensure autodiscover is only used if hostname is not set
This commit is contained in:
@ -65,5 +65,12 @@
|
|||||||
<artifactId>commons-net</artifactId>
|
<artifactId>commons-net</artifactId>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.ws</groupId>
|
||||||
|
<artifactId>jaxws-api</artifactId>
|
||||||
|
<version>2.3.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
package de.muehlencord.shared.network.mail;
|
package de.muehlencord.shared.network.mail;
|
||||||
|
|
||||||
import java.util.List;
|
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.MailReaderConfiguration;
|
||||||
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
||||||
import de.muehlencord.shared.network.mail.MailReaderException;
|
import de.muehlencord.shared.network.mail.MailReaderException;
|
||||||
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -55,8 +56,11 @@ public class ExchangeMailReader implements MailReader {
|
|||||||
|
|
||||||
ExchangeCredentials credentials = new WebCredentials(userName, password);
|
ExchangeCredentials credentials = new WebCredentials(userName, password);
|
||||||
service.setCredentials(credentials);
|
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());
|
LOGGER.info("Connected to " + getConnectionShortCut());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new MailReaderConnectionException(ex.getMessage(), ex);
|
throw new MailReaderConnectionException(ex.getMessage(), ex);
|
||||||
@ -242,8 +246,14 @@ public class ExchangeMailReader implements MailReader {
|
|||||||
|
|
||||||
class RedirectionUrlCallback implements IAutodiscoverRedirectionUrl {
|
class RedirectionUrlCallback implements IAutodiscoverRedirectionUrl {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(RedirectionUrlCallback.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean autodiscoverRedirectionUrlValidationCallback(String redirectionUrl) {
|
public boolean autodiscoverRedirectionUrlValidationCallback(String redirectionUrl) {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("redirectUrl found: {}", redirectionUrl);
|
||||||
|
}
|
||||||
|
|
||||||
return redirectionUrl.toLowerCase().startsWith("https://");
|
return redirectionUrl.toLowerCase().startsWith("https://");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ public class ExchangeMailReaderTest {
|
|||||||
public void testConnect() {
|
public void testConnect() {
|
||||||
try {
|
try {
|
||||||
LOGGER.info("testConnect");
|
LOGGER.info("testConnect");
|
||||||
String imapHost = null;
|
String imapHost = null; // use autodiscover
|
||||||
String smtpHost = null;
|
String smtpHost = null;
|
||||||
String folder = null;
|
String folder = null;
|
||||||
String testFolder = null;
|
String testFolder = null;
|
||||||
@ -32,7 +32,7 @@ public class ExchangeMailReaderTest {
|
|||||||
String password = null;
|
String password = null;
|
||||||
String emailaddress = null;
|
String emailaddress = null;
|
||||||
|
|
||||||
assumeNotNull(imapHost);
|
// disable tests if not all values are set
|
||||||
assumeNotNull(smtpHost);
|
assumeNotNull(smtpHost);
|
||||||
assumeNotNull(folder);
|
assumeNotNull(folder);
|
||||||
assumeNotNull(testFolder);
|
assumeNotNull(testFolder);
|
||||||
@ -40,7 +40,6 @@ public class ExchangeMailReaderTest {
|
|||||||
assumeNotNull(emailaddress);
|
assumeNotNull(emailaddress);
|
||||||
assumeNotNull(password);
|
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);
|
MailReader instance = new ExchangeMailReader(config);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user