Skip to content

Package: POP3Message

POP3Message

nameinstructionbranchcomplexitylinemethod
POP3Message(Folder, int)
M: 32 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
addHeader(String, String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
addHeaderLine(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getAllHeaderLines()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getAllHeaders()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getContentStream()
M: 35 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getHeader(String)
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getHeader(String, String)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getMatchingHeaderLines(String[])
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getMatchingHeaders(String[])
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getMimeStream()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getNonMatchingHeaderLines(String[])
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getNonMatchingHeaders(String[])
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getRawStream(boolean)
M: 212 C: 0
0%
M: 30 C: 0
0%
M: 16 C: 0
0%
M: 53 C: 0
0%
M: 1 C: 0
0%
getSize()
M: 63 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
invalidate(boolean)
M: 43 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
loadHeaders()
M: 89 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 25 C: 0
0%
M: 1 C: 0
0%
removeHeader(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
saveChanges()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setFlags(Flags, boolean)
M: 20 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
setHeader(String, String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
top(int)
M: 34 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
writeTo(OutputStream, String[])
M: 97 C: 0
0%
M: 18 C: 0
0%
M: 10 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.eclipse.angus.mail.pop3;
18:
19: import java.io.*;
20: import java.util.Enumeration;
21: import java.util.logging.Level;
22: import java.lang.ref.SoftReference;
23: import jakarta.mail.*;
24: import jakarta.mail.internet.*;
25: import jakarta.mail.event.*;
26: import org.eclipse.angus.mail.util.ReadableMime;
27:
28: /**
29: * A POP3 Message. Just like a MimeMessage except that
30: * some things are not supported.
31: *
32: * @author Bill Shannon
33: */
34: public class POP3Message extends MimeMessage implements ReadableMime {
35:
36: /*
37: * Our locking strategy is to always lock the POP3Folder before the
38: * POP3Message so we have to be careful to drop our lock before calling
39: * back to the folder to close it and notify of connection lost events.
40: */
41:
42: // flag to indicate we haven't tried to fetch the UID yet
43: static final String UNKNOWN = "UNKNOWN";
44:
45: private POP3Folder folder;        // overrides folder in MimeMessage
46: private int hdrSize = -1;
47: private int msgSize = -1;
48: String uid = UNKNOWN;        // controlled by folder lock
49:
50: // rawData itself is never null
51: private SoftReference<InputStream> rawData
52:          = new SoftReference<>(null);
53:
54: public POP3Message(Folder folder, int msgno)
55:                         throws MessagingException {
56:         super(folder, msgno);
57:•        assert folder instanceof POP3Folder;
58:         this.folder = (POP3Folder)folder;
59: }
60:
61: /**
62: * Set the specified flags on this message to the specified value.
63: *
64: * @param newFlags        the flags to be set
65: * @param set        the value to be set
66: */
67: @Override
68: public synchronized void setFlags(Flags newFlags, boolean set)
69:                                 throws MessagingException {
70:         Flags oldFlags = (Flags)flags.clone();
71:         super.setFlags(newFlags, set);
72:•        if (!flags.equals(oldFlags))
73:          folder.notifyMessageChangedListeners(
74:                                 MessageChangedEvent.FLAGS_CHANGED, this);
75: }
76:
77: /**
78: * Return the size of the content of this message in bytes.
79: * Returns -1 if the size cannot be determined. <p>
80: *
81: * Note that this number may not be an exact measure of the
82: * content size and may or may not account for any transfer
83: * encoding of the content. <p>
84: *
85: * @return size of content in bytes
86: * @exception        MessagingException for failures
87: */
88: @Override
89: public int getSize() throws MessagingException {
90:         try {
91:          synchronized (this) {
92:                 // if we already have the size, return it
93:•                if (msgSize > 0)
94:                  return msgSize;
95:          }
96:
97:          /*
98:          * Use LIST to determine the entire message
99:          * size and subtract out the header size
100:          * (which may involve loading the headers,
101:          * which may load the content as a side effect).
102:          * If the content is loaded as a side effect of
103:          * loading the headers, it will set the size.
104:          *
105:          * Make sure to call loadHeaders() outside of the
106:          * synchronization block. There's a potential race
107:          * condition here but synchronization will occur in
108:          * loadHeaders() to make sure the headers are only
109:          * loaded once, and again in the following block to
110:          * only compute msgSize once.
111:          */
112:•         if (headers == null)
113:                 loadHeaders();
114:
115:          synchronized (this) {
116:•                if (msgSize < 0)
117:                  msgSize = folder.getProtocol().list(msgnum) - hdrSize;
118:                 return msgSize;
119:          }
120:         } catch (EOFException eex) {
121:          folder.close(false);
122:          throw new FolderClosedException(folder, eex.toString());
123:         } catch (IOException ex) {
124:          throw new MessagingException("error getting size", ex);
125:         }
126: }
127:
128: /**
129: * Produce the raw bytes of the message. The data is fetched using
130: * the POP3 RETR command. If skipHeader is true, just the content
131: * is returned.
132: */
133: private InputStream getRawStream(boolean skipHeader)
134:                                 throws MessagingException {
135:         InputStream rawcontent = null;
136:         try {
137:         synchronized(this) {
138:          rawcontent = rawData.get();
139:•         if (rawcontent == null) {
140:                 TempFile cache = folder.getFileCache();
141:•                if (cache != null) {
142:•                 if (folder.logger.isLoggable(Level.FINE))
143:                         folder.logger.fine("caching message #" + msgnum +
144:                                          " in temp file");
145:                  AppendStream os = cache.getAppendStream();
146:                  BufferedOutputStream bos = new BufferedOutputStream(os);
147:                  try {
148:                         folder.getProtocol().retr(msgnum, bos);
149:                  } finally {
150:                         bos.close();
151:                  }
152:                  rawcontent = os.getInputStream();
153:                 } else {
154:                  rawcontent = folder.getProtocol().retr(msgnum,
155:•                                        msgSize > 0 ? msgSize + hdrSize : 0);
156:                 }
157:•                if (rawcontent == null) {
158:                  expunged = true;
159:                  throw new MessageRemovedException(
160:                         "can't retrieve message #" + msgnum +
161:                         " in POP3Message.getContentStream"); // XXX - what else?
162:                 }
163:
164:•                if (headers == null ||
165:•                        ((POP3Store)(folder.getStore())).forgetTopHeaders) {
166:                  headers = new InternetHeaders(rawcontent);
167:                  hdrSize =
168:                         (int)((SharedInputStream)rawcontent).getPosition();
169:                 } else {
170:                  /*
171:                  * Already have the headers, have to skip the headers
172:                  * in the content array and return the body.
173:                  *
174:                  * XXX - It seems that some mail servers return slightly
175:                  * different headers in the RETR results than were returned
176:                  * in the TOP results, so we can't depend on remembering
177:                  * the size of the headers from the TOP command and just
178:                  * skipping that many bytes. Instead, we have to process
179:                  * the content, skipping over the header until we come to
180:                  * the empty line that separates the header from the body.
181:                  */
182:                  for (;;) {
183:                         int len = 0;        // number of bytes in this line
184:                         int c1;
185:•                        while ((c1 = rawcontent.read()) >= 0) {
186:•                         if (c1 == '\n')        // end of line
187:                                 break;
188:•                         else if (c1 == '\r') {
189:                                 // got CR, is the next char LF?
190:•                                if (rawcontent.available() > 0) {
191:                                  rawcontent.mark(1);
192:•                                 if (rawcontent.read() != '\n')
193:                                         rawcontent.reset();
194:                                 }
195:                                 break;        // in any case, end of line
196:                          }
197:
198:                          // not CR, NL, or CRLF, count the byte
199:                          len++;
200:                         }
201:                         // here when end of line or out of data
202:
203:                         // if out of data, we're done
204:•                        if (rawcontent.available() == 0)
205:                          break;
206:                         
207:                         // if it was an empty line, we're done
208:•                        if (len == 0)
209:                          break;
210:                  }
211:                  hdrSize =
212:                         (int)((SharedInputStream)rawcontent).getPosition();
213:                 }
214:
215:                 // skipped the header, the message is what's left
216:                 msgSize = rawcontent.available();
217:
218:                 rawData = new SoftReference<>(rawcontent);
219:          }
220:         }
221:         } catch (EOFException eex) {
222:          folder.close(false);
223:          throw new FolderClosedException(folder, eex.toString());
224:         } catch (IOException ex) {
225:          throw new MessagingException("error fetching POP3 content", ex);
226:         }
227:
228:         /*
229:          * We have a cached stream, but we need to return
230:          * a fresh stream to read from the beginning and
231:          * that can be safely closed.
232:          */
233:         rawcontent = ((SharedInputStream)rawcontent).newStream(
234:•                                                skipHeader ? hdrSize : 0, -1);
235:         return rawcontent;
236: }
237:
238: /**
239: * Produce the raw bytes of the content. The data is fetched using
240: * the POP3 RETR command.
241: *
242: * @see #contentStream
243: */
244: @Override
245: protected synchronized InputStream getContentStream()
246:                                 throws MessagingException {
247:•        if (contentStream != null)
248:          return ((SharedInputStream)contentStream).newStream(0, -1);
249:
250:         InputStream cstream = getRawStream(true);
251:
252:         /*
253:          * Keep a hard reference to the data if we're using a file
254:          * cache or if the "mail.pop3.keepmessagecontent" prop is set.
255:          */
256:         TempFile cache = folder.getFileCache();
257:•        if (cache != null ||
258:•                ((POP3Store)(folder.getStore())).keepMessageContent)
259:          contentStream = ((SharedInputStream)cstream).newStream(0, -1);
260:         return cstream;
261: }
262:
263: /**
264: * Return the MIME format stream corresponding to this message part.
265: *
266: * @return        the MIME format stream
267: * @since        JavaMail 1.4.5
268: */
269: @Override
270: public InputStream getMimeStream() throws MessagingException {
271:         return getRawStream(false);
272: }
273:
274: /**
275: * Invalidate the cache of content for this message object, causing
276: * it to be fetched again from the server the next time it is needed.
277: * If <code>invalidateHeaders</code> is true, invalidate the headers
278: * as well.
279: *
280: * @param        invalidateHeaders        invalidate the headers as well?
281: */
282: public synchronized void invalidate(boolean invalidateHeaders) {
283:         content = null;
284:         InputStream rstream = rawData.get();
285:•        if (rstream != null) {
286:          // note that if the content is in the file cache, it will be lost
287:          // and fetched from the server if it's needed again
288:          try {
289:                 rstream.close();
290:          } catch (IOException ex) {
291:                 // ignore it
292:          }
293:          rawData = new SoftReference<>(null);
294:         }
295:•        if (contentStream != null) {
296:          try {
297:                 contentStream.close();
298:          } catch (IOException ex) {
299:                 // ignore it
300:          }
301:          contentStream = null;
302:         }
303:         msgSize = -1;
304:•        if (invalidateHeaders) {
305:          headers = null;
306:          hdrSize = -1;
307:         }
308: }
309:
310: /**
311: * Fetch the header of the message and the first <code>n</code> lines
312: * of the raw content of the message. The headers and data are
313: * available in the returned InputStream.
314: *
315: * @param        n        number of lines of content to fetch
316: * @return        InputStream containing the message headers and n content lines
317: * @exception        MessagingException for failures
318: */
319: public InputStream top(int n) throws MessagingException {
320:         try {
321:          synchronized (this) {
322:                 return folder.getProtocol().top(msgnum, n);
323:          }
324:         } catch (EOFException eex) {
325:          folder.close(false);
326:          throw new FolderClosedException(folder, eex.toString());
327:         } catch (IOException ex) {
328:          throw new MessagingException("error getting size", ex);
329:         }
330: }
331:
332: /**
333: * Get all the headers for this header_name. Note that certain
334: * headers may be encoded as per RFC 2047 if they contain
335: * non US-ASCII characters and these should be decoded. <p>
336: *
337: * @param        name        name of header
338: * @return        array of headers
339: * @exception        MessagingException for failures
340: * @see         jakarta.mail.internet.MimeUtility
341: */
342: @Override
343: public String[] getHeader(String name)
344:                         throws MessagingException {
345:•        if (headers == null)
346:          loadHeaders();
347:         return headers.getHeader(name);
348: }
349:
350: /**
351: * Get all the headers for this header name, returned as a single
352: * String, with headers separated by the delimiter. If the
353: * delimiter is <code>null</code>, only the first header is
354: * returned.
355: *
356: * @param name                the name of this header
357: * @param delimiter                delimiter between returned headers
358: * @return the value fields for all headers with
359: *                                this name
360: * @exception                MessagingException for failures
361: */
362: @Override
363: public String getHeader(String name, String delimiter)
364:                                 throws MessagingException {
365:•        if (headers == null)
366:          loadHeaders();
367:         return headers.getHeader(name, delimiter);
368: }
369:
370: /**
371: * Set the value for this header_name. Throws IllegalWriteException
372: * because POP3 messages are read-only.
373: *
374: * @param        name         header name
375: * @param        value        header value
376: * @see         jakarta.mail.internet.MimeUtility
377: * @exception        IllegalWriteException because the underlying
378: *                        implementation does not support modification
379: * @exception        IllegalStateException if this message is
380: *                        obtained from a READ_ONLY folder.
381: * @exception        MessagingException for other failures
382: */
383: @Override
384: public void setHeader(String name, String value)
385: throws MessagingException {
386:         // XXX - should check for read-only folder?
387:         throw new IllegalWriteException("POP3 messages are read-only");
388: }
389:
390: /**
391: * Add this value to the existing values for this header_name.
392: * Throws IllegalWriteException because POP3 messages are read-only.
393: *
394: * @param        name         header name
395: * @param        value        header value
396: * @see         jakarta.mail.internet.MimeUtility
397: * @exception        IllegalWriteException because the underlying
398: *                        implementation does not support modification
399: * @exception        IllegalStateException if this message is
400: *                        obtained from a READ_ONLY folder.
401: */
402: @Override
403: public void addHeader(String name, String value)
404: throws MessagingException {
405:         // XXX - should check for read-only folder?
406:         throw new IllegalWriteException("POP3 messages are read-only");
407: }
408:
409: /**
410: * Remove all headers with this name.
411: * Throws IllegalWriteException because POP3 messages are read-only.
412: *
413: * @exception        IllegalWriteException because the underlying
414: *                        implementation does not support modification
415: * @exception        IllegalStateException if this message is
416: *                        obtained from a READ_ONLY folder.
417: */
418: @Override
419: public void removeHeader(String name)
420: throws MessagingException {
421:         // XXX - should check for read-only folder?
422:         throw new IllegalWriteException("POP3 messages are read-only");
423: }
424:
425: /**
426: * Return all the headers from this Message as an enumeration
427: * of Header objects. <p>
428: *
429: * Note that certain headers may be encoded as per RFC 2047
430: * if they contain non US-ASCII characters and these should
431: * be decoded. <p>
432: *
433: * @return        array of header objects
434: * @exception        MessagingException for failures
435: * @see         jakarta.mail.internet.MimeUtility
436: */
437: @Override
438: public Enumeration<Header> getAllHeaders() throws MessagingException {
439:•        if (headers == null)
440:          loadHeaders();
441:         return headers.getAllHeaders();        
442: }
443:
444: /**
445: * Return matching headers from this Message as an Enumeration of
446: * Header objects.
447: *
448: * @exception        MessagingException for failures
449: */
450: @Override
451: public Enumeration<Header> getMatchingHeaders(String[] names)
452:                         throws MessagingException {
453:•        if (headers == null)
454:          loadHeaders();
455:         return headers.getMatchingHeaders(names);
456: }
457:
458: /**
459: * Return non-matching headers from this Message as an
460: * Enumeration of Header objects.
461: *
462: * @exception        MessagingException for failures
463: */
464: @Override
465: public Enumeration<Header> getNonMatchingHeaders(String[] names)
466:                         throws MessagingException {
467:•        if (headers == null)
468:          loadHeaders();
469:         return headers.getNonMatchingHeaders(names);
470: }
471:
472: /**
473: * Add a raw RFC822 header-line.
474: * Throws IllegalWriteException because POP3 messages are read-only.
475: *
476: * @exception        IllegalWriteException because the underlying
477: *                        implementation does not support modification
478: * @exception        IllegalStateException if this message is
479: *                        obtained from a READ_ONLY folder.
480: */
481: @Override
482: public void addHeaderLine(String line) throws MessagingException {
483:         // XXX - should check for read-only folder?
484:         throw new IllegalWriteException("POP3 messages are read-only");
485: }
486:
487: /**
488: * Get all header lines as an Enumeration of Strings. A Header
489: * line is a raw RFC822 header-line, containing both the "name"
490: * and "value" field.
491: *
492: * @exception        MessagingException for failures
493: */
494: @Override
495: public Enumeration<String> getAllHeaderLines() throws MessagingException {
496:•        if (headers == null)
497:          loadHeaders();
498:         return headers.getAllHeaderLines();
499: }
500:
501: /**
502: * Get matching header lines as an Enumeration of Strings.
503: * A Header line is a raw RFC822 header-line, containing both
504: * the "name" and "value" field.
505: *
506: * @exception        MessagingException for failures
507: */
508: @Override
509: public Enumeration<String> getMatchingHeaderLines(String[] names)
510: throws MessagingException {
511:•        if (headers == null)
512:          loadHeaders();
513:         return headers.getMatchingHeaderLines(names);
514: }
515:
516: /**
517: * Get non-matching header lines as an Enumeration of Strings.
518: * A Header line is a raw RFC822 header-line, containing both
519: * the "name" and "value" field.
520: *
521: * @exception        MessagingException for failures
522: */
523: @Override
524: public Enumeration<String> getNonMatchingHeaderLines(String[] names)
525: throws MessagingException {
526:•        if (headers == null)
527:          loadHeaders();
528:         return headers.getNonMatchingHeaderLines(names);
529: }
530:
531: /**
532: * POP3 message can't be changed. This method throws
533: * IllegalWriteException.
534: *
535: * @exception        IllegalWriteException because the underlying
536: *                        implementation does not support modification
537: */
538: @Override
539: public void saveChanges() throws MessagingException {
540:         // POP3 Messages are read-only
541:         throw new IllegalWriteException("POP3 messages are read-only");
542: }
543:
544: /**
545: * Output the message as an RFC 822 format stream, without
546: * specified headers. If the property "mail.pop3.cachewriteto"
547: * is set to "true", and ignoreList is null, and the message hasn't
548: * already been cached as a side effect of other operations, the message
549: * content is cached before being written. Otherwise, the message is
550: * streamed directly to the output stream without being cached.
551: *
552: * @exception IOException        if an error occurs writing to the stream
553: *                                or if an error is generated by the
554: *                                jakarta.activation layer.
555: * @exception MessagingException for other failures
556: * @see jakarta.activation.DataHandler#writeTo
557: */
558: @Override
559: public synchronized void writeTo(OutputStream os, String[] ignoreList)
560:                                 throws IOException, MessagingException {
561:         InputStream rawcontent = rawData.get();
562:•        if (rawcontent == null && ignoreList == null &&
563:•                        !((POP3Store)(folder.getStore())).cacheWriteTo) {
564:•         if (folder.logger.isLoggable(Level.FINE))
565:                 folder.logger.fine("streaming msg " + msgnum);
566:•         if (!folder.getProtocol().retr(msgnum, os)) {
567:                 expunged = true;
568:                 throw new MessageRemovedException("can't retrieve message #" +
569:                  msgnum + " in POP3Message.writeTo"); // XXX - what else?
570:          }
571:•        } else if (rawcontent != null && ignoreList == null) {
572:          // can just copy the cached data
573:          InputStream in = ((SharedInputStream)rawcontent).newStream(0, -1);
574:          try {
575:                 byte[] buf = new byte[16*1024];
576:                 int len;
577:•                while ((len = in.read(buf)) > 0)
578:                  os.write(buf, 0, len);
579:          } finally {
580:                 try {
581:•                 if (in != null)
582:                         in.close();
583:                 } catch (IOException ex) { }
584:          }
585:         } else
586:          super.writeTo(os, ignoreList);
587: }
588:
589: /**
590: * Load the headers for this message into the InternetHeaders object.
591: * The headers are fetched using the POP3 TOP command.
592: */
593: private void loadHeaders() throws MessagingException {
594:•        assert !Thread.holdsLock(this);
595:         try {
596:          boolean fetchContent = false;
597:          synchronized (this) {
598:•                if (headers != null) // check again under lock
599:                  return;
600:                 InputStream hdrs = null;
601:•                if (((POP3Store)(folder.getStore())).disableTop ||
602:•                        (hdrs = folder.getProtocol().top(msgnum, 0)) == null) {
603:                  // possibly because the TOP command isn't supported,
604:                  // load headers as a side effect of loading the entire
605:                  // content.
606:                  fetchContent = true;
607:                 } else {
608:                  try {
609:                         hdrSize = hdrs.available();
610:                         headers = new InternetHeaders(hdrs);
611:                  } finally {
612:                         hdrs.close();
613:                  }
614:                 }
615:          }
616:
617:          /*
618:          * Outside the synchronization block...
619:          *
620:          * Do we need to fetch the entire mesage content in order to
621:          * load the headers as a side effect? Yes, there's a race
622:          * condition here - multiple threads could decide that the
623:          * content needs to be fetched. Fortunately, they'll all
624:          * synchronize in the getContentStream method and the content
625:          * will only be loaded once.
626:          */
627:•         if (fetchContent) {
628:                 InputStream cs = null;
629:                 try {
630:                  cs = getContentStream();
631:                 } finally {
632:•                 if (cs != null)
633:                         cs.close();
634:                 }
635:          }
636:         } catch (EOFException eex) {
637:          folder.close(false);
638:          throw new FolderClosedException(folder, eex.toString());
639:         } catch (IOException ex) {
640:          throw new MessagingException("error loading POP3 headers", ex);
641:         }
642: }
643: }