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>
<developer>
<name>Mickaël Guessant</name>
<id>mguessan</id>
<email>mguessan@free.fr</email>
<url>http://mguessan.free.fr</url>
<roles>

View File

@ -68,7 +68,7 @@ public class CaldavConnection extends AbstractConnection {
}
protected void setSocketTimeout(String keepAliveValue) throws IOException {
if (keepAliveValue != null || keepAliveValue.length() > 0) {
if (keepAliveValue != null && keepAliveValue.length() > 0) {
int keepAlive;
try {
keepAlive = Integer.parseInt(keepAliveValue);
@ -320,7 +320,7 @@ public class CaldavConnection extends AbstractConnection {
String line;
String key = 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));
} else {
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);
sendClient("Date: " + formatter.format(new java.util.Date()));
if (headers != null) {
for (String header : headers.keySet()) {
sendClient(header + ": " + headers.get(header));
for (Map.Entry<String,String> header : headers.entrySet()) {
sendClient(header.getKey() + ": " + header.getValue());
}
}
if (contentType != null) {

View File

@ -1,8 +1,7 @@
package davmail.caldav;
import davmail.AbstractServer;
import davmail.AbstractConnection;
import davmail.pop.PopConnection;
import davmail.AbstractServer;
import java.io.IOException;
import java.net.Socket;
@ -16,6 +15,7 @@ public class CaldavServer extends AbstractServer {
/**
* Create a ServerSocket to listen for connections.
* Start the thread.
*
* @param port pop listen port, 80 if not defined (0)
* @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 {
LOGGER.debug("Form based authentication detected");
// build logon method with actual destination (baseUrl)
HttpMethod logonMethod = buildLogonMethod(httpClient, initmethod);
((PostMethod) logonMethod).addParameter("username", userName);
((PostMethod) logonMethod).addParameter("password", password);
@ -548,16 +548,16 @@ public class ExchangeSession {
String subject = "davmailtemp";
String line = reader.readLine();
StringBuffer mailBuffer = new StringBuffer();
while (!".".equals(line)) {
while (line != null && !".".equals(line)) {
mailBuffer.append(line);
mailBuffer.append("\n");
line = reader.readLine();
if (line != null) {
// patch thunderbird html in reply for correct outlook display
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());
// '/' is invalid as message URL
subject = subject.replaceAll("/", "_xF8FF_");
@ -566,6 +566,7 @@ public class ExchangeSession {
// TODO : test & in subject
}
}
}
createMessage(draftsUrl, subject, mailBuffer.toString());
@ -627,7 +628,7 @@ public class ExchangeSession {
return folder;
}
public class Folder {
public static class Folder {
public String folderUrl;
public int childCount;
public int unreadCount;
@ -953,29 +954,8 @@ public class ExchangeSession {
if (status != HttpStatus.SC_OK) {
throw new IOException("Unable to get user email from: " + getMethod.getPath());
}
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
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());
email = XMLStreamUtil.getElementContentByLocalName(getMethod.getResponseBodyAsStream(), "EM");
} finally {
try {
reader.close();
} catch (XMLStreamException e) {
LOGGER.error(e);
}
getMethod.releaseConnection();
}
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)");
}
private DavGatewayHttpClientFacade() {
}
/**
* 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
*/
private class TopOutputStream extends FilterOutputStream {
private static class TopOutputStream extends FilterOutputStream {
protected static final int START = 0;
protected static final int CR = 1;
protected static final int CRLF = 2;

View File

@ -9,14 +9,12 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URI;
import java.net.URISyntaxException;
/**
* DavMail settings frame
*/
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 popPortField;

View File

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