title: Set an email as SEEN on IMAP server
body: <p>I am trying to read mail from an Imap Server (Gmail). I would check if there are new mail (unseen) and check it as seen.
  I wrote this code but </p>
  
  <pre><code>imap_setflag_full
  </code></pre>
  
  <p>seems to not work. 
  If I have a new mail the script is unable to put the SEEN flag and it echo me that there is always one unseen mail.</p>
  
  <pre><code>  $mbox=imap_open( "{imap.gmail.com:993/ssl/novalidate-cert}" , $this-&gt;username, $this-&gt;password);
      if ($mbox) 
              {  echo "Connected\n&lt;br&gt;&lt;br&gt;"; 
              }  else { exit ("Can't connect: " . imap_last_error() ."\n");  echo "FAIL!\n";  }; 
  
          if ($hdr = imap_check($mbox)) {
            $msgCount = $hdr-&gt;Nmsgs;
            echo "There are ".$msgCount." mail";
          } else {
            echo "Failed to get mail";
  
          }
  
          $result = imap_search($mbox, 'UNSEEN');
          echo "&lt;br&gt;Result: ";
          print_r($result);
          if($result==false)
              echo "No email";
          else{
              echo "you have mail"; 
              echo("&lt;br&gt;now I set the Seen flag for this mail");
              rsort($result);
              $status = imap_setflag_full($mbox, "1", "\\Seen \\Flagged", ST_UID);      
          }
  
          echo"&lt;br&gt;&lt;br&gt;";
  
  
          $result = imap_search($mbox, 'UNSEEN');
          echo "&lt;br&gt;Result: ";
          print_r($result);
          if($result==false)
              echo "no mail";
          else{
              echo "there are still"; 
  
          }
  </code></pre>
  
  <p>Thank you so much.</p>