title: imap_mail_move not working
body: <p>I have written a class to connect to my mailbox and move the spam to my junk folder. It doesn't seem to be working though and I don't know why. Here is what I have:</p>
  
  <pre><code>&lt;?php
  $cleaner = new Mail_cleaner();
  
  echo 'Deleted '.$cleaner-&gt;deleted.' files';
  
  Class Mail_cleaner {
  
  public $server = '{mail.gridhost.co.uk:993/imap/ssl}';
  public $folder = 'INBOX';
  public $user = 'email@domain.com';
  public $password = 'password';
  
  public $mailbox;
  public $check;
  public $thelist;
  public $overviews;
  public $ids = array();
  public $deleted = 0;
  
  function __construct() {
      $this-&gt;open_connection();
      $this-&gt;get_messages();
  }
  
  function get_messages() {
      $this-&gt;ids = array();
      $this-&gt;overviews = imap_fetch_overview($this-&gt;mailbox,"1:{$this-&gt;check-&gt;Nmsgs}");
  
      foreach($this-&gt;overviews as $overview) {
          //print_r($overview); exit;
          if(stripos($overview-&gt;subject, 'SPAM')!==FALSE
          || stripos($overview-&gt;subject, 'Luxury Replicas')!==FALSE
          || stripos($overview-&gt;subject, 'Pharmacy')!==FALSE
          || stripos($overview-&gt;subject, 'viagra')!==FALSE
          || stripos($overview-&gt;subject, 'dr.maxman')!==FALSE
          || stripos($overview-&gt;subject, 'cialis')!==FALSE
          || stripos($overview-&gt;subject, 'penis enlarge')!==FALSE
          || stripos($overview-&gt;from, 'westin')!==FALSE
          || stripos($overview-&gt;from, 'rightmove')!==FALSE
          || stripos($overview-&gt;from, 'groupon')!==FALSE
          || stripos($overview-&gt;from, 'primelocation')!==FALSE
          || stripos($overview-&gt;from, 'mg-rover')!==FALSE
          ) {
              $this-&gt;ids[] = $overview-&gt;uid;
  
          }
      }
      if(count($this-&gt;ids) &gt; 0) {
          $this-&gt;move_and_delete();
      }
  }
  
  function move_and_delete() {
      foreach($this-&gt;ids as $id) {
          // move to junk
          $result = imap_mail_move($this-&gt;mailbox, $id, 'INBOX.Junk');
  
          if($result) {
              //imap_delete($this-&gt;mailbox, $id); 
              $this-&gt;deleted++;
          }
      }
      imap_expunge($this-&gt;mailbox);
      imap_close($this-&gt;mailbox);
  }
  
  function open_connection() {
      $this-&gt;mailbox = imap_open($this-&gt;server.$this-&gt;folder, $this-&gt;user, $this-&gt;password);
      $this-&gt;check = imap_check($this-&gt;mailbox);
      $this-&gt;thelist = imap_getmailboxes($this-&gt;mailbox, $this-&gt;server, "*");
  }
  
  }
  ?&gt;
  </code></pre>
  
  <p>I get the same output each time saying deleted 115 messages. If i run it twice in quick succession then the output the second time should be deleted 0 messages. So basically it's not moving them properly because they are not disappearing from the inbox into the junk. Anyone know why? It is getting all the messages and looping through them but it seems the move just isnt happening.</p>