From 57a7ed05dfa278d42d33b1544f8c6b3a39d4d5f1 Mon Sep 17 00:00:00 2001 From: j-dimension Date: Thu, 14 Sep 2023 20:23:00 +0200 Subject: [PATCH] improve sending encrypted to mail address that is used in multiple addresses. close #2074 --- .../jdimension/jlawyer/client/mail/EmailUtils.java | 14 ++++++++++++++ .../jlawyer/client/mail/SendEmailDialog.java | 6 ++++-- .../jlawyer/client/mail/SendEncryptedAction.java | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailUtils.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailUtils.java index b2fdf1550..88d97347b 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailUtils.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailUtils.java @@ -666,6 +666,7 @@ import com.jdimension.jlawyer.client.editors.EditorsRegistry; import com.jdimension.jlawyer.client.settings.UserSettings; import com.jdimension.jlawyer.client.utils.StringUtils; +import com.jdimension.jlawyer.persistence.AddressBean; import com.jdimension.jlawyer.persistence.AppUserBean; import com.jdimension.jlawyer.persistence.MailboxSetup; import com.jdimension.jlawyer.security.Crypto; @@ -1210,6 +1211,19 @@ public static Folder getTrashFolder(Folder[] inbox) throws Exception { public static boolean isIMAP(Folder f) { return (f instanceof IMAPFolder); } + + public static boolean sameCryptoPassword(AddressBean[] addresses) throws Exception { + ArrayList passwords=new ArrayList<>(); + for(AddressBean a: addresses) { + if(a.supportsCrypto()) { + if(!passwords.contains(a.getEncryptionPwd())) + passwords.add(a.getEncryptionPwd()); + } else { + return false; + } + } + return passwords.size()==1; + } // will only close the folder if it is IMAP, and do nothing otherwise public static void closeIfIMAP(Folder f) { diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java index a5409f2b9..19f5c9fec 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java @@ -1973,7 +1973,9 @@ private int cryptoRecipients(ArrayList mails) throws Exception { for (String m : mails) { AddressBean[] found = adr.searchSimple(m); if (found.length > 1) { - throw new Exception(m + " ist mehreren Kontakten zugeordnet - Verschlüsselung nicht möglich!"); + if(!EmailUtils.sameCryptoPassword(found)) { + throw new Exception(m + " ist mehreren Kontakten mit unterschiedlichen Verschlüsselungseinstellungen zugeordnet!"); + } } if (found.length == 0) { continue; @@ -1984,7 +1986,7 @@ private int cryptoRecipients(ArrayList mails) throws Exception { } return cryptoSupported; } - + private void cmdAttachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAttachActionPerformed String caseId = null; 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 695f64a9b..048c8f815 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 @@ -845,7 +845,7 @@ public PasswordAuthentication getPasswordAuthentication() { JLawyerServiceLocator locator = JLawyerServiceLocator.getInstance(settings.getLookupProperties()); AddressServiceRemote adr = locator.lookupAddressServiceRemote(); AddressBean[] found = adr.searchSimple(currentRecipientMail); - if (found != null && found.length == 1 && found[0].supportsCrypto()) { + if (found != null && found.length>0 && EmailUtils.sameCryptoPassword(found) && found[0].supportsCrypto()) { File fIn = new File(unencrypted); String fInDir = fIn.getParentFile().getPath(); String enc = PDFEncryptor.encryptPdf(unencrypted, fInDir, found[0].getEncryptionPwd());