mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
I18N: davmail package
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@531 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
b099a9aaa0
commit
041a8fb164
@ -12,8 +12,9 @@ import java.net.Socket;
|
||||
*/
|
||||
public abstract class AbstractServer extends Thread {
|
||||
private final int port;
|
||||
private final ServerSocket serverSocket;
|
||||
private ServerSocket serverSocket;
|
||||
|
||||
public abstract String getProtocolName();
|
||||
/**
|
||||
* Server socket TCP port
|
||||
*
|
||||
@ -30,16 +31,21 @@ public abstract class AbstractServer extends Thread {
|
||||
* @param name thread name
|
||||
* @param port tcp socket chosen port
|
||||
* @param defaultPort tcp socket default port
|
||||
* @throws IOException unable to create server socket
|
||||
*/
|
||||
public AbstractServer(String name, int port, int defaultPort) throws IOException {
|
||||
public AbstractServer(String name, int port, int defaultPort) {
|
||||
super(name);
|
||||
if (port == 0) {
|
||||
this.port = defaultPort;
|
||||
} else {
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind server socket on defined port.
|
||||
* @throws IOException unable to create server socket
|
||||
*/
|
||||
public void bind() throws IOException {
|
||||
String bindAddress = Settings.getProperty("davmail.bindAddress");
|
||||
//noinspection SocketOpenedButNotSafelyClosed
|
||||
if (bindAddress == null || bindAddress.length() == 0) {
|
||||
|
@ -21,4 +21,8 @@ public class BundleMessage {
|
||||
return MessageFormat.format(MESSAGE_BUNDLE.getString(key), arguments);
|
||||
}
|
||||
|
||||
public static String format(String key, Object ... arguments) {
|
||||
return MessageFormat.format(MESSAGE_BUNDLE.getString(key), arguments);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,19 +17,18 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.BindException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* DavGateway main class
|
||||
*/
|
||||
public class DavGateway {
|
||||
private static final String HTTP_DAVMAIL_SOURCEFORGE_NET_VERSION_TXT = "http://davmail.sourceforge.net/version.txt";
|
||||
|
||||
private DavGateway() {
|
||||
}
|
||||
|
||||
private static SmtpServer smtpServer;
|
||||
private static PopServer popServer;
|
||||
private static ImapServer imapServer;
|
||||
private static CaldavServer caldavServer;
|
||||
private static LdapServer ldapServer;
|
||||
private static final ArrayList<AbstractServer> serverList = new ArrayList<AbstractServer>();
|
||||
|
||||
/**
|
||||
* Start the gateway, listen on spécified smtp and pop3 ports
|
||||
@ -51,75 +50,69 @@ public class DavGateway {
|
||||
public static void start() {
|
||||
// register custom SSL Socket factory
|
||||
DavGatewaySSLProtocolSocketFactory.register();
|
||||
try {
|
||||
// prepare HTTP connection pool
|
||||
DavGatewayHttpClientFacade.start();
|
||||
|
||||
String message = "DavMail gateway listening on";
|
||||
int smtpPort = Settings.getIntProperty("davmail.smtpPort");
|
||||
if (smtpPort != 0) {
|
||||
smtpServer = new SmtpServer(smtpPort);
|
||||
smtpServer.start();
|
||||
message += " SMTP port " + smtpServer.getPort();
|
||||
}
|
||||
int popPort = Settings.getIntProperty("davmail.popPort");
|
||||
if (popPort != 0) {
|
||||
popServer = new PopServer(Settings.getIntProperty("davmail.popPort"));
|
||||
popServer.start();
|
||||
message += " POP port " + popServer.getPort();
|
||||
}
|
||||
int imapPort = Settings.getIntProperty("davmail.imapPort");
|
||||
if (imapPort != 0) {
|
||||
imapServer = new ImapServer(Settings.getIntProperty("davmail.imapPort"));
|
||||
imapServer.start();
|
||||
message += " IMAP port " + imapServer.getPort();
|
||||
}
|
||||
int caldavPort = Settings.getIntProperty("davmail.caldavPort");
|
||||
if (caldavPort != 0) {
|
||||
caldavServer = new CaldavServer(Settings.getIntProperty("davmail.caldavPort"));
|
||||
caldavServer.start();
|
||||
message += " Caldav port " + caldavServer.getPort();
|
||||
}
|
||||
int ldapPort = Settings.getIntProperty("davmail.ldapPort");
|
||||
if (ldapPort != 0) {
|
||||
ldapServer = new LdapServer(Settings.getIntProperty("davmail.ldapPort"));
|
||||
ldapServer.start();
|
||||
message += " LDAP port " + ldapServer.getPort();
|
||||
}
|
||||
// prepare HTTP connection pool
|
||||
DavGatewayHttpClientFacade.start();
|
||||
|
||||
DavGatewayTray.info(message);
|
||||
int smtpPort = Settings.getIntProperty("davmail.smtpPort");
|
||||
if (smtpPort != 0) {
|
||||
serverList.add(new SmtpServer(smtpPort));
|
||||
}
|
||||
int popPort = Settings.getIntProperty("davmail.popPort");
|
||||
if (popPort != 0) {
|
||||
serverList.add(new PopServer(popPort));
|
||||
}
|
||||
int imapPort = Settings.getIntProperty("davmail.imapPort");
|
||||
if (imapPort != 0) {
|
||||
serverList.add(new ImapServer(imapPort));
|
||||
}
|
||||
int caldavPort = Settings.getIntProperty("davmail.caldavPort");
|
||||
if (caldavPort != 0) {
|
||||
serverList.add(new CaldavServer(caldavPort));
|
||||
}
|
||||
int ldapPort = Settings.getIntProperty("davmail.ldapPort");
|
||||
if (ldapPort != 0) {
|
||||
serverList.add(new LdapServer(ldapPort));
|
||||
}
|
||||
|
||||
// check for new version
|
||||
String releasedVersion = getReleasedVersion();
|
||||
String currentVersion = getCurrentVersion();
|
||||
if (currentVersion != null && releasedVersion != null && currentVersion.compareTo(releasedVersion) < 0) {
|
||||
DavGatewayTray.info("A new version (" + releasedVersion + ") of DavMail Gateway is available !");
|
||||
StringBuilder message = new StringBuilder();
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
message.append(BundleMessage.format("LOG_DAVMAIL_GATEWAY_LISTENING"));
|
||||
for (AbstractServer server : serverList) {
|
||||
try {
|
||||
server.bind();
|
||||
server.start();
|
||||
message.append(' ').append(BundleMessage.format("LOG_PROTOCOL_PORT", server.getProtocolName(), server.getPort()));
|
||||
} catch (BindException e) {
|
||||
errorMessage.append(' ').append(BundleMessage.format("LOG_PROTOCOL_PORT", server.getProtocolName(), server.getPort()));
|
||||
} catch (IOException e) {
|
||||
errorMessage.append(' ').append(BundleMessage.format("LOG_PROTOCOL_PORT", server.getProtocolName(), server.getPort()));
|
||||
}
|
||||
} catch (BindException e) {
|
||||
DavGatewayTray.error("Unable to create server socket: the specified port is not allowed or in use by another process");
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.error("Exception creating server socket", e);
|
||||
}
|
||||
|
||||
DavGatewayTray.info(message.toString());
|
||||
if (errorMessage.length() > 0) {
|
||||
DavGatewayTray.error(new BundleMessage("LOG_SOCKET_BIND_FAILED", errorMessage.toString()));
|
||||
}
|
||||
|
||||
// check for new version
|
||||
String releasedVersion = getReleasedVersion();
|
||||
String currentVersion = getCurrentVersion();
|
||||
if (currentVersion != null && releasedVersion != null && currentVersion.compareTo(releasedVersion) < 0) {
|
||||
DavGatewayTray.info(new BundleMessage("LOG_NEW_VERSION_AVAILABLE", releasedVersion));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static void stopServer(AbstractServer server) {
|
||||
if (server != null) {
|
||||
public static void stop() {
|
||||
for (AbstractServer server:serverList) {
|
||||
server.close();
|
||||
try {
|
||||
server.join();
|
||||
} catch (InterruptedException e) {
|
||||
DavGatewayTray.warn("Exception waiting for listener to die", e);
|
||||
DavGatewayTray.warn(new BundleMessage("LOG_EXCEPTION_WAITING_SERVER_THREAD_DIE"), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
stopServer(smtpServer);
|
||||
stopServer(popServer);
|
||||
stopServer(imapServer);
|
||||
stopServer(caldavServer);
|
||||
stopServer(ldapServer);
|
||||
// close pooled connections
|
||||
DavGatewayHttpClientFacade.stop();
|
||||
// clear session cache
|
||||
@ -135,7 +128,7 @@ public class DavGateway {
|
||||
String version = null;
|
||||
BufferedReader versionReader = null;
|
||||
HttpClient httpClient = DavGatewayHttpClientFacade.getInstance();
|
||||
GetMethod getMethod = new GetMethod("http://davmail.sourceforge.net/version.txt");
|
||||
GetMethod getMethod = new GetMethod(HTTP_DAVMAIL_SOURCEFORGE_NET_VERSION_TXT);
|
||||
try {
|
||||
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(1000);
|
||||
int status = httpClient.executeMethod(getMethod);
|
||||
@ -144,7 +137,7 @@ public class DavGateway {
|
||||
version = versionReader.readLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.debug("Exception getting released version");
|
||||
DavGatewayTray.debug(new BundleMessage("LOG_UNABLE_TO_GET_RELEASED_VERSION"));
|
||||
} finally {
|
||||
if (versionReader != null) {
|
||||
try {
|
||||
|
@ -7,6 +7,7 @@ import java.io.*;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.Priority;
|
||||
|
||||
/**
|
||||
* Settings facade
|
||||
@ -55,31 +56,31 @@ public class Settings {
|
||||
SETTINGS.put("davmail.keepDelay", "30");
|
||||
SETTINGS.put("davmail.sentKeepDelay", "90");
|
||||
SETTINGS.put("davmail.caldavPastDelay", "90");
|
||||
SETTINGS.put("davmail.allowRemote", "false");
|
||||
SETTINGS.put("davmail.allowRemote", Boolean.FALSE.toString());
|
||||
SETTINGS.put("davmail.bindAddress", "");
|
||||
SETTINGS.put("davmail.enableProxy", "false");
|
||||
SETTINGS.put("davmail.enableProxy", Boolean.FALSE.toString());
|
||||
SETTINGS.put("davmail.proxyHost", "");
|
||||
SETTINGS.put("davmail.proxyPort", "");
|
||||
SETTINGS.put("davmail.proxyUser", "");
|
||||
SETTINGS.put("davmail.proxyPassword", "");
|
||||
SETTINGS.put("davmail.server", "false");
|
||||
SETTINGS.put("davmail.server", Boolean.FALSE.toString());
|
||||
SETTINGS.put("davmail.server.certificate.hash", "");
|
||||
|
||||
// logging
|
||||
SETTINGS.put("log4j.rootLogger", "WARN");
|
||||
SETTINGS.put("log4j.logger.davmail", "DEBUG");
|
||||
SETTINGS.put("log4j.logger.httpclient.wire", "WARN");
|
||||
SETTINGS.put("log4j.logger.org.apache.commons.httpclient", "WARN");
|
||||
SETTINGS.put("log4j.rootLogger", Priority.WARN.toString());
|
||||
SETTINGS.put("log4j.logger.davmail", Priority.DEBUG.toString());
|
||||
SETTINGS.put("log4j.logger.httpclient.wire", Priority.WARN.toString());
|
||||
SETTINGS.put("log4j.logger.org.apache.commons.httpclient", Priority.WARN.toString());
|
||||
save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.error("Unable to load settings: ", e);
|
||||
DavGatewayTray.error(new BundleMessage("LOG_UNABLE_TO_LOAD_SETTINGS"), e);
|
||||
} finally {
|
||||
if (fileInputStream != null) {
|
||||
try {
|
||||
fileInputStream.close();
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.debug("Error closing configuration file: ", e);
|
||||
DavGatewayTray.debug(new BundleMessage("LOG_ERROR_CLOGING_CONFIG_FILE"), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,13 +98,13 @@ public class Settings {
|
||||
fileOutputStream = new FileOutputStream(configFilePath);
|
||||
SETTINGS.store(fileOutputStream, "DavMail settings");
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.error("Unable to store settings: ", e);
|
||||
DavGatewayTray.error(new BundleMessage("LOG_UNABLE_TO_STORE_SETTINGS"), e);
|
||||
} finally {
|
||||
if (fileOutputStream != null) {
|
||||
try {
|
||||
fileOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.debug("Error closing configuration file: ", e);
|
||||
DavGatewayTray.debug(new BundleMessage("LOG_ERROR_CLOSING_CONFIG_FILE"), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -129,14 +130,14 @@ public class Settings {
|
||||
value = Integer.parseInt(propertyValue);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
DavGatewayTray.error("Invalid setting value in " + property, e);
|
||||
DavGatewayTray.error(new BundleMessage("LOG_INVALID_SETTING_VALUE", property), e);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static synchronized boolean getBooleanProperty(String property) {
|
||||
String propertyValue = SETTINGS.getProperty(property);
|
||||
return "true".equals(propertyValue);
|
||||
return Boolean.parseBoolean(propertyValue);
|
||||
}
|
||||
|
||||
protected static String getLoggingPrefix(String category) {
|
||||
|
@ -17,10 +17,14 @@ public class CaldavServer extends AbstractServer {
|
||||
* Start the thread.
|
||||
*
|
||||
* @param port pop listen port, 80 if not defined (0)
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public CaldavServer(int port) throws IOException {
|
||||
super("CaldavServer", port, CaldavServer.DEFAULT_PORT);
|
||||
public CaldavServer(int port) {
|
||||
super(CaldavServer.class.getName(), port, CaldavServer.DEFAULT_PORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName() {
|
||||
return "CALDAV";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,11 +1,10 @@
|
||||
package davmail.imap;
|
||||
|
||||
|
||||
import java.net.Socket;
|
||||
import java.io.IOException;
|
||||
|
||||
import davmail.AbstractServer;
|
||||
import davmail.AbstractConnection;
|
||||
import davmail.AbstractServer;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* Pop3 server
|
||||
@ -18,13 +17,18 @@ public class ImapServer extends AbstractServer {
|
||||
* Start the thread.
|
||||
*
|
||||
* @param port imap listen port, 143 if not defined (0)
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public ImapServer(int port) throws IOException {
|
||||
super("ImapServer", port, ImapServer.DEFAULT_PORT);
|
||||
public ImapServer(int port) {
|
||||
super(ImapServer.class.getName(), port, ImapServer.DEFAULT_PORT);
|
||||
}
|
||||
|
||||
@Override public AbstractConnection createConnectionHandler(Socket clientSocket) {
|
||||
@Override
|
||||
public String getProtocolName() {
|
||||
return "IMAP";
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractConnection createConnectionHandler(Socket clientSocket) {
|
||||
return new ImapConnection(clientSocket);
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,14 @@ public class LdapServer extends AbstractServer {
|
||||
* Start the thread.
|
||||
*
|
||||
* @param port pop listen port, 389 if not defined (0)
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public LdapServer(int port) throws IOException {
|
||||
super("LdapServer", port, LdapServer.DEFAULT_PORT);
|
||||
public LdapServer(int port) {
|
||||
super(LdapServer.class.getName(), port, LdapServer.DEFAULT_PORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName() {
|
||||
return "LDAP";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,11 +1,10 @@
|
||||
package davmail.pop;
|
||||
|
||||
|
||||
import davmail.AbstractServer;
|
||||
import davmail.AbstractConnection;
|
||||
import davmail.AbstractServer;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Pop3 server
|
||||
@ -17,10 +16,14 @@ public class PopServer extends AbstractServer {
|
||||
* Create a ServerSocket to listen for connections.
|
||||
* Start the thread.
|
||||
* @param port pop listen port, 110 if not defined (0)
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public PopServer(int port) throws IOException {
|
||||
super("PopServer", port, PopServer.DEFAULT_PORT);
|
||||
public PopServer(int port) {
|
||||
super(PopServer.class.getName(), port, PopServer.DEFAULT_PORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName() {
|
||||
return "POP";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,10 +1,9 @@
|
||||
package davmail.smtp;
|
||||
|
||||
import davmail.AbstractServer;
|
||||
import davmail.AbstractConnection;
|
||||
import davmail.AbstractServer;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SmtpServer extends AbstractServer {
|
||||
public static final int DEFAULT_PORT = 25;
|
||||
@ -13,10 +12,14 @@ public class SmtpServer extends AbstractServer {
|
||||
* Create a ServerSocket to listen for connections.
|
||||
* Start the thread.
|
||||
* @param port smtp port
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public SmtpServer(int port) throws IOException {
|
||||
super("SmtpServer", port, SmtpServer.DEFAULT_PORT);
|
||||
public SmtpServer(int port) {
|
||||
super(SmtpServer.class.getName(), port, SmtpServer.DEFAULT_PORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName() {
|
||||
return "SMTP";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,6 +110,10 @@ public class DavGatewayTray {
|
||||
displayMessage(message, Priority.ERROR);
|
||||
}
|
||||
|
||||
public static void error(BundleMessage message) {
|
||||
displayMessage(message, Priority.ERROR);
|
||||
}
|
||||
|
||||
public static void error(Exception e) {
|
||||
displayMessage((String) null, e, Priority.ERROR);
|
||||
}
|
||||
@ -118,6 +122,10 @@ public class DavGatewayTray {
|
||||
displayMessage(message, e, Priority.DEBUG);
|
||||
}
|
||||
|
||||
public static void debug(BundleMessage message, Exception e) {
|
||||
displayMessage(message, e, Priority.DEBUG);
|
||||
}
|
||||
|
||||
public static void info(String message, Exception e) {
|
||||
displayMessage(message, e, Priority.INFO);
|
||||
}
|
||||
|
@ -8,4 +8,16 @@ LOG_EXCEPTION_CLOSING_CLIENT_SOCKET=Exception closing client socket
|
||||
LOG_EXCEPTION_CLOSING_SERVER_SOCKET=Exception closing server socket
|
||||
LOG_EXCEPTION_GETTING_SOCKET_STREAMS=Exception while getting socket streams
|
||||
LOG_EXCEPTION_CLOSING_CLIENT_INPUT_STREAM=Exception closing client input stream
|
||||
LOG_EXCEPTION_CLOSING_CLIENT_OUTPUT_STREAM=Exception closing client output stream
|
||||
LOG_EXCEPTION_CLOSING_CLIENT_OUTPUT_STREAM=Exception closing client output stream
|
||||
LOG_UNABLE_TO_LOAD_SETTINGS=Unable to load settings:
|
||||
LOG_ERROR_CLOGING_CONFIG_FILE=Error closing configuration file
|
||||
LOG_UNABLE_TO_STORE_SETTINGS=Unable to store settings:
|
||||
LOG_ERROR_CLOSING_CONFIG_FILE=Error closing configuration file:
|
||||
LOG_INVALID_SETTING_VALUE=Invalid setting value in {0}
|
||||
LOG_PROTOCOL_PORT={0} port {1}
|
||||
LOG_DAVMAIL_GATEWAY_LISTENING=DavMail gateway listening on
|
||||
LOG_SOCKET_BIND_FAILED=Unable to bind server socket to {0}: port not allowed or in use by another process
|
||||
LOG_EXCEPTION_CREATING_SERVER_SOCKET=Exception creating server socket
|
||||
LOG_NEW_VERSION_AVAILABLE=A new version ({0}) of DavMail Gateway is available !
|
||||
LOG_EXCEPTION_WAITING_SERVER_THREAD_DIE=Exception waiting for server thread to die
|
||||
LOG_UNABLE_TO_GET_RELEASED_VERSION=Unable to get released version
|
Loading…
x
Reference in New Issue
Block a user