Various fixes and cleanup from FindBugs audit

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@189 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2008-12-02 10:20:46 +00:00
parent 3cd0212663
commit b394c718c1
9 changed files with 85 additions and 46 deletions

View File

@ -19,6 +19,7 @@
<developers> <developers>
<developer> <developer>
<name>Mickaël Guessant</name> <name>Mickaël Guessant</name>
<id>mguessan</id>
<email>mguessan@free.fr</email> <email>mguessan@free.fr</email>
<url>http://mguessan.free.fr</url> <url>http://mguessan.free.fr</url>
<roles> <roles>

View File

@ -68,7 +68,7 @@ public class CaldavConnection extends AbstractConnection {
} }
protected void setSocketTimeout(String keepAliveValue) throws IOException { protected void setSocketTimeout(String keepAliveValue) throws IOException {
if (keepAliveValue != null || keepAliveValue.length() > 0) { if (keepAliveValue != null && keepAliveValue.length() > 0) {
int keepAlive; int keepAlive;
try { try {
keepAlive = Integer.parseInt(keepAliveValue); keepAlive = Integer.parseInt(keepAliveValue);
@ -320,7 +320,7 @@ public class CaldavConnection extends AbstractConnection {
String line; String line;
String key = null; String key = null;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
if (line.startsWith(" ") & "ATTENDEE".equals(key)) { if (line.startsWith(" ") && "ATTENDEE".equals(key)) {
valueMap.put(key, valueMap.get(key)+line.substring(1)); valueMap.put(key, valueMap.get(key)+line.substring(1));
} else { } else {
int index = line.indexOf(':'); int index = line.indexOf(':');
@ -411,8 +411,8 @@ public class CaldavConnection extends AbstractConnection {
SimpleDateFormat formatter = new java.text.SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH); SimpleDateFormat formatter = new java.text.SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
sendClient("Date: " + formatter.format(new java.util.Date())); sendClient("Date: " + formatter.format(new java.util.Date()));
if (headers != null) { if (headers != null) {
for (String header : headers.keySet()) { for (Map.Entry<String,String> header : headers.entrySet()) {
sendClient(header + ": " + headers.get(header)); sendClient(header.getKey() + ": " + header.getValue());
} }
} }
if (contentType != null) { if (contentType != null) {

View File

@ -1,8 +1,7 @@
package davmail.caldav; package davmail.caldav;
import davmail.AbstractServer;
import davmail.AbstractConnection; import davmail.AbstractConnection;
import davmail.pop.PopConnection; import davmail.AbstractServer;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
@ -16,6 +15,7 @@ public class CaldavServer extends AbstractServer {
/** /**
* Create a ServerSocket to listen for connections. * Create a ServerSocket to listen for connections.
* Start the thread. * Start the thread.
*
* @param port pop listen port, 80 if not defined (0) * @param port pop listen port, 80 if not defined (0)
* @throws java.io.IOException on error * @throws java.io.IOException on error
*/ */

View File

@ -158,7 +158,7 @@ public class ExchangeSession {
protected HttpMethod formLogin(HttpClient httpClient, HttpMethod initmethod, String userName, String password) throws IOException { protected HttpMethod formLogin(HttpClient httpClient, HttpMethod initmethod, String userName, String password) throws IOException {
LOGGER.debug("Form based authentication detected"); LOGGER.debug("Form based authentication detected");
// build logon method with actual destination (baseUrl)
HttpMethod logonMethod = buildLogonMethod(httpClient, initmethod); HttpMethod logonMethod = buildLogonMethod(httpClient, initmethod);
((PostMethod) logonMethod).addParameter("username", userName); ((PostMethod) logonMethod).addParameter("username", userName);
((PostMethod) logonMethod).addParameter("password", password); ((PostMethod) logonMethod).addParameter("password", password);
@ -548,22 +548,23 @@ public class ExchangeSession {
String subject = "davmailtemp"; String subject = "davmailtemp";
String line = reader.readLine(); String line = reader.readLine();
StringBuffer mailBuffer = new StringBuffer(); StringBuffer mailBuffer = new StringBuffer();
while (!".".equals(line)) { while (line != null && !".".equals(line)) {
mailBuffer.append(line); mailBuffer.append(line);
mailBuffer.append("\n"); mailBuffer.append("\n");
line = reader.readLine(); line = reader.readLine();
// patch thunderbird html in reply for correct outlook display if (line != null) {
if (line.startsWith("<head>")) { // patch thunderbird html in reply for correct outlook display
line += "\n <style> blockquote { display: block; margin: 1em 0px; padding-left: 1em; border-left: solid; border-color: blue; border-width: thin;}</style>"; if (line.startsWith("<head>")) {
} line += "\n <style> blockquote { display: block; margin: 1em 0px; padding-left: 1em; border-left: solid; border-color: blue; border-width: thin;}</style>";
if (line.startsWith("Subject")) { } else if (line.startsWith("Subject")) {
subject = MimeUtility.decodeText(line.substring(8).trim()); subject = MimeUtility.decodeText(line.substring(8).trim());
// '/' is invalid as message URL // '/' is invalid as message URL
subject = subject.replaceAll("/", "_xF8FF_"); subject = subject.replaceAll("/", "_xF8FF_");
// '?' is also invalid // '?' is also invalid
subject = subject.replaceAll("\\?", ""); subject = subject.replaceAll("\\?", "");
// TODO : test & in subject // TODO : test & in subject
}
} }
} }
@ -627,7 +628,7 @@ public class ExchangeSession {
return folder; return folder;
} }
public class Folder { public static class Folder {
public String folderUrl; public String folderUrl;
public int childCount; public int childCount;
public int unreadCount; public int unreadCount;
@ -953,29 +954,8 @@ public class ExchangeSession {
if (status != HttpStatus.SC_OK) { if (status != HttpStatus.SC_OK) {
throw new IOException("Unable to get user email from: " + getMethod.getPath()); throw new IOException("Unable to get user email from: " + getMethod.getPath());
} }
XMLInputFactory inputFactory = XMLInputFactory.newInstance(); email = XMLStreamUtil.getElementContentByLocalName(getMethod.getResponseBodyAsStream(), "EM");
inputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
reader = inputFactory.createXMLStreamReader(getMethod.getResponseBodyAsStream());
boolean inEM = false;
while (reader.hasNext()) {
int event = reader.next();
if (event == XMLStreamConstants.START_ELEMENT && "EM".equals(reader.getLocalName())) {
inEM = true;
} else if (event == XMLStreamConstants.CHARACTERS && inEM) {
email = reader.getText();
inEM = false;
}
}
} catch (XMLStreamException e) {
throw new IOException(e.getMessage());
} finally { } finally {
try {
reader.close();
} catch (XMLStreamException e) {
LOGGER.error(e);
}
getMethod.releaseConnection(); getMethod.releaseConnection();
} }
if (email == null) { if (email == null) {

View File

@ -0,0 +1,54 @@
package davmail.exchange;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.IOException;
import java.io.InputStream;
/**
* XmlStreamReader utility methods
*/
public class XMLStreamUtil {
private XMLStreamUtil() {
}
public static XMLInputFactory getXmlInputFactory() {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
return inputFactory;
}
public static String getElementContentByLocalName(InputStream inputStream, String localName) throws IOException {
String elementContent = null;
XMLStreamReader reader = null;
try {
XMLInputFactory inputFactory = getXmlInputFactory();
reader = inputFactory.createXMLStreamReader(inputStream);
boolean inElement = false;
while (reader.hasNext()) {
int event = reader.next();
if (event == XMLStreamConstants.START_ELEMENT && localName.equals(reader.getLocalName())) {
inElement = true;
} else if (event == XMLStreamConstants.CHARACTERS && inElement) {
elementContent = reader.getText();
inElement = false;
}
}
} catch (XMLStreamException e) {
throw new IOException(e.getMessage());
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (XMLStreamException e) {
ExchangeSession.LOGGER.error(e);
}
}
return elementContent;
}
}

View File

@ -21,6 +21,9 @@ public class DavGatewayHttpClientFacade {
System.getProperties().setProperty("httpclient.useragent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"); System.getProperties().setProperty("httpclient.useragent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
} }
private DavGatewayHttpClientFacade() {
}
/** /**
* Create a configured HttpClient instance. * Create a configured HttpClient instance.
* *

View File

@ -252,7 +252,7 @@ public class PopConnection extends AbstractConnection {
/** /**
* Filter to limit output lines to max body lines after header * Filter to limit output lines to max body lines after header
*/ */
private class TopOutputStream extends FilterOutputStream { private static class TopOutputStream extends FilterOutputStream {
protected static final int START = 0; protected static final int START = 0;
protected static final int CR = 1; protected static final int CR = 1;
protected static final int CRLF = 2; protected static final int CRLF = 2;

View File

@ -9,14 +9,12 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.net.URI;
import java.net.URISyntaxException;
/** /**
* DavMail settings frame * DavMail settings frame
*/ */
public class SettingsFrame extends JFrame { public class SettingsFrame extends JFrame {
public static final Level[] LOG_LEVELS = {Level.OFF, Level.FATAL, Level.ERROR, Level.WARN, Level.INFO, Level.DEBUG, Level.ALL}; static final Level[] LOG_LEVELS = {Level.OFF, Level.FATAL, Level.ERROR, Level.WARN, Level.INFO, Level.DEBUG, Level.ALL};
protected JTextField urlField; protected JTextField urlField;
protected JTextField popPortField; protected JTextField popPortField;

View File

@ -9,6 +9,9 @@ import java.net.URI;
* Wrapper class to call SWT Program class to launch default browser. * Wrapper class to call SWT Program class to launch default browser.
*/ */
public class SwtDesktopBrowser { public class SwtDesktopBrowser {
private SwtDesktopBrowser() {
}
public static void browse(URI location) throws IOException { public static void browse(URI location) throws IOException {
Program.launch(location.toString()); Program.launch(location.toString());
} }