| 1 21 22 27 28 package javax.mail; 29 30 import java.io.*; 31 import java.lang.*; 32 import java.util.Vector ; 33 import java.util.StringTokenizer ; 34 import javax.mail.search.SearchTerm ; 35 import javax.mail.event.*; 36 37 98 99 public abstract class Folder { 100 101 104 protected Store store; 105 106 112 protected int mode = -1; 113 114 119 protected Folder(Store store) { 120 this.store = store; 121 } 122 123 130 public abstract String getName(); 131 132 142 public abstract String getFullName(); 143 144 152 public URLName getURLName() throws MessagingException { 153 URLName storeURL = getStore().getURLName(); 154 String fullname = getFullName(); 155 StringBuffer encodedName = new StringBuffer (); 156 char separator = getSeparator(); 157 158 if (fullname != null) { 159 174 encodedName.append(fullname); 176 } 177 178 182 return new URLName (storeURL.getProtocol(), storeURL.getHost(), 183 storeURL.getPort(), encodedName.toString(), 184 storeURL.getUsername(), 185 null ); 186 } 187 188 193 public Store getStore() { 194 return store; 195 } 196 197 207 public abstract Folder getParent() throws MessagingException ; 208 209 218 public abstract boolean exists() throws MessagingException ; 219 220 256 public abstract Folder [] list(String pattern) throws MessagingException ; 257 258 289 public Folder [] listSubscribed(String pattern) throws MessagingException { 290 return list(pattern); 291 } 292 293 306 307 public Folder [] list() throws MessagingException { 308 return list("%"); 309 } 310 311 325 public Folder [] listSubscribed() throws MessagingException { 326 return listSubscribed("%"); 327 } 328 329 338 public abstract char getSeparator() throws MessagingException ; 339 340 343 public final static int HOLDS_MESSAGES = 0x01; 344 345 348 public final static int HOLDS_FOLDERS = 0x02; 349 350 362 public abstract int getType() throws MessagingException ; 363 364 379 public abstract boolean create(int type) throws MessagingException ; 380 381 390 public boolean isSubscribed() { 391 return true; 392 } 393 394 410 public void setSubscribed(boolean subscribe) 411 throws MessagingException { 412 throw new MethodNotSupportedException (); 413 } 414 415 438 public abstract boolean hasNewMessages() throws MessagingException ; 439 440 460 public abstract Folder getFolder(String name) 461 throws MessagingException ; 462 463 531 public abstract boolean delete(boolean recurse) 532 throws MessagingException ; 533 534 551 public abstract boolean renameTo(Folder f) throws MessagingException ; 552 553 557 public static final int READ_ONLY = 1; 558 559 562 public static final int READ_WRITE = 2; 563 564 588 public abstract void open(int mode) throws MessagingException ; 589 590 603 public abstract void close(boolean expunge) throws MessagingException ; 604 605 609 public abstract boolean isOpen(); 610 611 622 public int getMode() { 623 if (!isOpen()) 624 throw new IllegalStateException ("Folder not open"); 625 return mode; 626 } 627 628 640 public abstract Flags getPermanentFlags(); 641 642 663 public abstract int getMessageCount() throws MessagingException ; 664 665 692 public synchronized int getNewMessageCount() 693 throws MessagingException { 694 if (!isOpen()) 695 return -1; 696 697 int newmsgs = 0; 698 int total = getMessageCount(); 699 for (int i = 1; i <= total; i++) { 700 try { 701 if (getMessage(i).isSet(Flags.Flag.RECENT)) 702 newmsgs++; 703 } catch (MessageRemovedException me) { 704 continue; 706 } 707 } 708 return newmsgs; 709 } 710 711 738 public synchronized int getUnreadMessageCount() 739 throws MessagingException { 740 if (!isOpen()) 741 return -1; 742 743 int unread = 0; 744 int total = getMessageCount(); 745 for (int i = 1; i <= total; i++) { 746 try { 747 if (!getMessage(i).isSet(Flags.Flag.SEEN)) 748 unread++; 749 } catch (MessageRemovedException me) { 750 continue; 752 } 753 } 754 return unread; 755 } 756 757 785 public synchronized int getDeletedMessageCount() throws MessagingException { 786 if (!isOpen()) 787 return -1; 788 789 int deleted = 0; 790 int total = getMessageCount(); 791 for (int i = 1; i <= total; i++) { 792 try { 793 if (getMessage(i).isSet(Flags.Flag.DELETED)) 794 deleted++; 795 } catch (MessageRemovedException me) { 796 continue; 798 } 799 } 800 return deleted; 801 } 802 803 835 public abstract Message getMessage(int msgnum) 836 throws MessagingException ; 837 838 862 public synchronized Message [] getMessages(int start, int end) 863 throws MessagingException { 864 Message [] msgs = new Message [end - start +1]; 865 for (int i = start; i <= end; i++) 866 msgs[i - start] = getMessage(i); 867 return msgs; 868 } 869 870 892 public synchronized Message [] getMessages(int[] msgnums) 893 throws MessagingException { 894 int len = msgnums.length; 895 Message [] msgs = new Message [len]; 896 for (int i = 0; i < len; i++) 897 msgs[i] = getMessage(msgnums[i]); 898 return msgs; 899 } 900 901 923 public synchronized Message [] getMessages() throws MessagingException { 924 if (!isOpen()) throw new IllegalStateException ("Folder not open"); 926 int total = getMessageCount(); 927 Message [] msgs = new Message [total]; 928 for (int i = 1; i <= total; i++) 929 msgs[i-1] = getMessage(i); 930 return msgs; 931 } 932 933 948 public abstract void appendMessages(Message [] msgs) 949 throws MessagingException ; 950 951 990 public void fetch(Message [] msgs, FetchProfile fp) 991 throws MessagingException { 992 return; 993 } 994 995 |