Cleanup from audit

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@523 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-04-16 21:16:40 +00:00
parent 59b19fee2b
commit 1f32b94aec
10 changed files with 46 additions and 82 deletions

View File

@ -69,7 +69,7 @@ public class AbstractConnection extends Thread {
* @throws IOException on error * @throws IOException on error
*/ */
public void sendClient(String prefix, String message) throws IOException { public void sendClient(String prefix, String message) throws IOException {
StringBuffer logBuffer = new StringBuffer("> "); StringBuilder logBuffer = new StringBuilder("> ");
if (prefix != null) { if (prefix != null) {
logBuffer.append(prefix); logBuffer.append(prefix);
os.write(prefix.getBytes()); os.write(prefix.getBytes());

View File

@ -23,7 +23,7 @@ public class Settings {
configFilePath = value; configFilePath = value;
} }
public static boolean isFirstStart() { public static synchronized boolean isFirstStart() {
return isFirstStart; return isFirstStart;
} }

View File

@ -573,7 +573,7 @@ public class CaldavConnection extends AbstractConnection {
} }
String fullkey = line.substring(0, index); String fullkey = line.substring(0, index);
String value = line.substring(index + 1); String value = line.substring(index + 1);
int semicolonIndex = fullkey.indexOf(";"); int semicolonIndex = fullkey.indexOf(';');
if (semicolonIndex > 0) { if (semicolonIndex > 0) {
key = fullkey.substring(0, semicolonIndex); key = fullkey.substring(0, semicolonIndex);
} else { } else {
@ -630,17 +630,6 @@ public class CaldavConnection extends AbstractConnection {
} }
public void sendRedirect(Map<String, String> headers, String path) throws IOException {
StringBuilder buffer = new StringBuilder();
if (headers.get("host") != null) {
buffer.append("http://").append(headers.get("host"));
}
buffer.append(path);
Map<String, String> responseHeaders = new HashMap<String, String>();
responseHeaders.put("Location", buffer.toString());
sendHttpResponse(HttpStatus.SC_MOVED_PERMANENTLY, responseHeaders);
}
public void sendErr(Exception e) throws IOException { public void sendErr(Exception e) throws IOException {
String message = e.getMessage(); String message = e.getMessage();
if (message == null) { if (message == null) {
@ -790,12 +779,12 @@ public class CaldavConnection extends AbstractConnection {
} }
protected class CaldavRequest { protected class CaldavRequest {
protected String command; protected final String command;
protected String path; protected final String path;
protected String[] pathElements; protected final String[] pathElements;
protected Map<String, String> headers; protected final Map<String, String> headers;
protected int depth; protected int depth;
protected String body; protected final String body;
protected final HashSet<String> properties = new HashSet<String>(); protected final HashSet<String> properties = new HashSet<String>();
protected HashSet<String> hrefs; protected HashSet<String> hrefs;
protected boolean isMultiGet; protected boolean isMultiGet;
@ -880,10 +869,6 @@ public class CaldavConnection extends AbstractConnection {
return value != null && value.equals(getPathElement(index)); return value != null && value.equals(getPathElement(index));
} }
public boolean isLastPath(String value) {
return value != null && value.equals(getPathElement(getPathLength() - 1));
}
protected String getPathElement(int index) { protected String getPathElement(int index) {
if (index < pathElements.length) { if (index < pathElements.length) {
return pathElements[index]; return pathElements[index];
@ -1009,7 +994,7 @@ public class CaldavConnection extends AbstractConnection {
if ("users".equals(getPathElement(1))) { if ("users".equals(getPathElement(1))) {
return session.buildCalendarPath(getPathElement(2), getPathElement(3)); return session.buildCalendarPath(getPathElement(2), getPathElement(3));
} else { } else {
return getPath(); return path;
} }
} }

View File

@ -188,7 +188,7 @@ public class ExchangeSession {
LOGGER.error(exc.toString()); LOGGER.error(exc.toString());
throw exc; throw exc;
} catch (IOException exc) { } catch (IOException exc) {
StringBuffer message = new StringBuffer(); StringBuilder message = new StringBuilder();
message.append("DavMail login exception: "); message.append("DavMail login exception: ");
if (exc.getMessage() != null) { if (exc.getMessage() != null) {
message.append(exc.getMessage()); message.append(exc.getMessage());
@ -322,8 +322,8 @@ public class ExchangeSession {
if (a_sUrlIndex >= 0 && a_sLgnIndex >= 0) { if (a_sUrlIndex >= 0 && a_sLgnIndex >= 0) {
a_sUrlIndex += "var a_sUrl = \"".length(); a_sUrlIndex += "var a_sUrl = \"".length();
a_sLgnIndex += "var a_sLgn = \"".length(); a_sLgnIndex += "var a_sLgn = \"".length();
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) {
String src = getAbsolutePathOrUri(initmethod, String src = getAbsolutePathOrUri(initmethod,
scriptValue.substring(a_sLgnIndex, a_sLgnEndIndex) + scriptValue.substring(a_sLgnIndex, a_sLgnEndIndex) +
@ -337,8 +337,8 @@ public class ExchangeSession {
if (a_sUrlIndex >= 0 && a_sLgnIndex >= 0) { if (a_sUrlIndex >= 0 && a_sLgnIndex >= 0) {
a_sUrlIndex += "var a_sUrl = \"".length(); a_sUrlIndex += "var a_sUrl = \"".length();
a_sLgnIndex += "var a_sLgnQS = \"".length(); a_sLgnIndex += "var a_sLgnQS = \"".length();
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) {
String src = initmethod.getPath() + String src = initmethod.getPath() +
scriptValue.substring(a_sLgnIndex, a_sLgnEndIndex) + scriptValue.substring(a_sLgnIndex, a_sLgnEndIndex) +
@ -391,7 +391,7 @@ public class ExchangeSession {
} }
if (line != null) { if (line != null) {
int start = line.toLowerCase().indexOf(BASE_HREF) + BASE_HREF.length(); int start = line.toLowerCase().indexOf(BASE_HREF) + BASE_HREF.length();
int end = line.indexOf("\"", start); int end = line.indexOf('\"', start);
String mailBoxBaseHref = line.substring(start, end); String mailBoxBaseHref = line.substring(start, end);
URL baseURL = new URL(mailBoxBaseHref); URL baseURL = new URL(mailBoxBaseHref);
mailPath = baseURL.getPath(); mailPath = baseURL.getPath();
@ -524,7 +524,6 @@ public class ExchangeSession {
PutMethod putmethod = new PutMethod(messageUrl); PutMethod putmethod = new PutMethod(messageUrl);
putmethod.setRequestHeader("Translate", "f"); putmethod.setRequestHeader("Translate", "f");
putmethod.setRequestHeader("Content-Type", "message/rfc822"); putmethod.setRequestHeader("Content-Type", "message/rfc822");
InputStream bodyStream = null;
try { try {
// use same encoding as client socket reader // use same encoding as client socket reader
putmethod.setRequestEntity(new ByteArrayRequestEntity(messageBody.getBytes())); putmethod.setRequestEntity(new ByteArrayRequestEntity(messageBody.getBytes()));
@ -534,18 +533,11 @@ public class ExchangeSession {
throw new IOException("Unable to create message " + messageUrl + ": " + code + " " + putmethod.getStatusLine()); throw new IOException("Unable to create message " + messageUrl + ": " + code + " " + putmethod.getStatusLine());
} }
} finally { } finally {
if (bodyStream != null) {
try {
bodyStream.close();
} catch (IOException e) {
LOGGER.error(e);
}
}
putmethod.releaseConnection(); putmethod.releaseConnection();
} }
// add bcc and other properties // add bcc and other properties
if (properties.size() > 0) { if (!properties.isEmpty()) {
patchMethod = new PropPatchMethod(messageUrl, buildProperties(properties)); patchMethod = new PropPatchMethod(messageUrl, buildProperties(properties));
try { try {
// update message with blind carbon copy and other flags // update message with blind carbon copy and other flags
@ -796,7 +788,7 @@ public class ExchangeSession {
} }
recipients.removeAll(visibleRecipients); recipients.removeAll(visibleRecipients);
StringBuffer bccBuffer = new StringBuffer(); StringBuilder bccBuffer = new StringBuilder();
for (String recipient : recipients) { for (String recipient : recipients) {
if (bccBuffer.length() > 0) { if (bccBuffer.length() > 0) {
bccBuffer.append(','); bccBuffer.append(',');
@ -1059,7 +1051,7 @@ public class ExchangeSession {
line = ".."; line = "..";
// patch text/calendar to include utf-8 encoding // patch text/calendar to include utf-8 encoding
} else if ("Content-Type: text/calendar;".equals(line)) { } else if ("Content-Type: text/calendar;".equals(line)) {
StringBuffer headerBuffer = new StringBuffer(); StringBuilder headerBuffer = new StringBuilder();
headerBuffer.append(line); headerBuffer.append(line);
while ((line = reader.readLine()) != null && line.startsWith("\t")) { while ((line = reader.readLine()) != null && line.startsWith("\t")) {
headerBuffer.append((char) 13); headerBuffer.append((char) 13);
@ -1122,7 +1114,7 @@ public class ExchangeSession {
} }
public int compareTo(Object message) { public int compareTo(Object message) {
long compareValue = (getImapUid() - ((Message) message).getImapUid()); long compareValue = (imapUid - ((Message) message).imapUid);
if (compareValue > 0) { if (compareValue > 0) {
return 1; return 1;
} else if (compareValue < 0) { } else if (compareValue < 0) {
@ -1134,7 +1126,7 @@ public class ExchangeSession {
@Override @Override
public boolean equals(Object message) { public boolean equals(Object message) {
return message instanceof Message && getImapUid() == ((Message) message).getImapUid(); return message instanceof Message && imapUid == ((Message) message).imapUid;
} }
@Override @Override
@ -1453,7 +1445,7 @@ public class ExchangeSession {
return "REQUEST"; return "REQUEST";
} }
int startIndex = methodIndex + "METHOD:".length(); int startIndex = methodIndex + "METHOD:".length();
int endIndex = icsBody.indexOf("\r", startIndex); int endIndex = icsBody.indexOf('\r', startIndex);
if (endIndex < 0) { if (endIndex < 0) {
return "REQUEST"; return "REQUEST";
} }
@ -1698,7 +1690,7 @@ public class ExchangeSession {
if (mailPath == null) { if (mailPath == null) {
return null; return null;
} }
int index = mailPath.lastIndexOf("/", mailPath.length() - 2); int index = mailPath.lastIndexOf('/', mailPath.length() - 2);
if (index >= 0 && mailPath.endsWith("/")) { if (index >= 0 && mailPath.endsWith("/")) {
return mailPath.substring(index + 1, mailPath.length() - 1); return mailPath.substring(index + 1, mailPath.length() - 1);
} else { } else {
@ -1710,33 +1702,20 @@ public class ExchangeSession {
if (mailPath == null) { if (mailPath == null) {
return null; return null;
} }
String alias; String displayName;
MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executePropFindMethod( MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executePropFindMethod(
httpClient, URIUtil.encodePath(mailPath), 0, DISPLAY_NAME); httpClient, URIUtil.encodePath(mailPath), 0, DISPLAY_NAME);
if (responses.length == 0) { if (responses.length == 0) {
throw new IOException("Unable to get mail folder"); throw new IOException("Unable to get mail folder");
} }
alias = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "displayname", Namespace.getNamespace("DAV:")); displayName = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "displayname", Namespace.getNamespace("DAV:"));
return alias; return displayName;
}
public String replacePrincipal(String folderUrl, String principal) throws IOException {
if (principal != null && !alias.equals(principal) && !email.equals(principal)) {
int index = mailPath.lastIndexOf("/", mailPath.length() - 2);
if (index >= 0 && mailPath.endsWith("/")) {
return mailPath.substring(0, index) + "/" + principal + "/" + folderUrl.substring(inboxUrl.lastIndexOf("/"));
} else {
throw new IOException("Invalid mail path: " + mailPath);
}
} else {
return folderUrl;
}
} }
public String buildCalendarPath(String principal, String folderName) throws IOException { public String buildCalendarPath(String principal, String folderName) throws IOException {
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
if (principal != null && !alias.equals(principal) && !email.equals(principal)) { if (principal != null && !alias.equals(principal) && !email.equals(principal)) {
int index = mailPath.lastIndexOf("/", mailPath.length() - 2); int index = mailPath.lastIndexOf('/', mailPath.length() - 2);
if (index >= 0 && mailPath.endsWith("/")) { if (index >= 0 && mailPath.endsWith("/")) {
buffer.append(mailPath.substring(0, index + 1)).append(principal).append("/"); buffer.append(mailPath.substring(0, index + 1)).append(principal).append("/");
} else { } else {
@ -1746,9 +1725,9 @@ public class ExchangeSession {
buffer.append(mailPath); buffer.append(mailPath);
} }
if ("calendar".equals(folderName)) { if ("calendar".equals(folderName)) {
buffer.append(calendarUrl.substring(calendarUrl.lastIndexOf("/") + 1)); buffer.append(calendarUrl.substring(calendarUrl.lastIndexOf('/') + 1));
} else if ("inbox".equals(folderName)) { } else if ("inbox".equals(folderName)) {
buffer.append(inboxUrl.substring(inboxUrl.lastIndexOf("/") + 1)); buffer.append(inboxUrl.substring(inboxUrl.lastIndexOf('/') + 1));
} else if (folderName != null && folderName.length() > 0) { } else if (folderName != null && folderName.length() > 0) {
buffer.append(folderName); buffer.append(folderName);
} }
@ -1839,7 +1818,7 @@ public class ExchangeSession {
} }
if (line != null) { if (line != null) {
int start = line.toLowerCase().indexOf(MAILBOX_BASE) + MAILBOX_BASE.length(); int start = line.toLowerCase().indexOf(MAILBOX_BASE) + MAILBOX_BASE.length();
int end = line.indexOf("<", start); int end = line.indexOf('<', start);
result = line.substring(start, end); result = line.substring(start, end);
} }
} catch (IOException e) { } catch (IOException e) {
@ -1911,7 +1890,7 @@ public class ExchangeSession {
} }
Map<String, Map<String, String>> results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "person", "alias"); Map<String, Map<String, String>> results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "person", "alias");
// add detailed information // add detailed information
if (results.size() > 0) { if (!results.isEmpty()) {
Map<String, String> fullperson = results.get(person.get("AN").toLowerCase()); Map<String, String> fullperson = results.get(person.get("AN").toLowerCase());
for (Map.Entry<String, String> entry : fullperson.entrySet()) { for (Map.Entry<String, String> entry : fullperson.entrySet()) {
person.put(entry.getKey(), entry.getValue()); person.put(entry.getKey(), entry.getValue());

View File

@ -104,7 +104,7 @@ public final class DavGatewayHttpClientFacade {
AuthScope authScope = new AuthScope(proxyHost, proxyPort, AuthScope.ANY_REALM); AuthScope authScope = new AuthScope(proxyHost, proxyPort, AuthScope.ANY_REALM);
// detect ntlm authentication (windows domain name in user name) // detect ntlm authentication (windows domain name in user name)
int backslashindex = proxyUser.indexOf("\\"); int backslashindex = proxyUser.indexOf('\\');
if (backslashindex > 0) { if (backslashindex > 0) {
httpClient.getState().setProxyCredentials(authScope, httpClient.getState().setProxyCredentials(authScope,
new NTCredentials(proxyUser.substring(backslashindex + 1), new NTCredentials(proxyUser.substring(backslashindex + 1),

View File

@ -852,7 +852,7 @@ public class ImapConnection extends AbstractConnection {
} }
} }
} }
if (properties.size() > 0) { if (!properties.isEmpty()) {
session.updateMessage(message, properties); session.updateMessage(message, properties);
} }
} }
@ -875,7 +875,7 @@ public class ImapConnection extends AbstractConnection {
} else { } else {
throw new IOException("Invalid credentials"); throw new IOException("Invalid credentials");
} }
int backslashindex = userName.indexOf("\\"); int backslashindex = userName.indexOf('\\');
if (backslashindex > 0) { if (backslashindex > 0) {
userName = userName.substring(0, backslashindex) + userName.substring(backslashindex + 1); userName = userName.substring(0, backslashindex) + userName.substring(backslashindex + 1);
} }

View File

@ -640,9 +640,9 @@ public class LdapConnection extends AbstractConnection {
* @throws IOException on error * @throws IOException on error
*/ */
protected void sendPersons(int currentMessageId, String baseContext, Map<String, Map<String, String>> persons, Set<String> returningAttributes) throws IOException { protected void sendPersons(int currentMessageId, String baseContext, Map<String, Map<String, String>> persons, Set<String> returningAttributes) throws IOException {
boolean needObjectClasses = returningAttributes.contains("objectclass") || returningAttributes.size() == 0; boolean needObjectClasses = returningAttributes.contains("objectclass") || returningAttributes.isEmpty();
boolean iCalSearch = returningAttributes.contains("apple-serviceslocator"); boolean iCalSearch = returningAttributes.contains("apple-serviceslocator");
boolean returnAllAttributes = returningAttributes.size() == 0; boolean returnAllAttributes = returningAttributes.isEmpty();
for (Map<String, String> person : persons.values()) { for (Map<String, String> person : persons.values()) {
boolean needDetails = returnAllAttributes; boolean needDetails = returnAllAttributes;
if (!needDetails) { if (!needDetails) {
@ -731,7 +731,7 @@ public class LdapConnection extends AbstractConnection {
} }
protected void addIf(Map<String, Object> attributes, Set<String> returningAttributes, String name, Object value) { protected void addIf(Map<String, Object> attributes, Set<String> returningAttributes, String name, Object value) {
if ((returningAttributes.size() == 0) || returningAttributes.contains(name)) { if ((returningAttributes.isEmpty()) || returningAttributes.contains(name)) {
attributes.put(name, value); attributes.put(name, value);
} }
} }

View File

@ -189,11 +189,11 @@ public class SettingsFrame extends JFrame {
enableProxyField.addActionListener(new ActionListener() { enableProxyField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
boolean enableProxy = enableProxyField.isSelected(); boolean newEnableProxy = enableProxyField.isSelected();
httpProxyField.setEnabled(enableProxy); httpProxyField.setEnabled(newEnableProxy);
httpProxyPortField.setEnabled(enableProxy); httpProxyPortField.setEnabled(newEnableProxy);
httpProxyUserField.setEnabled(enableProxy); httpProxyUserField.setEnabled(newEnableProxy);
httpProxyPasswordField.setEnabled(enableProxy); httpProxyPasswordField.setEnabled(newEnableProxy);
} }
}); });

View File

@ -25,8 +25,8 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
protected AwtGatewayTray() { protected AwtGatewayTray() {
} }
protected static AboutFrame aboutFrame; static AboutFrame aboutFrame;
protected static SettingsFrame settingsFrame; static SettingsFrame settingsFrame;
private static TrayIcon trayIcon = null; private static TrayIcon trayIcon = null;
private static Image image = null; private static Image image = null;

View File

@ -256,10 +256,10 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
if (Settings.isFirstStart()) { if (Settings.isFirstStart()) {
settingsFrame.setVisible(true); settingsFrame.setVisible(true);
} }
// ready
isReady = true;
synchronized (mainThread) { synchronized (mainThread) {
mainThread.notify(); // ready
isReady = true;
mainThread.notifyAll();
} }
while (!shell.isDisposed()) { while (!shell.isDisposed()) {