dongzhao8233 2013-12-10 15:34
浏览 111
已采纳

使用PHP和IMAP获取尚未抓取的电子邮件

This is more of a question about best practices - I hope that's ok.

I am using PHP and IMAP to grab emails from a Gmail account every 30 minutes. I only want the script to grab emails from 30 minutes ago, so it will never grab the same email twice.

There is a "since" command in the search query:

imap_search($inbox, 'SUBJECT "Ticket #" SINCE "'.date("Y-m-d").'"');

But this will only take a date and not a time.

I can technically do a loop through all emails and only grab emails that are 30 minutes away from the current time:

$email_time = strtotime($overview[0]->date);
$current_time = strtotime('-30 minutes');
if($email_time >= $current_time) {
    ...
}

I don't believe this to be a reliable solution though, because whose to say the emails aren't delayed, or what happens if the server goes down for a few minutes?

Every time the cron job executes the email script, I can store the time in the database and use that time as a reference to check all emails since. But then I need to create a brand new table, just for one field?

I'm thinking there must be a better solution....

  • 写回答

1条回答 默认 最新

  • dtmjqyfz21793 2013-12-10 20:25
    关注

    Indeed. You should track the UIDs of the messages you download. All new messages that arrive will have a higher UID than any previous message. So just fetch messages with UIDs higher than you already have.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作