Fixes from audit

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2249 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2014-03-10 22:17:40 +00:00
parent 0fc908b1e9
commit b75fb15483
2 changed files with 18 additions and 24 deletions

View File

@ -26,7 +26,6 @@ import davmail.http.DavGatewayHttpClientFacade;
import davmail.ui.tray.DavGatewayTray; import davmail.ui.tray.DavGatewayTray;
import davmail.util.IOUtil; import davmail.util.IOUtil;
import davmail.util.StringUtil; import davmail.util.StringUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*; import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.util.URIUtil; import org.apache.commons.httpclient.util.URIUtil;
@ -524,7 +523,7 @@ public class DavExchangeSession extends ExchangeSession {
mainPageReader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); mainPageReader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
//noinspection StatementWithEmptyBody //noinspection StatementWithEmptyBody
String line; String line;
while ((line = mainPageReader.readLine()) != null && line.toLowerCase().indexOf(BASE_HREF) == -1) { while ((line = mainPageReader.readLine()) != null && !line.toLowerCase().contains(BASE_HREF)) {
} }
if (line != null) { if (line != null) {
// Exchange 2003 // Exchange 2003
@ -912,6 +911,7 @@ public class DavExchangeSession extends ExchangeSession {
} else if (field.isIntValue()) { } else if (field.isIntValue()) {
// check value // check value
try { try {
//noinspection ResultOfMethodCallIgnored
Integer.parseInt(value); Integer.parseInt(value);
buffer.append(value); buffer.append(value);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
@ -1097,9 +1097,9 @@ public class DavExchangeSession extends ExchangeSession {
} }
} }
// workaround for messages in Sent folder // workaround for messages in Sent folder
if (messageHeaders.indexOf("From:") < 0) { 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"));
} }
@ -2098,6 +2098,7 @@ public class DavExchangeSession extends ExchangeSession {
ITEM_PROPERTIES.add("contentclass"); ITEM_PROPERTIES.add("contentclass");
} }
@Override
protected Set<String> getItemProperties() { protected Set<String> getItemProperties() {
return ITEM_PROPERTIES; return ITEM_PROPERTIES;
} }
@ -2871,7 +2872,7 @@ public class DavExchangeSession extends ExchangeSession {
return uri.getEscapedURI(); return uri.getEscapedURI();
} }
public String encodeAndFixUrl(String url) throws URIException { protected String encodeAndFixUrl(String url) throws URIException {
String originalUrl = URIUtil.encodePath(url); String originalUrl = URIUtil.encodePath(url);
if (restoreHostName && originalUrl.startsWith("http")) { if (restoreHostName && originalUrl.startsWith("http")) {
String targetPath = new URI(originalUrl, true).getEscapedPath(); String targetPath = new URI(originalUrl, true).getEscapedPath();

View File

@ -29,7 +29,6 @@ import davmail.exchange.VProperty;
import davmail.http.DavGatewayHttpClientFacade; import davmail.http.DavGatewayHttpClientFacade;
import davmail.util.IOUtil; import davmail.util.IOUtil;
import davmail.util.StringUtil; import davmail.util.StringUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.GetMethod;
@ -149,11 +148,7 @@ public class EwsExchangeSession extends ExchangeSession {
*/ */
@Override @Override
protected boolean isBasicAuthentication(HttpClient httpClient, String url) { protected boolean isBasicAuthentication(HttpClient httpClient, String url) {
if (url.toLowerCase().endsWith("/ews/exchange.asmx")) { return !url.toLowerCase().endsWith("/ews/exchange.asmx") && super.isBasicAuthentication(httpClient, url);
return false;
} else {
return super.isBasicAuthentication(httpClient, url);
}
} }
@Override @Override
@ -228,7 +223,7 @@ public class EwsExchangeSession extends ExchangeSession {
alias = getAliasFromLogin(); alias = getAliasFromLogin();
// try to get email address with ResolveNames // try to get email address with ResolveNames
email = resolveEmailAddress(userName); resolveEmailAddress(userName);
// failover, build from host name // failover, build from host name
if (email == null) { if (email == null) {
email = getAliasFromLogin() + getEmailSuffixFromHostname(); email = getAliasFromLogin() + getEmailSuffixFromHostname();
@ -308,8 +303,7 @@ public class EwsExchangeSession extends ExchangeSession {
LOGGER.debug("Current user email is " + email + ", alias is " + alias + " on " + serverVersion); LOGGER.debug("Current user email is " + email + ", alias is " + alias + " on " + serverVersion);
} }
public String resolveEmailAddress(String userName) { protected void resolveEmailAddress(String userName) {
String email = null;
String searchValue = userName; String searchValue = userName;
int index = searchValue.indexOf('\\'); int index = searchValue.indexOf('\\');
if (index >= 0) { if (index >= 0) {
@ -328,7 +322,6 @@ public class EwsExchangeSession extends ExchangeSession {
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} }
return email;
} }
protected static class AutoDiscoverMethod extends PostMethod { protected static class AutoDiscoverMethod extends PostMethod {
@ -367,8 +360,8 @@ public class EwsExchangeSession extends ExchangeSession {
String line; String line;
// find ews url // find ews url
while ((line = autodiscoverReader.readLine()) != null while ((line = autodiscoverReader.readLine()) != null
&& (line.indexOf("<EwsUrl>") == -1) && (!line.contains("<EwsUrl>"))
&& (line.indexOf("</EwsUrl>") == -1)) { && (!line.contains("</EwsUrl>"))) {
} }
if (line != null) { if (line != null) {
ewsUrl = line.substring(line.indexOf("<EwsUrl>") + 8, line.indexOf("</EwsUrl>")); ewsUrl = line.substring(line.indexOf("<EwsUrl>") + 8, line.indexOf("</EwsUrl>"));
@ -1287,7 +1280,7 @@ public class EwsExchangeSession extends ExchangeSession {
if ("photo".equals(entry.getKey())) { if ("photo".equals(entry.getKey())) {
updates.add(Field.createFieldUpdate("haspicture", "true")); updates.add(Field.createFieldUpdate("haspicture", "true"));
} else if (!entry.getKey().startsWith("email") && !entry.getKey().startsWith("smtpemail") } else if (!entry.getKey().startsWith("email") && !entry.getKey().startsWith("smtpemail")
&& !entry.getKey().equals("fileas")) { && !"fileas".equals(entry.getKey())) {
updates.add(Field.createFieldUpdate(entry.getKey(), entry.getValue())); updates.add(Field.createFieldUpdate(entry.getKey(), entry.getValue()));
} }
} }
@ -1727,11 +1720,10 @@ public class EwsExchangeSession extends ExchangeSession {
executeMethod(getItemMethod); executeMethod(getItemMethod);
if ("Task".equals(type)) { if ("Task".equals(type)) {
VObject vTimezone = getVTimezone();
VCalendar localVCalendar = new VCalendar(); VCalendar localVCalendar = new VCalendar();
VObject vTodo = new VObject(); VObject vTodo = new VObject();
vTodo.type = "VTODO"; vTodo.type = "VTODO";
localVCalendar.setTimezone(vTimezone); localVCalendar.setTimezone(getVTimezone());
vTodo.setPropertyValue("LAST-MODIFIED", convertDateFromExchange(getItemMethod.getResponseItem().get(Field.get("lastmodified").getResponseName()))); vTodo.setPropertyValue("LAST-MODIFIED", convertDateFromExchange(getItemMethod.getResponseItem().get(Field.get("lastmodified").getResponseName())));
vTodo.setPropertyValue("CREATED", convertDateFromExchange(getItemMethod.getResponseItem().get(Field.get("created").getResponseName()))); vTodo.setPropertyValue("CREATED", convertDateFromExchange(getItemMethod.getResponseItem().get(Field.get("created").getResponseName())));
String calendarUid = getItemMethod.getResponseItem().get(Field.get("calendaruid").getResponseName()); String calendarUid = getItemMethod.getResponseItem().get(Field.get("calendaruid").getResponseName());
@ -1934,6 +1926,7 @@ public class EwsExchangeSession extends ExchangeSession {
EVENT_REQUEST_PROPERTIES.add("urlcompname"); EVENT_REQUEST_PROPERTIES.add("urlcompname");
} }
@Override
protected Set<String> getItemProperties() { protected Set<String> getItemProperties() {
return ITEM_PROPERTIES; return ITEM_PROPERTIES;
} }
@ -2005,7 +1998,7 @@ public class EwsExchangeSession extends ExchangeSession {
@Override @Override
public ContactPhoto getContactPhoto(ExchangeSession.Contact contact) throws IOException { public ContactPhoto getContactPhoto(ExchangeSession.Contact contact) throws IOException {
ContactPhoto contactPhoto = null; ContactPhoto contactPhoto;
GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, ((EwsExchangeSession.Contact) contact).itemId, false); GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, ((EwsExchangeSession.Contact) contact).itemId, false);
getItemMethod.addAdditionalProperty(Field.get("attachments")); getItemMethod.addAdditionalProperty(Field.get("attachments"));
@ -2164,11 +2157,11 @@ public class EwsExchangeSession extends ExchangeSession {
// find email // find email
//noinspection StatementWithEmptyBody //noinspection StatementWithEmptyBody
while ((line = optionsPageReader.readLine()) != null while ((line = optionsPageReader.readLine()) != null
&& (line.indexOf("tblTmZn") == -1) && (!line.contains("tblTmZn"))
&& (line.indexOf("selTmZn") == -1)) { && (!line.contains("selTmZn"))) {
} }
if (line != null) { if (line != null) {
if (line.indexOf("tblTmZn") >= 0) { if (line.contains("tblTmZn")) {
int start = line.indexOf("oV=\"") + 4; int start = line.indexOf("oV=\"") + 4;
int end = line.indexOf('\"', start); int end = line.indexOf('\"', start);
result = line.substring(start, end); result = line.substring(start, end);