1 17 18 package javax.mail; 19 import java.io.IOException; 20 import java.io.InputStream; 21 import java.io.OutputStream; 22 import java.util.Arrays; 23 import java.util.Date; 24 import java.util.Enumeration; 25 import java.util.LinkedList; 26 import java.util.List; 27 import javax.activation.DataHandler; 28 import javax.mail.internet.InternetAddress; 29 32 public class SimpleTextMessage extends Message { 33 public static final Address[] ADDRESS_ARRAY = new Address[0]; 34 private List _bcc = new LinkedList(); 35 private List _cc = new LinkedList(); 36 private String _description; 37 private Flags _flags = new Flags(); 38 private List _from = new LinkedList(); 39 private Date _received; 40 private Date _sent; 41 private String _subject; 42 private String _text; 43 private List _to = new LinkedList(); 44 48 public SimpleTextMessage(Folder folder, int number) { 49 super(folder, number); 50 } 51 54 public void addFrom(Address[] addresses) throws MessagingException { 55 _from.addAll(Arrays.asList(addresses)); 56 } 57 60 public void addHeader(String name, String value) 61 throws MessagingException { 62 throw new UnsupportedOperationException("Method not implemented"); 63 } 64 67 public void addRecipients(RecipientType type, Address[] addresses) 68 throws MessagingException { 69 getList(type).addAll(Arrays.asList(addresses)); 70 } 71 74 public Enumeration getAllHeaders() throws MessagingException { 75 throw new UnsupportedOperationException("Method not implemented"); 76 } 77 80 public Object getContent() throws IOException, MessagingException { 81 return _text; 82 } 83 86 public String getContentType() throws MessagingException { 87 return "text/plain"; 88 } 89 92 public DataHandler getDataHandler() throws MessagingException { 93 throw new UnsupportedOperationException("Method not implemented"); 94 } 95 98 public String getDescription() throws MessagingException { 99 return _description; 100 } 101 104 public String getDisposition() throws MessagingException { 105 return Part.INLINE; 106 } 107 110 public String getFileName() throws MessagingException { 111 return null; 112 } 113 116 public Flags getFlags() throws MessagingException { 117 return _flags; 118 } 119 122 public Address[] getFrom() throws MessagingException { 123 return (Address[]) _from.toArray(ADDRESS_ARRAY); 124 } 125 128 public String[] getHeader(String name) throws MessagingException { 129 throw new UnsupportedOperationException("Method not implemented"); 130 } 131 134 public InputStream getInputStream() 135 throws IOException, MessagingException { 136 throw new UnsupportedOperationException("Method not implemented"); 137 } 138 141 public int getLineCount() throws MessagingException { 142 throw new UnsupportedOperationException("Method not implemented"); 143 } 144 private List getList(RecipientType type) throws MessagingException { 145 List list; 146 if (type == RecipientType.TO) { 147 list = _to; 148 } else if (type == RecipientType.CC) { 149 list = _cc; 150 } else if (type == RecipientType.BCC) { 151 list = _bcc; 152 } else { 153 throw new MessagingException("Address type not understood"); 154 } 155 return list; 156 } 157 160 public Enumeration getMatchingHeaders(String[] names) 161 throws MessagingException { 162 throw new UnsupportedOperationException("Method not implemented"); 163 } 164 167 public Enumeration getNonMatchingHeaders(String[] names) 168 throws MessagingException { 169 throw new UnsupportedOperationException("Method not implemented"); 170 } 171 174 public Date getReceivedDate() throws MessagingException { 175 return _received; 176 } 177 180 public Address[] getRecipients(RecipientType type) 181 throws MessagingException { 182 return (Address[]) getList(type).toArray(ADDRESS_ARRAY); 183 } 184 187 public Date getSentDate() throws MessagingException { 188 return _sent; 189 } 190 193 public int getSize() throws MessagingException { 194 return _text.length(); 195 } 196 199 public String getSubject() throws MessagingException { 200 return _subject; 201 } 202 205 public boolean isMimeType(String mimeType) throws MessagingException { 206 return mimeType.equals("text/plain") || mimeType.equals("text/*"); 207 } 208 211 public void removeHeader(String name) throws MessagingException { 212 throw new UnsupportedOperationException("Method not implemented"); 213 } 214 217 public Message reply(boolean replyToAll) throws MessagingException { 218 try { 219 SimpleTextMessage reply = (SimpleTextMessage) this.clone(); 220 reply._to = new LinkedList(_from); 221 if (replyToAll) { 222 reply._to.addAll(_cc); 223 } 224 return reply; 225 } catch (CloneNotSupportedException e) { 226 throw new MessagingException(e.getMessage()); 227 } 228 } 229 232 public void saveChanges() throws MessagingException { 233 throw new UnsupportedOperationException("Method not implemented"); 234 } 235 238 public void setContent(Multipart content) throws MessagingException { 239 throw new UnsupportedOperationException("Method not implemented"); 240 } 241 244 public void setContent(Object content, String type) 245 throws MessagingException { 246 setText((String) content); 247 } 248 251 public void setDataHandler(DataHandler handler) throws MessagingException { 252 throw new UnsupportedOperationException("Method not implemented"); 253 } 254 257 public void setDescription(String description) throws MessagingException { 258 _description = description; 259 } 260 263 public void setDisposition(String disposition) throws MessagingException { 264 throw new UnsupportedOperationException("Method not implemented"); 265 } 266 269 public void setFileName(String name) throws MessagingException { 270 throw new UnsupportedOperationException("Method not implemented"); 271 } 272 275 public void setFlags(Flags flags, boolean set) throws MessagingException { 276 if (set) { 277 _flags.add(flags); 278 } else { 279 _flags.remove(flags); 280 } 281 } 282 285 public void setFrom() throws MessagingException { 286 setFrom(new InternetAddress("root@localhost")); 287 } 288 291 public void setFrom(Address address) throws MessagingException { 292 _from.clear(); 293 _from.add(address); 294 } 295 298 public void setHeader(String name, String value) 299 throws MessagingException { 300 throw new UnsupportedOperationException("Method not implemented"); 301 } 302 305 public void setRecipients(RecipientType type, Address[] addresses) 306 throws MessagingException { 307 List list = getList(type); 308 list.clear(); 309 list.addAll(Arrays.asList(addresses)); 310 } 311 314 public void setSentDate(Date sent) throws MessagingException { 315 _sent = sent; 316 } 317 320 public void setSubject(String subject) throws MessagingException { 321 _subject = subject; 322 } 323 326 public void setText(String content) throws MessagingException { 327 _text = content; 328 } 329 332 public void writeTo(OutputStream out) 333 throws IOException, MessagingException { 334 throw new UnsupportedOperationException("Method not implemented"); 335 } 336 } 337 | Popular Tags |