1 21 22 27 28 package javax.mail; 29 30 import java.util.Vector ; 31 import java.util.Date ; 32 import java.util.Properties ; 33 import java.io.*; 34 import javax.mail.search.SearchTerm ; 35 36 69 70 public abstract class Message implements Part { 71 72 76 protected int msgnum = 0; 77 78 81 protected boolean expunged = false; 82 83 86 protected Folder folder = null; 87 88 91 protected Session session = null; 92 93 96 protected Message() { } 97 98 105 protected Message(Folder folder, int msgnum) { 106 this.folder = folder; 107 this.msgnum = msgnum; 108 session = folder.store.session; 109 } 110 111 117 protected Message(Session session) { 118 this.session = session; 119 } 120 121 136 public abstract Address [] getFrom() throws MessagingException ; 137 138 150 public abstract void setFrom() throws MessagingException ; 151 152 163 public abstract void setFrom(Address address) 164 throws MessagingException ; 165 166 177 public abstract void addFrom(Address [] addresses) 178 throws MessagingException ; 179 180 203 public static class RecipientType implements Serializable { 204 207 public static final RecipientType TO = new RecipientType("To"); 208 211 public static final RecipientType CC = new RecipientType("Cc"); 212 215 public static final RecipientType BCC = new RecipientType("Bcc"); 216 217 223 protected String type; 224 225 private static final long serialVersionUID = -7479791750606340008L; 226 227 230 protected RecipientType(String type) { 231 this.type = type; 232 } 233 234 241 protected Object readResolve() throws ObjectStreamException { 242 if (type.equals("To")) 243 return TO; 244 else if (type.equals("Cc")) 245 return CC; 246 else if (type.equals("Bcc")) 247 return BCC; 248 else 249 throw new InvalidObjectException( 250 "Attempt to resolve unknown RecipientType: " + type); 251 } 252 253 public String toString() { 254 return type; 255 } 256 } 257 258 272 public abstract Address [] getRecipients(RecipientType type) 273 throws MessagingException ; 274 275 291 public Address [] getAllRecipients() throws MessagingException { 292 Address [] to = getRecipients(RecipientType.TO); 293 Address [] cc = getRecipients(RecipientType.CC); 294 Address [] bcc = getRecipients(RecipientType.BCC); 295 296 if (cc == null && bcc == null) 297 return to; 299 int numRecip = 300 (to != null ? to.length : 0) + 301 (cc != null ? cc.length : 0) + 302 (bcc != null ? bcc.length : 0); 303 Address [] addresses = new Address [numRecip]; 304 int pos = 0; 305 if (to != null) { 306 System.arraycopy(to, 0, addresses, pos, to.length); 307 pos += to.length; 308 } 309 if (cc != null) { 310 System.arraycopy(cc, 0, addresses, pos, cc.length); 311 pos += cc.length; 312 } 313 if (bcc != null) { 314 System.arraycopy(bcc, 0, addresses, pos, bcc.length); 315 pos += bcc.length; 316 } 317 return addresses; 318 } 319 320 333 public abstract void setRecipients(RecipientType type, Address [] addresses) 334 throws MessagingException ; 335 336 349 public void setRecipient(RecipientType type, Address address) 350 throws MessagingException { 351 Address [] a = new Address [1]; 352 a[0] = address; 353 setRecipients(type, a); 354 } 355 356 368 public abstract void addRecipients(RecipientType type, Address [] addresses) 369 throws MessagingException ; 370 371 383 public void addRecipient(RecipientType type, Address address) 384 throws MessagingException { 385 Address [] a = new Address [1]; 386 a[0] = address; 387 addRecipients(type, a); 388 } 389 390 406 public Address [] getReplyTo() throws MessagingException { 407 return getFrom(); 408 } 409 410 430 public void setReplyTo(Address [] addresses) throws MessagingException { 431 throw new MethodNotSupportedException ("setReplyTo not supported"); 432 } 433 434 440 public abstract String getSubject() throws MessagingException ; 441 442 453 public abstract void setSubject(String subject) 454 throws MessagingException ; 455 456 462 public abstract Date getSentDate() throws MessagingException ; 463 464 475 public abstract void setSentDate(Date date) throws MessagingException ; 476 477 483 public abstract Date getReceivedDate() throws MessagingException ; 484 485 498 public abstract Flags getFlags() throws MessagingException ; 499 500 517 public boolean isSet(Flags.Flag flag) throws MessagingException { 518 return getFlags().contains(flag); 519 } 520 521 540 public abstract void setFlags(Flags flag, boolean set) 541 throws MessagingException ; 542 543 562 public void setFlag(Flags.Flag flag, boolean set) 563 throws MessagingException { 564 Flags f = new Flags (flag); 565 setFlags(f, set); 566 } 567 568 581 public int getMessageNumber() { 582 return msgnum; 583 } 584 585 589 protected void setMessageNumber(int msgnum) { 590 this.msgnum = msgnum; 591 } 592 593 600 public Folder getFolder() { 601 return folder; 602 } 603 604 621 public boolean isExpunged() { 622 return expunged; 623 } 624 625 631 protected void setExpunged(boolean expunged) { 632 this.expunged = expunged; 633 } 634 635 657 public abstract Message reply(boolean replyToAll) throws MessagingException ; 658 659 680 public abstract void saveChanges() throws MessagingException ; 681 682 691 public boolean match(SearchTerm term) throws MessagingException { 692 return term.match(this); 693 } 694 } 695 | Popular Tags |