Solved

Mark IMAP mails unseen & unread

Posted on 2006-11-26
1
3,407 Views
Last Modified: 2008-01-09
     $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.
0
Comment
Question by:mnb93
1 Comment
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 18017800
fputs is the wron way on a mailbox. See
http://de3.php.net/manual/en/function.imap-clearflag-full.php
http://de3.php.net/manual/en/function.imap-setflag-full.php

more like the  following:
$status = imap_clearflag_full($mbox, $i, "\\Seen \\Recent");
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now