1 22 23 package gnu.mail.providers.pop3; 24 25 import java.io.InputStream ; 26 import java.io.IOException ; 27 import java.io.OutputStream ; 28 import java.util.Enumeration ; 29 import javax.activation.DataHandler ; 30 import javax.mail.MessagingException ; 31 import javax.mail.Session ; 32 import javax.mail.internet.InternetHeaders ; 33 import javax.mail.internet.MimeMessage ; 34 35 import gnu.mail.providers.ReadOnlyMessage; 36 37 44 public final class POP3Message 45 extends MimeMessage 49 { 50 51 54 int size; 55 56 59 POP3Message(POP3Folder folder, InputStream in, int msgnum) 60 throws MessagingException 61 { 62 super(folder, in, msgnum); 63 setFrame (size); 64 } 65 66 78 POP3Message(POP3Folder folder, int msgnum, int size) 79 throws MessagingException 80 { 81 super (folder, msgnum); 82 setFrame (size); 83 } 84 85 97 POP3Message(POP3Folder folder, InputStream in, int msgnum, int size) 98 throws MessagingException 99 { 100 this (folder, in, msgnum); 101 setFrame (size); 102 } 103 104 private void setFrame (int size) 105 { 106 this.size = size; 107 POP3Headers h = (POP3Headers) headers; 108 if (headers!=null && h.isEmpty()) 109 headers = null; 110 if (content!=null && content.length==0) 111 content = null; 112 } 113 114 116 120 void fetchContent() 121 throws MessagingException 122 { 123 POP3Store str = (POP3Store)folder.getStore(); 125 parse(str.popRETR(msgnum)); 126 } 127 128 131 public DataHandler getDataHandler() 132 throws MessagingException 133 { 134 if (content==null) 135 fetchContent(); 136 return super.getDataHandler(); 137 } 138 139 142 protected InputStream getContentStream() 143 throws MessagingException 144 { 145 if (content==null) 146 fetchContent(); 147 return super.getContentStream(); 148 } 149 150 154 public int getSize() 155 throws MessagingException 156 { 157 if (size>-1) 158 return size; 159 if (content==null) 160 fetchContent(); 161 return super.getSize(); 162 } 163 164 166 169 void fetchHeaders() 170 throws MessagingException 171 { 172 POP3Store str = (POP3Store)folder.getStore(); 173 headers = createInternetHeaders(str.popTOP(msgnum)); 174 } 175 176 179 public String [] getHeader(String name) 180 throws MessagingException 181 { 182 if (headers==null) 183 fetchHeaders(); 184 return super.getHeader(name); 185 } 186 187 190 public String getHeader(String name, String delimiter) 191 throws MessagingException 192 { 193 if (headers==null) 194 fetchHeaders(); 195 return super.getHeader(name, delimiter); 196 } 197 198 201 public Enumeration getAllHeaders() 202 throws MessagingException 203 { 204 if (headers==null) 205 fetchHeaders(); 206 return super.getAllHeaders(); 207 } 208 209 212 public Enumeration getAllHeaderLines() 213 throws MessagingException 214 { 215 if (headers==null) 216 fetchHeaders(); 217 return super.getAllHeaderLines(); 218 } 219 220 223 public Enumeration getMatchingHeaders(String [] names) 224 throws MessagingException 225 { 226 if (headers==null) 227 fetchHeaders(); 228 return super.getMatchingHeaders(names); 229 } 230 231 234 public Enumeration getMatchingHeaderLines(String [] names) 235 throws MessagingException 236 { 237 if (headers==null) 238 fetchHeaders(); 239 return super.getMatchingHeaderLines(names); 240 } 241 242 245 public Enumeration getNonMatchingHeaders(String [] names) 246 throws MessagingException 247 { 248 if (headers==null) 249 fetchHeaders(); 250 return super.getNonMatchingHeaders(names); 251 } 252 253 256 public Enumeration getNonMatchingHeaderLines(String [] names) 257 throws MessagingException 258 { 259 if (headers==null) 260 fetchHeaders(); 261 return super.getNonMatchingHeaderLines(names); 262 } 263 264 protected InternetHeaders createInternetHeaders(InputStream is) 265 throws MessagingException 266 { 267 return new POP3Headers(is); 268 } 269 270 272 public void writeTo(OutputStream msgStream) 273 throws IOException , MessagingException 274 { 275 if (content==null) 276 fetchContent(); 277 super.writeTo(msgStream); 278 } 279 280 public void writeTo(OutputStream msgStream, String [] ignoreList) 281 throws IOException , MessagingException 282 { 283 if (content==null) 284 fetchContent(); 285 super.writeTo(msgStream, ignoreList); 286 } 287 288 } 289 | Popular Tags |