01: package org.bouncycastle.mail.smime;
02:
03: import org.bouncycastle.cms.CMSException;
04: import org.bouncycastle.cms.CMSProcessable;
05: import org.bouncycastle.mail.smime.util.CRLFOutputStream;
06:
07: import javax.mail.BodyPart;
08: import javax.mail.MessagingException;
09: import javax.mail.internet.MimeBodyPart;
10: import java.io.IOException;
11: import java.io.OutputStream;
12:
13: /**
14: * a holding class for a BodyPart to be processed which does CRLF canocicalisation if
15: * dealing with non-binary data.
16: */
17: public class CMSProcessableBodyPartOutbound implements CMSProcessable {
18: private BodyPart bodyPart;
19: private String defaultContentTransferEncoding;
20:
21: /**
22: * Create a processable with the default transfer encoding of 7bit
23: *
24: * @param bodyPart body part to be processed
25: */
26: public CMSProcessableBodyPartOutbound(BodyPart bodyPart) {
27: this .bodyPart = bodyPart;
28: }
29:
30: /**
31: * Create a processable with the a default transfer encoding of
32: * the passed in value.
33: *
34: * @param bodyPart body part to be processed
35: * @param defaultContentTransferEncoding the new default to use.
36: */
37: public CMSProcessableBodyPartOutbound(BodyPart bodyPart,
38: String defaultContentTransferEncoding) {
39: this .bodyPart = bodyPart;
40: this .defaultContentTransferEncoding = defaultContentTransferEncoding;
41: }
42:
43: public void write(OutputStream out) throws IOException,
44: CMSException {
45: try {
46: if (SMIMEUtil.isCanonicalisationRequired(
47: (MimeBodyPart) bodyPart,
48: defaultContentTransferEncoding)) {
49: out = new CRLFOutputStream(out);
50: }
51:
52: bodyPart.writeTo(out);
53: } catch (MessagingException e) {
54: throw new CMSException("can't write BodyPart to stream.", e);
55: }
56: }
57:
58: public Object getContent() {
59: return bodyPart;
60: }
61: }
|