尝试使用PHP imap_search查明邮箱中是否已存在给定消息(使用IMAP同步/迁移工具)。
我知道我的测试消息在那里:
Connected to imap.example.com
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE
STARTTLS AUTH=PLAIN AUTH=LOGIN] Welcome to mofoMail.
a1 LOGIN {username} {password}
a1 OK [snip] Logged in
a2 examine INBOX
a2 OK [READ-ONLY] Select completed.
a3 SEARCH HEADER Message-ID <001a11490a9ecd38280569bfcddf@google.com>
* SEARCH 1 11 19 21 25 35 39 48 54
a3 OK Search completed (0.402 secs).
现在,在迁移脚本中(修改php_imap_sync),我可以正常工作了,它只是将所有消息从源复制到目标,因此连接等仍在工作...但是现在我想修改这样,如果作业被中断或必须分阶段完成,它就不会重新复制已经迁移过的消息,因此尝试检查消息ID是否已经存在...
$array_mailbox[ $dst ] = imap_open( '{' . ${$dst}['server'] . ':' . ${$dst}['port'] . ${$dst}['str_connection'] . '}INBOX', ${$dst}['username'], ${$dst}['password']);
// stuff skipped
// getting header of current message from source mailbox
$header = imap_headerinfo($array_mailbox[ 'origin' ], $key+1);
$messageHeader = imap_fetchheader($array_mailbox['origin'], $key+1);
$msgHeader = imap_rfc822_parse_headers($messageHeader);
// above works as expected, my message-ID, same from example is in
// $msgHeader->message_id
// so why doesn't the following work?
$search_str = sprintf("HEADER Message-ID %s", $msgHeader->message_id);
$test = imap_search($array_mailbox['target'], $search_str);
echo "TESTING"; print_r($test);
if($test) {
printf("Already ported %s\n", $msgHeader->message_id);
next;
}
$ test始终为假。即使我遇到与上面的telnet测试相同的message-id。
我显然缺少有关imap_search()的东西,但我不知道它是什么。