mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 17:31:52 -05:00
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:
parent
3cd0212663
commit
b394c718c1
1
pom.xml
1
pom.xml
@ -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>
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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,22 +548,23 @@ 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();
|
||||
|
||||
// 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")) {
|
||||
subject = MimeUtility.decodeText(line.substring(8).trim());
|
||||
// '/' is invalid as message URL
|
||||
subject = subject.replaceAll("/", "_xF8FF_");
|
||||
// '?' is also invalid
|
||||
subject = subject.replaceAll("\\?", "");
|
||||
// TODO : test & in subject
|
||||
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>";
|
||||
} else if (line.startsWith("Subject")) {
|
||||
subject = MimeUtility.decodeText(line.substring(8).trim());
|
||||
// '/' is invalid as message URL
|
||||
subject = subject.replaceAll("/", "_xF8FF_");
|
||||
// '?' is also invalid
|
||||
subject = subject.replaceAll("\\?", "");
|
||||
// TODO : test & in subject
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
54
src/java/davmail/exchange/XMLStreamUtil.java
Normal file
54
src/java/davmail/exchange/XMLStreamUtil.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user