title: imap_delete and imap_expunge doesn't permanently delete?
body: <p>I'm currently testing a script that will go through an e-mail account deleting 20 of the oldest e-mails per page load. (Number is just for testing purposes) However. I've noticed a couple of issues with what I'm doing:</p>
  
  <p>1 - It seems to sometimes ignore e-mails. For example. I had 12 e-mails that could have been deleted. Yet it only deleted 6, When I ran the script again, it deleted 3, then down to 2, and finally I had to refresh again to delete the final one. Does anyone know why this may be? When the limit is 20. So would loop through 20 times anyway.</p>
  
  <p>2 - The main issue is that although it removes from the Inbox. When I go to All Mail. Every single e-mail is still in there. </p>
  
  <p>The code is as follows incase anyone can spot why I experience these difficulties. (although removed the imap_open call. 
          
  
  <pre><code>$numMessages = imap_num_msg($imap);
  //for ($i = $numMessages; $i &gt; ($numMessages - 20); $i--) {
  for($i=1; $i&lt;=20; $i++)
  {
      $header = imap_header($imap, $i);
  
      $fromInfo = $header-&gt;from[0];
      $replyInfo = $header-&gt;reply_to[0];
  
      $details = array(
          "fromAddr" =&gt; (isset($fromInfo-&gt;mailbox) &amp;&amp; isset($fromInfo-&gt;host))
              ? $fromInfo-&gt;mailbox . "@" . $fromInfo-&gt;host : "",
          "fromName" =&gt; (isset($fromInfo-&gt;personal))
              ? $fromInfo-&gt;personal : "",
          "replyAddr" =&gt; (isset($replyInfo-&gt;mailbox) &amp;&amp; isset($replyInfo-&gt;host))
              ? $replyInfo-&gt;mailbox . "@" . $replyInfo-&gt;host : "",
          "replyName" =&gt; (isset($replyTo-&gt;personal))
              ? $replyto-&gt;personal : "",
          "subject" =&gt; (isset($header-&gt;subject))
              ? $header-&gt;subject : "",
          "udate" =&gt; (isset($header-&gt;udate))
              ? $header-&gt;udate : ""
      );
  
      $uid = imap_uid($imap, $i);
  
      echo "&lt;ul&gt;";
      echo "&lt;li&gt;&lt;strong&gt;From:&lt;/strong&gt;" . $details["fromName"];
      echo " " . $details["fromAddr"] . "&lt;/li&gt;";
      echo "&lt;li&gt;&lt;strong&gt;Subject:&lt;/strong&gt; " . $details["subject"] . "&lt;/li&gt;";
      echo '&lt;li&gt;&lt;a href="mail.php?folder=' . $folder . '&amp;uid=' . $uid . '&amp;func=read"&gt;Read&lt;/a&gt;';
      echo " | ";
      echo '&lt;a href="mail.php?folder=' . $folder . '&amp;uid=' . $uid . '&amp;func=delete"&gt;Delete&lt;/a&gt;';
      echo " | ";
      echo date("F j, Y, g:i a",$details['udate']) . '&lt;/li&gt;';
      echo "&lt;/ul&gt;";
  
      imap_delete($imap, $uid, FT_UID);
  }
  imap_expunge($imap);
  imap_close($imap);
  ?&gt;
  </code></pre>
  
  <p>Thank you</p>