imap_fetchheader字节与实际文件大小

时间:2014-04-03 15:32:14

标签: php email filesystems imap

我正在使用 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。

1 个答案:

答案 0 :(得分:2)

它通常大约增加33%,因为它增加了多少额外的base64编码。

但并不总是33%:还有其他编码,base64只是附件中最常见的编码。