Link to home
Start Free TrialLog in
Avatar of mnb93
mnb93

asked on

Mark IMAP mails unseen & unread

     $mbox = imap_open($box, $user, $pass) OR die('error');
      
      for ($i = 1; $i <= imap_num_msg($mbox); $i++)
      {
            $header = imap_headerinfo($mbox, $i, 80, 80);
            if($header->Unseen == 'U' || $header->Recent == 'N') //Strange Behaviour in PHP
            {
                  echo '<div class="msg">';      
                  $fromemail = $header->from[0]->mailbox.'@'.$header->from[0]->host;
      $from = (strlen($header->from[0]->personal)>2) ? $header->from[0]->personal.' <'.$fromemail.'>' : $fromemail;
                  
                  $subject = $header->fetchsubject;
                  echo '<span class="from">'.htmlescape(substr_replace($from, '...', 77)).'</span><span class="subject">'.htmlescape(substr_replace($subject, '...', 77))."</span>";
                  $body = retrieve_message($mbox, $i);
                  $body = $body['body'];
                  echo '<p class="body">'.htmlescape(substr_replace($body, '...', 77));
                  echo '</p></div>';
                  fputs($mbox, "STORE $i -FLAGS (\\Seen)"); //Mark Unread
                  fputs($mbox, "STORE $i -FLAGS (\\Recent)"); //Mark Seen
                  $x++;
            }
      }

Is my current code, however

                  fputs($mbox, "STORE $i -FLAGS (\\Seen)"); //Mark Unread
                  fputs($mbox, "STORE $i -FLAGS (\\Recent)"); //Mark Unread

Doesn't seem to mark it unseen & unread.
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial