01: package org.bouncycastle.mail.smime.examples;
02:
03: import java.io.File;
04: import java.io.FileOutputStream;
05: import java.util.Properties;
06:
07: import javax.activation.DataHandler;
08: import javax.activation.FileDataSource;
09: import javax.mail.Address;
10: import javax.mail.Message;
11: import javax.mail.Session;
12: import javax.mail.internet.InternetAddress;
13: import javax.mail.internet.MimeBodyPart;
14: import javax.mail.internet.MimeMessage;
15:
16: import org.bouncycastle.mail.smime.SMIMECompressedGenerator;
17:
18: /**
19: * a simple example that creates a single compressed mail message using the large
20: * file model.
21: */
22: public class CreateLargeCompressedMail {
23: public static void main(String args[]) throws Exception {
24: //
25: // create the generator for creating an smime/compressed message
26: //
27: SMIMECompressedGenerator gen = new SMIMECompressedGenerator();
28:
29: //
30: // create the base for our message
31: //
32: MimeBodyPart msg = new MimeBodyPart();
33:
34: msg.setDataHandler(new DataHandler(new FileDataSource(new File(
35: args[0]))));
36: msg.setHeader("Content-Type", "application/octet-stream");
37: msg.setHeader("Content-Transfer-Encoding", "binary");
38:
39: MimeBodyPart mp = gen.generate(msg,
40: SMIMECompressedGenerator.ZLIB);
41:
42: //
43: // Get a Session object and create the mail message
44: //
45: Properties props = System.getProperties();
46: Session session = Session.getDefaultInstance(props, null);
47:
48: Address fromUser = new InternetAddress(
49: "\"Eric H. Echidna\"<eric@bouncycastle.org>");
50: Address toUser = new InternetAddress("example@bouncycastle.org");
51:
52: MimeMessage body = new MimeMessage(session);
53: body.setFrom(fromUser);
54: body.setRecipient(Message.RecipientType.TO, toUser);
55: body.setSubject("example compressed message");
56: body.setContent(mp.getContent(), mp.getContentType());
57: body.saveChanges();
58:
59: body.writeTo(new FileOutputStream("compressed.message"));
60: }
61: }
|