title: duplicate empty messages in php imap?
body: <p>I am fetching mail messages in php via imap.
  Its working well to retrieve the email header and body however frequently some of the messages seem to be coming through twice, the only difference being that in that duplicate the email BODY is empty - all that exists are the email headers.</p>
  
  <p>I have added logging and it seems that the EMPTY message normally comes through first and then on subsequent fetches the full message is retrieved.</p>
  
  <p>Can anyone explain this to me? Is there any reason why retrieving messages from imap will first return empty body emails in SOME but not all cases?</p>
  
  <p>This is my code that is fetching the emails.</p>
  
  <pre><code>$messages = imap_sort($imap, SORTARRIVAL, $sortorder,0,$searchval);
  foreach ($messages as $message) {
  
      $header = imap_header($imap, $message);
  
       //Get user from reply-to header info
      $useremail = "{$header-&gt;reply_to[0]-&gt;mailbox}@{$header-&gt;reply_to[0]-&gt;host}";
      $userfullname = $header-&gt;reply_to[0]-&gt;personal;
      //get subject from header
      $subject = $header-&gt;subject;    
  
      $fh = imap_fetchheader($imap, $message);
      $fb = imap_body($imap, $message);
      $fullbody = $fh.$fb;
  
      // GET TEXT BODY
      $bodyTxt = get_part($imap, $message, "TEXT/PLAIN");
      //GET HTML BODY
      $bodyHtml = get_part($imap, $message, "TEXT/HTML");
  </code></pre>
  
  <p>In many cases the first time the message is retrieved it will have an empty body (ie $fullbody will be empty). Often this comes in batches for eg 10 messages will be logged as having empty body.</p>
  
  <p>Subsequently the same batch is then retrieved but this time with a body - and I have no explanation for it.</p>
  
  <p>Can anyone offer any ideas?
  Thanks</p>