Fix 3562031, implement davmail.noProxyFor setting to exclude hosts from proxy settings

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2000 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2012-08-27 20:35:47 +00:00
parent 4ff6290cc0
commit 8a670d22d5
8 changed files with 36 additions and 13 deletions

View File

@ -150,6 +150,7 @@ public final class Settings {
SETTINGS.put("davmail.proxyPort", "");
SETTINGS.put("davmail.proxyUser", "");
SETTINGS.put("davmail.proxyPassword", "");
SETTINGS.put("davmail.noProxyFor", "");
SETTINGS.put("davmail.server", Boolean.FALSE.toString());
SETTINGS.put("davmail.server.certificate.hash", "");
SETTINGS.put("davmail.caldavAlarmSound", "");

View File

@ -173,11 +173,15 @@ public final class DavGatewayHttpClientFacade {
String proxyUser = null;
String proxyPassword = null;
if (useSystemProxies) {
// get proxy for url from system settings
System.setProperty("java.net.useSystemProxies", "true");
try {
List<Proxy> proxyList = getProxyForURI(new java.net.URI(url));
try {
java.net.URI uri = new java.net.URI(url);
String noProxyFor = Settings.getProperty("davmail.noProxyFor");
if (noProxyFor != null && noProxyFor.contains(uri.getHost())) {
LOGGER.debug("no proxy for "+uri.getHost());
} else if (useSystemProxies) {
// get proxy for url from system settings
System.setProperty("java.net.useSystemProxies", "true");
List<Proxy> proxyList = getProxyForURI(uri);
if (!proxyList.isEmpty() && proxyList.get(0).address() != null) {
InetSocketAddress inetSocketAddress = (InetSocketAddress) proxyList.get(0).address();
proxyHost = inetSocketAddress.getHostName();
@ -187,14 +191,14 @@ public final class DavGatewayHttpClientFacade {
proxyUser = Settings.getProperty("davmail.proxyUser");
proxyPassword = Settings.getProperty("davmail.proxyPassword");
}
} catch (URISyntaxException e) {
throw new DavMailException("LOG_INVALID_URL", url);
} else if (enableProxy) {
proxyHost = Settings.getProperty("davmail.proxyHost");
proxyPort = Settings.getIntProperty("davmail.proxyPort");
proxyUser = Settings.getProperty("davmail.proxyUser");
proxyPassword = Settings.getProperty("davmail.proxyPassword");
}
} else if (enableProxy) {
proxyHost = Settings.getProperty("davmail.proxyHost");
proxyPort = Settings.getIntProperty("davmail.proxyPort");
proxyUser = Settings.getProperty("davmail.proxyUser");
proxyPassword = Settings.getProperty("davmail.proxyPassword");
} catch (URISyntaxException e) {
throw new DavMailException("LOG_INVALID_URL", url);
}
// configure proxy

View File

@ -67,6 +67,7 @@ public class SettingsFrame extends JFrame {
JTextField httpProxyPortField;
JTextField httpProxyUserField;
JTextField httpProxyPasswordField;
JTextField noProxyForField;
JCheckBox allowRemoteField;
JTextField bindAddressField;
@ -248,7 +249,7 @@ public class SettingsFrame extends JFrame {
}
protected JPanel getProxyPanel() {
JPanel proxyPanel = new JPanel(new GridLayout(6, 2));
JPanel proxyPanel = new JPanel(new GridLayout(7, 2));
proxyPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_PROXY")));
boolean useSystemProxies = Settings.getBooleanProperty("davmail.useSystemProxies", Boolean.FALSE);
@ -261,12 +262,14 @@ public class SettingsFrame extends JFrame {
httpProxyPortField = new JTextField(Settings.getProperty("davmail.proxyPort"), 4);
httpProxyUserField = new JTextField(Settings.getProperty("davmail.proxyUser"), 10);
httpProxyPasswordField = new JPasswordField(Settings.getProperty("davmail.proxyPassword"), 10);
noProxyForField = new JTextField(Settings.getProperty("davmail.noProxyFor"), 15);
enableProxyField.setEnabled(!useSystemProxies);
httpProxyField.setEnabled(enableProxy);
httpProxyPortField.setEnabled(enableProxy);
httpProxyUserField.setEnabled(enableProxy || useSystemProxies);
httpProxyPasswordField.setEnabled(enableProxy || useSystemProxies);
noProxyForField.setEnabled(enableProxy || useSystemProxies);
useSystemProxiesField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
@ -277,6 +280,7 @@ public class SettingsFrame extends JFrame {
httpProxyPortField.setEnabled(!newUseSystemProxies && newEnableProxy);
httpProxyUserField.setEnabled(newUseSystemProxies || newEnableProxy);
httpProxyPasswordField.setEnabled(newUseSystemProxies || newEnableProxy);
noProxyForField.setEnabled(newUseSystemProxies || newEnableProxy);
}
});
enableProxyField.addActionListener(new ActionListener() {
@ -286,6 +290,7 @@ public class SettingsFrame extends JFrame {
httpProxyPortField.setEnabled(newEnableProxy);
httpProxyUserField.setEnabled(newEnableProxy);
httpProxyPasswordField.setEnabled(newEnableProxy);
noProxyForField.setEnabled(newEnableProxy);
}
});
@ -295,6 +300,7 @@ public class SettingsFrame extends JFrame {
addSettingComponent(proxyPanel, BundleMessage.format("UI_PROXY_PORT"), httpProxyPortField);
addSettingComponent(proxyPanel, BundleMessage.format("UI_PROXY_USER"), httpProxyUserField);
addSettingComponent(proxyPanel, BundleMessage.format("UI_PROXY_PASSWORD"), httpProxyPasswordField);
addSettingComponent(proxyPanel, BundleMessage.format("UI_NO_PROXY"), noProxyForField);
updateMaximumSize(proxyPanel);
return proxyPanel;
}
@ -569,10 +575,12 @@ public class SettingsFrame extends JFrame {
httpProxyPortField.setEnabled(!useSystemProxies && enableProxy);
httpProxyUserField.setEnabled(useSystemProxies || enableProxy);
httpProxyPasswordField.setEnabled(useSystemProxies || enableProxy);
noProxyForField.setEnabled(useSystemProxies || enableProxy);
httpProxyField.setText(Settings.getProperty("davmail.proxyHost"));
httpProxyPortField.setText(Settings.getProperty("davmail.proxyPort"));
httpProxyUserField.setText(Settings.getProperty("davmail.proxyUser"));
httpProxyPasswordField.setText(Settings.getProperty("davmail.proxyPassword"));
noProxyForField.setText(Settings.getProperty("davmail.noProxyFor"));
bindAddressField.setText(Settings.getProperty("davmail.bindAddress"));
allowRemoteField.setSelected(Settings.getBooleanProperty(("davmail.allowRemote")));
@ -732,6 +740,7 @@ public class SettingsFrame extends JFrame {
Settings.setProperty("davmail.proxyPort", httpProxyPortField.getText());
Settings.setProperty("davmail.proxyUser", httpProxyUserField.getText());
Settings.setProperty("davmail.proxyPassword", httpProxyPasswordField.getText());
Settings.setProperty("davmail.noProxyFor", noProxyForField.getText());
Settings.setProperty("davmail.bindAddress", bindAddressField.getText());
Settings.setProperty("davmail.clientSoTimeout", String.valueOf(clientSoTimeoutField.getText()));

View File

@ -219,6 +219,7 @@ UI_PROXY_PASSWORD=Proxy password:
UI_PROXY_PORT=Proxy port:
UI_PROXY_SERVER=Proxy server:
UI_PROXY_USER=Proxy user:
UI_NO_PROXY=No proxy for:
UI_SENT_KEEP_DELAY=Sent keep delay (POP):
UI_SENT_KEEP_DELAY_HELP=Number of days to keep messages in sent folder
UI_SERIAL=Serial

View File

@ -194,6 +194,7 @@ UI_PROXY_PASSWORD=Mot de passe proxy :
UI_PROXY_PORT=Port du serveur proxy :
UI_PROXY_SERVER=Serveur proxy :
UI_PROXY_USER=Identifiant proxy :
UI_NO_PROXY=Pas de proxy pour :
UI_SENT_KEEP_DELAY=Délai de rétention envoyés (POP) :
UI_SENT_KEEP_DELAY_HELP=Nombre de jours de conservation des messages dans le dossier des messages envoyés
UI_SERIAL=Numéro de série

View File

@ -56,6 +56,11 @@
<th>Description</th>
<th>Sample value</th>
</tr>
<tr>
<td>No proxy for</td>
<td>comma separated list of hosts accessible without a proxy</td>
<td>davmail.sourceforge.net</td>
</tr>
<tr>
<td>Allow remote connections</td>
<td>Allow remote connections to the gateway (server mode)</td>

View File

@ -45,6 +45,7 @@ davmail.proxyHost=
davmail.proxyPort=
davmail.proxyUser=
davmail.proxyPassword=
davmail.noProxyFor=
davmail.ssl.keystoreType=JKS
davmail.ssl.keyPass=
davmail.ssl.keystoreFile=

View File

@ -11,6 +11,7 @@ davmail.proxyHost=
davmail.proxyPort=
davmail.proxyUser=
davmail.proxyPassword=
davmail.noProxyFor=
davmail.allowRemote=true
davmail.bindAddress=