mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
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:
parent
59b19fee2b
commit
1f32b94aec
@ -69,7 +69,7 @@ public class AbstractConnection extends Thread {
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public void sendClient(String prefix, String message) throws IOException {
|
||||
StringBuffer logBuffer = new StringBuffer("> ");
|
||||
StringBuilder logBuffer = new StringBuilder("> ");
|
||||
if (prefix != null) {
|
||||
logBuffer.append(prefix);
|
||||
os.write(prefix.getBytes());
|
||||
|
@ -23,7 +23,7 @@ public class Settings {
|
||||
configFilePath = value;
|
||||
}
|
||||
|
||||
public static boolean isFirstStart() {
|
||||
public static synchronized boolean isFirstStart() {
|
||||
return isFirstStart;
|
||||
}
|
||||
|
||||
|
@ -573,7 +573,7 @@ public class CaldavConnection extends AbstractConnection {
|
||||
}
|
||||
String fullkey = line.substring(0, index);
|
||||
String value = line.substring(index + 1);
|
||||
int semicolonIndex = fullkey.indexOf(";");
|
||||
int semicolonIndex = fullkey.indexOf(';');
|
||||
if (semicolonIndex > 0) {
|
||||
key = fullkey.substring(0, semicolonIndex);
|
||||
} 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 {
|
||||
String message = e.getMessage();
|
||||
if (message == null) {
|
||||
@ -790,12 +779,12 @@ public class CaldavConnection extends AbstractConnection {
|
||||
}
|
||||
|
||||
protected class CaldavRequest {
|
||||
protected String command;
|
||||
protected String path;
|
||||
protected String[] pathElements;
|
||||
protected Map<String, String> headers;
|
||||
protected final String command;
|
||||
protected final String path;
|
||||
protected final String[] pathElements;
|
||||
protected final Map<String, String> headers;
|
||||
protected int depth;
|
||||
protected String body;
|
||||
protected final String body;
|
||||
protected final HashSet<String> properties = new HashSet<String>();
|
||||
protected HashSet<String> hrefs;
|
||||
protected boolean isMultiGet;
|
||||
@ -880,10 +869,6 @@ public class CaldavConnection extends AbstractConnection {
|
||||
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) {
|
||||
if (index < pathElements.length) {
|
||||
return pathElements[index];
|
||||
@ -1009,7 +994,7 @@ public class CaldavConnection extends AbstractConnection {
|
||||
if ("users".equals(getPathElement(1))) {
|
||||
return session.buildCalendarPath(getPathElement(2), getPathElement(3));
|
||||
} else {
|
||||
return getPath();
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ public class ExchangeSession {
|
||||
LOGGER.error(exc.toString());
|
||||
throw exc;
|
||||
} catch (IOException exc) {
|
||||
StringBuffer message = new StringBuffer();
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append("DavMail login exception: ");
|
||||
if (exc.getMessage() != null) {
|
||||
message.append(exc.getMessage());
|
||||
@ -322,8 +322,8 @@ public class ExchangeSession {
|
||||
if (a_sUrlIndex >= 0 && a_sLgnIndex >= 0) {
|
||||
a_sUrlIndex += "var a_sUrl = \"".length();
|
||||
a_sLgnIndex += "var a_sLgn = \"".length();
|
||||
int a_sUrlEndIndex = scriptValue.indexOf("\"", a_sUrlIndex);
|
||||
int a_sLgnEndIndex = scriptValue.indexOf("\"", a_sLgnIndex);
|
||||
int a_sUrlEndIndex = scriptValue.indexOf('\"', a_sUrlIndex);
|
||||
int a_sLgnEndIndex = scriptValue.indexOf('\"', a_sLgnIndex);
|
||||
if (a_sUrlEndIndex >= 0 && a_sLgnEndIndex >= 0) {
|
||||
String src = getAbsolutePathOrUri(initmethod,
|
||||
scriptValue.substring(a_sLgnIndex, a_sLgnEndIndex) +
|
||||
@ -337,8 +337,8 @@ public class ExchangeSession {
|
||||
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);
|
||||
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) +
|
||||
@ -391,7 +391,7 @@ public class ExchangeSession {
|
||||
}
|
||||
if (line != null) {
|
||||
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);
|
||||
URL baseURL = new URL(mailBoxBaseHref);
|
||||
mailPath = baseURL.getPath();
|
||||
@ -524,7 +524,6 @@ public class ExchangeSession {
|
||||
PutMethod putmethod = new PutMethod(messageUrl);
|
||||
putmethod.setRequestHeader("Translate", "f");
|
||||
putmethod.setRequestHeader("Content-Type", "message/rfc822");
|
||||
InputStream bodyStream = null;
|
||||
try {
|
||||
// use same encoding as client socket reader
|
||||
putmethod.setRequestEntity(new ByteArrayRequestEntity(messageBody.getBytes()));
|
||||
@ -534,18 +533,11 @@ public class ExchangeSession {
|
||||
throw new IOException("Unable to create message " + messageUrl + ": " + code + " " + putmethod.getStatusLine());
|
||||
}
|
||||
} finally {
|
||||
if (bodyStream != null) {
|
||||
try {
|
||||
bodyStream.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
}
|
||||
putmethod.releaseConnection();
|
||||
}
|
||||
|
||||
// add bcc and other properties
|
||||
if (properties.size() > 0) {
|
||||
if (!properties.isEmpty()) {
|
||||
patchMethod = new PropPatchMethod(messageUrl, buildProperties(properties));
|
||||
try {
|
||||
// update message with blind carbon copy and other flags
|
||||
@ -796,7 +788,7 @@ public class ExchangeSession {
|
||||
}
|
||||
recipients.removeAll(visibleRecipients);
|
||||
|
||||
StringBuffer bccBuffer = new StringBuffer();
|
||||
StringBuilder bccBuffer = new StringBuilder();
|
||||
for (String recipient : recipients) {
|
||||
if (bccBuffer.length() > 0) {
|
||||
bccBuffer.append(',');
|
||||
@ -1059,7 +1051,7 @@ public class ExchangeSession {
|
||||
line = "..";
|
||||
// patch text/calendar to include utf-8 encoding
|
||||
} else if ("Content-Type: text/calendar;".equals(line)) {
|
||||
StringBuffer headerBuffer = new StringBuffer();
|
||||
StringBuilder headerBuffer = new StringBuilder();
|
||||
headerBuffer.append(line);
|
||||
while ((line = reader.readLine()) != null && line.startsWith("\t")) {
|
||||
headerBuffer.append((char) 13);
|
||||
@ -1122,7 +1114,7 @@ public class ExchangeSession {
|
||||
}
|
||||
|
||||
public int compareTo(Object message) {
|
||||
long compareValue = (getImapUid() - ((Message) message).getImapUid());
|
||||
long compareValue = (imapUid - ((Message) message).imapUid);
|
||||
if (compareValue > 0) {
|
||||
return 1;
|
||||
} else if (compareValue < 0) {
|
||||
@ -1134,7 +1126,7 @@ public class ExchangeSession {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object message) {
|
||||
return message instanceof Message && getImapUid() == ((Message) message).getImapUid();
|
||||
return message instanceof Message && imapUid == ((Message) message).imapUid;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1453,7 +1445,7 @@ public class ExchangeSession {
|
||||
return "REQUEST";
|
||||
}
|
||||
int startIndex = methodIndex + "METHOD:".length();
|
||||
int endIndex = icsBody.indexOf("\r", startIndex);
|
||||
int endIndex = icsBody.indexOf('\r', startIndex);
|
||||
if (endIndex < 0) {
|
||||
return "REQUEST";
|
||||
}
|
||||
@ -1698,7 +1690,7 @@ public class ExchangeSession {
|
||||
if (mailPath == null) {
|
||||
return null;
|
||||
}
|
||||
int index = mailPath.lastIndexOf("/", mailPath.length() - 2);
|
||||
int index = mailPath.lastIndexOf('/', mailPath.length() - 2);
|
||||
if (index >= 0 && mailPath.endsWith("/")) {
|
||||
return mailPath.substring(index + 1, mailPath.length() - 1);
|
||||
} else {
|
||||
@ -1710,33 +1702,20 @@ public class ExchangeSession {
|
||||
if (mailPath == null) {
|
||||
return null;
|
||||
}
|
||||
String alias;
|
||||
String displayName;
|
||||
MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executePropFindMethod(
|
||||
httpClient, URIUtil.encodePath(mailPath), 0, DISPLAY_NAME);
|
||||
if (responses.length == 0) {
|
||||
throw new IOException("Unable to get mail folder");
|
||||
}
|
||||
alias = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "displayname", Namespace.getNamespace("DAV:"));
|
||||
return alias;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
displayName = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "displayname", Namespace.getNamespace("DAV:"));
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public String buildCalendarPath(String principal, String folderName) throws IOException {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
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("/")) {
|
||||
buffer.append(mailPath.substring(0, index + 1)).append(principal).append("/");
|
||||
} else {
|
||||
@ -1746,9 +1725,9 @@ public class ExchangeSession {
|
||||
buffer.append(mailPath);
|
||||
}
|
||||
if ("calendar".equals(folderName)) {
|
||||
buffer.append(calendarUrl.substring(calendarUrl.lastIndexOf("/") + 1));
|
||||
buffer.append(calendarUrl.substring(calendarUrl.lastIndexOf('/') + 1));
|
||||
} 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) {
|
||||
buffer.append(folderName);
|
||||
}
|
||||
@ -1839,7 +1818,7 @@ public class ExchangeSession {
|
||||
}
|
||||
if (line != null) {
|
||||
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);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -1911,7 +1890,7 @@ public class ExchangeSession {
|
||||
}
|
||||
Map<String, Map<String, String>> results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "person", "alias");
|
||||
// add detailed information
|
||||
if (results.size() > 0) {
|
||||
if (!results.isEmpty()) {
|
||||
Map<String, String> fullperson = results.get(person.get("AN").toLowerCase());
|
||||
for (Map.Entry<String, String> entry : fullperson.entrySet()) {
|
||||
person.put(entry.getKey(), entry.getValue());
|
||||
|
@ -104,7 +104,7 @@ public final class DavGatewayHttpClientFacade {
|
||||
AuthScope authScope = new AuthScope(proxyHost, proxyPort, AuthScope.ANY_REALM);
|
||||
|
||||
// detect ntlm authentication (windows domain name in user name)
|
||||
int backslashindex = proxyUser.indexOf("\\");
|
||||
int backslashindex = proxyUser.indexOf('\\');
|
||||
if (backslashindex > 0) {
|
||||
httpClient.getState().setProxyCredentials(authScope,
|
||||
new NTCredentials(proxyUser.substring(backslashindex + 1),
|
||||
|
@ -852,7 +852,7 @@ public class ImapConnection extends AbstractConnection {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (properties.size() > 0) {
|
||||
if (!properties.isEmpty()) {
|
||||
session.updateMessage(message, properties);
|
||||
}
|
||||
}
|
||||
@ -875,7 +875,7 @@ public class ImapConnection extends AbstractConnection {
|
||||
} else {
|
||||
throw new IOException("Invalid credentials");
|
||||
}
|
||||
int backslashindex = userName.indexOf("\\");
|
||||
int backslashindex = userName.indexOf('\\');
|
||||
if (backslashindex > 0) {
|
||||
userName = userName.substring(0, backslashindex) + userName.substring(backslashindex + 1);
|
||||
}
|
||||
|
@ -640,9 +640,9 @@ public class LdapConnection extends AbstractConnection {
|
||||
* @throws IOException on error
|
||||
*/
|
||||
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 returnAllAttributes = returningAttributes.size() == 0;
|
||||
boolean returnAllAttributes = returningAttributes.isEmpty();
|
||||
for (Map<String, String> person : persons.values()) {
|
||||
boolean needDetails = returnAllAttributes;
|
||||
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) {
|
||||
if ((returningAttributes.size() == 0) || returningAttributes.contains(name)) {
|
||||
if ((returningAttributes.isEmpty()) || returningAttributes.contains(name)) {
|
||||
attributes.put(name, value);
|
||||
}
|
||||
}
|
||||
|
@ -189,11 +189,11 @@ public class SettingsFrame extends JFrame {
|
||||
|
||||
enableProxyField.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
boolean enableProxy = enableProxyField.isSelected();
|
||||
httpProxyField.setEnabled(enableProxy);
|
||||
httpProxyPortField.setEnabled(enableProxy);
|
||||
httpProxyUserField.setEnabled(enableProxy);
|
||||
httpProxyPasswordField.setEnabled(enableProxy);
|
||||
boolean newEnableProxy = enableProxyField.isSelected();
|
||||
httpProxyField.setEnabled(newEnableProxy);
|
||||
httpProxyPortField.setEnabled(newEnableProxy);
|
||||
httpProxyUserField.setEnabled(newEnableProxy);
|
||||
httpProxyPasswordField.setEnabled(newEnableProxy);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -25,8 +25,8 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||
protected AwtGatewayTray() {
|
||||
}
|
||||
|
||||
protected static AboutFrame aboutFrame;
|
||||
protected static SettingsFrame settingsFrame;
|
||||
static AboutFrame aboutFrame;
|
||||
static SettingsFrame settingsFrame;
|
||||
|
||||
private static TrayIcon trayIcon = null;
|
||||
private static Image image = null;
|
||||
|
@ -256,10 +256,10 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
||||
if (Settings.isFirstStart()) {
|
||||
settingsFrame.setVisible(true);
|
||||
}
|
||||
// ready
|
||||
isReady = true;
|
||||
synchronized (mainThread) {
|
||||
mainThread.notify();
|
||||
// ready
|
||||
isReady = true;
|
||||
mainThread.notifyAll();
|
||||
}
|
||||
|
||||
while (!shell.isDisposed()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user