Solved

Mark IMAP mails unseen & unread

Posted on 2006-11-26
1
3,439 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to fix Datetime in MySQL? 4 51
What is wrong with this PDO Delete Query? 2 17
php help 34 58
PHP breaks when used in Wordpress template file 3 31
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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…
The viewer will learn how to dynamically set the form action using jQuery.

828 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