1 package SnowMailClient.gnupg.model; 2 3 import java.text.*; 4 import java.util.*; 5 import SnowMailClient.Language.*; 6 7 public final class SignatureVerificationResult 8 { 9 final static private SimpleDateFormat madeFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss"); 10 private boolean goodSignature = false; 11 12 private String madeString = ""; 13 private long madeDate = -1; 14 private String signatureFrom = ""; 15 private String warning = ""; 16 17 public SignatureVerificationResult() 18 { 19 } 20 21 24 public void parseLine(String line) throws Exception 25 { 26 int pos = line.indexOf("Signature made"); 27 if(pos>=0) 28 { 29 madeString = line.substring(pos+15); 30 try 32 { 33 madeDate = madeFormat.parse(madeString).getTime(); 34 } 35 catch(Exception e) { e.printStackTrace(); } 36 } 37 38 pos = line.indexOf("Good signature"); 39 if(pos>=0) 40 { 41 goodSignature = true; 42 pos = line.indexOf("from"); 43 if(pos==-1) throw new Exception ("No from in the good signature text"); 44 signatureFrom = line.substring(pos+5); 45 } 46 47 pos = line.indexOf("BAD signature"); 48 if(pos>=0) 49 { 50 goodSignature = false; 51 pos = line.indexOf("from"); 52 if(pos==-1) throw new Exception ("No from in the good signature text"); 53 signatureFrom = line.substring(pos+5); 54 } 55 56 pos = line.toUpperCase().indexOf("WARNING"); 57 if(pos>=0) 58 { 59 warning = line.substring(pos+9).trim(); 60 } 61 } 62 63 public boolean isSignatureGood() { return goodSignature; } 64 public String getSigner() { return signatureFrom; } 65 public long getSignatureDate() { return this.madeDate; } 66 67 68 public String toString() 69 { 70 StringBuffer sb = new StringBuffer (); 71 if(goodSignature) 72 { 73 sb.append( Language.translate("GOOD signature from %", signatureFrom) + " ("+madeFormat.format(new Date(madeDate))+")" ); 75 } 76 else 77 { 78 sb.append( Language.translate("BAD signature from %", signatureFrom) ); 79 } 80 81 if(warning.length()>0) 82 { 83 sb.append("\n "+Language.translate("Warning")+": "+warning); 84 } 85 86 return sb.toString(); 87 } 88 89 90 91 92 } | Popular Tags |