01: package org.bouncycastle.mail.smime;
02:
03: import java.io.BufferedInputStream;
04: import java.io.IOException;
05: import java.io.InputStream;
06:
07: import javax.mail.MessagingException;
08: import javax.mail.Part;
09: import javax.mail.internet.MimeBodyPart;
10: import javax.mail.internet.MimeMessage;
11: import javax.mail.internet.MimePart;
12:
13: import org.bouncycastle.cms.CMSCompressedDataParser;
14: import org.bouncycastle.cms.CMSException;
15:
16: /**
17: * Stream based containing class for an S/MIME pkcs7-mime compressed MimePart.
18: */
19: public class SMIMECompressedParser extends CMSCompressedDataParser {
20: private final MimePart message;
21:
22: private static InputStream getInputStream(Part bodyPart,
23: int bufferSize) throws MessagingException {
24: try {
25: InputStream in = bodyPart.getInputStream();
26:
27: if (bufferSize == 0) {
28: return new BufferedInputStream(in);
29: } else {
30: return new BufferedInputStream(in, bufferSize);
31: }
32: } catch (IOException e) {
33: throw new MessagingException("can't extract input stream: "
34: + e);
35: }
36: }
37:
38: public SMIMECompressedParser(MimeBodyPart message)
39: throws MessagingException, CMSException {
40: this (message, 0);
41: }
42:
43: public SMIMECompressedParser(MimeMessage message)
44: throws MessagingException, CMSException {
45: this (message, 0);
46: }
47:
48: /**
49: * Create a parser from a MimeBodyPart using the passed in buffer size
50: * for reading it.
51: *
52: * @param message body part to be parsed.
53: * @param bufferSize bufferSoze to be used.
54: */
55: public SMIMECompressedParser(MimeBodyPart message, int bufferSize)
56: throws MessagingException, CMSException {
57: super (getInputStream(message, bufferSize));
58:
59: this .message = message;
60: }
61:
62: /**
63: * Create a parser from a MimeMessage using the passed in buffer size
64: * for reading it.
65: *
66: * @param message message to be parsed.
67: * @param bufferSize bufferSoze to be used.
68: */
69: public SMIMECompressedParser(MimeMessage message, int bufferSize)
70: throws MessagingException, CMSException {
71: super (getInputStream(message, bufferSize));
72:
73: this .message = message;
74: }
75:
76: public MimePart getCompressedContent() {
77: return message;
78: }
79: }
|