fix other checkstyle detected errors

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@59 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2007-05-09 23:37:24 +00:00
parent f6594bcd55
commit 2658817680
10 changed files with 280 additions and 238 deletions

View File

@ -12,8 +12,8 @@ import java.net.Socket;
* Generic connection common to pop3 and smtp implementations
*/
public class AbstractConnection extends Thread {
protected Socket client;
protected BufferedReader in;
protected OutputStream os;
// user name and password initialized through connection
@ -26,7 +26,7 @@ public class AbstractConnection extends Thread {
// Initialize the streams and start the thread
public AbstractConnection(Socket clientSocket) {
client = clientSocket;
this.client = clientSocket;
try {
in = new BufferedReader(new InputStreamReader(client.getInputStream()));
os = client.getOutputStream();
@ -34,7 +34,7 @@ public class AbstractConnection extends Thread {
try {
client.close();
} catch (IOException e2) {
DavGatewayTray.error("Exception while getting socket streams", e2);
DavGatewayTray.warn("Exception closing client socket", e2);
}
DavGatewayTray.error("Exception while getting socket streams", e);
return;

View File

@ -15,8 +15,12 @@ public abstract class AbstractServer extends Thread {
* Create a ServerSocket to listen for connections.
* Start the thread.
*/
public AbstractServer(int port) {
public AbstractServer(int port, int defaultPort) {
if (port == 0) {
this.port = defaultPort;
} else {
this.port = port;
}
try {
//noinspection SocketOpenedButNotSafelyClosed
serverSocket = new ServerSocket(port);
@ -56,7 +60,7 @@ public abstract class AbstractServer extends Thread {
clientSocket.close();
}
} catch (IOException e) {
// ignore
DavGatewayTray.warn("Exception closing client socket", e);
}
}
}

View File

@ -7,11 +7,15 @@ import davmail.smtp.SmtpServer;
* DavGateway main class
*/
public class DavGateway {
protected static SmtpServer smtpServer;
protected static PopServer popServer;
protected DavGateway() {
}
private static SmtpServer smtpServer;
private static PopServer popServer;
/**
* Start the gateway, listen on spécified smtp and pop3 ports
*
* @param args command line parameter config file path
*/
public static void main(String[] args) {

View File

@ -16,18 +16,21 @@ import java.net.URL;
* Tray icon handler
*/
public class DavGatewayTray {
protected static final Logger logger = Logger.getLogger("davmail");
protected DavGatewayTray() {
}
// lock for synchronized block
protected static final Object lock = new Object();
protected static final Logger LOGGER = Logger.getLogger("davmail");
protected static TrayIcon trayIcon = null;
protected static Image image = null;
protected static Image image2 = null;
// LOCK for synchronized block
protected static final Object LOCK = new Object();
private static TrayIcon trayIcon = null;
private static Image image = null;
private static Image image2 = null;
public static void switchIcon() {
try {
synchronized (lock) {
synchronized (LOCK) {
if (trayIcon.getImage() == image) {
trayIcon.setImage(image2);
} else {
@ -35,23 +38,23 @@ public class DavGatewayTray {
}
}
} catch (NoClassDefFoundError e) {
// ignore, jdk <= 1.6
LOGGER.debug("JDK not at least 1.6, tray not supported");
}
}
public static void resetIcon() {
try {
synchronized (lock) {
synchronized (LOCK) {
trayIcon.setImage(image);
}
} catch (NoClassDefFoundError e) {
// ignore, jdk <= 1.6
LOGGER.debug("JDK not at least 1.6, tray not supported");
}
}
protected static void displayMessage(String message, Priority priority) {
synchronized (lock) {
synchronized (LOCK) {
if (trayIcon != null) {
TrayIcon.MessageType messageType = null;
if (priority == Priority.INFO) {
@ -66,7 +69,7 @@ public class DavGatewayTray {
}
trayIcon.setToolTip("DavMail gateway \n" + message);
}
logger.log(priority, message);
LOGGER.log(priority, message);
}
}
@ -109,9 +112,8 @@ public class DavGatewayTray {
// set native look and feel
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
// ignore
} catch (Exception e) {
LOGGER.warn("Unable to set system look and feel");
}
// get the SystemTray instance

View File

@ -10,59 +10,83 @@ import java.io.IOException;
* Settings facade
*/
public class Settings {
protected static final Properties settings = new Properties();
protected static String configFilePath;
protected Settings() {
}
private static final Properties SETTINGS = new Properties();
private static String configFilePath;
public static synchronized void setConfigFilePath(String value) {
configFilePath = value;
}
public static synchronized void load() {
FileReader fileReader = null;
try {
if (configFilePath == null) {
//noinspection AccessOfSystemProperties
configFilePath = System.getProperty("user.home") + "/.davmail.properties";
}
File configFile = new File(configFilePath);
if (configFile.exists()) {
settings.load(new FileReader(configFile));
fileReader = new FileReader(configFile);
SETTINGS.load(fileReader);
} else {
settings.put("davmail.url", "http://exchangeServer/exchange/");
settings.put("davmail.popPort", "110");
settings.put("davmail.smtpPort", "25");
settings.put("davmail.keepDelay", "30");
settings.put("davmail.enableProxy", "false");
settings.put("davmail.proxyHost", "");
settings.put("davmail.proxyPort", "");
settings.put("davmail.proxyUser", "");
settings.put("davmail.proxyPassword", "");
SETTINGS.put("davmail.url", "http://exchangeServer/exchange/");
SETTINGS.put("davmail.popPort", "110");
SETTINGS.put("davmail.smtpPort", "25");
SETTINGS.put("davmail.keepDelay", "30");
SETTINGS.put("davmail.enableProxy", "false");
SETTINGS.put("davmail.proxyHost", "");
SETTINGS.put("davmail.proxyPort", "");
SETTINGS.put("davmail.proxyUser", "");
SETTINGS.put("davmail.proxyPassword", "");
save();
}
} catch (IOException e) {
DavGatewayTray.error("Unable to load settings: ", e);
} finally {
if (fileReader != null) {
try {
fileReader.close();
} catch (IOException e) {
DavGatewayTray.debug("Error closing configuration file: ", e);
}
}
}
}
public static synchronized void save() {
FileWriter fileWriter = null;
try {
settings.store(new FileWriter(configFilePath), "DavMail settings");
fileWriter = new FileWriter(configFilePath);
SETTINGS.store(fileWriter, "DavMail settings");
} catch (IOException e) {
DavGatewayTray.error("Unable to store settings: ", e);
} finally {
if (fileWriter != null) {
try {
fileWriter.close();
} catch (IOException e) {
DavGatewayTray.debug("Error closing configuration file: ", e);
}
}
}
}
public static synchronized String getProperty(String property) {
return settings.getProperty(property);
return SETTINGS.getProperty(property);
}
public static synchronized void setProperty(String property, String value) {
settings.setProperty(property, value);
SETTINGS.setProperty(property, value);
}
public static synchronized int getIntProperty(String property) {
int value = 0;
try {
String propertyValue = settings.getProperty(property);
String propertyValue = SETTINGS.getProperty(property);
if (propertyValue != null && propertyValue.length() > 0) {
value = Integer.valueOf(propertyValue);
}

View File

@ -776,7 +776,11 @@ public class ExchangeSession {
int parsedAttachmentIndex = 0;
try {
parsedAttachmentIndex = Integer.parseInt(attachmentName);
} catch (Exception e) {/* ignore */}
} catch (Exception e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Current attachment name " + attachmentName + " is not an index", e);
}
}
if (parsedAttachmentIndex == 0) {
Attachment attachment = attachmentsMap.get(attachmentName);
String attachmentContentType = getAttachmentContentType(attachment.href);
@ -819,7 +823,7 @@ public class ExchangeSession {
try {
reader.close();
} catch (IOException e) {
// ignore
LOGGER.warn("Error closing header reader", e);
}
}
}
@ -856,7 +860,7 @@ public class ExchangeSession {
try {
reader.close();
} catch (IOException e) {
// ignore
LOGGER.warn("Error closing header reader", e);
}
}
}
@ -887,9 +891,8 @@ public class ExchangeSession {
&& partHeader.contentType.startsWith("multipart")
&& partHeader.boundary != null) {
writeMimeMessage(reader, os, partHeader);
}
} else if (attachmentIndex <= 0) {
// body part
else if (attachmentIndex <= 0) {
attachmentIndex++;
writeBody(os, partHeader);
} else {
@ -990,7 +993,7 @@ public class ExchangeSession {
try {
bis.close();
} catch (IOException e) {
// ignore
LOGGER.warn("Error closing message input stream", e);
}
}
}
@ -1086,10 +1089,10 @@ public class ExchangeSession {
}
*/
wdr.moveMethod(messageUrl, destination);
if (wdr.getStatusCode() == 412) {
if (wdr.getStatusCode() == HttpURLConnection.HTTP_PRECON_FAILED) {
int count = 2;
// name conflict, try another name
while (wdr.getStatusCode() == 412) {
while (wdr.getStatusCode() == HttpURLConnection.HTTP_PRECON_FAILED) {
wdr.moveMethod(messageUrl, destination.substring(0, destination.lastIndexOf('.')) + "-" + count++ + ".eml");
}
}
@ -1117,7 +1120,7 @@ public class ExchangeSession {
try {
reader.close();
} catch (IOException e) {
// ignore
LOGGER.warn("Error closing header reader", e);
}
}
}
@ -1133,7 +1136,7 @@ public class ExchangeSession {
public boolean isConnectionCloseForced() {
// force connection if attachment not found
return getStatusCode() == 404;
return getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND;
}
}
@ -1146,7 +1149,7 @@ public class ExchangeSession {
ConnectionCloseHeadMethod method = new ConnectionCloseHeadMethod(URIUtil.encodePathQuery(decodedPath));
wdr.retrieveSessionInstance().executeMethod(method);
if (method.getStatusCode() == 404) {
if (method.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
method.releaseConnection();
System.err.println("Unable to retrieve attachment");
}
@ -1203,7 +1206,7 @@ public class ExchangeSession {
GetMethod getMethod = new GetMethod(URIUtil.encodePathQuery(messageUrl + "?Cmd=Open&unfiltered=1"));
wdr.retrieveSessionInstance().executeMethod(getMethod);
if (getMethod.getStatusCode() != 200) {
if (getMethod.getStatusCode() != HttpURLConnection.HTTP_OK) {
throw new IOException("Unable to get attachments: " + getMethod.getStatusCode()
+ " " + getMethod.getStatusLine());
}

View File

@ -9,14 +9,14 @@ import davmail.AbstractServer;
* Pop3 server
*/
public class ImapServer extends AbstractServer {
public final static int DEFAULT_PORT = 143;
public static final int DEFAULT_PORT = 143;
/**
* Create a ServerSocket to listen for connections.
* Start the thread.
*/
public ImapServer(int port) {
super((port == 0) ? ImapServer.DEFAULT_PORT : port);
super(port, ImapServer.DEFAULT_PORT);
}
public void createConnectionHandler(Socket clientSocket) {

View File

@ -17,7 +17,7 @@ public class PopServer extends AbstractServer {
* @param port pop listen port, 110 if not defined (0)
*/
public PopServer(int port) {
super((port == 0) ? PopServer.DEFAULT_PORT : port);
super(port, PopServer.DEFAULT_PORT);
}
public void createConnectionHandler(Socket clientSocket) {

View File

@ -12,7 +12,7 @@ public class SmtpServer extends AbstractServer {
* Start the thread.
*/
public SmtpServer(int port) {
super((port == 0) ? SmtpServer.DEFAULT_PORT : port);
super(port, SmtpServer.DEFAULT_PORT);
}
public void createConnectionHandler(Socket clientSocket) {

View File

@ -7,19 +7,24 @@ import org.apache.commons.httpclient.util.URIUtil;
*
*/
public class TestExchangeSession {
protected TestExchangeSession() {
}
public static void main(String[] argv) {
Settings.setConfigFilePath(argv[0]);
int currentArg = 0;
Settings.setConfigFilePath(argv[currentArg++]);
Settings.load();
ExchangeSession session = new ExchangeSession();
// test auth
try {
ExchangeSession.checkConfig();
session.login(argv[1], argv[2]);
session.login(argv[currentArg++], argv[currentArg++]);
ExchangeSession.Folder folder = session.selectFolder(argv[3]);
ExchangeSession.Folder folder = session.selectFolder(argv[currentArg++]);
String messageName;
messageName = URIUtil.decode(argv[4]);
messageName = URIUtil.decode(argv[currentArg]);
long startTime = System.currentTimeMillis();
ExchangeSession.Message messageTest = session.getMessage(folder.folderUrl + "/" + messageName);