1

Actually I am using imap functions but the problem is the count I am getting is of all the emails I want count that give me unread mail count can anyone tell me how can I do it. I can delete the seen mail and then it is working fine but I want to keep the mail and read the unread one.

I am taking help from this class

    for ($i = 0; $i < $total_messages; $i++) {

    $email = $vars->email_get($i+1);
    $ismsgdb = $vars->db_add_message($email); // vars INSERTS EACH MSG INTO DATABASE
    #Get store dir
    $dir = $vars->dir_name();
    $id_log = $vars->add_db_log($email, 'Copy e-mail - start ');

    foreach($vars->partsarray as $part){

    if($part[text][type] == 'HTML'){
        #$message_HTML = $part[text][string];
        $vars->db_update_message($part[text][string], $type= 'HTML');
    }
    elseif($part[text][type] == 'PLAIN'){
        $message_PLAIN = $part[text][string];
        $vars->db_update_message($part[text][string], $type= 'PLAIN');
    }
    elseif($part[attachment]){
    #Save files(attachments) on local disc

    foreach(array($part[attachment]) as $attach){
        $attach[filename] = $vars->mimie_text_decode($attach[filename]);
        $attach[filename] = preg_replace('/[^a-z0-9_\-\.]/i', '_', $attach[filename]);
        $vars->add_db_log($email, 'Start coping file:"'.strip_tags($attach[filename]).'"');

        $vars->save_files($vars->newid.$attach[filename], $attach[string]);
        $filename =  $dir.$vars->newid.$attach[filename];
        $vars->db_add_attach($attach[filename], $filename);
        $vars->update_db_log('<b>'.$filename.'</b>Finish coping:  "'.strip_tags($attach[filename]).'"', $vars->logid);
    }

    }elseif($part[image]){
    #Save files(attachments) on local disc

    $message_IMAGE[] = $part[image];

    foreach($message_IMAGE as $image){
        $image[filename] = $vars->mimie_text_decode($image[filename]);
        $image[filename] = preg_replace('/[^a-z0-9_\-\.]/i', '_', $image[filename]);
        $vars->add_db_log($email, 'Start coping file: "'.strip_tags($image[filename]).'"');


        $vars->save_files($vars->newid.$image[filename], $image[string]);
        $filename =  $dir.$vars->newid.$image[filename];
        $vars->db_add_attach($image[filename], $filename);
        $vars->update_db_log('<b>'.$filename.'</b>Finish  
        coping:"'.strip_tags($image[filename]).'"', $vars->logid);
        }

       }

     }
       $vars->spam_detect();
       $vars->email_setflag(); 
      //$vars->email_delete(); // WHEN I REMOVE vars THE SCRIPT WONT GRAB NEW EMAILS
      //$vars->email_expunge(); // WHEN I REMOVE vars THE SCRIPT WONT GRAB NEW EMAILS

      $vars->update_db_log('Finish coping', $id_log);
}

2 Answers 2

1

I didn't try this code but i think it will run without error.You can try something like this :

$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = '[email protected]';
$password = 'xyz123';

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,'UNSEEN');
 echo count($emails);

imap_close($inbox);

Only pass unseen parameter to search function.For details please read this.

Sign up to request clarification or add additional context in comments.

2 Comments

i have tried this before but the thing is that it is returning me the total count although i have visited the mail before
After changing the parameter didn't effect ?
1

After one day of work, ] found a solution. We need to replace UNSEEM with UNREAD like this:

$inbox = imap_open ("{".$serveur_entrant.$port.$protocole."}".$boite, $identifiant, $mot_de_passe);
$emails = imap_search($inbox,'UNREAD');
echo count($emails);
imap_close($inbox);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.