1 17 18 package javax.mail; 19 import java.util.Iterator; 20 import java.util.LinkedList; 21 import java.util.List; 22 25 public class SimpleFolder extends Folder { 26 private static final Message[] MESSAGE_ARRAY = new Message[0]; 27 private List _messages = new LinkedList(); 28 private String _name; 29 public SimpleFolder(Store store) { 30 this(store, "SimpleFolder"); 31 } 32 SimpleFolder(Store store, String name) { 33 super(store); 34 _name = name; 35 } 36 39 public void appendMessages(Message[] messages) throws MessagingException { 40 for (int i = 0; i < messages.length; i++) { 41 Message message = messages[i]; 42 _messages.add(message); 43 } 44 } 45 48 public void close(boolean expunge) throws MessagingException { 49 if (expunge) { 50 expunge(); 51 } 52 } 53 56 public boolean create(int type) throws MessagingException { 57 if (type == HOLDS_MESSAGES) { 58 return true; 59 } else { 60 throw new MessagingException("Cannot create folders that hold folders"); 61 } 62 } 63 66 public boolean delete(boolean recurse) throws MessagingException { 67 _messages = new LinkedList(); 68 return true; 69 } 70 73 public boolean exists() throws MessagingException { 74 return true; 75 } 76 79 public Message[] expunge() throws MessagingException { 80 Iterator it = _messages.iterator(); 81 List result = new LinkedList(); 82 while (it.hasNext()) { 83 Message message = (Message) it.next(); 84 if (message.isSet(Flags.Flag.DELETED)) { 85 it.remove(); 86 result.add(message); 87 } 88 } 89 for (int i = 0; i < _messages.size(); i++) { 91 Message message = (Message) _messages.get(i); 92 message.setMessageNumber(i); 93 } 94 return (Message[]) result.toArray(MESSAGE_ARRAY); 95 } 96 99 public Folder getFolder(String name) throws MessagingException { 100 return null; 101 } 102 105 public String getFullName() { 106 return getName(); 107 } 108 111 public Message getMessage(int id) throws MessagingException { 112 return (Message) _messages.get(id); 113 } 114 117 public int getMessageCount() throws MessagingException { 118 return _messages.size(); 119 } 120 123 public String getName() { 124 return _name; 125 } 126 129 public Folder getParent() throws MessagingException { 130 return null; 131 } 132 135 public Flags getPermanentFlags() { 136 return null; 137 } 138 141 public char getSeparator() throws MessagingException { 142 return '/'; 143 } 144 147 public int getType() throws MessagingException { 148 return HOLDS_MESSAGES; 149 } 150 153 public boolean hasNewMessages() throws MessagingException { 154 return false; 155 } 156 159 public boolean isOpen() { 160 return true; 161 } 162 165 public Folder[] list(String pattern) throws MessagingException { 166 return null; 167 } 168 171 public void open(int mode) throws MessagingException { 172 if (mode != HOLDS_MESSAGES) { 173 throw new MessagingException("SimpleFolder can only be opened with HOLDS_MESSAGES"); 174 } 175 } 176 179 public boolean renameTo(Folder newName) throws MessagingException { 180 _name = newName.getName(); 181 return true; 182 } 183 } 184 | Popular Tags |