From f76f11a5a0c3ac161c2380e6bf5b0e9fd49a9a93 Mon Sep 17 00:00:00 2001 From: j-dimension Date: Fri, 6 Dec 2024 16:47:36 +0100 Subject: [PATCH] prototype for O365 and MFA. #2724 --- .../configuration/MailSettingsTestAction.java | 10 +- .../configuration/MailboxSetupDialog.form | 234 ++++++++------ .../configuration/MailboxSetupDialog.java | 306 +++++++++--------- .../O365OAuthCouplingDialog.form | 6 +- .../O365OAuthCouplingDialog.java | 6 +- .../mail/EmailFolderTreeCellRenderer.java | 54 ++-- .../jlawyer/client/mail/EmailInboxPanel.java | 13 +- .../jlawyer/client/mail/FolderContainer.java | 5 +- .../jlawyer/client/mail/LoadFolderAction.java | 78 +++-- .../jlawyer/client/mail/SendAction.java | 16 +- .../client/mail/SendEncryptedAction.java | 26 +- ...24dp_0E72B5_FILL0_wght400_GRAD0_opsz24.png | Bin 0 -> 521 bytes .../services/SystemManagementRemote.java | 4 +- .../jlawyer/services/EmailService.java | 16 +- .../jlawyer/services/SystemManagement.java | 16 +- .../jlawyer/timer/MailboxScannerTask.java | 2 +- 16 files changed, 444 insertions(+), 348 deletions(-) create mode 100644 j-lawyer-client/src/icons16/material/link_24dp_0E72B5_FILL0_wght400_GRAD0_opsz24.png diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailSettingsTestAction.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailSettingsTestAction.java index 2183fc57b..2fd416811 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailSettingsTestAction.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailSettingsTestAction.java @@ -698,10 +698,8 @@ public class MailSettingsTestAction extends ProgressableAction { private boolean isMsExchange=false; private String authToken=null; - private String clientId=null; - private String clientSecret=null; - public MailSettingsTestAction(ProgressIndicator i, JDialog owner, JButton cmdTestMail, String address, String outServer, String outPort, String outUser, String outPwd, boolean outSsl, boolean outStartTls, String inServer, String inUser, String inPwd, boolean inSsl, String inType, boolean isMsExchange, String clientId, String clientSecret, String authToken) { + public MailSettingsTestAction(ProgressIndicator i, JDialog owner, JButton cmdTestMail, String address, String outServer, String outPort, String outUser, String outPwd, boolean outSsl, boolean outStartTls, String inServer, String inUser, String inPwd, boolean inSsl, String inType, boolean isMsExchange, String authToken) { super(i, false); this.owner = owner; this.cmdTestMail = cmdTestMail; @@ -721,8 +719,6 @@ public MailSettingsTestAction(ProgressIndicator i, JDialog owner, JButton cmdTes this.isMsExchange=isMsExchange; this.authToken=authToken; - this.clientId=clientId; - this.clientSecret=clientSecret; } @Override @@ -758,12 +754,12 @@ public boolean execute() throws Exception { port = Integer.parseInt(this.outPort); } this.progress("Test läuft (Versand)..."); - sysMan.testSendMail(this.outServer, port, this.outUser, this.outPwd, this.outSsl, this.outStartTls, this.address); + sysMan.testSendMail(this.outServer, port, this.outUser, this.outPwd, this.outSsl, this.outStartTls, this.address, this.isMsExchange, this.authToken); this.progress("VERSAND: Testnachricht erfolgreich verschickt - bitte Posteingang prüfen"); Thread.sleep(5000); process="Empfang / Posteingang"; this.progress("Test läuft (Empfang)..."); - sysMan.testReceiveMail(this.address, this.inServer, this.inType, this.inSsl, this.inUser, this.inPwd, this.isMsExchange, this.clientId, this.clientSecret, this.authToken); + sysMan.testReceiveMail(this.address, this.inServer, this.inType, this.inSsl, this.inUser, this.inPwd, this.isMsExchange, this.authToken); this.progress("EMPFANG: Posteingang erfolgreich geprüft"); Thread.sleep(3000); SwingUtilities.invokeLater(() -> { diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailboxSetupDialog.form b/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailboxSetupDialog.form index 8c6d6bb19..b65799bc1 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailboxSetupDialog.form +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailboxSetupDialog.form @@ -8,6 +8,11 @@ + + + + + @@ -285,7 +290,7 @@ - + @@ -326,108 +331,107 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - - - - - - + - + - + + + + + + + + + + + + + + + + - + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + - - - - + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + @@ -480,28 +484,30 @@ - - - + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -510,7 +516,7 @@ - + @@ -665,6 +671,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -690,7 +720,7 @@ - + @@ -788,7 +818,7 @@ - + diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailboxSetupDialog.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailboxSetupDialog.java index 63bfdacc1..23d132139 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailboxSetupDialog.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/MailboxSetupDialog.java @@ -664,6 +664,7 @@ You should also get your employer (if you work as a programmer) or school, package com.jdimension.jlawyer.client.configuration; import com.jdimension.jlawyer.client.editors.EditorsRegistry; +import com.jdimension.jlawyer.client.mail.EmailUtils; import com.jdimension.jlawyer.email.MissingConsentException; import com.jdimension.jlawyer.email.MsExchangeUtils; import com.jdimension.jlawyer.client.mail.oauth.OAuthUserConsentDialog; @@ -697,8 +698,8 @@ public class MailboxSetupDialog extends javax.swing.JDialog { private static final Logger log = Logger.getLogger(MailboxSetupDialog.class.getName()); - private ArrayList availableDocumentTags=new ArrayList<>(); - + private ArrayList availableDocumentTags = new ArrayList<>(); + /** * Creates new form MailboxSetupDialog * @@ -731,12 +732,12 @@ public MailboxSetupDialog(java.awt.Frame parent, boolean modal) { } ComponentUtils.autoSizeColumns(tblMailboxes); - + AppOptionGroupBean[] allDocTags = settings.getDocumentTagDtos(); for (AppOptionGroupBean aog : allDocTags) { availableDocumentTags.add(aog.getValue()); } - + this.buildScanTagsPopup(availableDocumentTags, new String[0]); } @@ -757,12 +758,12 @@ private void resetDetails() { this.chkEmailInSsl.setSelected(true); this.chkEmailOutSsl.setSelected(true); this.chkEmailStartTls.setSelected(false); - + this.chkMsExchange.setSelected(false); this.txtClientId.setText(""); this.txtClientSecret.setText(""); this.txtTenantId.setText(""); - + this.chkScanInbox.setSelected(false); this.txtScanBlacklist.setText(""); this.txtScanExclusionList.setText(""); @@ -771,7 +772,7 @@ private void resetDetails() { this.chkIgnoreInlineAttachments.setSelected(true); } - + private void buildScanTagsPopup(List availableTags, String[] selectedTags) { if (availableTags == null) { @@ -833,6 +834,7 @@ private void buildScanTagsPopup(List availableTags, String[] selectedTag private void initComponents() { popScanTags = new javax.swing.JPopupMenu(); + jLabel23 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); tblMailboxes = new javax.swing.JTable(); @@ -882,6 +884,8 @@ private void initComponents() { jSeparator1 = new javax.swing.JSeparator(); cmdTestMail = new javax.swing.JButton(); lblTestProgress = new javax.swing.JLabel(); + cmdO365Coupling = new javax.swing.JButton(); + jLabel24 = new javax.swing.JLabel(); jPanel4 = new javax.swing.JPanel(); htmlEmailSig = new com.jdimension.jlawyer.client.mail.HtmlEditorPanel(); jPanel5 = new javax.swing.JPanel(); @@ -899,6 +903,8 @@ private void initComponents() { chkIgnoreInlineAttachments = new javax.swing.JCheckBox(); sldMinAttachmentSizeKb = new javax.swing.JSlider(); + jLabel23.setText("jLabel23"); + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("E-Mail - Postfächer"); @@ -1035,7 +1041,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtEmailSender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel10)) - .addContainerGap(428, Short.MAX_VALUE)) + .addContainerGap(427, Short.MAX_VALUE)) ); jTabbedPane1.addTab("Postfach", jPanel2); @@ -1092,85 +1098,98 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { lblTestProgress.setText("jLabel21"); + cmdO365Coupling.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons16/material/link_24dp_0E72B5_FILL0_wght400_GRAD0_opsz24.png"))); // NOI18N + cmdO365Coupling.setToolTipText("Postfach koppeln"); + cmdO365Coupling.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cmdO365CouplingActionPerformed(evt); + } + }); + + jLabel24.setFont(jLabel24.getFont().deriveFont(jLabel24.getFont().getStyle() | java.awt.Font.BOLD, jLabel24.getFont().getSize()-2)); + jLabel24.setForeground(new java.awt.Color(153, 153, 153)); + jLabel24.setText("Office 365"); + javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel24, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel7) - .addComponent(jLabel13)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(chkEmailInSsl) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(txtInServer) - .addComponent(txtInUser)) - .addGap(18, 18, 18) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel14) - .addComponent(jLabel15)) - .addGap(18, 18, 18) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(cmbAccountType, 0, 256, Short.MAX_VALUE) - .addComponent(pwdInPassword))))) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jLabel5) - .addGap(0, 0, Short.MAX_VALUE)) - .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel9) - .addComponent(jLabel8)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(txtOutServer) - .addComponent(txtOutUsername)) - .addGap(18, 18, 18) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel17) - .addComponent(jLabel16)) + .addComponent(jLabel7) + .addComponent(jLabel13)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(txtOutPort, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(chkEmailInSsl) .addGap(0, 0, Short.MAX_VALUE)) - .addComponent(pwdOutPassword))) + .addGroup(jPanel3Layout.createSequentialGroup() + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(txtInServer) + .addComponent(txtInUser)) + .addGap(18, 18, 18) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel14) + .addComponent(jLabel15)) + .addGap(18, 18, 18) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(cmbAccountType, 0, 256, Short.MAX_VALUE) + .addComponent(pwdInPassword))))) + .addGroup(jPanel3Layout.createSequentialGroup() + .addComponent(jLabel5) + .addGap(0, 0, Short.MAX_VALUE)) + .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel3Layout.createSequentialGroup() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(chkEmailOutSsl) - .addComponent(chkEmailStartTls) + .addComponent(jLabel9) + .addComponent(jLabel8)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(chkMsExchange) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(txtOutServer, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE) + .addComponent(txtOutUsername)) .addGap(18, 18, 18) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGap(12, 12, 12)) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel17) + .addComponent(jLabel16)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jLabel18) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(txtClientId) - .addComponent(txtClientSecret) - .addComponent(txtTenantId, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGap(0, 49, Short.MAX_VALUE))))) + .addComponent(txtOutPort, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 135, Short.MAX_VALUE)) + .addComponent(pwdOutPassword))) + .addGroup(jPanel3Layout.createSequentialGroup() + .addComponent(chkEmailStartTls) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(chkEmailOutSsl) + .addGap(0, 0, Short.MAX_VALUE)))) + .addComponent(jSeparator1) + .addGroup(jPanel3Layout.createSequentialGroup() + .addComponent(cmdTestMail) + .addGap(7, 7, 7) + .addComponent(lblTestProgress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) + .addGroup(jPanel3Layout.createSequentialGroup() + .addComponent(chkMsExchange) + .addGap(18, 18, 18) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel3) + .addComponent(jLabel2) + .addComponent(jLabel18)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(txtClientSecret) + .addComponent(txtTenantId) + .addComponent(txtClientId)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cmdO365Coupling))) .addContainerGap()) - .addComponent(jSeparator1) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(cmdTestMail) - .addGap(7, 7, 7) - .addComponent(lblTestProgress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -1212,31 +1231,33 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(jLabel16) .addComponent(pwdOutPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(chkEmailStartTls) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(chkEmailOutSsl) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(chkEmailStartTls) + .addComponent(chkEmailOutSsl)) .addGap(18, 18, 18) + .addComponent(jLabel24) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(chkMsExchange) - .addGroup(jPanel3Layout.createSequentialGroup() - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel2) - .addComponent(txtClientId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(txtClientSecret, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(txtTenantId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel18)))) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(chkMsExchange) + .addComponent(jLabel2) + .addComponent(txtClientId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(cmdO365Coupling, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(txtClientSecret, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(txtTenantId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel18)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cmdTestMail) .addComponent(lblTestProgress)) - .addContainerGap(56, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jTabbedPane1.addTab("Verbindung", jPanel3); @@ -1254,7 +1275,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addContainerGap() - .addComponent(htmlEmailSig, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)) + .addComponent(htmlEmailSig, javax.swing.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE)) ); jTabbedPane1.addTab("Signatur", jPanel4); @@ -1366,7 +1387,7 @@ public void stateChanged(javax.swing.event.ChangeEvent evt) { .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblMinAttachmentSize) .addComponent(sldMinAttachmentSizeKb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(59, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jTabbedPane1.addTab("Automation", jPanel5); @@ -1451,7 +1472,7 @@ private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST: MailboxSetup savedMailbox = locator.lookupSecurityServiceRemote().addMailboxSetup(ms); ((DefaultTableModel) this.tblMailboxes.getModel()).addRow(new Object[]{savedMailbox, savedMailbox.getEmailAddress()}); - int selectedRow=TableUtils.getRowForObject(tblMailboxes, 0, savedMailbox); + int selectedRow = TableUtils.getRowForObject(tblMailboxes, 0, savedMailbox); this.tblMailboxes.getSelectionModel().setSelectionInterval(selectedRow, selectedRow); this.updatedUI(savedMailbox); @@ -1491,13 +1512,13 @@ private void cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST ms.setClientId(this.txtClientId.getText()); ms.setClientSecret(this.txtClientSecret.getText()); ms.setTenantId(this.txtTenantId.getText()); - + ms.setScanInbox(this.chkScanInbox.isSelected()); ms.setScanBlacklistedTypes(this.txtScanBlacklist.getText()); ms.setScanExclusionList(this.txtScanExclusionList.getText()); ms.setScanIgnoreInline(this.chkIgnoreInlineAttachments.isSelected()); - ms.setScanMinAttachmentSize(this.sldMinAttachmentSizeKb.getValue()*1024); - + ms.setScanMinAttachmentSize(this.sldMinAttachmentSizeKb.getValue() * 1024); + List al = ComponentUtils.getSelectedPopupMenuItems(popScanTags); ms.setScanDocumentTagsArray(al.toArray(String[]::new)); @@ -1505,11 +1526,11 @@ private void cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST try { ms.setEmailOutPwd(CryptoProvider.defaultCrypto().encrypt(new String(this.pwdOutPassword.getPassword()))); ms.setEmailInPwd(CryptoProvider.defaultCrypto().encrypt(new String(this.pwdInPassword.getPassword()))); - + JLawyerServiceLocator locator = JLawyerServiceLocator.getInstance(settings.getLookupProperties()); MailboxSetup savedMailbox = locator.lookupSecurityServiceRemote().updateMailboxSetup(ms); - row=this.tblMailboxes.convertRowIndexToModel(row); + row = this.tblMailboxes.convertRowIndexToModel(row); ((DefaultTableModel) this.tblMailboxes.getModel()).setValueAt(savedMailbox, row, 0); ((DefaultTableModel) this.tblMailboxes.getModel()).setValueAt(savedMailbox.getEmailAddress(), row, 1); UserSettings.getInstance().invalidateMailboxes(UserSettings.getInstance().getCurrentUser().getPrincipalId()); @@ -1533,7 +1554,7 @@ private void cmdRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR JLawyerServiceLocator locator = JLawyerServiceLocator.getInstance(settings.getLookupProperties()); locator.lookupSecurityServiceRemote().removeMailboxSetup(ms); - row=this.tblMailboxes.convertRowIndexToModel(row); + row = this.tblMailboxes.convertRowIndexToModel(row); ((DefaultTableModel) this.tblMailboxes.getModel()).removeRow(row); this.resetDetails(); @@ -1558,57 +1579,28 @@ private void tblMailboxesKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:e private void cmdTestMailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdTestMailActionPerformed - - - String authToken = null; + String authToken=null; if (this.chkMsExchange.isSelected()) { - - this.cmdSaveActionPerformed(evt); - - int row = this.tblMailboxes.getSelectedRow(); - MailboxSetup ms=null; - if (row >= 0) { - ms = (MailboxSetup) this.tblMailboxes.getValueAt(row, 0); - } else { - return; - } - - - O365OAuthCouplingDialog dlg=new O365OAuthCouplingDialog(this, ms); - FrameUtils.centerDialog(dlg, this); - dlg.setVisible(true); - -// try { -// authToken = MsExchangeUtils.getAuthToken(this.txtTenantId.getText(), this.txtClientId.getText(), this.txtClientSecret.getText(), this.txtInUser.getText(), new String(this.pwdInPassword.getPassword())); -// } catch (MissingConsentException ex) { -// log.error("Consent required for client id " + this.txtClientId.getText(), ex); -// // get consent and then proceed to test action -// OAuthUserConsentDialog oDlg=new OAuthUserConsentDialog(this, true, this.txtTenantId.getText(), this.txtClientId.getText()); -// FrameUtils.centerDialog(oDlg, EditorsRegistry.getInstance().getMainWindow()); -// oDlg.setTitle("Zustimmung zum Postfachzugriff"); -// oDlg.setVisible(true); -// -// // retry getting an auth token -// try { -// authToken = MsExchangeUtils.getAuthToken(this.txtTenantId.getText(), this.txtClientId.getText(), this.txtClientSecret.getText(), this.txtInUser.getText(), new String(this.pwdInPassword.getPassword())); -// } catch (Exception exc) { -// log.error("Unable to acquire auth token for client id " + this.txtClientId.getText(), exc); -// JOptionPane.showMessageDialog(this, "Autorisierungstoken für Microsoft Exchange kann nicht ermittelt werden: " + exc.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR, JOptionPane.ERROR_MESSAGE); -// // no sense in executing the test -// return; -// } -// } catch (Exception ex) { -// log.error("Unable to acquire auth token for client id " + this.txtClientId.getText(), ex); -// JOptionPane.showMessageDialog(this, "Autorisierungstoken für Microsoft Exchange kann nicht ermittelt werden: " +ex.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR, JOptionPane.ERROR_MESSAGE); -// // no sense in executing the test -// return; -// } + + try { + int row = this.tblMailboxes.getSelectedRow(); + MailboxSetup ms = null; + if (row >= 0) { + ms = (MailboxSetup) this.tblMailboxes.getValueAt(row, 0); + authToken = EmailUtils.getOffice365AuthToken(ms.getId()); + } else { + return; + } + } catch (Exception ex) { + log.error("Error getting access token", ex); + JOptionPane.showMessageDialog(this, ex.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR, JOptionPane.ERROR_MESSAGE); + } } ProgressIndicator pi = new ProgressIndicator(EditorsRegistry.getInstance().getMainWindow(), true); pi.setShowCancelButton(false); - - MailSettingsTestAction a = new MailSettingsTestAction(pi, this, this.cmdTestMail, this.txtEmailAddress.getText(), this.txtOutServer.getText(), this.txtOutPort.getText(), this.txtOutUsername.getText(), new String(this.pwdOutPassword.getPassword()), this.chkEmailOutSsl.isSelected(), this.chkEmailStartTls.isSelected(), this.txtInServer.getText(), this.txtInUser.getText(), new String(this.pwdInPassword.getPassword()), this.chkEmailInSsl.isSelected(), this.cmbAccountType.getSelectedItem().toString(), this.chkMsExchange.isSelected(), this.txtClientId.getText(), this.txtClientSecret.getText(), authToken); + + MailSettingsTestAction a = new MailSettingsTestAction(pi, this, this.cmdTestMail, this.txtEmailAddress.getText(), this.txtOutServer.getText(), this.txtOutPort.getText(), this.txtOutUsername.getText(), new String(this.pwdOutPassword.getPassword()), this.chkEmailOutSsl.isSelected(), this.chkEmailStartTls.isSelected(), this.txtInServer.getText(), this.txtInUser.getText(), new String(this.pwdInPassword.getPassword()), this.chkEmailInSsl.isSelected(), this.cmbAccountType.getSelectedItem().toString(), this.chkMsExchange.isSelected(), authToken); a.start(); @@ -1622,6 +1614,27 @@ private void sldMinAttachmentSizeKbStateChanged(javax.swing.event.ChangeEvent ev this.lblMinAttachmentSize.setText("Anlagen nicht speichern, die kleiner als " + sldMinAttachmentSizeKb.getValue() + "KB sind:"); }//GEN-LAST:event_sldMinAttachmentSizeKbStateChanged + private void cmdO365CouplingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdO365CouplingActionPerformed + if (this.chkMsExchange.isSelected()) { + + this.cmdSaveActionPerformed(evt); + + int row = this.tblMailboxes.getSelectedRow(); + MailboxSetup ms = null; + if (row >= 0) { + ms = (MailboxSetup) this.tblMailboxes.getValueAt(row, 0); + } else { + return; + } + + O365OAuthCouplingDialog dlg = new O365OAuthCouplingDialog(this, ms); + FrameUtils.centerDialog(dlg, this); + dlg.setVisible(true); + } + + + }//GEN-LAST:event_cmdO365CouplingActionPerformed + private void updatedUI(MailboxSetup ms) { this.txtDisplayName.setText(ms.getDisplayName()); @@ -1645,13 +1658,13 @@ private void updatedUI(MailboxSetup ms) { outPwd = CryptoProvider.defaultCrypto().decrypt(ms.getEmailOutPwd()); } catch (Throwable t) { log.error(t); - outPwd=""; + outPwd = ""; } try { inPwd = CryptoProvider.defaultCrypto().decrypt(ms.getEmailInPwd()); } catch (Throwable t) { log.error(t); - inPwd=""; + inPwd = ""; } this.pwdInPassword.setText(inPwd); this.txtOutServer.setText(ms.getEmailOutServer()); @@ -1661,18 +1674,18 @@ private void updatedUI(MailboxSetup ms) { this.chkEmailInSsl.setSelected(ms.isEmailInSsl()); this.chkEmailOutSsl.setSelected(ms.isEmailOutSsl()); this.chkEmailStartTls.setSelected(ms.isEmailStartTls()); - + this.chkMsExchange.setSelected(ms.isMsExchange()); this.txtClientId.setText(ms.getClientId()); this.txtClientSecret.setText(ms.getClientSecret()); this.txtTenantId.setText(ms.getTenantId()); - + this.chkScanInbox.setSelected(ms.isScanInbox()); this.txtScanBlacklist.setText(ms.getScanBlacklistedTypes()); this.txtScanExclusionList.setText(ms.getScanExclusionList()); this.chkIgnoreInlineAttachments.setSelected(ms.isScanIgnoreInline()); - this.sldMinAttachmentSizeKb.setValue((int)((int)ms.getScanMinAttachmentSize()/(int)1024)); - + this.sldMinAttachmentSizeKb.setValue((int) ((int) ms.getScanMinAttachmentSize() / (int) 1024)); + this.buildScanTagsPopup(this.availableDocumentTags, ms.getScanDocumentTagsArray()); } @@ -1727,6 +1740,7 @@ public void windowClosing(java.awt.event.WindowEvent e) { private javax.swing.JComboBox cmbAccountType; private javax.swing.JButton cmdAdd; private javax.swing.JButton cmdClose; + private javax.swing.JButton cmdO365Coupling; private javax.swing.JButton cmdRemove; private javax.swing.JButton cmdSave; private javax.swing.JButton cmdScanTags; @@ -1747,6 +1761,8 @@ public void windowClosing(java.awt.event.WindowEvent e) { private javax.swing.JLabel jLabel20; private javax.swing.JLabel jLabel21; private javax.swing.JLabel jLabel22; + private javax.swing.JLabel jLabel23; + private javax.swing.JLabel jLabel24; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/O365OAuthCouplingDialog.form b/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/O365OAuthCouplingDialog.form index 8d5022e9d..ae96e93c6 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/O365OAuthCouplingDialog.form +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/O365OAuthCouplingDialog.form @@ -65,9 +65,9 @@ - - - + + + diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/O365OAuthCouplingDialog.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/O365OAuthCouplingDialog.java index 71ff70ac7..89c25cd94 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/O365OAuthCouplingDialog.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/configuration/O365OAuthCouplingDialog.java @@ -797,9 +797,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(txtUrl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(cmdUrl)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(txtCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(cmdCopy, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(txtCode) + .addComponent(cmdCopy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailFolderTreeCellRenderer.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailFolderTreeCellRenderer.java index 001413a26..846476aae 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailFolderTreeCellRenderer.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailFolderTreeCellRenderer.java @@ -667,7 +667,9 @@ import java.awt.Color; import java.awt.Component; import java.awt.Font; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.mail.Folder; import javax.swing.Icon; @@ -691,7 +693,10 @@ public class EmailFolderTreeCellRenderer extends DefaultTreeCellRenderer { private static final String FOLDER_INBOX = "inbox"; private static final String FOLDER_DRAFTS = "drafts"; + // for special folders like inbox, trash, .... private static final Map folderIcons = new HashMap<>(); + // for ordinary folders + private static final List defaultFolderIcons = new ArrayList<>(); private final ImageIcon draftsIcon = new javax.swing.ImageIcon(EmailFolderTreeCellRenderer.class.getResource("/icons/drafts.png")); private final ImageIcon trashIcon = new javax.swing.ImageIcon(EmailFolderTreeCellRenderer.class.getResource("/icons/trashcan_full.png")); @@ -773,38 +778,43 @@ public Component getTreeCellRendererComponent(JTree jTree, Object object, boolea private Icon getIconByFolder(Folder f) { - if (!folderIcons.containsKey(f.getName())) { + String folderName=f.getName(); + + if(defaultFolderIcons.contains(folderName)) + return null; + + if (!folderIcons.containsKey(folderName)) { - if (FOLDER_TRASH.equalsIgnoreCase(f.getName())) { - folderIcons.put(f.getName(), trashIcon); - } else if (FOLDER_SENT.equalsIgnoreCase(f.getName())) { - folderIcons.put(f.getName(), sentIcon); - } else if (FOLDER_DRAFTS.equalsIgnoreCase(f.getName())) { - folderIcons.put(f.getName(), draftsIcon); - } else if (FOLDER_INBOX.equalsIgnoreCase(f.getName())) { - folderIcons.put(f.getName(), inboxIcon); - } else if ("in Akte importiert".equalsIgnoreCase(f.getName())) { - folderIcons.put(f.getName(), importedIcon); + if (FOLDER_TRASH.equalsIgnoreCase(folderName)) { + folderIcons.put(folderName, trashIcon); + } else if (FOLDER_SENT.equalsIgnoreCase(folderName)) { + folderIcons.put(folderName, sentIcon); + } else if (FOLDER_DRAFTS.equalsIgnoreCase(folderName)) { + folderIcons.put(folderName, draftsIcon); + } else if (FOLDER_INBOX.equalsIgnoreCase(folderName)) { + folderIcons.put(folderName, inboxIcon); + } else if ("in Akte importiert".equalsIgnoreCase(folderName)) { + folderIcons.put(folderName, importedIcon); } else { boolean iconIsSet = false; for (String a : EmailUtils.getFolderAliases(CommonMailUtils.TRASH)) { - if (a.equalsIgnoreCase(f.getName())) { - folderIcons.put(f.getName(), trashIcon); + if (a.equalsIgnoreCase(folderName)) { + folderIcons.put(folderName, trashIcon); iconIsSet = true; break; } } for (String a : EmailUtils.getFolderAliases(CommonMailUtils.DRAFTS)) { - if (a.equalsIgnoreCase(f.getName())) { - folderIcons.put(f.getName(), draftsIcon); + if (a.equalsIgnoreCase(folderName)) { + folderIcons.put(folderName, draftsIcon); iconIsSet = true; break; } } if (!iconIsSet) { for (String a : EmailUtils.getFolderAliases(CommonMailUtils.SENT)) { - if (a.equalsIgnoreCase(f.getName())) { - folderIcons.put(f.getName(), sentIcon); + if (a.equalsIgnoreCase(folderName)) { + folderIcons.put(folderName, sentIcon); iconIsSet = true; break; } @@ -812,15 +822,19 @@ private Icon getIconByFolder(Folder f) { } if (!iconIsSet) { for (String a : EmailUtils.getFolderAliases(CommonMailUtils.INBOX)) { - if (a.equalsIgnoreCase(f.getName())) { - folderIcons.put(f.getName(), inboxIcon); + if (a.equalsIgnoreCase(folderName)) { + folderIcons.put(folderName, inboxIcon); break; } } } } } - return folderIcons.get(f.getName()); + + if(folderIcons.get(folderName)==null && !defaultFolderIcons.contains(folderName)) + defaultFolderIcons.add(folderName); + + return folderIcons.get(folderName); } } diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailInboxPanel.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailInboxPanel.java index 4c74e30ad..dae76646e 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailInboxPanel.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailInboxPanel.java @@ -1681,7 +1681,18 @@ public boolean isCellEditable(int row, int column) { Folder folder = folderC.getFolder(); try { if (!folder.isOpen()) { - folder.open(Folder.READ_WRITE); + try { + folder.open(Folder.READ_WRITE); + } catch (Exception ex) { + MailboxSetup ms=this.getMailboxSetup(selNode); + log.warn("Attempting to reconnect to " + ms.getEmailAddress()); + String pw=ms.getEmailInPwd(); + if(ms.isMsExchange()) + pw=ms.getAuthToken(); + folder.getStore().connect(ms.getEmailInServer(), ms.getEmailInUser(), pw); + folder.close(false); + folder.open(Folder.READ_WRITE); + } } DefaultTableModel tm = new DefaultTableModel(new String[]{"Betreff", "Absender", "Empfänger", "Gesendet"}, 0) { diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/FolderContainer.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/FolderContainer.java index 83e43e910..177b2f9fe 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/FolderContainer.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/FolderContainer.java @@ -732,6 +732,7 @@ public int getUnreadMessageCount() { if (this.cachedUnreadUpdated == -1 || ((System.currentTimeMillis() - cachedUnreadUpdated) > this.getRetentionTime())) { if (this.folder != null) { + this.cachedUnreadUpdated = System.currentTimeMillis(); try { this.cachedUnread = this.folder.getUnreadMessageCount(); } catch (StoreClosedException stex) { @@ -739,7 +740,6 @@ public int getUnreadMessageCount() { } catch (MessagingException ex) { log.error("Unable to determine number of unread messages", ex); } - this.cachedUnreadUpdated = System.currentTimeMillis(); } } return cachedUnread; @@ -766,7 +766,8 @@ public String toString() { } } - int msgCount = this.folder.getMessageCount(); + //int msgCount = this.folder.getMessageCount(); + int msgCount = this.getUnreadMessageCount(); cachedToStringUpdated = System.currentTimeMillis(); if (msgCount < 0) { cachedToString = name; diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/LoadFolderAction.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/LoadFolderAction.java index f2ebc287c..3c160c34e 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/LoadFolderAction.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/LoadFolderAction.java @@ -663,7 +663,6 @@ */ package com.jdimension.jlawyer.client.mail; -import com.jdimension.jlawyer.client.editors.EditorsRegistry; import com.jdimension.jlawyer.client.processing.ProgressIndicator; import com.jdimension.jlawyer.client.processing.ProgressableAction; import com.jdimension.jlawyer.client.settings.ClientSettings; @@ -678,6 +677,7 @@ import javax.mail.Flags; import javax.mail.Folder; import javax.mail.Message; +import javax.mail.search.AndTerm; import javax.mail.search.BodyTerm; import javax.mail.search.FlagTerm; import javax.mail.search.FromStringTerm; @@ -703,7 +703,7 @@ public class LoadFolderAction extends ProgressableAction { private JTable table = null; private int sortCol = -1; private int scrollToRow = -1; - private String searchTerm=null; + private String searchTerm = null; public LoadFolderAction(ProgressIndicator i, Folder f, JTable table, int sortCol, int scrollToRow, String searchTerm) { super(i, false); @@ -711,7 +711,7 @@ public LoadFolderAction(ProgressIndicator i, Folder f, JTable table, int sortCol this.table = table; this.sortCol = sortCol; this.scrollToRow = scrollToRow; - this.searchTerm=searchTerm; + this.searchTerm = searchTerm; } @Override @@ -732,18 +732,17 @@ public int getMin() { @Override public boolean execute() throws Exception { try { - EditorsRegistry.getInstance().updateStatus("Öffne Ordner " + f.getName(), true); - if (!(f.isOpen())) { f.open(Folder.READ_WRITE); } - try { - if (EmailUtils.isIMAP(f)) { - f.expunge(); - } - } catch (Throwable t) { - log.error("Could not expunge folder", t); - } +// try { +// if (EmailUtils.isIMAP(f)) { +// f.expunge(); +// } +// } catch (Throwable t) { +// log.error("Could not expunge folder", t); +// } +// System.out.println("load 20 = " + (System.currentTimeMillis() - start)); ClientSettings cs = ClientSettings.getInstance(); String restriction = cs.getConfiguration(ClientSettings.CONF_MAIL_DOWNLOADRESTRICTION, "" + LoadFolderRestriction.RESTRICTION_50); @@ -757,38 +756,57 @@ public boolean execute() throws Exception { int fromIndex = 1; int toIndex = f.getMessageCount(); - int maxQuantity=Integer.MAX_VALUE; + int maxQuantity = Integer.MAX_VALUE; switch (currentRestriction.getRestriction()) { case LoadFolderRestriction.RESTRICTION_20: fromIndex = Math.max(1, toIndex - 20); - maxQuantity=20; + maxQuantity = 20; break; case LoadFolderRestriction.RESTRICTION_50: fromIndex = Math.max(1, toIndex - 50); - maxQuantity=50; + maxQuantity = 50; break; case LoadFolderRestriction.RESTRICTION_100: fromIndex = Math.max(1, toIndex - 100); - maxQuantity=100; + maxQuantity = 100; break; case LoadFolderRestriction.RESTRICTION_500: fromIndex = Math.max(1, toIndex - 500); - maxQuantity=500; + maxQuantity = 500; break; default: break; } - Message[] messages =null; - if(StringUtils.isEmpty(this.searchTerm)) { - messages = f.getMessages(fromIndex, toIndex); + Message[] messages = null; + FlagTerm notDeleted = new FlagTerm(new Flags(Flags.Flag.DELETED), false); + if (StringUtils.isEmpty(this.searchTerm)) { if (currentRestriction.getRestriction() == LoadFolderRestriction.RESTRICTION_UNREAD) { - messages=f.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false), messages); + // Combine unread filter with notDeleted filter + FlagTerm unread = new FlagTerm(new Flags(Flags.Flag.SEEN), false); + AndTerm filter = new AndTerm(unread, notDeleted); + messages = f.search(filter, messages); + } else { + messages = f.getMessages(fromIndex, toIndex); + + // Apply the filter to the subset of messages + messages = f.search(notDeleted, messages); } } else { - maxQuantity=Integer.MAX_VALUE; - OrTerm orTerm=new OrTerm(new SearchTerm[] {new SubjectTerm(this.searchTerm), new FromStringTerm(this.searchTerm), new RecipientStringTerm(Message.RecipientType.TO, this.searchTerm), new RecipientStringTerm(Message.RecipientType.CC, this.searchTerm), new RecipientStringTerm(Message.RecipientType.BCC, this.searchTerm), new BodyTerm(this.searchTerm)}); - messages=f.search(orTerm); + maxQuantity = Integer.MAX_VALUE; + // Build the OR search term for subject, sender, recipients, and body + OrTerm orTerm = new OrTerm(new SearchTerm[]{ + new SubjectTerm(this.searchTerm), + new FromStringTerm(this.searchTerm), + new RecipientStringTerm(Message.RecipientType.TO, this.searchTerm), + new RecipientStringTerm(Message.RecipientType.CC, this.searchTerm), + new RecipientStringTerm(Message.RecipientType.BCC, this.searchTerm), + new BodyTerm(this.searchTerm) + }); + + // Combine the OR term with notDeleted filter + AndTerm filter = new AndTerm(orTerm, notDeleted); + messages = f.search(filter); } FetchProfile fp = new FetchProfile(); @@ -812,7 +830,6 @@ public boolean execute() throws Exception { if ((i % 100) == 0 || i == (messages.length - 1)) { this.progress("Lade Nachrichten... " + (i + 1)); - EditorsRegistry.getInstance().updateStatus("Lade Nachricht " + (i + 1), true); } final Message msg = messages[i]; @@ -863,9 +880,9 @@ public boolean execute() throws Exception { } } - String sentString=""; - if(msg.getSentDate()!=null) { - sentString=df.format(msg.getSentDate()); + String sentString = ""; + if (msg.getSentDate() != null) { + sentString = df.format(msg.getSentDate()); } Object[] newRow = new Object[]{new MessageContainer(msg, msg.getSubject(), msg.isSet(Flags.Flag.SEEN)), from, toString, sentString}; tableRows.add(newRow); @@ -881,7 +898,7 @@ public boolean execute() throws Exception { try { for (Object[] rowObject : tableRowsClone) { ((DefaultTableModel) table.getModel()).addRow(rowObject); - + } if (scrollToRow > 0) { if (currentIndex == (indexMax)) { @@ -913,8 +930,6 @@ public boolean execute() throws Exception { ComponentUtils.autoSizeColumns(table, 0); }); - EditorsRegistry.getInstance().clearStatus(true); - new Thread(() -> { try { Thread.sleep(5000); @@ -925,7 +940,6 @@ public boolean execute() throws Exception { log.error(t); } }).start(); - } catch (Throwable ex) { log.error(ex); return false; diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendAction.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendAction.java index 0fbba0666..6aac7dc9f 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendAction.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendAction.java @@ -753,15 +753,19 @@ public boolean execute() throws Exception { this.progress("Verbinde..."); String inPwd = ""; - try { - inPwd = CryptoProvider.defaultCrypto().decrypt(ms.getEmailInPwd()); - } catch (Throwable t) { - log.error(t); + if (ms.isMsExchange()) { + inPwd = EmailUtils.getOffice365AuthToken(ms.getId()); + } else { + try { + inPwd = CryptoProvider.defaultCrypto().decrypt(ms.getEmailInPwd()); + } catch (Throwable t) { + log.error(t); + } } - + String outPwd = ""; if (ms.isMsExchange()) { - outPwd = EmailUtils.getOffice365AuthToken(ms.getId()); + outPwd = inPwd; } else { try { outPwd = CryptoProvider.defaultCrypto().decrypt(ms.getEmailOutPwd()); diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEncryptedAction.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEncryptedAction.java index 08d8234c2..671bef527 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEncryptedAction.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEncryptedAction.java @@ -763,21 +763,25 @@ public boolean execute() throws Exception { this.progress("Verbinde..."); String inPwd = ""; - try { - inPwd = CryptoProvider.defaultCrypto().decrypt(ms.getEmailInPwd()); - } catch (Throwable t) { - log.error(t); + if (ms.isMsExchange()) { + inPwd = EmailUtils.getOffice365AuthToken(ms.getId()); + } else { + try { + inPwd = CryptoProvider.defaultCrypto().decrypt(ms.getEmailInPwd()); + } catch (Throwable t) { + log.error(t); + } } - + String outPwd = ""; if (ms.isMsExchange()) { - outPwd = EmailUtils.getOffice365AuthToken(ms.getId()); + outPwd = inPwd; } else { - try { - outPwd = CryptoProvider.defaultCrypto().decrypt(ms.getEmailOutPwd()); - } catch (Throwable t) { - log.error(t); - } + try { + outPwd = CryptoProvider.defaultCrypto().decrypt(ms.getEmailOutPwd()); + } catch (Throwable t) { + log.error(t); + } } diff --git a/j-lawyer-client/src/icons16/material/link_24dp_0E72B5_FILL0_wght400_GRAD0_opsz24.png b/j-lawyer-client/src/icons16/material/link_24dp_0E72B5_FILL0_wght400_GRAD0_opsz24.png new file mode 100644 index 0000000000000000000000000000000000000000..e08925b14062733151d78ae5981efb506f1cb57c GIT binary patch literal 521 zcmV+k0`~ohP)kcdAaML^U=8?iS(KtvPK$`pz7A;#U=dn|NDAuDXBMc(o`ocDafzWzJO z9ulnvwXfl@Yl~l?^iaA9V0Y~Cf|)?`crg1!G}-QL7)7QUk4~w|b%bLgVv3Mc@2oh@ z#dB{8rm7D3EXu8TaDm^B7Pzd!Qut-8 zp23Z>LwoJX5GtD}@BQGwxt-e=<9_yac)C^1{q8G8PODcrk=?ztCt3-0zhDfDuvUFL6`u7pIB=RHPg^oNgTz z-)$)7ZIE+*dwD$RXXK&T$M$>2dkLH=MlP>x8_(uI7g5XBhgH2wfwJ7a<4C4qTs>7LI?Yp)exy11t)KPm>mTX|7ZkL-H6y@m00000 LNkvXXu0mjf@G|Yp literal 0 HcmV?d00001 diff --git a/j-lawyer-server-api/src/com/jdimension/jlawyer/services/SystemManagementRemote.java b/j-lawyer-server-api/src/com/jdimension/jlawyer/services/SystemManagementRemote.java index 10654bbbb..843fbb6c8 100644 --- a/j-lawyer-server-api/src/com/jdimension/jlawyer/services/SystemManagementRemote.java +++ b/j-lawyer-server-api/src/com/jdimension/jlawyer/services/SystemManagementRemote.java @@ -738,9 +738,9 @@ public interface SystemManagementRemote { void statusMail(String subject, String body); - void testSendMail(String smtpHost, int smtpPort, String smtpUser, String smtpPwd, boolean smtpSsl, boolean smtpStartTls, String mailAddress) throws Exception; + void testSendMail(String smtpHost, int smtpPort, String smtpUser, String smtpPwd, boolean smtpSsl, boolean smtpStartTls, String mailAddress, boolean isMsExchange, String authToken) throws Exception; - void testReceiveMail(String mailAddress, String host, String protocol, boolean ssl, String user, String pwd, boolean isMsExchange, String clientId, String clientSecret, String authToken) throws Exception; + void testReceiveMail(String mailAddress, String host, String protocol, boolean ssl, String user, String pwd, boolean isMsExchange, String authToken) throws Exception; boolean validateFileOnServer(File file, boolean isDirectory); diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/EmailService.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/EmailService.java index 21d7c8d55..625c2879f 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/EmailService.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/EmailService.java @@ -728,15 +728,11 @@ public void refreshAuthTokens() { List mailboxes = this.mailboxSetupFacade.findByMsExchange(true); for (MailboxSetup ms : mailboxes) { - List usage = this.mailboxAccessFacade.findByMailbox(ms.getId()); - if (!usage.isEmpty()) { - // only refresh token for mailboxes that are in use - if (ms.getTokenExpiry() == 0 || ((ms.getTokenExpiry() - System.currentTimeMillis()) < (6l * 60l * 1000l))) { - try { - this.updateAuthToken(ms); - } catch (Exception ex) { - log.error("failed to retrieve new access token for mailbox " + ms.getEmailAddress(), ex); - } + if (ms.getTokenExpiry() == 0 || ((ms.getTokenExpiry() - System.currentTimeMillis()) < (6l * 60l * 1000l))) { + try { + this.updateAuthToken(ms); + } catch (Exception ex) { + log.error("failed to retrieve new access token for mailbox " + ms.getEmailAddress(), ex); } } } @@ -778,7 +774,7 @@ private boolean updateAuthToken(MailboxSetup mailbox) throws Exception { response.getEntity().getContent(), Map.class ); - + String accessToken = (String) responseBody.get("access_token"); String refreshToken = (String) responseBody.get("refresh_token"); int expiresIn = (int) responseBody.get("expires_in"); diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagement.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagement.java index 81d34b436..25062bad7 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagement.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagement.java @@ -1418,11 +1418,15 @@ public PasswordAuthentication getPasswordAuthentication() { @Override @RolesAllowed({"loginRole"}) - public void testSendMail(String smtpHost, int smtpPort, String smtpUser, String smtpPwd, boolean smtpSsl, boolean smtpStartTls, String mailAddress) throws Exception { + public void testSendMail(String smtpHost, int smtpPort, String smtpUser, String smtpPwd, boolean smtpSsl, boolean smtpStartTls, String mailAddress, boolean isMsExchange, String accessToken) throws Exception { if (smtpHost == null || smtpUser == null || smtpPwd == null || mailAddress == null) { throw new Exception("incomplete configuration for sending test mails"); } + + if (isMsExchange) { + smtpPwd=accessToken; + } Properties props = new Properties(); @@ -1442,7 +1446,7 @@ public void testSendMail(String smtpHost, int smtpPort, String smtpUser, String log.error("Invalid SMTP port: " + smtpHost); } } - + props.put("mail.smtp.host", smtpHost); props.put("mail.smtp.user", smtpUser); props.put("mail.smtp.auth", true); @@ -1452,6 +1456,12 @@ public void testSendMail(String smtpHost, int smtpPort, String smtpUser, String props.put("mail.from", smtpUser); props.put("mail.password", smtpPwd); + if (isMsExchange) { + + props.put("mail.smtp.auth.mechanisms", "XOAUTH2"); + props.put("mail.smtps.auth.mechanisms", "XOAUTH2"); + } + javax.mail.Authenticator auth = new javax.mail.Authenticator() { @Override @@ -1484,7 +1494,7 @@ public PasswordAuthentication getPasswordAuthentication() { @Override @RolesAllowed({"loginRole"}) - public void testReceiveMail(String mailAddress, String host, String protocol, boolean ssl, String user, String pwd, boolean isMsExchange, String clientId, String clientSecret, String authToken) throws Exception { + public void testReceiveMail(String mailAddress, String host, String protocol, boolean ssl, String user, String pwd, boolean isMsExchange, String authToken) throws Exception { Properties props = System.getProperties(); //Properties props = new Properties(); props.setProperty("mail.imap.partialfetch", "false"); diff --git a/j-lawyer-server/j-lawyer-server-war/src/java/com/jdimension/jlawyer/timer/MailboxScannerTask.java b/j-lawyer-server/j-lawyer-server-war/src/java/com/jdimension/jlawyer/timer/MailboxScannerTask.java index 855fb717f..e1ff7247c 100644 --- a/j-lawyer-server/j-lawyer-server-war/src/java/com/jdimension/jlawyer/timer/MailboxScannerTask.java +++ b/j-lawyer-server/j-lawyer-server-war/src/java/com/jdimension/jlawyer/timer/MailboxScannerTask.java @@ -788,7 +788,7 @@ private void processMailbox(MailboxSetup ms, ArchiveFileServiceLocal caseSvc, Ad server = ms.getEmailInServer(); if (ms.isMsExchange()) { - String authToken = MsExchangeUtils.getAuthToken(ms.getTenantId(), ms.getClientId(), ms.getClientSecret(), ms.getEmailInUser(), emailInPwd); + String authToken = ms.getAuthToken(); props.put("mail.imaps.sasl.enable", "true"); props.put("mail.imaps.port", "993");