【发布时间】:2014-04-03 15:32:13
【问题描述】:
我正在使用 imap_fetcheader 来获取邮件的附件,只是内容。这是代码-
if (isset($content->ifdparameters) && $content->ifdparameters == 1 && isset($content->dparameters) && is_array($content->dparameters)) {
foreach ($content->dparameters as $object) {
if (isset($object->attribute) && preg_match('~filename~i', $object->attribute)) {
$attachment = new EmailAttachment();
$attachment->attachment_name = $object->value;
$attachment->attachment_size = $this->format_bytes($content->bytes);
$attachment->attachment_part_id = empty($actualpart) ? 1 : $actualpart;
$attachment->attachment_encoding = $content->encoding;
$results[] = $attachment;
}
}
}
format_bytes 函数在这里 -
private function format_bytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}
当用户点击附件时,我从邮件服务器抓取附件内容并将内容回显。
问题是——
$content->bytes 属性报告的字节与下载到客户端计算机的字节大不相同...
这是一个已知问题吗?
邮件服务器是托管在 CentOS 操作系统上的 POSTFIX。
【问题讨论】:
标签: php email filesystems imap