1

We have a PHP script that opens a mailbox with imap_open, checks it for new messages, posts them onto our intranet, and then imap_deletes the message and imap_expunges the mailbox.

Generally this works okay, but sometimes the script fails to evict the message from the mailbox. This usually seems to be when the mail has a .xls attachment, though there exists the possibility that that's a red herring.

I've tried reworking things several times to get this to work properly, but without any success. Most of the time imap_delete does exactly what we want it to. Is there any obvious reason why imap_delete / expunge would fail to delete from a mailbox?

Or can anyone suggest a better way of deleting a mail that is being "difficult"?

ETA:

$check = imap_mailboxmsginfo($mailbox);
echo "Messages before delete: " . $check->Nmsgs . "<br />\n";

imap_delete($mailbox, $i);

$check = imap_mailboxmsginfo($mailbox);
echo "Messages after delete: " . $check->Nmsgs . "<br />\n";

imap_expunge($mailbox);

$check = imap_mailboxmsginfo($mailbox);
echo "Messages after expunge: " . $check->Nmsgs . "<br />\n";

Results in:

Messages before delete: 1
Messages after delete: 1
Messages after expunge: 1

Both imap_delete and imap_expunge are giving a return value of true. imap_errors() is empty at all points during and after the process. Nothing looks out of the ordinary in the access log.

imap_fetch_overview after the imap_delete call does indicate that the delete flag has been correctly set. The imap_fetch_overview call after imap_expunge() returns just the same thing, delete flag still set. So I guess the expunge seems to be not expunging, in the case of certain mails... The results of imap_fetch_overview both times:

array(1) { [0]=> object(stdClass)#16 (14) { ["subject"]=> string(23) "(Subject)" ["from"]=> string(40) "(Sender)" ["to"]=> string(24) "undisclosed-recipients: " ["date"]=> string(31) "Sun, 30 Dec 2012 23:36:34 +0000" ["message_id"]=> string(50) "" ["size"]=> int(89752) ["uid"]=> int(1) ["msgno"]=> int(1) ["recent"]=> int(1) ["flagged"]=> int(0) ["answered"]=> int(0) ["deleted"]=> int(1) ["seen"]=> int(1) ["draft"]=> int(0) } }

4

1 回答 1

0

服务器端可能存在导致此问题的某些情况。记录 imap_errors() 的结果以查看删除是否失败。查看 Excel 附件是否是原因,以及是否应归咎于特定的文件/文件格式也应该非常简单。也许帖子在内部网被拒绝,因此永远不会被删除?

于 2012-11-05T11:13:26.130 回答