如何使用Zend Framework 2获取电子邮件附件

时间:2013-09-15 16:29:55

标签: php zend-framework2 imap

我设法获得了电子邮件的text / html和text / plain部分,但现在我需要使用strtok($part->contentType, ';') == "text/plain"strtok($part->contentType, ';') == "text/plain",但现在我需要获取附件(名称和解码)他们)。 我试图通过等同于附件的Content-Disposition来做到这一点,但我无法从标头数组中找到Content-Disposition。 所以我的问题是如何使用IMAP和ZF2从电子邮件中获取附件? 我看到了类似这样的问题,并且它们都是针对以前的版本提交的,我需要一些更新的解决方案。

使用Zend \ Mail \ Storage \ Imap。

这是我使用print_r( $part->getHeaders() );时获得的(这只是带附件的电子邮件部分):

Zend\Mail\Headers Object
(
    [pluginClassLoader:protected] => Zend\Mail\Header\HeaderLoader Object
        (
            [plugins:protected] => Array
                (
                    [bcc] => Zend\Mail\Header\Bcc
                    [cc] => Zend\Mail\Header\Cc
                    [contenttype] => Zend\Mail\Header\ContentType
                    [content_type] => Zend\Mail\Header\ContentType
                    [content-type] => Zend\Mail\Header\ContentType
                    [date] => Zend\Mail\Header\Date
                    [from] => Zend\Mail\Header\From
                    [message-id] => Zend\Mail\Header\MessageId
                    [mimeversion] => Zend\Mail\Header\MimeVersion
                    [mime_version] => Zend\Mail\Header\MimeVersion
                    [mime-version] => Zend\Mail\Header\MimeVersion
                    [received] => Zend\Mail\Header\Received
                    [replyto] => Zend\Mail\Header\ReplyTo
                    [reply_to] => Zend\Mail\Header\ReplyTo
                    [reply-to] => Zend\Mail\Header\ReplyTo
                    [sender] => Zend\Mail\Header\Sender
                    [subject] => Zend\Mail\Header\Subject
                    [to] => Zend\Mail\Header\To
                )

        )

    [headersKeys:protected] => Array
        (
            [0] => contenttype
            [1] => contentdisposition
            [2] => contenttransferencoding
            [3] => xattachmentid
        )

    [headers:protected] => Array
        (
            [0] => Zend\Mail\Header\ContentType Object
                (
                    [type:protected] => application/octet-stream
                    [parameters:protected] => Array
                        (
                            [name] => listen.pls
                        )

                )

            [1] => Zend\Mail\Header\GenericHeader Object
                (
                    [fieldName:protected] => Content-Disposition
                    [fieldValue:protected] => attachment; filename="listen.pls"
                    [encoding:protected] => ASCII
                )

            [2] => Zend\Mail\Header\GenericHeader Object
                (
                    [fieldName:protected] => Content-Transfer-Encoding
                    [fieldValue:protected] => base64
                    [encoding:protected] => ASCII
                )

            [3] => Zend\Mail\Header\GenericHeader Object
                (
                    [fieldName:protected] => X-Attachment-Id
                    [fieldValue:protected] => f_hlmfqj9o2
                    [encoding:protected] => ASCII
                )

        )

    [encoding:protected] => ASCII
)

0 个答案:

没有答案