Solved

Mark IMAP mails unseen & unread

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
The viewer will learn how to count occurrences of each item in an array.

743 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

8 Experts available now in Live!

Get 1:1 Help Now