title: Java mail api 1.5.5 strange behaviour
body: <p>I am using <code>javamail (1.5.5)</code> to fetch mails from exchange <code>2010 server</code>. It fails to fetch few messages (<code>java.lang.OutOfMemoryError: Java heap space</code>). But it is working fine when using <code>java mail api 1.4.5</code> without heap space error.</p>
  
  <p>What's strange here is the size of that peculiar message is 136516 Bytes. So when using IMAP, it should be fetched within 9 batches ( default fetch size is 16KB ). But from the debug trace referred below, something is strange.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Message messObj = message[i]; String messSubject = null;
  String messMsgId = null;
  java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
  messObj.writeTo(bos);
  bos.close();
  javax.mail.util.SharedByteArrayInputStream bis = new javax.mail.util.SharedByteArrayInputStream(bos.toByteArray());
  MimeMessage cmsg = new MimeMessage(session, bis);
  bis.close(); mp.setMessage(cmsg);
  messSubject = cmsg.getSubject();
  messMsgId = ((MimeMessage) cmsg).getMessageID();
  System.out.println("debugging:::subject::"+messSubject+"::msgid::"+messMsgId);
  </code></pre>
  
  <hr>
  
  <blockquote>
    <p>FLAGS (\Seen \Answered))|
    [14:48:21:205]|[09-26-2018]|[SYSOUT]|[INFO]|[73]: A3893 OK FETCH
    completed.| [14:48:21:205]|[09-26-2018]|[SYSOUT]|[INFO]|[73]: A3894
    FETCH 1 (BODY[]&lt;536512690.16384>)|
    [14:48:21:220]|[09-26-2018]|[SYSOUT]|[INFO]|[73]: * 1 FETCH (UID 91149
    BODY[] {137921}|</p>
    
    <p>FLAGS (\Seen \Answered))|
    [14:48:21:236]|[09-26-2018]|[SYSOUT]|[INFO]|[73]: A3894 OK FETCH
    completed.| [14:48:21:236]|[09-26-2018]|[SYSOUT]|[INFO]|[73]: A3895
    FETCH 1 (BODY[]&lt;536650611.16384>)|
    [14:48:21:251]|[09-26-2018]|[SYSOUT]|[INFO]|[73]: * 1 FETCH (UID 91149
    BODY[] {137921}|</p>
    
    <p>--5c3ef07b8737170331214bb435ce7be6--| [14:48:21:267]|[09-26-2018]|[SYSOUT]|[INFO]|[73]:  FLAGS (\Seen
    \Answered))| [14:48:21:267]|[09-26-2018]|[SYSOUT]|[INFO]|[73]: A3895
    OK FETCH completed.| [14:48:21:267]|[09-26-2018]|[SYSOUT]|[INFO]|[73]:
    A3896 FETCH 1 (BODY[]&lt;536788532.16384>)|
    [14:48:21:283]|[09-26-2018]|[SYSOUT]|[INFO]|[73]: * 1 FETCH (UID 91149
    BODY[] {137921}|</p>
    
    <hr>
  </blockquote>
  
  <p>Error occurs before the system print. Each time the entire message is fetched and it is fetched for 3896 times ( after that memory heap error occurs and stops the process ). Could someone tell me what am I missing here?</p>