ensure autodiscover is only used if hostname is not set
This commit is contained in:
145
network/pom.xml
145
network/pom.xml
@ -1,69 +1,76 @@
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.muehlencord.shared</groupId>
|
||||
<artifactId>shared-network</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>shared-network</name>
|
||||
|
||||
<parent>
|
||||
<artifactId>shared</artifactId>
|
||||
<groupId>de.muehlencord</groupId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.enterprisedt</groupId>
|
||||
<artifactId>edtFTPj</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.muehlencord.shared</groupId>
|
||||
<artifactId>shared-util</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>javax.mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.ews-java-api</groupId>
|
||||
<artifactId>ews-java-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.muehlencord.shared</groupId>
|
||||
<artifactId>shared-network</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>shared-network</name>
|
||||
|
||||
<parent>
|
||||
<artifactId>shared</artifactId>
|
||||
<groupId>de.muehlencord</groupId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.enterprisedt</groupId>
|
||||
<artifactId>edtFTPj</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.muehlencord.shared</groupId>
|
||||
<artifactId>shared-util</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>javax.mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.ews-java-api</groupId>
|
||||
<artifactId>ews-java-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<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;
|
||||
@ -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