mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 11:12:22 -05:00
Another hack to make Exchange 2007 authentication work
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@241 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
6c327fe4cf
commit
621e894204
@ -210,13 +210,29 @@ public class ExchangeSession {
|
|||||||
int a_sUrlEndIndex = scriptValue.indexOf("\"", a_sUrlIndex);
|
int a_sUrlEndIndex = scriptValue.indexOf("\"", a_sUrlIndex);
|
||||||
int a_sLgnEndIndex = scriptValue.indexOf("\"", a_sLgnIndex);
|
int a_sLgnEndIndex = scriptValue.indexOf("\"", a_sLgnIndex);
|
||||||
if (a_sUrlEndIndex >= 0 && a_sLgnEndIndex >= 0) {
|
if (a_sUrlEndIndex >= 0 && a_sLgnEndIndex >= 0) {
|
||||||
LOGGER.debug("Detected script based logon, redirect to form");
|
|
||||||
String src = getAbsolutePath(initmethod,
|
String src = getAbsolutePath(initmethod,
|
||||||
scriptValue.substring(a_sLgnIndex, a_sLgnEndIndex) +
|
scriptValue.substring(a_sLgnIndex, a_sLgnEndIndex) +
|
||||||
scriptValue.substring(a_sUrlIndex, a_sUrlEndIndex));
|
scriptValue.substring(a_sUrlIndex, a_sUrlEndIndex));
|
||||||
|
LOGGER.debug("Detected script based logon, redirect to form at " + src);
|
||||||
HttpMethod newInitMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, src);
|
HttpMethod newInitMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, src);
|
||||||
logonMethod = buildLogonMethod(httpClient, newInitMethod);
|
logonMethod = buildLogonMethod(httpClient, newInitMethod);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
a_sLgnIndex = scriptValue.indexOf("var a_sLgnQS = \"");
|
||||||
|
if (a_sUrlIndex >= 0 && a_sLgnIndex >= 0) {
|
||||||
|
a_sUrlIndex += "var a_sUrl = \"".length();
|
||||||
|
a_sLgnIndex += "var a_sLgnQS = \"".length();
|
||||||
|
int a_sUrlEndIndex = scriptValue.indexOf("\"", a_sUrlIndex);
|
||||||
|
int a_sLgnEndIndex = scriptValue.indexOf("\"", a_sLgnIndex);
|
||||||
|
if (a_sUrlEndIndex >= 0 && a_sLgnEndIndex >= 0) {
|
||||||
|
String src = initmethod.getPath() +
|
||||||
|
scriptValue.substring(a_sLgnIndex, a_sLgnEndIndex) +
|
||||||
|
scriptValue.substring(a_sUrlIndex, a_sUrlEndIndex);
|
||||||
|
LOGGER.debug("Detected script based logon, redirect to form at " + src);
|
||||||
|
HttpMethod newInitMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, src);
|
||||||
|
logonMethod = buildLogonMethod(httpClient, newInitMethod);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,6 +281,9 @@ public class ExchangeSession {
|
|||||||
String mailBoxBaseHref = line.substring(start, end);
|
String mailBoxBaseHref = line.substring(start, end);
|
||||||
URL baseURL = new URL(mailBoxBaseHref);
|
URL baseURL = new URL(mailBoxBaseHref);
|
||||||
result = baseURL.getPath();
|
result = baseURL.getPath();
|
||||||
|
} else {
|
||||||
|
// failover for Exchange 2007 : try to get mailbox from options
|
||||||
|
result = getMailPathFromOptions(method.getPath());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("Error parsing main page at " + method.getPath());
|
LOGGER.error("Error parsing main page at " + method.getPath());
|
||||||
@ -282,6 +301,41 @@ public class ExchangeSession {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getMailPathFromOptions(String path) {
|
||||||
|
String result = null;
|
||||||
|
// get user mail URL from html body
|
||||||
|
BufferedReader optionsPageReader = null;
|
||||||
|
GetMethod optionsMethod = new GetMethod(path+"?ae=Options&t=About");
|
||||||
|
try {
|
||||||
|
wdr.retrieveSessionInstance().executeMethod(optionsMethod);
|
||||||
|
optionsPageReader = new BufferedReader(new InputStreamReader(optionsMethod.getResponseBodyAsStream()));
|
||||||
|
String line;
|
||||||
|
// find mailbox full name
|
||||||
|
final String MAILBOX_BASE = "cn=recipients/cn=";
|
||||||
|
//noinspection StatementWithEmptyBody
|
||||||
|
while ((line = optionsPageReader.readLine()) != null && line.toLowerCase().indexOf(MAILBOX_BASE) == -1) {
|
||||||
|
}
|
||||||
|
if (line != null) {
|
||||||
|
int start = line.toLowerCase().indexOf(MAILBOX_BASE) + MAILBOX_BASE.length();
|
||||||
|
int end = line.indexOf("<", start);
|
||||||
|
result = "/exchange/"+line.substring(start, end);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Error parsing options page at " + optionsMethod.getPath());
|
||||||
|
} finally {
|
||||||
|
if (optionsPageReader != null) {
|
||||||
|
try {
|
||||||
|
optionsPageReader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Error parsing options page at " + optionsMethod.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
optionsMethod.releaseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void login() throws IOException {
|
void login() throws IOException {
|
||||||
LOGGER.debug("Session " + this + " login");
|
LOGGER.debug("Session " + this + " login");
|
||||||
try {
|
try {
|
||||||
@ -420,7 +474,7 @@ public class ExchangeSession {
|
|||||||
/**
|
/**
|
||||||
* Create message in current folder
|
* Create message in current folder
|
||||||
*
|
*
|
||||||
* @param messageName message name
|
* @param messageName message name
|
||||||
* @param bcc blind carbon copy header
|
* @param bcc blind carbon copy header
|
||||||
* @param messageBody mail body
|
* @param messageBody mail body
|
||||||
* @param allowOverwrite allow existing message overwrite
|
* @param allowOverwrite allow existing message overwrite
|
||||||
@ -435,7 +489,7 @@ public class ExchangeSession {
|
|||||||
* Will overwrite an existing message with same subject in the same folder
|
* Will overwrite an existing message with same subject in the same folder
|
||||||
*
|
*
|
||||||
* @param folderUrl Exchange folder URL
|
* @param folderUrl Exchange folder URL
|
||||||
* @param messageName message name
|
* @param messageName message name
|
||||||
* @param bcc blind carbon copy header
|
* @param bcc blind carbon copy header
|
||||||
* @param messageBody mail body
|
* @param messageBody mail body
|
||||||
* @param allowOverwrite allow existing message overwrite
|
* @param allowOverwrite allow existing message overwrite
|
||||||
|
@ -165,7 +165,7 @@ public final class ExchangeSessionFactory {
|
|||||||
int status = httpClient.executeMethod(testMethod);
|
int status = httpClient.executeMethod(testMethod);
|
||||||
ExchangeSession.LOGGER.debug("Test configuration status: " + status);
|
ExchangeSession.LOGGER.debug("Test configuration status: " + status);
|
||||||
if (status != HttpStatus.SC_OK && status != HttpStatus.SC_UNAUTHORIZED
|
if (status != HttpStatus.SC_OK && status != HttpStatus.SC_UNAUTHORIZED
|
||||||
&& status != HttpStatus.SC_MOVED_TEMPORARILY) {
|
&& status != HttpStatus.SC_MOVED_TEMPORARILY && status != HttpStatus.SC_MOVED_PERMANENTLY) {
|
||||||
throw new IOException("Unable to connect to OWA at " + url + ", status code " +
|
throw new IOException("Unable to connect to OWA at " + url + ", status code " +
|
||||||
status + ", check configuration");
|
status + ", check configuration");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user