在PHP中使用IMAP获取唯一的电子邮件ID [英] Getting unique email id with IMAP in PHP

查看:363
本文介绍了在PHP中使用IMAP获取唯一的电子邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为IMAP帐户中的每封电子邮件计算唯一的ID字符串?

How can I calculate a unique id string for each email in an IMAP account?

我正在编写一个脚本,该脚本必须经常将所有丢失的邮件从一个IMAP帐户复制到另一个帐户.我想避免在每次更新时重复,所以我必须确定一个帐户上有什么,另一个帐户上有什么.

I am making a script which must frequently copy all missing mails from one IMAP account to another one. I want to avoid making duplicates on each update, so I have to identify what is on one account and what is on the other.

并非所有电子邮件都有message_id,我看不到message_iduid之间的区别是什么-有人可以告诉我吗?

Not all emails have a message_id, and I can't see what the difference between message_id and uid is - can anybody tell me?

在我看来,使用 imap_append -有人可以确认吗?

It seems to me that the message_id is not changed when using imap_append - can anybody confirm that?

为每封电子邮件生成唯一的ID字符串时,除了消息ID,FX电子邮件标题和日期以外,还有许多其他选项,但是我不知道该怎么选择: http://www.php.net/manual/zh/function.imap -headerinfo.php

When generating a unique id string for each email there is many other options than just the message id, fx email title and date, but I don't know what to pick: http://www.php.net/manual/en/function.imap-headerinfo.php

推荐答案

UID在邮箱中是唯一的,但不会在邮箱之间进行映射,因此在邮箱之间匹配电子邮件没有用.

UID is unique within a mailbox, but does not map between mailboxes, so is of no use for matching emails between mailboxes.

message_id旨在对所有电子邮件都具有全局唯一性,并由发送电子邮件服务器生成.如果服务器配置正确,则它发送的每封邮件都将有一个message_id,可用于匹配各个邮箱中的电子邮件.但是,配置错误的服务器可能无法分配message_id.在这种情况下,senderaddress& udate一直被证明对我来说是独一无二的-如果电子邮件是在同一微秒内来自同一个人的,那将是同一封邮件.注意-使用发件人而不是发件人-发件人比发件人容易被欺骗.

message_id is intended to be globally unique for all emails and is generated by the sending email server. If the server is configured correctly, every message it sends will have a message_id, and this can be used to match an email across mailboxes. However, badly configured servers may not assign a message_id. In this case, a hash of senderaddress & udate has always proved to be unique for me - if the emails came from the same person at the same microsecond, it's gonna be the same message. Note - use sender rather than from - from can be spoofed easier than sender.

这篇关于在PHP中使用IMAP获取唯一的电子邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆