From coverity: synchronize HttpClient cookies access
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2263 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
93515d8ddb
commit
61dcfae33f
|
@ -3294,43 +3294,46 @@ public abstract class ExchangeSession {
|
||||||
static final String MAILBOX_BASE = "/cn=";
|
static final String MAILBOX_BASE = "/cn=";
|
||||||
|
|
||||||
protected void getEmailAndAliasFromOptions() {
|
protected void getEmailAndAliasFromOptions() {
|
||||||
Cookie[] currentCookies = httpClient.getState().getCookies();
|
synchronized (httpClient.getState()) {
|
||||||
// get user mail URL from html body
|
Cookie[] currentCookies = httpClient.getState().getCookies();
|
||||||
BufferedReader optionsPageReader = null;
|
// get user mail URL from html body
|
||||||
GetMethod optionsMethod = new GetMethod("/owa/?ae=Options&t=About");
|
BufferedReader optionsPageReader = null;
|
||||||
try {
|
GetMethod optionsMethod = new GetMethod("/owa/?ae=Options&t=About");
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, optionsMethod, false);
|
try {
|
||||||
optionsPageReader = new BufferedReader(new InputStreamReader(optionsMethod.getResponseBodyAsStream()));
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, optionsMethod, false);
|
||||||
String line;
|
optionsPageReader = new BufferedReader(new InputStreamReader(optionsMethod.getResponseBodyAsStream()));
|
||||||
|
String line;
|
||||||
|
|
||||||
// find email and alias
|
// find email and alias
|
||||||
while ((line = optionsPageReader.readLine()) != null
|
//noinspection StatementWithEmptyBody
|
||||||
&& (line.indexOf('[') == -1
|
while ((line = optionsPageReader.readLine()) != null
|
||||||
|| line.indexOf('@') == -1
|
&& (line.indexOf('[') == -1
|
||||||
|| line.indexOf(']') == -1)
|
|| line.indexOf('@') == -1
|
||||||
&& line.toLowerCase().indexOf(MAILBOX_BASE) == -1) {
|
|| line.indexOf(']') == -1)
|
||||||
}
|
&& !line.toLowerCase().contains(MAILBOX_BASE)) {
|
||||||
if (line != null) {
|
|
||||||
int start = line.toLowerCase().lastIndexOf(MAILBOX_BASE) + MAILBOX_BASE.length();
|
|
||||||
int end = line.indexOf('<', start);
|
|
||||||
alias = line.substring(start, end);
|
|
||||||
end = line.lastIndexOf(']');
|
|
||||||
start = line.lastIndexOf('[', end) + 1;
|
|
||||||
email = line.substring(start, end);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// restore cookies on error
|
|
||||||
httpClient.getState().addCookies(currentCookies);
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
if (line != null) {
|
||||||
|
int start = line.toLowerCase().lastIndexOf(MAILBOX_BASE) + MAILBOX_BASE.length();
|
||||||
|
int end = line.indexOf('<', start);
|
||||||
|
alias = line.substring(start, end);
|
||||||
|
end = line.lastIndexOf(']');
|
||||||
|
start = line.lastIndexOf('[', end) + 1;
|
||||||
|
email = line.substring(start, end);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// restore cookies on error
|
||||||
|
httpClient.getState().addCookies(currentCookies);
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
optionsMethod.releaseConnection();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -752,31 +752,32 @@ public class DavExchangeSession extends ExchangeSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkPublicFolder() {
|
protected void checkPublicFolder() {
|
||||||
|
synchronized (httpClient.getState()) {
|
||||||
Cookie[] currentCookies = httpClient.getState().getCookies();
|
Cookie[] currentCookies = httpClient.getState().getCookies();
|
||||||
// check public folder access
|
// check public folder access
|
||||||
try {
|
|
||||||
publicFolderUrl = httpClient.getHostConfiguration().getHostURL() + PUBLIC_ROOT;
|
|
||||||
DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
|
|
||||||
davPropertyNameSet.add(Field.getPropertyName("displayname"));
|
|
||||||
PropFindMethod propFindMethod = new PropFindMethod(publicFolderUrl, davPropertyNameSet, 0);
|
|
||||||
try {
|
try {
|
||||||
DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod);
|
publicFolderUrl = httpClient.getHostConfiguration().getHostURL() + PUBLIC_ROOT;
|
||||||
} catch (IOException e) {
|
DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
|
||||||
// workaround for NTLM authentication only on /public
|
davPropertyNameSet.add(Field.getPropertyName("displayname"));
|
||||||
if (!DavGatewayHttpClientFacade.hasNTLMorNegotiate(httpClient)) {
|
PropFindMethod propFindMethod = new PropFindMethod(publicFolderUrl, davPropertyNameSet, 0);
|
||||||
DavGatewayHttpClientFacade.addNTLM(httpClient);
|
try {
|
||||||
DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod);
|
DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// workaround for NTLM authentication only on /public
|
||||||
|
if (!DavGatewayHttpClientFacade.hasNTLMorNegotiate(httpClient)) {
|
||||||
|
DavGatewayHttpClientFacade.addNTLM(httpClient);
|
||||||
|
DavGatewayHttpClientFacade.executeMethod(httpClient, propFindMethod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// update public folder URI
|
||||||
|
publicFolderUrl = propFindMethod.getURI().getURI();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// restore cookies on error
|
||||||
|
httpClient.getState().addCookies(currentCookies);
|
||||||
|
LOGGER.warn("Public folders not available: " + (e.getMessage() == null ? e : e.getMessage()));
|
||||||
|
// default public folder path
|
||||||
|
publicFolderUrl = PUBLIC_ROOT;
|
||||||
}
|
}
|
||||||
// update public folder URI
|
|
||||||
publicFolderUrl = propFindMethod.getURI().getURI();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// restore cookies on error
|
|
||||||
httpClient.getState().addCookies(currentCookies);
|
|
||||||
LOGGER.warn("Public folders not available: " + (e.getMessage() == null ? e : e.getMessage()));
|
|
||||||
// default public folder path
|
|
||||||
publicFolderUrl = PUBLIC_ROOT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1099,7 +1100,7 @@ public class DavExchangeSession extends ExchangeSession {
|
||||||
// workaround for messages in Sent folder
|
// workaround for messages in Sent folder
|
||||||
if (!messageHeaders.contains("From:")) {
|
if (!messageHeaders.contains("From:")) {
|
||||||
String from = getItemProperty(permanentUrl, "from");
|
String from = getItemProperty(permanentUrl, "from");
|
||||||
messageHeaders = "From: "+from+ '\n' +messageHeaders;
|
messageHeaders = "From: " + from + '\n' + messageHeaders;
|
||||||
}
|
}
|
||||||
result = new ByteArrayInputStream(messageHeaders.getBytes("UTF-8"));
|
result = new ByteArrayInputStream(messageHeaders.getBytes("UTF-8"));
|
||||||
}
|
}
|
||||||
|
@ -1358,7 +1359,7 @@ public class DavExchangeSession extends ExchangeSession {
|
||||||
@Override
|
@Override
|
||||||
public byte[] getEventContent() throws IOException {
|
public byte[] getEventContent() throws IOException {
|
||||||
byte[] result = null;
|
byte[] result = null;
|
||||||
LOGGER.debug("Get event subject: " + subject + " contentclass: "+contentClass+" href: " + getHref() + " permanentUrl: " + permanentUrl);
|
LOGGER.debug("Get event subject: " + subject + " contentclass: " + contentClass + " href: " + getHref() + " permanentUrl: " + permanentUrl);
|
||||||
// do not try to load tasks MIME body
|
// do not try to load tasks MIME body
|
||||||
if (!"urn:content-classes:task".equals(contentClass)) {
|
if (!"urn:content-classes:task".equals(contentClass)) {
|
||||||
// try to get PR_INTERNET_CONTENT
|
// try to get PR_INTERNET_CONTENT
|
||||||
|
@ -1706,7 +1707,7 @@ public class DavExchangeSession extends ExchangeSession {
|
||||||
// Set contentclass to make ActiveSync happy
|
// Set contentclass to make ActiveSync happy
|
||||||
propertyList.add(Field.createDavProperty("contentclass", contentClass));
|
propertyList.add(Field.createDavProperty("contentclass", contentClass));
|
||||||
// ... but also set PR_INTERNET_CONTENT to preserve custom properties
|
// ... but also set PR_INTERNET_CONTENT to preserve custom properties
|
||||||
propertyList.add(Field.createDavProperty("internetContent",IOUtil.encodeBase64AsString(mimeContent)));
|
propertyList.add(Field.createDavProperty("internetContent", IOUtil.encodeBase64AsString(mimeContent)));
|
||||||
PropPatchMethod propPatchMethod = new PropPatchMethod(encodedHref, propertyList);
|
PropPatchMethod propPatchMethod = new PropPatchMethod(encodedHref, propertyList);
|
||||||
int patchStatus = DavGatewayHttpClientFacade.executeHttpMethod(httpClient, propPatchMethod);
|
int patchStatus = DavGatewayHttpClientFacade.executeHttpMethod(httpClient, propPatchMethod);
|
||||||
if (patchStatus != HttpStatus.SC_MULTI_STATUS) {
|
if (patchStatus != HttpStatus.SC_MULTI_STATUS) {
|
||||||
|
|
Loading…
Reference in New Issue