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 SignedAttachment extends Attachment { 18 19 boolean parsed = false; 20 21 24 public SignedAttachment(MimePart mp) throws MessagingException { 25 super(mp); 26 } 27 28 31 public boolean checkSignature(EncryptionUtils utils, Key key) 32 throws MessagingException, java.io.IOException , java.security.GeneralSecurityException { 33 34 Object content = getDataHandler().getContent(); 35 if (content instanceof MimeMultipart) { 36 return utils.checkSignature((MimeMultipart) content, key); 37 } else { 38 return false; 39 } 40 } 41 42 45 public MimeBodyPart getSignedPart() throws javax.mail.MessagingException , 46 java.io.IOException { 47 Object content = getDataHandler().getContent(); 48 if (content instanceof MimeMultipart) { 49 MimeMultipart mm = (MimeMultipart) content; 50 51 for (int i = 0; i < mm.getCount(); i++) { 54 MimeBodyPart mbp = (MimeBodyPart) mm.getBodyPart(i); 56 ContentType ct = new ContentType(mbp.getContentType()); 57 if (! ct.getSubType().toLowerCase().endsWith("signature")) { 58 return mbp; 59 } 60 } 61 } 62 63 return null; 64 } 65 66 69 public DataHandler getDataHandler() { 70 return super.getDataHandler(); 71 } 72 73 74 77 86 } 87 | Popular Tags |