1 26 27 package org.objectweb.jonas.mail.factory; 28 29 import java.util.Properties ; 31 32 import javax.naming.BinaryRefAddr ; 33 import javax.naming.NamingException ; 34 import javax.naming.Reference ; 35 36 import org.objectweb.jonas.common.PropDump; 37 import org.objectweb.jonas.common.JNDIUtils; 38 import org.objectweb.jonas.mail.MailService; 39 import org.objectweb.jonas.service.ServiceManager; 40 import org.objectweb.util.monolog.api.BasicLevel; 41 42 47 public class JavaMailMimePartDS extends JavaMail { 48 49 52 private static final String FACTORY_TYPE = "javax.mail.internet.MimePartDataSource"; 53 54 57 private Properties messageProperties = null; 58 59 62 protected static final String MIMEMESSAGE_TO = "mail.to"; 63 64 67 68 protected static final String MIMEMESSAGE_CC = "mail.cc"; 69 70 73 protected static final String MIMEMESSAGE_BCC = "mail.bcc"; 74 75 78 protected static final String MIMEMESSAGE_SUBJECT = "mail.subject"; 79 80 83 85 89 public String getType() { 90 return FACTORY_TYPE; 91 } 92 93 94 100 public JavaMailMimePartDS(String factoryName, String name, Properties mailProperties) { 101 super(factoryName, name, mailProperties); 102 103 PropDump.print("Received props:", mailProperties, getLogger(), BasicLevel.DEBUG); 104 105 messageProperties = new Properties (); 107 String propValue = null; 108 propValue = (String ) getMailSessionProperties().remove(MIMEMESSAGE_TO); 109 if (propValue != null) { 110 messageProperties.setProperty(MIMEMESSAGE_TO, propValue); 111 } 112 propValue = (String ) getMailSessionProperties().remove(MIMEMESSAGE_CC); 113 if (propValue != null) { 114 messageProperties.setProperty(MIMEMESSAGE_CC, propValue); 115 } 116 propValue = (String ) getMailSessionProperties().remove(MIMEMESSAGE_BCC); 117 if (propValue != null) { 118 messageProperties.setProperty(MIMEMESSAGE_BCC, propValue); 119 } 120 propValue = (String ) getMailSessionProperties().remove(MIMEMESSAGE_SUBJECT); 121 if (propValue != null) { 122 messageProperties.setProperty(MIMEMESSAGE_SUBJECT, propValue); 123 } 124 125 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 126 PropDump.print("Message props:", messageProperties, getLogger(), BasicLevel.DEBUG); 127 } 128 } 129 130 131 135 Properties getMimeMessageProperties() { 136 return messageProperties; 137 } 138 139 143 void setMimeMessageProperties(Properties props) { 144 this.messageProperties = props; 145 try { 146 ((MailService) ServiceManager.getInstance().getMailService()).recreateJavaMailFactory(this); 147 } catch (Exception e) { 148 } 150 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 152 PropDump.print("These are the udated message props", 153 this.messageProperties, getLogger(), BasicLevel.DEBUG); 154 } 155 } 156 157 158 168 public Reference getReference() throws NamingException { 169 170 Reference reference = new Reference (FACTORY_TYPE, 172 "org.objectweb.jonas.mail.factory.JavaMailMimePartDSFactory", 173 null); 174 byte[] bytes = null; 175 176 bytes = JNDIUtils.getBytesFromObject(getMailSessionProperties()); 178 if (bytes != null) { 179 reference.add(new BinaryRefAddr ("javaxmailSession.properties", bytes)); 180 } 181 182 bytes = JNDIUtils.getBytesFromObject(messageProperties); 184 if (bytes != null) { 185 reference.add(new BinaryRefAddr ("javaxInternetMimeMessage.properties", bytes)); 186 } 187 188 bytes = JNDIUtils.getBytesFromObject(getAuthenticationProperties()); 190 if (bytes != null) { 191 reference.add(new BinaryRefAddr ("authentication.properties", bytes)); 192 } 193 194 return reference; 195 196 } 197 } 198 | Popular Tags |