1 package SnowMailClient.gnupg; 2 3 import SnowMailClient.model.*; 4 import snow.utils.gui.*; 5 import snow.concurrent.*; 6 import SnowMailClient.SnowMailClientApp; 7 import SnowMailClient.gnupg.model.*; 8 import SnowMailClient.Language.*; 9 import java.util.*; 10 11 13 public final class MessageActions 14 { 15 public MessageActions() 16 { 17 } 18 19 23 public static void prepare_Signing_Mail( MailMessage mess, Interrupter interrupter) throws Exception 24 { 25 String fromMailAddress = mess.getFromAddress().getMailAddress(); 26 GnuPGLink gpg = SnowMailClientApp.getInstance().getGnuPGLink(); 27 28 if(!gpg.isGPG_available()) 29 { 30 throw new Exception (Language.translate("GnuPG is not available, please install it first or send without signing.")); 31 } 32 33 GnuPGKeyID[] kids = gpg.getSecretKeyIDForAddress(fromMailAddress); 34 if(kids.length==0) throw new Exception (Language.translate("No key to sign with %", fromMailAddress)); 35 36 byte[] pass = gpg.getPasswordForKeyAskIfNotFoundOrNotValid(kids[0], true, SnowMailClientApp.getInstance()); 37 if(pass==null) throw new Exception (Language.translate("No password given to sign with %", fromMailAddress)); 38 39 41 if(mess.getMimeTree().isMimeMessageFormat()) 42 { 43 throw new Exception ("Signing messages with attachement is not implemented yet !"); 44 } 45 46 String signedTest = gpg.sign(mess.getCompleteContentAsString(), kids[0], pass, interrupter); 47 48 49 } 50 51 52 54 public static void prepareEncryptMail(MailMessage mess) throws Exception 55 { 56 Vector<Address> toMailAddress = mess.getToAddresses(); 57 if(toMailAddress.size()>1) 58 { 59 throw new Exception (Language.translate("Only one recipient is allowed for encrypted mail")); 60 } 61 62 GnuPGLink gpg = SnowMailClientApp.getInstance().getGnuPGLink(); 63 64 if(!gpg.isGPG_available()) 65 { 66 throw new Exception (Language.translate("GnuPG is not available, please install it first or send without encrypting.")); 67 } 68 69 StringBuffer errorBuffer = new StringBuffer (); 70 for(Address to: toMailAddress) 71 { 72 String toAddress = to.getMailAddress(); 73 GnuPGKeyID[] kids = gpg.getPublicKeyIDForAddress(toAddress); 74 if(kids.length==0) 75 { 76 errorBuffer.append("\n" + toAddress); 77 } 78 else 79 { 80 GnuPGKeyID kid = kids[0]; 82 String ct = kid.getCalculatedTrust(); 83 if(!(ct.equals("u") || ct.equals("f"))) 84 { 85 errorBuffer.append("\n"+Language.translate("Bad trust for %", toAddress)+": "+kid.getCalculatedTrustMessage()); 86 } 87 } 88 } 89 90 if(errorBuffer.length()>0) 91 { 92 throw new Exception ( 93 Language.translate("No public keys found for following recipient,\nplease import them first or do not encrypt.") 94 +"\n"+errorBuffer.toString()); 95 } 96 97 } 98 99 } | Popular Tags |