FileDocCategorySizeDatePackage
SMIMECompressedGenerator.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)4411Wed Oct 01 10:55:28 BST 2008org.bouncycastle.mail.smime

SMIMECompressedGenerator

public class SMIMECompressedGenerator extends SMIMEGenerator
General class for generating a pkcs7-mime compressed message. A simple example of usage.
SMIMECompressedGenerator fact = new SMIMECompressedGenerator();

MimeBodyPart smime = fact.generate(content, algorithm);
Note: Most clients expect the MimeBodyPart to be in a MimeMultipart when it's sent.

Fields Summary
public static final String
ZLIB
private static final String
COMPRESSED_CONTENT_TYPE
Constructors Summary
Methods Summary
public javax.mail.internet.MimeBodyPartgenerate(javax.mail.internet.MimeBodyPart content, java.lang.String compressionOID)
generate an compressed object that contains an SMIME Compressed object using the given provider from the contents of the passed in message

        return make(makeContentBodyPart(content), compressionOID);
    
public javax.mail.internet.MimeBodyPartgenerate(javax.mail.internet.MimeMessage message, java.lang.String compressionOID)
generate an compressed object that contains an SMIME Compressed object using the given provider from the contents of the passed in message

        try
        {
            message.saveChanges();      // make sure we're up to date.
        }
        catch (MessagingException e)
        {
            throw new SMIMEException("unable to save message", e);
        }
                        
        return make(makeContentBodyPart(message), compressionOID);
    
private javax.mail.internet.MimeBodyPartmake(javax.mail.internet.MimeBodyPart content, java.lang.String compressionOID)
generate an compressed object that contains an SMIME Compressed object using the given compression algorithm.


    
    
        MailcapCommandMap mc = (MailcapCommandMap)CommandMap.getDefaultCommandMap();

        mc.addMailcap("application/pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_mime");
        mc.addMailcap("application/x-pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_mime");

        CommandMap.setDefaultCommandMap(mc);
    
        try
        {  
            MimeBodyPart data = new MimeBodyPart();
        
            data.setContent(new ContentCompressor(content, compressionOID), COMPRESSED_CONTENT_TYPE);
            data.addHeader("Content-Type", COMPRESSED_CONTENT_TYPE);
            data.addHeader("Content-Disposition", "attachment; filename=\"smime.p7z\"");
            data.addHeader("Content-Description", "S/MIME Compressed Message");
            data.addHeader("Content-Transfer-Encoding", encoding);

            return data;
        }
        catch (MessagingException e)
        {
            throw new SMIMEException("exception putting multi-part together.", e);
        }