1

实际上我正在使用 imap 功能,但问题是我得到的计数是我想要计数的所有电子邮件,这些电子邮件给我未读邮件计数谁能告诉我我该怎么做。我可以删除看到的邮件,然后它工作正常,但我想保留邮件并阅读未读的邮件。

我正在这门课上寻求帮助

    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);
}
4

2 回答 2

1

我没有尝试此代码,但我认为它会毫无错误地运行。您可以尝试这样的事情:

$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'yourid@gmail.com';
$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);

只将不可见的参数传递给搜索功能。有关详细信息,请阅读内容。

于 2013-10-25T09:25:24.360 回答
1

经过一天的工作,] 找到了解决方案。我们需要像这样UNSEEM替换UNREAD

$inbox = imap_open ("{".$serveur_entrant.$port.$protocole."}".$boite, $identifiant, $mot_de_passe);
$emails = imap_search($inbox,'UNREAD');
echo count($emails);
imap_close($inbox);
于 2016-01-30T21:53:46.223 回答