View Javadoc
1   /*
2    * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
3    * Copyright (C) 2009  Mickael Guessant
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18   */
19  package davmail.ui;
20  
21  import davmail.BundleMessage;
22  import davmail.DavGateway;
23  import davmail.Settings;
24  import davmail.ui.browser.DesktopBrowser;
25  import davmail.ui.tray.DavGatewayTray;
26  import org.apache.log4j.Level;
27  
28  import javax.swing.*;
29  import java.awt.*;
30  import java.awt.event.ActionEvent;
31  import java.awt.event.ActionListener;
32  
33  /**
34   * DavMail settings frame
35   */
36  public class SettingsFrame extends JFrame {
37      static final Level[] LOG_LEVELS = {Level.OFF, Level.FATAL, Level.ERROR, Level.WARN, Level.INFO, Level.DEBUG, Level.ALL};
38  
39      protected JTextField urlField;
40      protected JTextField popPortField;
41      protected JCheckBox popPortCheckBox;
42      protected JCheckBox popNoSSLCheckBox;
43      protected JTextField imapPortField;
44      protected JCheckBox imapPortCheckBox;
45      protected JCheckBox imapNoSSLCheckBox;
46      protected JTextField smtpPortField;
47      protected JCheckBox smtpPortCheckBox;
48      protected JCheckBox smtpNoSSLCheckBox;
49      protected JTextField caldavPortField;
50      protected JCheckBox caldavPortCheckBox;
51      protected JCheckBox caldavNoSSLCheckBox;
52      protected JTextField ldapPortField;
53      protected JCheckBox ldapPortCheckBox;
54      protected JCheckBox ldapNoSSLCheckBox;
55      protected JTextField keepDelayField;
56      protected JTextField sentKeepDelayField;
57      protected JTextField caldavPastDelayField;
58      protected JCheckBox caldavAutoScheduleCheckBox;
59      protected JTextField imapIdleDelayField;
60  
61      protected JCheckBox useSystemProxiesField;
62      protected JCheckBox enableProxyField;
63      protected JTextField httpProxyField;
64      protected JTextField httpProxyPortField;
65      protected JTextField httpProxyUserField;
66      protected JTextField httpProxyPasswordField;
67      protected JTextField noProxyForField;
68  
69      protected JCheckBox allowRemoteField;
70      protected JTextField bindAddressField;
71      protected JTextField clientSoTimeoutField;
72      protected JTextField certHashField;
73      protected JCheckBox disableUpdateCheck;
74  
75      protected JComboBox<String> keystoreTypeCombo;
76      protected JTextField keystoreFileField;
77      protected JPasswordField keystorePassField;
78      protected JPasswordField keyPassField;
79  
80      protected JComboBox<String> clientKeystoreTypeCombo;
81      protected JTextField clientKeystoreFileField;
82      protected JPasswordField clientKeystorePassField;
83      protected JTextField pkcs11LibraryField;
84      protected JTextArea pkcs11ConfigField;
85  
86      protected JComboBox<Level> rootLoggingLevelField;
87      protected JComboBox<Level> davmailLoggingLevelField;
88      protected JComboBox<Level> httpclientLoggingLevelField;
89      protected JComboBox<Level> wireLoggingLevelField;
90      protected JTextField logFilePathField;
91      protected JTextField logFileSizeField;
92  
93      protected JCheckBox caldavEditNotificationsField;
94      protected JTextField caldavAlarmSoundField;
95      protected JCheckBox forceActiveSyncUpdateCheckBox;
96      protected JTextField defaultDomainField;
97      protected JCheckBox showStartupBannerCheckBox;
98      protected JCheckBox disableGuiNotificationsCheckBox;
99      protected JCheckBox disableTrayActivitySwitchCheckBox;
100 
101     protected JCheckBox imapAutoExpungeCheckBox;
102     protected JCheckBox enableKeepAliveCheckBox;
103     protected JCheckBox popMarkReadOnRetrCheckBox;
104     protected JComboBox<String> modeComboBox;
105     protected JCheckBox enableKerberosCheckBox;
106     protected JTextField folderSizeLimitField;
107     protected JCheckBox smtpSaveInSentCheckBox;
108 	protected JCheckBox imapAlwaysApproxMsgSizeCheckBox;
109 
110     protected JTextField oauthTenantIdField;
111     protected JTextField oauthClientIdField;
112     protected JTextField oauthRedirectUriField;
113 
114     JCheckBox osxHideFromDockCheckBox;
115 
116     protected void addSettingComponent(JPanel panel, String label, JComponent component) {
117         addSettingComponent(panel, label, component, null);
118     }
119 
120     protected JLabel buildFieldLabel(String label, String toolTipText) {
121         JLabel fieldLabel = new JLabel(label);
122         fieldLabel.setHorizontalAlignment(SwingConstants.RIGHT);
123         fieldLabel.setVerticalAlignment(SwingConstants.CENTER);
124         if (toolTipText != null) {
125             fieldLabel.setToolTipText(toolTipText);
126         }
127         return fieldLabel;
128     }
129 
130     protected void addSettingComponent(JPanel panel, String label, JComponent component, String toolTipText) {
131         panel.add(buildFieldLabel(label, toolTipText));
132 
133         component.setMaximumSize(component.getPreferredSize());
134         JPanel innerPanel = new JPanel();
135         innerPanel.setBorder(BorderFactory.createEmptyBorder(1,0,0,0));
136         innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.X_AXIS));
137         innerPanel.add(component);
138         panel.add(innerPanel);
139         if (toolTipText != null) {
140             component.setToolTipText(toolTipText);
141         }
142     }
143 
144     protected void addPortSettingComponent(JPanel panel, String label, JComponent component, JComponent checkboxComponent, JComponent checkboxSSLComponent, String toolTipText) {
145         panel.add(buildFieldLabel(label, toolTipText));
146         component.setMaximumSize(component.getPreferredSize());
147         JPanel innerPanel = new JPanel();
148         innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.X_AXIS));
149         innerPanel.add(checkboxComponent);
150         innerPanel.add(component);
151         innerPanel.add(checkboxSSLComponent);
152         panel.add(innerPanel);
153         if (toolTipText != null) {
154             component.setToolTipText(toolTipText);
155         }
156     }
157 
158     protected JPanel getSettingsPanel() {
159         JPanel settingsPanel = new JPanel(new GridLayout(7, 2));
160         settingsPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_GATEWAY")));
161 
162         modeComboBox = new JComboBox<>();
163         modeComboBox.addItem(Settings.EWS);
164         modeComboBox.addItem(Settings.O365);
165         modeComboBox.addItem(Settings.O365_MODERN);
166         modeComboBox.addItem(Settings.O365_INTERACTIVE);
167         modeComboBox.addItem(Settings.O365_MANUAL);
168         modeComboBox.addItem(Settings.WEBDAV);
169         modeComboBox.addItem(Settings.AUTO);
170         modeComboBox.setSelectedItem(Settings.getProperty("davmail.mode", Settings.EWS));
171         modeComboBox.addActionListener(evt -> {
172             String selectedItem = (String)modeComboBox.getSelectedItem();
173             modeComboBox.setToolTipText(BundleMessage.format("UI_"+selectedItem+"_HELP"));
174             if (selectedItem != null && selectedItem.startsWith("O365")) {
175                 urlField.setEnabled(false);
176                 urlField.setText(Settings.O365_URL);
177             } else {
178                 urlField.setEnabled(true);
179             }
180         });
181         urlField = new JTextField(Settings.getProperty("davmail.url"), 20);
182         popPortField = new JTextField(Settings.getProperty("davmail.popPort"), 4);
183         popPortCheckBox = new JCheckBox();
184         popNoSSLCheckBox = new JCheckBox(BundleMessage.format("UI_NO_SSL"), Settings.getBooleanProperty("davmail.ssl.nosecurepop"));
185         popPortCheckBox.setSelected(Settings.getProperty("davmail.popPort") != null && !Settings.getProperty("davmail.popPort").isEmpty());
186         popPortField.setEnabled(popPortCheckBox.isSelected());
187         popNoSSLCheckBox.setEnabled(popPortCheckBox.isSelected() && isSslEnabled());
188         popPortCheckBox.addActionListener(evt -> {
189             popPortField.setEnabled(popPortCheckBox.isSelected());
190             popNoSSLCheckBox.setEnabled(popPortCheckBox.isSelected() && isSslEnabled());
191         });
192 
193         imapPortField = new JTextField(Settings.getProperty("davmail.imapPort"), 4);
194         imapPortCheckBox = new JCheckBox();
195         imapNoSSLCheckBox = new JCheckBox(BundleMessage.format("UI_NO_SSL"), Settings.getBooleanProperty("davmail.ssl.nosecureimap"));
196         imapPortCheckBox.setSelected(Settings.getProperty("davmail.imapPort") != null && !Settings.getProperty("davmail.imapPort").isEmpty());
197         imapPortField.setEnabled(imapPortCheckBox.isSelected());
198         imapNoSSLCheckBox.setEnabled(imapPortCheckBox.isSelected() && isSslEnabled());
199         imapPortCheckBox.addActionListener(evt -> {
200             imapPortField.setEnabled(imapPortCheckBox.isSelected());
201             imapNoSSLCheckBox.setEnabled(imapPortCheckBox.isSelected() && isSslEnabled());
202         });
203 
204         smtpPortField = new JTextField(Settings.getProperty("davmail.smtpPort"), 4);
205         smtpPortCheckBox = new JCheckBox();
206         smtpNoSSLCheckBox = new JCheckBox(BundleMessage.format("UI_NO_SSL"), Settings.getBooleanProperty("davmail.ssl.nosecuresmtp"));
207         smtpPortCheckBox.setSelected(Settings.getProperty("davmail.smtpPort") != null && !Settings.getProperty("davmail.smtpPort").isEmpty());
208         smtpPortField.setEnabled(smtpPortCheckBox.isSelected());
209         smtpNoSSLCheckBox.setEnabled(smtpPortCheckBox.isSelected() && isSslEnabled());
210         smtpPortCheckBox.addActionListener(evt -> {
211             smtpPortField.setEnabled(smtpPortCheckBox.isSelected());
212             smtpNoSSLCheckBox.setEnabled(smtpPortCheckBox.isSelected() && isSslEnabled());
213         });
214 
215         caldavPortField = new JTextField(Settings.getProperty("davmail.caldavPort"), 4);
216         caldavPortCheckBox = new JCheckBox();
217         caldavNoSSLCheckBox = new JCheckBox(BundleMessage.format("UI_NO_SSL"), Settings.getBooleanProperty("davmail.ssl.nosecurecaldav"));
218         caldavPortCheckBox.setSelected(Settings.getProperty("davmail.caldavPort") != null && !Settings.getProperty("davmail.caldavPort").isEmpty());
219         caldavPortField.setEnabled(caldavPortCheckBox.isSelected());
220         caldavNoSSLCheckBox.setEnabled(caldavPortCheckBox.isSelected() && isSslEnabled());
221         caldavPortCheckBox.addActionListener(evt -> {
222             caldavPortField.setEnabled(caldavPortCheckBox.isSelected());
223             caldavNoSSLCheckBox.setEnabled(caldavPortCheckBox.isSelected() && isSslEnabled());
224         });
225 
226         ldapPortField = new JTextField(Settings.getProperty("davmail.ldapPort"), 4);
227         ldapPortCheckBox = new JCheckBox();
228         ldapNoSSLCheckBox = new JCheckBox(BundleMessage.format("UI_NO_SSL"), Settings.getBooleanProperty("davmail.ssl.nosecureldap"));
229         ldapPortCheckBox.setSelected(Settings.getProperty("davmail.ldapPort") != null && !Settings.getProperty("davmail.ldapPort").isEmpty());
230         ldapPortField.setEnabled(ldapPortCheckBox.isSelected());
231         ldapNoSSLCheckBox.setEnabled(ldapPortCheckBox.isSelected() && isSslEnabled());
232         ldapPortCheckBox.addActionListener(evt -> {
233             ldapPortField.setEnabled(ldapPortCheckBox.isSelected());
234             ldapNoSSLCheckBox.setEnabled(ldapPortCheckBox.isSelected() && isSslEnabled());
235         });
236 
237         addSettingComponent(settingsPanel, BundleMessage.format("UI_ENABLE_EWS"), modeComboBox,
238                 BundleMessage.format("UI_ENABLE_EWS_HELP"));
239         addSettingComponent(settingsPanel, BundleMessage.format("UI_OWA_URL"), urlField, BundleMessage.format("UI_OWA_URL_HELP"));
240         addPortSettingComponent(settingsPanel, BundleMessage.format("UI_POP_PORT"), popPortField, popPortCheckBox,
241                 popNoSSLCheckBox, BundleMessage.format("UI_POP_PORT_HELP"));
242         addPortSettingComponent(settingsPanel, BundleMessage.format("UI_IMAP_PORT"), imapPortField, imapPortCheckBox,
243                 imapNoSSLCheckBox, BundleMessage.format("UI_IMAP_PORT_HELP"));
244         addPortSettingComponent(settingsPanel, BundleMessage.format("UI_SMTP_PORT"), smtpPortField, smtpPortCheckBox,
245                 smtpNoSSLCheckBox, BundleMessage.format("UI_SMTP_PORT_HELP"));
246         addPortSettingComponent(settingsPanel, BundleMessage.format("UI_CALDAV_PORT"), caldavPortField, caldavPortCheckBox,
247                 caldavNoSSLCheckBox, BundleMessage.format("UI_CALDAV_PORT_HELP"));
248         addPortSettingComponent(settingsPanel, BundleMessage.format("UI_LDAP_PORT"), ldapPortField, ldapPortCheckBox,
249                 ldapNoSSLCheckBox, BundleMessage.format("UI_LDAP_PORT_HELP"));
250         return settingsPanel;
251     }
252 
253     protected JPanel getDelaysPanel() {
254         JPanel delaysPanel = new JPanel(new GridLayout(4, 2));
255         delaysPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_DELAYS")));
256 
257         keepDelayField = new JTextField(Settings.getProperty("davmail.keepDelay"), 4);
258         sentKeepDelayField = new JTextField(Settings.getProperty("davmail.sentKeepDelay"), 4);
259         caldavPastDelayField = new JTextField(Settings.getProperty("davmail.caldavPastDelay"), 4);
260         imapIdleDelayField = new JTextField(Settings.getProperty("davmail.imapIdleDelay"), 4);
261 
262         addSettingComponent(delaysPanel, BundleMessage.format("UI_KEEP_DELAY"), keepDelayField,
263                 BundleMessage.format("UI_KEEP_DELAY_HELP"));
264         addSettingComponent(delaysPanel, BundleMessage.format("UI_SENT_KEEP_DELAY"), sentKeepDelayField,
265                 BundleMessage.format("UI_SENT_KEEP_DELAY_HELP"));
266         addSettingComponent(delaysPanel, BundleMessage.format("UI_CALENDAR_PAST_EVENTS"), caldavPastDelayField,
267                 BundleMessage.format("UI_CALENDAR_PAST_EVENTS_HELP"));
268         addSettingComponent(delaysPanel, BundleMessage.format("UI_IMAP_IDLE_DELAY"), imapIdleDelayField,
269                 BundleMessage.format("UI_IMAP_IDLE_DELAY_HELP"));
270         return delaysPanel;
271     }
272 
273     protected JPanel getProxyPanel() {
274         JPanel proxyPanel = new JPanel(new GridLayout(7, 2));
275         proxyPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_PROXY")));
276 
277         boolean useSystemProxies = Settings.getBooleanProperty("davmail.useSystemProxies", Boolean.FALSE);
278         boolean enableProxy = Settings.getBooleanProperty("davmail.enableProxy");
279         useSystemProxiesField = new JCheckBox();
280         useSystemProxiesField.setSelected(useSystemProxies);
281         enableProxyField = new JCheckBox();
282         enableProxyField.setSelected(enableProxy);
283         httpProxyField = new JTextField(Settings.getProperty("davmail.proxyHost"), 15);
284         httpProxyPortField = new JTextField(Settings.getProperty("davmail.proxyPort"), 4);
285         httpProxyUserField = new JTextField(Settings.getProperty("davmail.proxyUser"), 10);
286         httpProxyPasswordField = new JPasswordField(Settings.getProperty("davmail.proxyPassword"), 10);
287         noProxyForField = new JTextField(Settings.getProperty("davmail.noProxyFor"), 15);
288 
289         enableProxyField.setEnabled(!useSystemProxies);
290         httpProxyField.setEnabled(enableProxy);
291         httpProxyPortField.setEnabled(enableProxy);
292         httpProxyUserField.setEnabled(enableProxy || useSystemProxies);
293         httpProxyPasswordField.setEnabled(enableProxy || useSystemProxies);
294         noProxyForField.setEnabled(enableProxy);
295 
296         useSystemProxiesField.addActionListener(evt -> {
297             boolean newUseSystemProxies = useSystemProxiesField.isSelected();
298             if (newUseSystemProxies) {
299                 enableProxyField.setSelected(false);
300                 enableProxyField.setEnabled(false);
301                 httpProxyField.setEnabled(false);
302                 httpProxyPortField.setEnabled(false);
303                 httpProxyUserField.setEnabled(true);
304                 httpProxyPasswordField.setEnabled(true);
305                 noProxyForField.setEnabled(false);
306             } else {
307                 enableProxyField.setEnabled(true);
308                 httpProxyUserField.setEnabled(false);
309                 httpProxyPasswordField.setEnabled(false);
310             }
311         });
312         enableProxyField.addActionListener(evt -> {
313             boolean newEnableProxy = enableProxyField.isSelected();
314             httpProxyField.setEnabled(newEnableProxy);
315             httpProxyPortField.setEnabled(newEnableProxy);
316             httpProxyUserField.setEnabled(newEnableProxy);
317             httpProxyPasswordField.setEnabled(newEnableProxy);
318             noProxyForField.setEnabled(newEnableProxy);
319         });
320 
321         addSettingComponent(proxyPanel, BundleMessage.format("UI_USE_SYSTEM_PROXIES"), useSystemProxiesField);
322         addSettingComponent(proxyPanel, BundleMessage.format("UI_ENABLE_PROXY"), enableProxyField);
323         addSettingComponent(proxyPanel, BundleMessage.format("UI_PROXY_SERVER"), httpProxyField);
324         addSettingComponent(proxyPanel, BundleMessage.format("UI_PROXY_PORT"), httpProxyPortField);
325         addSettingComponent(proxyPanel, BundleMessage.format("UI_PROXY_USER"), httpProxyUserField);
326         addSettingComponent(proxyPanel, BundleMessage.format("UI_PROXY_PASSWORD"), httpProxyPasswordField);
327         addSettingComponent(proxyPanel, BundleMessage.format("UI_NO_PROXY"), noProxyForField);
328         updateMaximumSize(proxyPanel);
329         return proxyPanel;
330     }
331 
332     protected JPanel getKeystorePanel() {
333         JPanel keyStorePanel = new JPanel(new GridLayout(4, 2));
334         keyStorePanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_DAVMAIL_SERVER_CERTIFICATE")));
335 
336         keystoreTypeCombo = new JComboBox<>(new String[]{"JKS", "PKCS12"});
337         keystoreTypeCombo.setSelectedItem(Settings.getProperty("davmail.ssl.keystoreType"));
338         keystoreFileField = new JTextField(Settings.getProperty("davmail.ssl.keystoreFile"), 20);
339         keystorePassField = new JPasswordField(Settings.getProperty("davmail.ssl.keystorePass"), 20);
340         keyPassField = new JPasswordField(Settings.getProperty("davmail.ssl.keyPass"), 20);
341 
342         addSettingComponent(keyStorePanel, BundleMessage.format("UI_KEY_STORE_TYPE"), keystoreTypeCombo,
343                 BundleMessage.format("UI_KEY_STORE_TYPE_HELP"));
344         addSettingComponent(keyStorePanel, BundleMessage.format("UI_KEY_STORE"), keystoreFileField,
345                 BundleMessage.format("UI_KEY_STORE_HELP"));
346         addSettingComponent(keyStorePanel, BundleMessage.format("UI_KEY_STORE_PASSWORD"), keystorePassField,
347                 BundleMessage.format("UI_KEY_STORE_PASSWORD_HELP"));
348         addSettingComponent(keyStorePanel, BundleMessage.format("UI_KEY_PASSWORD"), keyPassField,
349                 BundleMessage.format("UI_KEY_PASSWORD_HELP"));
350         updateMaximumSize(keyStorePanel);
351         return keyStorePanel;
352     }
353 
354     protected JPanel getSmartCardPanel() {
355         JPanel clientKeystorePanel = new JPanel(new GridLayout(2, 1));
356         clientKeystorePanel.setLayout(new BoxLayout(clientKeystorePanel, BoxLayout.Y_AXIS));
357         clientKeystorePanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_CLIENT_CERTIFICATE")));
358 
359         if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
360             clientKeystoreTypeCombo = new JComboBox<>(new String[]{"MSCAPI", "PKCS11", "JKS", "PKCS12"});
361         } else {
362             clientKeystoreTypeCombo = new JComboBox<>(new String[]{"PKCS11", "JKS", "PKCS12"});
363         }
364         clientKeystoreTypeCombo.setSelectedItem(Settings.getProperty("davmail.ssl.clientKeystoreType"));
365         clientKeystoreFileField = new JTextField(Settings.getProperty("davmail.ssl.clientKeystoreFile"), 20);
366         clientKeystorePassField = new JPasswordField(Settings.getProperty("davmail.ssl.clientKeystorePass"), 20);
367 
368         pkcs11LibraryField = new JTextField(Settings.getProperty("davmail.ssl.pkcs11Library"), 20);
369         pkcs11ConfigField = new JTextArea(2, 20);
370         pkcs11ConfigField.setText(Settings.getProperty("davmail.ssl.pkcs11Config"));
371         pkcs11ConfigField.setBorder(pkcs11LibraryField.getBorder());
372         pkcs11ConfigField.setFont(pkcs11LibraryField.getFont());
373 
374         JPanel clientKeystoreTypePanel = new JPanel(new GridLayout(1, 2));
375         addSettingComponent(clientKeystoreTypePanel, BundleMessage.format("UI_CLIENT_KEY_STORE_TYPE"), clientKeystoreTypeCombo,
376                 BundleMessage.format("UI_CLIENT_KEY_STORE_TYPE_HELP"));
377         clientKeystorePanel.add(clientKeystoreTypePanel);
378 
379         final JPanel cardPanel = new JPanel(new CardLayout());
380         clientKeystorePanel.add(cardPanel);
381 
382         JPanel clientKeystoreFilePanel = new JPanel(new GridLayout(2, 2));
383         addSettingComponent(clientKeystoreFilePanel, BundleMessage.format("UI_CLIENT_KEY_STORE"), clientKeystoreFileField,
384                 BundleMessage.format("UI_CLIENT_KEY_STORE_HELP"));
385         addSettingComponent(clientKeystoreFilePanel, BundleMessage.format("UI_CLIENT_KEY_STORE_PASSWORD"), clientKeystorePassField,
386                 BundleMessage.format("UI_CLIENT_KEY_STORE_PASSWORD_HELP"));
387         JPanel wrapperPanel = new JPanel();
388         wrapperPanel.add(clientKeystoreFilePanel);
389         cardPanel.add(wrapperPanel, "FILE");
390 
391         JPanel pkcs11Panel = new JPanel(new GridLayout(2, 2));
392         addSettingComponent(pkcs11Panel, BundleMessage.format("UI_PKCS11_LIBRARY"), pkcs11LibraryField,
393                 BundleMessage.format("UI_PKCS11_LIBRARY_HELP"));
394         addSettingComponent(pkcs11Panel, BundleMessage.format("UI_PKCS11_CONFIG"), pkcs11ConfigField,
395                 BundleMessage.format("UI_PKCS11_CONFIG_HELP"));
396         cardPanel.add(pkcs11Panel, "PKCS11");
397 
398         ((CardLayout) cardPanel.getLayout()).show(cardPanel, (String) clientKeystoreTypeCombo.getSelectedItem());
399 
400         clientKeystoreTypeCombo.addItemListener(event -> {
401             CardLayout cardLayout = (CardLayout) (cardPanel.getLayout());
402             if ("PKCS11".equals(event.getItem())) {
403                 cardLayout.show(cardPanel, "PKCS11");
404             } else {
405                 cardLayout.show(cardPanel, "FILE");
406             }
407         });
408         updateMaximumSize(clientKeystorePanel);
409         return clientKeystorePanel;
410     }
411 
412     protected JPanel getOauthPanel() {
413         JPanel oAuthPanel = new JPanel(new GridLayout(3, 2));
414         oAuthPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_OAUTH")));
415 
416         oauthTenantIdField = new JTextField(Settings.getProperty("davmail.oauth.tenantId"), 20);
417         oauthClientIdField = new JTextField(Settings.getProperty("davmail.oauth.clientId"), 20);
418         oauthRedirectUriField = new JTextField(Settings.getProperty("davmail.oauth.redirectUri"), 20);
419 
420         addSettingComponent(oAuthPanel, BundleMessage.format("UI_OAUTH_TENANTID"), oauthTenantIdField,
421                 BundleMessage.format("UI_OAUTH_TENANTID_HELP"));
422         addSettingComponent(oAuthPanel, BundleMessage.format("UI_OAUTH_CLIENTID"), oauthClientIdField,
423                 BundleMessage.format("UI_OAUTH_CLIENTID_HELP"));
424         addSettingComponent(oAuthPanel, BundleMessage.format("UI_OAUTH_REDIRECTURI"), oauthRedirectUriField,
425                 BundleMessage.format("UI_OAUTH_REDIRECTURI_HELP"));
426         updateMaximumSize(oAuthPanel);
427         return oAuthPanel;
428     }
429 
430     protected JPanel getNetworkSettingsPanel() {
431         JPanel networkSettingsPanel = new JPanel(new GridLayout(4, 2));
432         networkSettingsPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_NETWORK")));
433 
434         allowRemoteField = new JCheckBox();
435         allowRemoteField.setSelected(Settings.getBooleanProperty("davmail.allowRemote"));
436 
437         bindAddressField = new JTextField(Settings.getProperty("davmail.bindAddress"), 15);
438         clientSoTimeoutField = new JTextField(Settings.getProperty("davmail.clientSoTimeout"), 15);
439 
440         certHashField = new JTextField(Settings.getProperty("davmail.server.certificate.hash"), 15);
441 
442         addSettingComponent(networkSettingsPanel, BundleMessage.format("UI_BIND_ADDRESS"), bindAddressField,
443                 BundleMessage.format("UI_BIND_ADDRESS_HELP"));
444         addSettingComponent(networkSettingsPanel, BundleMessage.format("UI_CLIENT_SO_TIMEOUT"), clientSoTimeoutField,
445                 BundleMessage.format("UI_CLIENT_SO_TIMEOUT_HELP"));
446         addSettingComponent(networkSettingsPanel, BundleMessage.format("UI_ALLOW_REMOTE_CONNECTION"), allowRemoteField,
447                 BundleMessage.format("UI_ALLOW_REMOTE_CONNECTION_HELP"));
448         addSettingComponent(networkSettingsPanel, BundleMessage.format("UI_SERVER_CERTIFICATE_HASH"), certHashField,
449                 BundleMessage.format("UI_SERVER_CERTIFICATE_HASH_HELP"));
450         updateMaximumSize(networkSettingsPanel);
451         return networkSettingsPanel;
452     }
453 
454     protected JPanel getOtherSettingsPanel() {
455         JPanel otherSettingsPanel = new JPanel(new GridLayout(16, 2));
456         otherSettingsPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_OTHER")));
457 
458         folderSizeLimitField = new JTextField(Settings.getProperty("davmail.folderSizeLimit"), 6);
459         enableKerberosCheckBox = new JCheckBox();
460         enableKerberosCheckBox.setSelected(Settings.getBooleanProperty("davmail.enableKerberos"));
461         caldavEditNotificationsField = new JCheckBox();
462         caldavEditNotificationsField.setSelected(Settings.getBooleanProperty("davmail.caldavEditNotifications"));
463         caldavAlarmSoundField = new JTextField(Settings.getProperty("davmail.caldavAlarmSound"), 15);
464         forceActiveSyncUpdateCheckBox = new JCheckBox();
465         forceActiveSyncUpdateCheckBox.setSelected(Settings.getBooleanProperty("davmail.forceActiveSyncUpdate"));
466         defaultDomainField = new JTextField(Settings.getProperty("davmail.defaultDomain"), 15);
467         showStartupBannerCheckBox = new JCheckBox();
468         showStartupBannerCheckBox.setSelected(Settings.getBooleanProperty("davmail.showStartupBanner", true));
469         disableGuiNotificationsCheckBox = new JCheckBox();
470         disableGuiNotificationsCheckBox.setSelected(Settings.getBooleanProperty("davmail.disableGuiNotifications", false));
471         disableTrayActivitySwitchCheckBox =  new JCheckBox();
472         disableTrayActivitySwitchCheckBox.setSelected(Settings.getBooleanProperty("davmail.disableTrayActivitySwitch", false));
473         imapAutoExpungeCheckBox = new JCheckBox();
474         imapAutoExpungeCheckBox.setSelected(Settings.getBooleanProperty("davmail.imapAutoExpunge", true));
475 		imapAlwaysApproxMsgSizeCheckBox = new JCheckBox();
476 		imapAlwaysApproxMsgSizeCheckBox.setSelected(Settings.getBooleanProperty("davmail.imapAlwaysApproxMsgSize", false));
477         enableKeepAliveCheckBox = new JCheckBox();
478         enableKeepAliveCheckBox.setSelected(Settings.getBooleanProperty("davmail.enableKeepAlive", false));
479         popMarkReadOnRetrCheckBox = new JCheckBox();
480         popMarkReadOnRetrCheckBox.setSelected(Settings.getBooleanProperty("davmail.popMarkReadOnRetr", false));
481         smtpSaveInSentCheckBox = new JCheckBox();
482         smtpSaveInSentCheckBox.setSelected(Settings.getBooleanProperty("davmail.smtpSaveInSent", true));
483         disableUpdateCheck = new JCheckBox();
484         disableUpdateCheck.setSelected(Settings.getBooleanProperty("davmail.disableUpdateCheck"));
485         caldavAutoScheduleCheckBox = new JCheckBox();
486         caldavAutoScheduleCheckBox.setSelected(Settings.getBooleanProperty("davmail.caldavAutoSchedule"));
487 
488         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_FOLDER_SIZE_LIMIT"), folderSizeLimitField,
489                 BundleMessage.format("UI_FOLDER_SIZE_LIMIT_HELP"));
490         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_ENABLE_KERBEROS"), enableKerberosCheckBox,
491                 BundleMessage.format("UI_ENABLE_KERBEROS_HELP"));
492         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_CALDAV_EDIT_NOTIFICATIONS"), caldavEditNotificationsField,
493                 BundleMessage.format("UI_CALDAV_EDIT_NOTIFICATIONS_HELP"));
494         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_CALDAV_ALARM_SOUND"), caldavAlarmSoundField,
495                 BundleMessage.format("UI_CALDAV_ALARM_SOUND_HELP"));
496         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_FORCE_ACTIVESYNC_UPDATE"), forceActiveSyncUpdateCheckBox,
497                 BundleMessage.format("UI_FORCE_ACTIVESYNC_UPDATE_HELP"));
498         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_DEFAULT_DOMAIN"), defaultDomainField,
499                 BundleMessage.format("UI_DEFAULT_DOMAIN_HELP"));
500         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_SHOW_STARTUP_BANNER"), showStartupBannerCheckBox,
501                 BundleMessage.format("UI_SHOW_STARTUP_BANNER_HELP"));
502         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_DISABLE_GUI_NOTIFICATIONS"), disableGuiNotificationsCheckBox,
503                 BundleMessage.format("UI_DISABLE_GUI_NOTIFICATIONS_HELP"));
504         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_DISABLE_TRAY_ACTIVITY_SWITCH"), disableTrayActivitySwitchCheckBox,
505                 BundleMessage.format("UI_DISABLE_TRAY_ACTIVITY_SWITCH_HELP"));
506         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_IMAP_AUTO_EXPUNGE"), imapAutoExpungeCheckBox,
507                 BundleMessage.format("UI_IMAP_AUTO_EXPUNGE_HELP"));
508         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_ALWAYS_APPROXIMATE_MSG_SIZE"), imapAlwaysApproxMsgSizeCheckBox,
509                 BundleMessage.format("UI_ALWAYS_APPROXIMATE_MSG_SIZE_HELP"));
510         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_ENABLE_KEEPALIVE"), enableKeepAliveCheckBox,
511                 BundleMessage.format("UI_ENABLE_KEEPALIVE_HELP"));
512         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_POP_MARK_READ"), popMarkReadOnRetrCheckBox,
513                 BundleMessage.format("UI_POP_MARK_READ_HELP"));
514         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_SAVE_IN_SENT"), smtpSaveInSentCheckBox,
515                 BundleMessage.format("UI_SAVE_IN_SENT_HELP"));
516         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_DISABLE_UPDATE_CHECK"), disableUpdateCheck,
517                 BundleMessage.format("UI_DISABLE_UPDATE_CHECK_HELP"));
518 
519         addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_CALDAV_AUTO_SCHEDULE"), caldavAutoScheduleCheckBox,
520                 BundleMessage.format("UI_CALDAV_AUTO_SCHEDULE_HELP"));
521 
522         updateMaximumSize(otherSettingsPanel);
523         return otherSettingsPanel;
524     }
525 
526     protected JPanel getOSXPanel() {
527         JPanel osxSettingsPanel = new JPanel(new GridLayout(1, 2));
528         osxSettingsPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_OSX")));
529 
530         osxHideFromDockCheckBox = new JCheckBox();
531         osxHideFromDockCheckBox.setSelected(OSXInfoPlist.isHideFromDock());
532 
533         addSettingComponent(osxSettingsPanel, BundleMessage.format("UI_OSX_HIDE_FROM_DOCK"), osxHideFromDockCheckBox,
534                 BundleMessage.format("UI_OSX_HIDE_FROM_DOCK_HELP"));
535 
536         updateMaximumSize(osxSettingsPanel);
537         return osxSettingsPanel;
538     }
539 
540     protected JPanel getLoggingSettingsPanel() {
541         JPanel loggingLevelPanel = new JPanel();
542         JPanel leftLoggingPanel = new JPanel(new GridLayout(2, 2));
543         JPanel rightLoggingPanel = new JPanel(new GridLayout(2, 2));
544         loggingLevelPanel.add(leftLoggingPanel);
545         loggingLevelPanel.add(rightLoggingPanel);
546 
547         rootLoggingLevelField = new JComboBox<>(LOG_LEVELS);
548         davmailLoggingLevelField = new JComboBox<>(LOG_LEVELS);
549         httpclientLoggingLevelField = new JComboBox<>(LOG_LEVELS);
550         wireLoggingLevelField = new JComboBox<>(LOG_LEVELS);
551         logFilePathField = new JTextField(Settings.getProperty("davmail.logFilePath"), 15);
552         logFileSizeField = new JTextField(Settings.getProperty("davmail.logFileSize"), 15);
553 
554         rootLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("rootLogger"));
555         davmailLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("davmail"));
556         httpclientLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("httpclient"));
557         wireLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("httpclient.wire"));
558 
559         addSettingComponent(leftLoggingPanel, BundleMessage.format("UI_LOG_DEFAULT"), rootLoggingLevelField);
560         addSettingComponent(leftLoggingPanel, BundleMessage.format("UI_LOG_DAVMAIL"), davmailLoggingLevelField);
561         addSettingComponent(rightLoggingPanel, BundleMessage.format("UI_LOG_HTTPCLIENT"), httpclientLoggingLevelField);
562         addSettingComponent(rightLoggingPanel, BundleMessage.format("UI_LOG_WIRE"), wireLoggingLevelField);
563 
564         JPanel logFilePathPanel = new JPanel(new GridLayout(2, 2));
565         addSettingComponent(logFilePathPanel, BundleMessage.format("UI_LOG_FILE_PATH"), logFilePathField);
566         addSettingComponent(logFilePathPanel, BundleMessage.format("UI_LOG_FILE_SIZE"), logFileSizeField, BundleMessage.format("UI_LOG_FILE_SIZE_HELP"));
567 
568         JButton defaultButton = new JButton(BundleMessage.format("UI_BUTTON_DEFAULT"));
569         defaultButton.setToolTipText(BundleMessage.format("UI_BUTTON_DEFAULT_HELP"));
570         defaultButton.addActionListener(e -> {
571             rootLoggingLevelField.setSelectedItem(Level.WARN);
572             davmailLoggingLevelField.setSelectedItem(Level.DEBUG);
573             httpclientLoggingLevelField.setSelectedItem(Level.WARN);
574             wireLoggingLevelField.setSelectedItem(Level.WARN);
575         });
576 
577         JPanel loggingPanel = new JPanel();
578         loggingPanel.setLayout(new BoxLayout(loggingPanel, BoxLayout.Y_AXIS));
579         loggingPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_LOGGING_LEVELS")));
580         loggingPanel.add(logFilePathPanel);
581         loggingPanel.add(loggingLevelPanel);
582         loggingPanel.add(defaultButton);
583 
584         updateMaximumSize(loggingPanel);
585         return loggingPanel;
586     }
587 
588     protected void updateMaximumSize(JPanel panel) {
589         Dimension preferredSize = panel.getPreferredSize();
590         preferredSize.width = Integer.MAX_VALUE;
591         panel.setMaximumSize(preferredSize);
592     }
593 
594     /**
595      * Reload settings from properties.
596      */
597     public void reload() {
598         // reload settings in form
599         urlField.setText(Settings.getProperty("davmail.url"));
600         popPortField.setText(Settings.getProperty("davmail.popPort"));
601         popPortCheckBox.setSelected(Settings.getProperty("davmail.popPort") != null && !Settings.getProperty("davmail.popPort").isEmpty());
602         popNoSSLCheckBox.setSelected(Settings.getBooleanProperty("davmail.ssl.nosecurepop"));
603         imapPortField.setText(Settings.getProperty("davmail.imapPort"));
604         imapPortCheckBox.setSelected(Settings.getProperty("davmail.imapPort") != null && !Settings.getProperty("davmail.imapPort").isEmpty());
605         imapNoSSLCheckBox.setSelected(Settings.getBooleanProperty("davmail.ssl.nosecureimap"));
606         smtpPortField.setText(Settings.getProperty("davmail.smtpPort"));
607         smtpPortCheckBox.setSelected(Settings.getProperty("davmail.smtpPort") != null && !Settings.getProperty("davmail.smtpPort").isEmpty());
608         smtpNoSSLCheckBox.setSelected(Settings.getBooleanProperty("davmail.ssl.nosecuresmtp"));
609         caldavPortField.setText(Settings.getProperty("davmail.caldavPort"));
610         caldavPortCheckBox.setSelected(Settings.getProperty("davmail.caldavPort") != null && !Settings.getProperty("davmail.caldavPort").isEmpty());
611         caldavNoSSLCheckBox.setSelected(Settings.getBooleanProperty("davmail.ssl.nosecurecaldav"));
612         ldapPortField.setText(Settings.getProperty("davmail.ldapPort"));
613         ldapPortCheckBox.setSelected(Settings.getProperty("davmail.ldapPort") != null && !Settings.getProperty("davmail.ldapPort").isEmpty());
614         ldapNoSSLCheckBox.setSelected(Settings.getBooleanProperty("davmail.ssl.nosecureldap"));
615         keepDelayField.setText(Settings.getProperty("davmail.keepDelay"));
616         sentKeepDelayField.setText(Settings.getProperty("davmail.sentKeepDelay"));
617         caldavPastDelayField.setText(Settings.getProperty("davmail.caldavPastDelay"));
618         imapIdleDelayField.setText(Settings.getProperty("davmail.imapIdleDelay"));
619         boolean useSystemProxies = Settings.getBooleanProperty("davmail.useSystemProxies", Boolean.FALSE);
620         useSystemProxiesField.setSelected(useSystemProxies);
621         boolean enableProxy = Settings.getBooleanProperty("davmail.enableProxy");
622         enableProxyField.setSelected(enableProxy);
623         enableProxyField.setEnabled(!useSystemProxies);
624         httpProxyField.setEnabled(enableProxy);
625         httpProxyPortField.setEnabled(enableProxy);
626         httpProxyUserField.setEnabled(useSystemProxies || enableProxy);
627         httpProxyPasswordField.setEnabled(useSystemProxies || enableProxy);
628         noProxyForField.setEnabled(enableProxy);
629         httpProxyField.setText(Settings.getProperty("davmail.proxyHost"));
630         httpProxyPortField.setText(Settings.getProperty("davmail.proxyPort"));
631         httpProxyUserField.setText(Settings.getProperty("davmail.proxyUser"));
632         httpProxyPasswordField.setText(Settings.getProperty("davmail.proxyPassword"));
633         noProxyForField.setText(Settings.getProperty("davmail.noProxyFor"));
634 
635         bindAddressField.setText(Settings.getProperty("davmail.bindAddress"));
636         allowRemoteField.setSelected(Settings.getBooleanProperty(("davmail.allowRemote")));
637         certHashField.setText(Settings.getProperty("davmail.server.certificate.hash"));
638         disableUpdateCheck.setSelected(Settings.getBooleanProperty(("davmail.disableUpdateCheck")));
639 
640         caldavEditNotificationsField.setSelected(Settings.getBooleanProperty("davmail.caldavEditNotifications"));
641         clientSoTimeoutField.setText(Settings.getProperty("davmail.clientSoTimeout"));
642         caldavAlarmSoundField.setText(Settings.getProperty("davmail.caldavAlarmSound"));
643         forceActiveSyncUpdateCheckBox.setSelected(Settings.getBooleanProperty("davmail.forceActiveSyncUpdate"));
644         defaultDomainField.setText(Settings.getProperty("davmail.defaultDomain"));
645         showStartupBannerCheckBox.setSelected(Settings.getBooleanProperty("davmail.showStartupBanner", true));
646         disableGuiNotificationsCheckBox.setSelected(Settings.getBooleanProperty("davmail.disableGuiNotifications", false));
647         disableTrayActivitySwitchCheckBox.setSelected(Settings.getBooleanProperty("davmail.disableTrayActivitySwitch", false));
648         imapAutoExpungeCheckBox.setSelected(Settings.getBooleanProperty("davmail.imapAutoExpunge", true));
649         imapAlwaysApproxMsgSizeCheckBox.setSelected(Settings.getBooleanProperty("davmail.imapAlwaysApproxMsgSize", false));
650         enableKeepAliveCheckBox.setSelected(Settings.getBooleanProperty("davmail.enableKeepAlive", false));
651         popMarkReadOnRetrCheckBox.setSelected(Settings.getBooleanProperty("davmail.popMarkReadOnRetr", false));
652         modeComboBox.setSelectedItem(Settings.getProperty("davmail.mode", Settings.EWS));
653         smtpSaveInSentCheckBox.setSelected(Settings.getBooleanProperty("davmail.smtpSaveInSent", true));
654         enableKerberosCheckBox.setSelected(Settings.getBooleanProperty("davmail.enableKerberos", false));
655         folderSizeLimitField.setText(Settings.getProperty("davmail.folderSizeLimit"));
656 
657         keystoreTypeCombo.setSelectedItem(Settings.getProperty("davmail.ssl.keystoreType"));
658         keystoreFileField.setText(Settings.getProperty("davmail.ssl.keystoreFile"));
659         keystorePassField.setText(Settings.getProperty("davmail.ssl.keystorePass"));
660         keyPassField.setText(Settings.getProperty("davmail.ssl.keyPass"));
661 
662         clientKeystoreTypeCombo.setSelectedItem(Settings.getProperty("davmail.ssl.clientKeystoreType"));
663         pkcs11LibraryField.setText(Settings.getProperty("davmail.ssl.pkcs11Library"));
664         pkcs11ConfigField.setText(Settings.getProperty("davmail.ssl.pkcs11Config"));
665 
666         oauthTenantIdField.setText(Settings.getProperty("davmail.oauth.tenantId"));
667         oauthClientIdField.setText(Settings.getProperty("davmail.oauth.clientId"));
668         oauthRedirectUriField.setText(Settings.getProperty("davmail.oauth.redirectUri"));
669 
670         rootLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("rootLogger"));
671         davmailLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("davmail"));
672         httpclientLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("httpclient"));
673         wireLoggingLevelField.setSelectedItem(Settings.getLoggingLevel("httpclient.wire"));
674         logFilePathField.setText(Settings.getProperty("davmail.logFilePath"));
675         logFileSizeField.setText(Settings.getProperty("davmail.logFileSize"));
676 
677         if (osxHideFromDockCheckBox != null) {
678             osxHideFromDockCheckBox.setSelected(OSXInfoPlist.isHideFromDock());
679         }
680     }
681 
682     protected boolean isSslEnabled() {
683         if (keystoreFileField != null) {
684             return !keystoreFileField.getText().isEmpty();
685         } else {
686             return Settings.getProperty("davmail.ssl.keystoreFile") != null &&
687                     (!Settings.getProperty("davmail.ssl.keystoreFile").isEmpty());
688         }
689     }
690 
691     /**
692      * DavMail settings frame.
693      */
694     public SettingsFrame() {
695         setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
696         setTitle(BundleMessage.format("UI_DAVMAIL_SETTINGS"));
697         try {
698             setIconImages(DavGatewayTray.getFrameIcons());
699         } catch (NoSuchMethodError error) {
700             DavGatewayTray.debug(new BundleMessage("LOG_UNABLE_TO_SET_ICON_IMAGE"));
701         }
702 
703         JTabbedPane tabbedPane = new JTabbedPane();
704         // add help (F1 handler)
705         tabbedPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("F1"),
706                 "help");
707         tabbedPane.getActionMap().put("help", new AbstractAction() {
708             public void actionPerformed(ActionEvent e) {
709                 DesktopBrowser.browse("https://davmail.sourceforge.net");
710             }
711         });
712         tabbedPane.addChangeListener(e -> {
713             boolean isSslEnabled = isSslEnabled();
714             popNoSSLCheckBox.setEnabled(Settings.getProperty("davmail.popPort") != null && isSslEnabled);
715             imapNoSSLCheckBox.setEnabled(imapPortCheckBox.isSelected() && isSslEnabled);
716             smtpNoSSLCheckBox.setEnabled(smtpPortCheckBox.isSelected() && isSslEnabled);
717             caldavNoSSLCheckBox.setEnabled(caldavPortCheckBox.isSelected() && isSslEnabled);
718             ldapNoSSLCheckBox.setEnabled(ldapPortCheckBox.isSelected() && isSslEnabled);
719         });
720 
721         JPanel mainPanel = new JPanel();
722         mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
723         mainPanel.add(getSettingsPanel());
724         mainPanel.add(getDelaysPanel());
725         mainPanel.add(Box.createVerticalGlue());
726 
727         tabbedPane.add(BundleMessage.format("UI_TAB_MAIN"), mainPanel);
728 
729         JPanel proxyPanel = new JPanel();
730         proxyPanel.setLayout(new BoxLayout(proxyPanel, BoxLayout.Y_AXIS));
731         proxyPanel.add(getProxyPanel());
732         proxyPanel.add(getNetworkSettingsPanel());
733         tabbedPane.add(BundleMessage.format("UI_TAB_NETWORK"), proxyPanel);
734 
735         JPanel encryptionPanel = new JPanel();
736         encryptionPanel.setLayout(new BoxLayout(encryptionPanel, BoxLayout.Y_AXIS));
737         encryptionPanel.add(getKeystorePanel());
738         encryptionPanel.add(getSmartCardPanel());
739         encryptionPanel.add(getOauthPanel());
740         // empty panel
741         encryptionPanel.add(new JPanel());
742         tabbedPane.add(BundleMessage.format("UI_TAB_ENCRYPTION"), encryptionPanel);
743 
744         JPanel loggingPanel = new JPanel();
745         loggingPanel.setLayout(new BoxLayout(loggingPanel, BoxLayout.Y_AXIS));
746         loggingPanel.add(getLoggingSettingsPanel());
747         // empty panel
748         loggingPanel.add(new JPanel());
749 
750         tabbedPane.add(BundleMessage.format("UI_TAB_LOGGING"), loggingPanel);
751 
752         JPanel advancedPanel = new JPanel();
753         advancedPanel.setLayout(new BoxLayout(advancedPanel, BoxLayout.Y_AXIS));
754 
755         advancedPanel.add(getOtherSettingsPanel());
756         // empty panel
757         advancedPanel.add(new JPanel());
758 
759         tabbedPane.add(BundleMessage.format("UI_TAB_ADVANCED"), advancedPanel);
760 
761         if (OSXInfoPlist.isOSX()) {
762             JPanel osxPanel = new JPanel();
763             osxPanel.setLayout(new BoxLayout(osxPanel, BoxLayout.Y_AXIS));
764             osxPanel.add(getOSXPanel());
765             // empty panel
766             osxPanel.add(new JPanel());
767 
768             tabbedPane.add(BundleMessage.format("UI_TAB_OSX"), osxPanel);
769         }
770 
771         add(BorderLayout.CENTER, tabbedPane);
772 
773         JPanel buttonPanel = new JPanel();
774         JButton cancel = new JButton(BundleMessage.format("UI_BUTTON_CANCEL"));
775         JButton ok = new JButton(BundleMessage.format("UI_BUTTON_SAVE"));
776         JButton help = new JButton(BundleMessage.format("UI_BUTTON_HELP"));
777         ActionListener save = evt -> {
778             // save options
779             Settings.setProperty("davmail.url", urlField.getText().trim());
780             Settings.setProperty("davmail.popPort", popPortCheckBox.isSelected() ? popPortField.getText() : "");
781             Settings.setProperty("davmail.ssl.nosecurepop", String.valueOf(popNoSSLCheckBox.isSelected()));
782             Settings.setProperty("davmail.imapPort", imapPortCheckBox.isSelected() ? imapPortField.getText() : "");
783             Settings.setProperty("davmail.ssl.nosecureimap", String.valueOf(imapNoSSLCheckBox.isSelected()));
784             Settings.setProperty("davmail.smtpPort", smtpPortCheckBox.isSelected() ? smtpPortField.getText() : "");
785             Settings.setProperty("davmail.ssl.nosecuresmtp", String.valueOf(smtpNoSSLCheckBox.isSelected()));
786             Settings.setProperty("davmail.caldavPort", caldavPortCheckBox.isSelected() ? caldavPortField.getText() : "");
787             Settings.setProperty("davmail.ssl.nosecurecaldav", String.valueOf(caldavNoSSLCheckBox.isSelected()));
788             Settings.setProperty("davmail.ldapPort", ldapPortCheckBox.isSelected() ? ldapPortField.getText() : "");
789             Settings.setProperty("davmail.ssl.nosecureldap", String.valueOf(ldapNoSSLCheckBox.isSelected()));
790             Settings.setProperty("davmail.keepDelay", keepDelayField.getText());
791             Settings.setProperty("davmail.sentKeepDelay", sentKeepDelayField.getText());
792             Settings.setProperty("davmail.caldavPastDelay", caldavPastDelayField.getText());
793             Settings.setProperty("davmail.imapIdleDelay", imapIdleDelayField.getText());
794             Settings.setProperty("davmail.useSystemProxies", String.valueOf(useSystemProxiesField.isSelected()));
795             Settings.setProperty("davmail.enableProxy", String.valueOf(enableProxyField.isSelected()));
796             Settings.setProperty("davmail.proxyHost", httpProxyField.getText());
797             Settings.setProperty("davmail.proxyPort", httpProxyPortField.getText());
798             Settings.setProperty("davmail.proxyUser", httpProxyUserField.getText());
799             Settings.setProperty("davmail.proxyPassword", httpProxyPasswordField.getText());
800             Settings.setProperty("davmail.noProxyFor", noProxyForField.getText());
801 
802             Settings.setProperty("davmail.bindAddress", bindAddressField.getText());
803             Settings.setProperty("davmail.clientSoTimeout", String.valueOf(clientSoTimeoutField.getText()));
804             Settings.setProperty("davmail.allowRemote", String.valueOf(allowRemoteField.isSelected()));
805             Settings.setProperty("davmail.server.certificate.hash", certHashField.getText());
806             Settings.setProperty("davmail.disableUpdateCheck", String.valueOf(disableUpdateCheck.isSelected()));
807             Settings.setProperty("davmail.caldavAutoSchedule", String.valueOf(caldavAutoScheduleCheckBox.isSelected()));
808 
809             Settings.setProperty("davmail.caldavEditNotifications", String.valueOf(caldavEditNotificationsField.isSelected()));
810             Settings.setProperty("davmail.caldavAlarmSound", String.valueOf(caldavAlarmSoundField.getText()));
811             Settings.setProperty("davmail.forceActiveSyncUpdate", String.valueOf(forceActiveSyncUpdateCheckBox.isSelected()));
812             Settings.setProperty("davmail.defaultDomain", String.valueOf(defaultDomainField.getText()));
813             Settings.setProperty("davmail.showStartupBanner", String.valueOf(showStartupBannerCheckBox.isSelected()));
814             Settings.setProperty("davmail.disableGuiNotifications", String.valueOf(disableGuiNotificationsCheckBox.isSelected()));
815             Settings.setProperty("davmail.disableTrayActivitySwitch", String.valueOf(disableTrayActivitySwitchCheckBox.isSelected()));
816             Settings.setProperty("davmail.imapAutoExpunge", String.valueOf(imapAutoExpungeCheckBox.isSelected()));
817             Settings.setProperty("davmail.imapAlwaysApproxMsgSize", String.valueOf(imapAlwaysApproxMsgSizeCheckBox.isSelected()));
818             Settings.setProperty("davmail.enableKeepAlive", String.valueOf(enableKeepAliveCheckBox.isSelected()));
819             Settings.setProperty("davmail.popMarkReadOnRetr", String.valueOf(popMarkReadOnRetrCheckBox.isSelected()));
820 
821             Settings.setProperty("davmail.mode", (String) modeComboBox.getSelectedItem());
822             Settings.setProperty("davmail.enableKerberos", String.valueOf(enableKerberosCheckBox.isSelected()));
823             Settings.setProperty("davmail.folderSizeLimit", folderSizeLimitField.getText());
824             Settings.setProperty("davmail.smtpSaveInSent", String.valueOf(smtpSaveInSentCheckBox.isSelected()));
825 
826             Settings.setProperty("davmail.ssl.keystoreType", (String) keystoreTypeCombo.getSelectedItem());
827             Settings.setProperty("davmail.ssl.keystoreFile", keystoreFileField.getText());
828             Settings.setProperty("davmail.ssl.keystorePass", String.valueOf(keystorePassField.getPassword()));
829             Settings.setProperty("davmail.ssl.keyPass", String.valueOf(keyPassField.getPassword()));
830 
831             Settings.setProperty("davmail.ssl.clientKeystoreType", (String) clientKeystoreTypeCombo.getSelectedItem());
832             Settings.setProperty("davmail.ssl.clientKeystoreFile", clientKeystoreFileField.getText());
833             Settings.setProperty("davmail.ssl.clientKeystorePass", String.valueOf(clientKeystorePassField.getPassword()));
834             Settings.setProperty("davmail.ssl.pkcs11Library", pkcs11LibraryField.getText());
835             Settings.setProperty("davmail.ssl.pkcs11Config", pkcs11ConfigField.getText());
836 
837             Settings.setProperty("davmail.oauth.tenantId", oauthTenantIdField.getText());
838             Settings.setProperty("davmail.oauth.clientId", oauthClientIdField.getText());
839             Settings.setProperty("davmail.oauth.redirectUri", oauthRedirectUriField.getText());
840 
841             Settings.setLoggingLevel("rootLogger", (Level) rootLoggingLevelField.getSelectedItem());
842             Settings.setLoggingLevel("davmail", (Level) davmailLoggingLevelField.getSelectedItem());
843             Settings.setLoggingLevel("httpclient", (Level) httpclientLoggingLevelField.getSelectedItem());
844             Settings.setLoggingLevel("httpclient.wire", (Level) wireLoggingLevelField.getSelectedItem());
845             Settings.setProperty("davmail.logFilePath", logFilePathField.getText());
846             Settings.setProperty("davmail.logFileSize", logFileSizeField.getText());
847 
848             setVisible(false);
849             Settings.save();
850 
851             if (osxHideFromDockCheckBox != null) {
852                 OSXInfoPlist.setOSXHideFromDock(osxHideFromDockCheckBox.isSelected());
853             }
854 
855             // restart listeners with new config
856             DavGateway.restart();
857         };
858         ok.addActionListener(save);
859 
860         cancel.addActionListener(evt -> {
861             reload();
862             setVisible(false);
863         });
864 
865         help.addActionListener(e -> DesktopBrowser.browse("https://davmail.sourceforge.net"));
866 
867         buttonPanel.add(ok);
868         buttonPanel.add(cancel);
869         buttonPanel.add(help);
870 
871         add(BorderLayout.SOUTH, buttonPanel);
872 
873         pack();
874         //setResizable(false);
875         // center frame
876         setLocationRelativeTo(null);
877         urlField.requestFocus();
878     }
879 }