1 20 21 package org.jdesktop.jdic.desktop; 22 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 30 38 public class Message { 39 40 43 private List toAddrs; 44 45 48 private List ccAddrs; 49 50 53 private List bccAddrs; 54 55 58 private String subject; 59 60 63 private String body; 64 65 68 private List attachments; 69 70 73 public Message() { 74 toAddrs= new ArrayList (); 75 ccAddrs = new ArrayList (); 76 bccAddrs = new ArrayList (); 77 attachments = new ArrayList (); 78 } 79 80 85 public Iterator getToAddrs() { 86 return toAddrs.iterator(); 87 } 88 89 94 public void setToAddrs(List atoList) { 95 toAddrs.clear(); 96 97 if(atoList == null) 98 return; 99 Iterator iter = atoList.iterator(); 100 if(iter == null) 101 return; 102 while(iter.hasNext()) 103 toAddrs.add(iter.next()); 104 } 105 106 111 public Iterator getCcAddrs() { 112 return ccAddrs.iterator(); 113 } 114 115 120 public void setCcAddrs(List accList) { 121 ccAddrs.clear(); 122 123 if(accList == null) 124 return; 125 Iterator iter = accList.iterator(); 126 if(iter == null) 127 return; 128 while(iter.hasNext()) 129 ccAddrs.add(iter.next()); 130 } 131 132 137 public Iterator getBccAddrs() { 138 return bccAddrs.iterator(); 139 } 140 141 146 public void setBccAddrs(List abccList) { 147 bccAddrs.clear(); 148 149 if(abccList == null) 150 return; 151 Iterator iter = abccList.iterator(); 152 if(iter == null) 153 return; 154 while(iter.hasNext()) 155 bccAddrs.add(iter.next()); 156 } 157 158 159 164 public String getSubject() { 165 return subject; 166 } 167 168 174 public void setSubject(String asubject) { 175 subject = asubject; 176 } 177 178 183 public String getBody() { 184 return body; 185 } 186 187 192 public void setBody(String abody) { 193 body = abody; 194 } 195 196 202 public Iterator getAttachments() { 203 return attachments.iterator(); 204 } 205 206 213 public void setAttachments(List attachList) throws IOException { 214 boolean hasUnreadable = false; 215 boolean hasDuplicated = false; 216 List unattachedlist = new ArrayList (); 217 String unattach_filenames = ""; 218 attachments.clear(); 219 220 if(attachList == null) 221 return; 222 Iterator iter = attachList.iterator(); 223 if(iter == null) 224 return; 225 while(iter.hasNext()) { 226 String filename = (String )iter.next(); 227 Iterator inner_iter = attachments.iterator(); 228 if(inner_iter != null) { 229 while(inner_iter.hasNext()) { 230 if(hasDuplicated 231 = filename.equals((String )(inner_iter.next()))) 232 break; 233 } 234 } 235 if(hasDuplicated) 236 continue; 237 File attfile = new File (filename); 238 239 if (attfile.canRead() && !attfile.isHidden()) { 241 if (attfile.isFile()) 242 attachments.add(attfile.getAbsolutePath()); 243 } 244 245 else { 248 hasUnreadable = true; 249 unattachedlist.add(attfile.getAbsolutePath()); 250 continue; 251 } 252 } 253 254 if(hasUnreadable) { 256 Iterator unattach_iter = unattachedlist.iterator(); 257 if (unattach_iter != null) { 258 while(unattach_iter.hasNext()) { 259 unattach_filenames += (String )unattach_iter.next() + "\n"; 260 } 261 throw new IOException ("Following files cannot be added to " + 262 "the attachments:\n" + unattach_filenames); 263 } 264 } 265 } 266 } 267 | Popular Tags |