1 21 22 27 package com.sun.mail.handlers; 28 29 import java.io.*; 30 import java.util.Properties ; 31 import java.awt.datatransfer.DataFlavor ; 32 import javax.activation.*; 33 import javax.mail.*; 34 import javax.mail.internet.*; 35 36 37 41 42 43 public class message_rfc822 implements DataContentHandler { 44 45 ActivationDataFlavor ourDataFlavor = new ActivationDataFlavor( 46 javax.mail.Message .class, 47 "message/rfc822", 48 "Message"); 49 50 54 public DataFlavor [] getTransferDataFlavors() { 55 return new DataFlavor [] { ourDataFlavor }; 56 } 57 58 64 public Object getTransferData(DataFlavor df, DataSource ds) 65 throws IOException { 66 if (ourDataFlavor.equals(df)) 68 return getContent(ds); 69 else 70 return null; 71 } 72 73 76 public Object getContent(DataSource ds) throws IOException { 77 try { 79 Session session; 80 if (ds instanceof MessageAware) { 81 MessageContext mc = ((MessageAware)ds).getMessageContext(); 82 session = mc.getSession(); 83 } else { 84 session = Session.getDefaultInstance(new Properties (), null); 89 } 90 return new MimeMessage(session, ds.getInputStream()); 91 } catch (MessagingException me) { 92 throw new IOException("Exception creating MimeMessage in " + 93 "message/rfc822 DataContentHandler: " + me.toString()); 94 } 95 } 96 97 102 public void writeTo(Object obj, String mimeType, OutputStream os) 103 throws IOException { 104 if (obj instanceof Message) { 106 Message m = (Message)obj; 107 try { 108 m.writeTo(os); 109 } catch (MessagingException me) { 110 throw new IOException(me.toString()); 111 } 112 113 } else { 114 throw new IOException("unsupported object"); 115 } 116 } 117 } 118 | Popular Tags |