Skip to content

Commit

Permalink
improve sending encrypted to mail address that is used in multiple ad…
Browse files Browse the repository at this point in the history
…dresses. close #2074
  • Loading branch information
j-dimension committed Sep 14, 2023
1 parent f2ec818 commit 57a7ed0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,9 @@ private int cryptoRecipients(ArrayList<String> 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;
Expand All @@ -1984,7 +1986,7 @@ private int cryptoRecipients(ArrayList<String> mails) throws Exception {
}
return cryptoSupported;
}

private void cmdAttachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAttachActionPerformed

String caseId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 57a7ed0

Please sign in to comment.