1 package net.suberic.pooka.cache; 2 import javax.mail.*; 3 import javax.mail.internet.*; 4 import net.suberic.pooka.FolderInfo; 5 import net.suberic.pooka.Pooka; 6 import net.suberic.pooka.UIDMimeMessage; 7 import net.suberic.pooka.UIDFolderInfo; 8 import javax.activation.DataHandler ; 9 import java.util.Enumeration ; 10 import java.io.InputStream ; 11 import java.io.ByteArrayInputStream ; 12 13 17 18 public class CachingMimeMessage extends UIDMimeMessage { 19 20 public CachingMimeMessage(CachingFolderInfo parentFolderInfo, long newUid) { 21 super(parentFolderInfo, newUid); 22 } 23 24 public int getSize() throws MessagingException { 25 return getCache().getSize(getUID()); 26 38 } 39 40 public synchronized DataHandler getDataHandler() 41 throws MessagingException { 42 return getCache().getDataHandler(getUID(), getUIDValidity(), ! getCacheHeadersOnly()); 43 } 44 45 public String [] getHeader(String name) 46 throws MessagingException { 47 return getHeaders().getHeader(name); 48 } 49 50 public String getHeader(String name, String delimiter) 51 throws MessagingException { 52 return getHeaders().getHeader(name, delimiter); 53 } 54 55 public void setHeader(String name, String value) 56 throws MessagingException { 57 throw new IllegalWriteException(Pooka.getProperty("error.cache.illegalWrite", "Cannot write to an existing message.")); 58 } 59 60 public void addHeader(String name, String value) 61 throws MessagingException { 62 throw new IllegalWriteException(Pooka.getProperty("error.cache.illegalWrite", "Cannot write to an existing message.")); 63 } 64 65 public void removeHeader(String name) 66 throws MessagingException { 67 throw new IllegalWriteException(Pooka.getProperty("error.cache.illegalWrite", "Cannot write to an existing message.")); 68 } 69 70 public Enumeration getAllHeaders() throws MessagingException { 71 return getHeaders().getAllHeaders(); 72 } 73 74 public Enumeration getMatchingHeaders(String [] names) 75 throws MessagingException { 76 return getHeaders().getMatchingHeaders(names); 77 } 78 79 80 87 public Enumeration getNonMatchingHeaders(String [] names) 88 throws MessagingException { 89 return getHeaders().getNonMatchingHeaders(names); 90 } 91 92 101 public void addHeaderLine(String line) throws MessagingException { 102 throw new IllegalWriteException(Pooka.getProperty("error.cache.illegalWrite", "Cannot write to an existing message.")); 103 } 104 105 112 public Enumeration getAllHeaderLines() throws MessagingException { 113 return getHeaders().getAllHeaderLines(); 114 } 115 116 123 public Enumeration getMatchingHeaderLines(String [] names) 124 throws MessagingException { 125 return getHeaders().getMatchingHeaderLines(names); 126 } 127 128 135 public Enumeration getNonMatchingHeaderLines(String [] names) 136 throws MessagingException { 137 return getHeaders().getNonMatchingHeaderLines(names); 138 } 139 140 152 public synchronized Flags getFlags() throws MessagingException { 153 try { 154 return (Flags) getCache().getFlags(getUID(), getUIDValidity()).clone(); 155 } catch (MessagingException me) { 156 if (me instanceof MessageRemovedException) { 157 return new Flags(); 158 } else { 159 throw me; 160 } 161 } 162 163 } 164 165 183 public synchronized boolean isSet(Flags.Flag flag) 184 throws MessagingException { 185 try { 186 return getFlags().contains(flag); 187 } catch (MessagingException me) { 188 System.out.println("caught exception: " + me); 189 me.printStackTrace(); 190 throw me; 191 } 192 } 193 194 205 public synchronized void setFlags(Flags flag, boolean set) 206 throws MessagingException { 207 if (set) 208 getCache().addFlag(getUID(), getUIDValidity(), flag); 209 else 210 getCache().removeFlag(getUID(), getUIDValidity(), flag); 211 } 212 213 public MessageCache getCache() { 214 return ((CachingFolderInfo)getParent()).getCache(); 215 } 216 217 public void setExpungedValue(boolean newValue) { 218 expunged=newValue; 219 } 220 221 224 public boolean isExpunged() { 225 return expunged; 226 } 227 228 public InternetHeaders getHeaders() throws MessagingException { 229 try { 230 return getCache().getHeaders(getUID(), getUIDValidity()); 231 } catch (MessagingException me) { 232 if (me instanceof MessageRemovedException) { 233 return new InternetHeaders(); 234 } else { 235 throw me; 236 } 237 } 238 } 239 240 public void writeTo(java.io.OutputStream os, String [] ignoreList) 241 throws java.io.IOException , MessagingException { 242 getCache().getMessageRepresentation(getUID(), getUIDValidity(), ! getCacheHeadersOnly()).writeTo(os, ignoreList); 243 } 244 245 248 public boolean getCacheHeadersOnly() { 249 return ((CachingFolderInfo)getParent()).getCacheHeadersOnly(); 250 } 251 252 } 253 254 255 256 257 | Popular Tags |