1 package com.openedit.modules.email; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 import javax.mail.MessagingException ; 8 9 import com.openedit.OpenEditException; 10 import com.openedit.WebPageRequest; 11 import com.openedit.page.Page; 12 import com.openedit.page.PageRequestKeys; 13 14 public abstract class WebEmail 15 { 16 public static final String EMAIL_TEMPLATE_REQUEST_PARAMETER = "e-mail_layout"; 17 18 protected List fieldRecipients; 19 protected String fieldFrom; 20 protected String fieldSubject; 21 protected String fieldWebServerName; 22 protected WebPageRequest fieldWebPageContext; 23 24 protected String fieldMessage; 25 protected String fieldAlternativeMessage; 26 protected PostMail postMail; 27 public PostMail getPostMail() { 28 return postMail; 29 } 30 31 public void setPostMail(PostMail postMail) { 32 this.postMail = postMail; 33 } 34 protected WebEmail() 35 { 36 37 } 38 39 public WebPageRequest getWebPageContext() 40 { 41 return fieldWebPageContext; 42 } 43 public void loadSettings( Page inPage ) throws OpenEditException 44 { 45 String from = inPage.get( "from" ); 46 setFrom(from); 47 48 String subject = inPage.get( "subject" ); 49 setSubject(subject); 50 51 String to = inPage.get( "to" ); 52 if( to != null) 53 { 54 setTo(to); 55 } 56 57 } 58 public void loadSettings( WebPageRequest inContext) throws OpenEditException 59 { 60 Page page = inContext.getPage(); 61 loadSettings(page); 62 if( getFrom() == null) 63 { 64 String from = inContext.getRequestParameter( "from" ); 65 setFrom( from ); 66 } 67 if( getSubject() == null) 68 { 69 String subject = inContext.getRequestParameter( "subject" ); 70 setSubject(subject); 71 } 72 if( getRecipients() == null || getRecipients().size() == 0) 73 { 74 String to = inContext.getRequestParameter( "to" ); 75 setTo( to ); 76 } 77 78 setWebServerName( (String ) inContext.getPageValue(PageRequestKeys.WEB_SERVER_PATH)); 80 setWebPageContext(inContext); 81 } 82 83 public List getRecipients() 84 { 85 86 return fieldRecipients; 87 } 88 89 public String [] getTo() 90 { 91 if( getRecipients() == null) 92 { 93 return null; 94 } 95 String [] tos = new String [getRecipients().size()]; 96 for (int i = 0; i < getRecipients().size(); i++) 97 { 98 Recipient rec = (Recipient) getRecipients().get(i); 99 tos[i] = rec.getEmailAddress(); 100 } 101 return tos; 102 } 103 104 public void setTo(String inTo) 105 { 106 List recipients = new ArrayList (); 107 String [] emails = inTo.split(","); 108 for (int i = 0; i < emails.length; i++) 109 { 110 String value = emails[i].trim(); 111 Recipient recipient = parseRecipient(value); 112 113 recipients.add( recipient ); 114 } 115 setRecipients(recipients); 116 } 117 118 private Recipient parseRecipient(String inValue) 119 { 120 Recipient rec = new Recipient(); 121 rec.setEmailAddress( inValue ); 122 123 return rec; 124 } 125 126 public String getWebServerName() 127 { 128 return fieldWebServerName; 129 } 130 131 public void setWebServerName(String inWebServerName) 132 { 133 fieldWebServerName = inWebServerName; 134 } 135 136 public String getFrom() 137 { 138 return fieldFrom; 139 } 140 141 public void setFrom(String inFrom) 142 { 143 fieldFrom = inFrom; 144 } 145 146 public String getSubject() 147 { 148 return fieldSubject; 149 } 150 151 public void setSubject(String inSubject) 152 { 153 fieldSubject = inSubject; 154 } 155 156 public void setWebPageContext(WebPageRequest inWebPageContext) 157 { 158 fieldWebPageContext = inWebPageContext; 159 } 160 161 public void setRecipients(List inList) 162 { 163 fieldRecipients = inList; 164 } 165 166 public void setRecipientsFromStrings(List inToAddresses) 167 { 168 List all = new ArrayList (); 169 for (Iterator iter = inToAddresses.iterator(); iter.hasNext();) 170 { 171 String email = (String ) iter.next(); 172 Recipient one = parseRecipient(email); 173 all.add(one); 174 } 175 setRecipients(all); 176 } 177 178 public void setRecipient(Recipient inRecipient) 179 { 180 List one = new ArrayList (1); 181 one.add(inRecipient); 182 setRecipients(one); 183 } 184 185 public String getMessage() 186 { 187 return fieldMessage; 188 } 189 190 public void setMessage(String inMessage) 191 { 192 fieldMessage = inMessage; 193 } 194 195 public String getAlternativeMessage() 196 { 197 return fieldAlternativeMessage; 198 } 199 200 public void setAlternativeMessage(String inAlternativeMessage) 201 { 202 fieldAlternativeMessage = inAlternativeMessage; 203 } 204 205 public abstract void send() throws OpenEditException, MessagingException ; 206 } 207 | Popular Tags |