1 7 8 package org.enhydra.oyster.mail; 9 10 import org.enhydra.oyster.smime.BaseSMIMEObject; 11 import org.enhydra.oyster.exception.SMIMEException; 12 import javax.mail.Multipart ; 13 import javax.mail.internet.MimeMessage ; 14 import javax.mail.internet.MimeBodyPart ; 15 import javax.mail.internet.MimeMultipart ; 16 import java.util.SimpleTimeZone ; 17 import java.util.GregorianCalendar ; 18 19 20 26 public class PureMIME extends BaseSMIMEObject 27 { 28 29 54 public PureMIME (String smtpHost, String fromAddress, String subject, 55 String content, String charset) throws SMIMEException 56 { 57 super(smtpHost, fromAddress, subject, content, charset); 58 } 59 60 61 80 public PureMIME (String smtpHost, String fromAddress, String subject, 81 String charset) throws SMIMEException 82 { 83 super(smtpHost, fromAddress, subject, null, charset); 84 } 85 86 87 104 public PureMIME (MimeMessage mimeMessage) throws SMIMEException 105 { 106 super(mimeMessage); 107 } 108 109 110 119 public void addRecipient (String recipientAddress, String type) throws SMIMEException 120 { 121 super.addRecipient(recipientAddress, type, null); 122 } 123 124 130 public void composeMessage() throws SMIMEException { 131 try { 132 if (super.indicatorTo != true) 133 throw new SMIMEException(this, 1043); 134 135 if(!super.externalMessagePresence) { 137 if (super.contentPresence & super.bodyPartArray.size() == 1) { if(super.bodyPartArray.elementAt(0) instanceof MimeBodyPart ) { MimeBodyPart contentBody = (MimeBodyPart )super.bodyPartArray.elementAt(0); 140 super.message.setContent((String )contentBody.getContent(), contentBody.getContentType()); 141 super.message.setDisposition(super.message.INLINE); 142 } 143 else super.message.setContent((MimeMultipart )super.bodyPartArray.elementAt(0)); 145 } 146 else if ( super.bodyPartArray.size() != 0) { 147 Multipart mp = new MimeMultipart (); 148 for (int i = 0; i != super.bodyPartArray.size(); i++) { 149 if(super.bodyPartArray.elementAt(i) instanceof MimeMultipart ) { 150 MimeBodyPart forMulti = new MimeBodyPart (); 151 forMulti.setContent((MimeMultipart )super.bodyPartArray.elementAt(i)); 152 mp.addBodyPart(forMulti); 153 } 154 else 155 mp.addBodyPart((MimeBodyPart )super.bodyPartArray.elementAt(i)); 156 } 157 super.message.setContent(mp); 158 } 159 else 160 throw new SMIMEException(this, 1044); 161 162 } 163 164 super.message.saveChanges(); 165 super.message.saveChanges(); 166 SimpleTimeZone tz = (SimpleTimeZone )SimpleTimeZone.getDefault(); GregorianCalendar cal = new GregorianCalendar (tz); 168 super.message.setSentDate(cal.getTime()); 169 170 clean(); 171 } 172 catch (Exception e) { 173 throw SMIMEException.getInstance(this, e, "composeMessage"); 174 } 175 176 } 177 178 181 private void clean () { 182 super.reset(); 183 System.gc(); } 185 186 } | Popular Tags |