1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 03:02:22 -05:00

Various code cleanup from audit

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@236 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2008-12-17 15:31:08 +00:00
parent f3f28ac7c3
commit 4a4e515c9c
12 changed files with 40 additions and 35 deletions

View File

@ -150,7 +150,7 @@ public class AbstractConnection extends Thread {
return new String(Base64.encode(value.getBytes())); return new String(Base64.encode(value.getBytes()));
} }
protected String base64Decode(String value) throws IOException { protected String base64Decode(String value) {
return new String(Base64.decode(value.getBytes())); return new String(Base64.decode(value.getBytes()));
} }
} }

View File

@ -11,7 +11,7 @@ import java.net.Socket;
* Generic abstract server common to SMTP and POP3 implementations * Generic abstract server common to SMTP and POP3 implementations
*/ */
public abstract class AbstractServer extends Thread { public abstract class AbstractServer extends Thread {
private int port; private final int port;
private ServerSocket serverSocket; private ServerSocket serverSocket;
/** /**

View File

@ -16,14 +16,14 @@ import java.util.*;
/** /**
* Create ExchangeSession instances. * Create ExchangeSession instances.
*/ */
public class ExchangeSessionFactory { public final class ExchangeSessionFactory {
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private static final Map<PoolKey, ExchangeSessionStack> poolMap = new HashMap<PoolKey, ExchangeSessionStack>(); private static final Map<PoolKey, ExchangeSessionStack> poolMap = new HashMap<PoolKey, ExchangeSessionStack>();
static class PoolKey { static class PoolKey {
public String url; public final String url;
public String userName; public final String userName;
public String password; public final String password;
public PoolKey(String url, String userName, String password) { public PoolKey(String url, String userName, String password) {
this.url = url; this.url = url;
@ -177,8 +177,8 @@ public class ExchangeSessionFactory {
ExchangeSession.LOGGER.error(message, exc); ExchangeSession.LOGGER.error(message, exc);
throw new IOException(message); throw new IOException(message);
} else { } else {
message += "All network interfaces down !"; message = "All network interfaces down !";
ExchangeSession.LOGGER.error(message, exc); ExchangeSession.LOGGER.error(message);
throw new NetworkDownException(message); throw new NetworkDownException(message);
} }

View File

@ -2,6 +2,7 @@ package davmail.http;
import org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory; import org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory;
import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.HttpsURL;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManager;
@ -33,7 +34,7 @@ public class DavGatewaySSLProtocolSocketFactory extends SSLProtocolSocketFactory
if ("https".equals(protocol)) { if ("https".equals(protocol)) {
int port = url.getPort(); int port = url.getPort();
if (port < 0) { if (port < 0) {
port = 443; port = HttpsURL.DEFAULT_PORT;
} }
Protocol.registerProtocol(url.getProtocol(), Protocol.registerProtocol(url.getProtocol(),
new Protocol(protocol, new DavGatewaySSLProtocolSocketFactory(), port)); new Protocol(protocol, new DavGatewaySSLProtocolSocketFactory(), port));

View File

@ -260,7 +260,7 @@ public class PopConnection extends AbstractConnection {
protected static final int BODY = 4; protected static final int BODY = 4;
protected int maxLines; protected int maxLines;
protected int STATE = START; protected int state = START;
public TopOutputStream(OutputStream os, int maxLines) { public TopOutputStream(OutputStream os, int maxLines) {
super(os); super(os);
@ -269,34 +269,34 @@ public class PopConnection extends AbstractConnection {
@Override @Override
public void write(int b) throws IOException { public void write(int b) throws IOException {
if (STATE != BODY || maxLines > 0) { if (state != BODY || maxLines > 0) {
super.write(b); super.write(b);
} }
if (STATE == BODY) { if (state == BODY) {
if (b == '\n') { if (b == '\n') {
maxLines--; maxLines--;
} }
} else if (STATE == START) { } else if (state == START) {
if (b == '\r') { if (b == '\r') {
STATE = CR; state = CR;
} }
} else if (STATE == CR) { } else if (state == CR) {
if (b == '\n') { if (b == '\n') {
STATE = CRLF; state = CRLF;
} else { } else {
STATE = START; state = START;
} }
} else if (STATE == CRLF) { } else if (state == CRLF) {
if (b == '\r') { if (b == '\r') {
STATE = CRLFCR; state = CRLFCR;
} else { } else {
STATE = START; state = START;
} }
} else if (STATE == CRLFCR) { } else if (state == CRLFCR) {
if (b == '\n') { if (b == '\n') {
STATE = BODY; state = BODY;
} else { } else {
STATE = START; state = START;
} }
} }
} }

View File

@ -17,6 +17,7 @@ public class PopServer 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, 110 if not defined (0) * @param port pop listen port, 110 if not defined (0)
* @throws java.io.IOException on error
*/ */
public PopServer(int port) throws IOException { public PopServer(int port) throws IOException {
super("PopServer", port, PopServer.DEFAULT_PORT); super("PopServer", port, PopServer.DEFAULT_PORT);

View File

@ -33,6 +33,8 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
private boolean isActive = true; private boolean isActive = true;
private boolean isReady = false; private boolean isReady = false;
private final Thread mainThread = Thread.currentThread();
public java.awt.Image getFrameIcon() { public java.awt.Image getFrameIcon() {
return awtImage; return awtImage;
} }
@ -84,15 +86,14 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
} else if (priority == Priority.ERROR) { } else if (priority == Priority.ERROR) {
messageType = SWT.ICON_ERROR; messageType = SWT.ICON_ERROR;
} }
if (messageType == 0) { if (messageType != 0) {
trayItem.setToolTipText("DavMail gateway \n" + message);
} else {
final ToolTip toolTip = new ToolTip(shell, SWT.BALLOON | messageType); final ToolTip toolTip = new ToolTip(shell, SWT.BALLOON | messageType);
toolTip.setText("DavMail gateway"); toolTip.setText("DavMail gateway");
toolTip.setMessage(message); toolTip.setMessage(message);
trayItem.setToolTip(toolTip); trayItem.setToolTip(toolTip);
toolTip.setVisible(true); toolTip.setVisible(true);
} }
trayItem.setToolTipText("DavMail gateway \n" + message);
} }
}); });
} }
@ -129,8 +130,6 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
DavGatewayTray.warn("Unable to set look and feel"); DavGatewayTray.warn("Unable to set look and feel");
} }
final Thread mainThread = Thread.currentThread();
new Thread("SWT") { new Thread("SWT") {
public void run() { public void run() {
display = new Display(); display = new Display();

View File

@ -20,7 +20,7 @@ import java.net.URISyntaxException;
* About frame * About frame
*/ */
public class AboutFrame extends JFrame { public class AboutFrame extends JFrame {
protected JEditorPane jEditorPane; private final JEditorPane jEditorPane;
public AboutFrame() { public AboutFrame() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
@ -86,7 +86,7 @@ public class AboutFrame extends JFrame {
getSize().height / 2); getSize().height / 2);
} }
public String getContent() { String getContent() {
Package davmailPackage = DavGateway.class.getPackage(); Package davmailPackage = DavGateway.class.getPackage();
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
buffer.append("<html><b>DavMail Gateway</b><br>"); buffer.append("<html><b>DavMail Gateway</b><br>");

View File

@ -7,7 +7,9 @@ import java.awt.*;
/** /**
* Wrapper class to call Java6 Desktop class to launch default browser. * Wrapper class to call Java6 Desktop class to launch default browser.
*/ */
public class AwtDesktopBrowser { public final class AwtDesktopBrowser {
private AwtDesktopBrowser() {
}
public static void browse(URI location) throws IOException { public static void browse(URI location) throws IOException {
Desktop desktop = Desktop.getDesktop(); Desktop desktop = Desktop.getDesktop();

View File

@ -9,7 +9,10 @@ import java.net.URISyntaxException;
/** /**
* Open default browser. * Open default browser.
*/ */
public class DesktopBrowser { public final class DesktopBrowser {
private DesktopBrowser() {
}
public static void browse(URI location) { public static void browse(URI location) {
try { try {
// trigger ClassNotFoundException // trigger ClassNotFoundException

View File

@ -8,11 +8,11 @@ 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 final class SwtDesktopBrowser {
private SwtDesktopBrowser() { private SwtDesktopBrowser() {
} }
public static void browse(URI location) throws IOException { public static void browse(URI location) {
Program.launch(location.toString()); Program.launch(location.toString());
} }

View File

@ -19,7 +19,6 @@
<item name="Home" href="/index.html"/> <item name="Home" href="/index.html"/>
<item name="Download" href="http://sourceforge.net/project/platformdownload.php?group_id=184600"/> <item name="Download" href="http://sourceforge.net/project/platformdownload.php?group_id=184600"/>
<item name="SourceForge site" href="http://sourceforge.net/projects/davmail"/> <item name="SourceForge site" href="http://sourceforge.net/projects/davmail"/>
</menu> </menu>
<menu name="DavMail Setup"> <menu name="DavMail Setup">