【发布时间】:2012-04-13 22:21:09
【问题描述】:
我正在尝试构建一个小型网络邮件应用程序。当我阅读收件箱中的所有电子邮件时,我想为每封邮件显示是否有附件。这行得通,但问题是这样做需要很长时间,1Mb 电子邮件附件大约需要 0.5 秒。将其与收件箱中具有大附件文件的所有电子邮件相乘:| 我的问题是:如何在不加载整个电子邮件的情况下检查电子邮件是否已附加?那可能吗 ? 下面是我现在使用的代码:
function existAttachment($part)
{
if (isset($part->parts))
{
foreach ($part->parts as $partOfPart)
{
$this->existAttachment($partOfPart);
}
}
else
{
if (isset($part->disposition))
{
if ($part->disposition == 'attachment')
{
echo '<p>' . $part->dparameters[0]->value . '</p>';
// here you can create a link to the file whose name is $part->dparameters[0]->value to download it
return true;
}
}
}
return false;
}
function hasAttachments($msgno)
{
$struct = imap_fetchstructure($this->_connection,$msgno,FT_UID);
$existAttachments = $this->existAttachment($struct);
return $existAttachments;
}
【问题讨论】: