Zend framework 使用Zend从IMAP检索到特定日期的邮件
我正在使用Zend_Mail_Storage_Imap库从Imap检索电子邮件Zend framework 使用Zend从IMAP检索到特定日期的邮件,zend-framework,object,imap,Zend Framework,Object,Imap,我正在使用Zend_Mail_Storage_Imap库从Imap检索电子邮件 $mail = new Zend_Mail_Storage_Imap(array('connection details')); foreach($mail as $message) { if($message->date > $myDesiredDate) { //do stuff }else{ continue; } 此代码检索所有邮件,首先检索最旧的邮件。变量$my
$mail = new Zend_Mail_Storage_Imap(array('connection details'));
foreach($mail as $message)
{
if($message->date > $myDesiredDate)
{
//do stuff
}else{
continue;
}
此代码检索所有邮件,首先检索最旧的邮件。变量$myDesiredDate是日期/时间,超过该日期/时间的邮件不需要发送。有没有办法跳过对所有邮件的检索,逐个检查每封邮件的日期?如果没有,我可以反转$mail对象以获取顶部的最新电子邮件吗
更新:我现在稍微修改了代码,从最新的邮件开始,检查当前邮件的日期和时间。当我遇到一封超过我不想解析电子邮件时间的电子邮件时,我打破了循环
//time upto which I want to fetch emails (in seconds from current time)
$time = 3600;
$mail = new Zend_Mail_Storage_Imap(array('connection details'));
//get total number of messages
$total = $mail->countMessages()
//loop through the mails, starting from the latest mail
while($total>0)
{
$mailTime = strtotime(substr($mail->getMessage($total)->date,0,strlen($mail->getMessage($total)->date)-6));
//check if the email was received before the time limit
if($mailTime < (time()-$time))
break;
else
//do my thing
$total--;
}
//close mail connection
$mail->close();
//time upto which I want to fetch emails (in seconds from current time)
$time = 3600;
$mail = new Zend_Mail_Storage_Imap(array('connection details'));
//get total number of messages
$total = $mail->countMessages()
//loop through the mails, starting from the latest mail
while($total>0)
{
$mailTime = strtotime(substr($mail->getMessage($total)->date,0,strlen($mail->getMessage($total)->date)-6));
//check if the email was received before the time limit
if($mailTime < (time()-$time))
break;
else
//do my thing
$total--;
}
//close mail connection
$mail->close();
//我要获取电子邮件的时间(从当前时间算起,以秒为单位)
$time=3600;
$mail=新Zend_mail_Storage_Imap(阵列(“连接详细信息”);
//获取消息总数
$total=$mail->countMessages()
//循环浏览邮件,从最新的邮件开始
而($total>0)
{
$mailTime=strotime(substr($mail->getMessage($total)->日期,0,strlen($mail->getMessage($total)->日期)-6);
//检查电子邮件是否在时间限制之前收到
如果($mailTime<(time()-$time))
打破
其他的
//做我的事
$total——;
}
//关闭邮件连接
$mail->close();
这里我唯一关心的是,如果我从邮件计数开始到0,我是否应该以正确的顺序收到邮件?因为我的代码工作得非常好,我将把它作为一个答案(快速和肮脏)。我现在从最新的邮件开始,检查当前邮件的日期和时间。当我遇到一封超过我不想解析电子邮件时间的电子邮件时,我打破了循环
//time upto which I want to fetch emails (in seconds from current time)
$time = 3600;
$mail = new Zend_Mail_Storage_Imap(array('connection details'));
//get total number of messages
$total = $mail->countMessages()
//loop through the mails, starting from the latest mail
while($total>0)
{
$mailTime = strtotime(substr($mail->getMessage($total)->date,0,strlen($mail->getMessage($total)->date)-6));
//check if the email was received before the time limit
if($mailTime < (time()-$time))
break;
else
//do my thing
$total--;
}
//close mail connection
$mail->close();
//time upto which I want to fetch emails (in seconds from current time)
$time = 3600;
$mail = new Zend_Mail_Storage_Imap(array('connection details'));
//get total number of messages
$total = $mail->countMessages()
//loop through the mails, starting from the latest mail
while($total>0)
{
$mailTime = strtotime(substr($mail->getMessage($total)->date,0,strlen($mail->getMessage($total)->date)-6));
//check if the email was received before the time limit
if($mailTime < (time()-$time))
break;
else
//do my thing
$total--;
}
//close mail connection
$mail->close();
//我要获取电子邮件的时间(从当前时间算起,以秒为单位)
$time=3600;
$mail=新Zend_mail_Storage_Imap(阵列(“连接详细信息”);
//获取消息总数
$total=$mail->countMessages()
//循环浏览邮件,从最新的邮件开始
而($total>0)
{
$mailTime=strotime(substr($mail->getMessage($total)->日期,0,strlen($mail->getMessage($total)->日期)-6);
//检查电子邮件是否在时间限制之前收到
如果($mailTime<(time()-$time))
打破
其他的
//做我的事
$total——;
}
//关闭邮件连接
$mail->close();