1 package net.suberic.pooka.crypto; 2 3 import net.suberic.pooka.*; 4 import net.suberic.crypto.*; 5 6 import javax.mail.internet.*; 7 import javax.mail.*; 8 import javax.activation.DataHandler ; 9 10 import java.security.Key ; 11 12 import java.io.*; 13 14 17 public class CryptoAttachment extends Attachment { 18 19 boolean parsed = false; 20 21 boolean encrypted = false; 22 23 boolean signed = false; 24 25 BodyPart decryptedBodyPart = null; 26 27 DataHandler msgDataHandler = null; 28 29 32 public CryptoAttachment(MimePart mp) throws MessagingException { 33 super(mp); 34 ContentType ct = new ContentType(mp.getContentType()); 35 if (ct.getSubType().equalsIgnoreCase("encrypted")) 36 encrypted = true; 37 else if (ct.getSubType().equalsIgnoreCase("signed")) 38 signed = true; 39 else if (ct.getPrimaryType().equalsIgnoreCase("application") && ct.getSubType().equalsIgnoreCase("pkcs7-mime")) { 40 encrypted = true; 41 } 42 } 43 44 47 public BodyPart decryptAttachment(EncryptionUtils utils, Key key) 48 throws MessagingException, java.io.IOException , java.security.GeneralSecurityException { 49 50 if (decryptedBodyPart != null) 51 return decryptedBodyPart; 52 else { 53 MimeBodyPart mbp = new MimeBodyPart(); 54 mbp.setDataHandler(super.getDataHandler()); 55 mbp.setHeader("Content-Type", super.getDataHandler().getContentType()); 56 57 decryptedBodyPart = utils.decryptBodyPart(mbp, key); 58 59 return decryptedBodyPart; 60 } 61 62 } 63 64 66 74 public String getText(boolean withHeaders, boolean showFullHeaders, int maxLength, String truncationMessage) throws java.io.IOException { 75 StringBuffer retVal = new StringBuffer (); 76 if (withHeaders) 77 retVal.append(getHeaderInformation(showFullHeaders)); 78 79 retVal.append(Pooka.getProperty("Pooka.crypto.encryptedMessage", "****** This is an encrypted message. Click on the 'encryption' button or go to Encrypt->Decrypt message to read it. ******")); 80 81 return retVal.toString(); 82 } 83 84 87 public boolean decryptedSuccessfully() { 88 return (decryptedBodyPart != null); 89 } 90 91 } 92 | Popular Tags |