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