gpt4 book ai didi

php - 使用 imap php 函数获取未读消息的计数

转载 作者:行者123 更新时间:2023-11-29 06:44:21 24 4
gpt4 key购买 nike

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

我正在从 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);
}

最佳答案

我没有尝试这段代码,但我认为它可以正常运行。您可以尝试这样的操作:

$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);

只传递看不见的参数给搜索函数。详情请阅读this .

关于php - 使用 imap php 函数获取未读消息的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19585097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com