Solved

Mark IMAP mails unseen & unread

Posted on 2006-11-26
1
3,532 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
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 count occurrences of each item in an array.

635 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