PHP Horde imap如何获取

PHP Horde imap如何获取,php,imap,horde,Php,Imap,Horde,我看到了类似的问题,但对我没有帮助。我正试着去拿信息。我需要所有部分,标题,附件完整的消息 $fetchQuery = new Horde_Imap_Client_Fetch_Query(); $fetchQuery->fullText(); /** @var Horde_Imap_Client_Fetch_Results $mail */ $results = $client->fetch('INBOX', $fetchQuery, ['ids' => new Hord

我看到了类似的问题,但对我没有帮助。我正试着去拿信息。我需要所有部分,标题,附件完整的消息

$fetchQuery =  new Horde_Imap_Client_Fetch_Query();
$fetchQuery->fullText();


/** @var Horde_Imap_Client_Fetch_Results $mail */
$results = $client->fetch('INBOX', $fetchQuery, ['ids' => new Horde_Imap_Client_Ids(11632)]);

var_dump($results->first()->getEnvelope()->subject);

我尝试了很多变体。但我不能得到任何关于这个消息的信息。主题为空字符串。我确信,这种带有uid的邮件是存在的,我也用Horde得到了这个uid

试试下面提到的代码$results阵列包含您需要的所有项目

$fetchQuery =  new Horde_Imap_Client_Fetch_Query();
$fetchQuery->fullText();


/** @var Horde_Imap_Client_Fetch_Results $mail */
$results = $client->fetch('INBOX', $fetchQuery, ['ids' => new Horde_Imap_Client_Ids(11632)]);

var_dump($results->first()->getFullMsg());
    $uids = new \Horde_Imap_Client_Ids($thread_uids); 

    $query = new \Horde_Imap_Client_Fetch_Query();
    $query->envelope();
    $query->structure();


    $messages = $oClient->fetch($mailbox, $query, array('ids' => $uids));



    $results = [];
    foreach($messages as $message){

    $envelope = $message->getEnvelope();
    $structure = $message->getStructure();


        $msghdr = new StdClass;
        $msghdr->recipients = $envelope->to->bare_addresses;
        $msghdr->senders    = $envelope->from->bare_addresses;
        $msghdr->cc         = $envelope->cc->bare_addresses;
        $msghdr->bcc         = $envelope->bcc->bare_addresses;
        $msghdr->subject    = $envelope->subject;
        $msghdr->timestamp  = $envelope->date->getTimestamp();



        $query = new Horde_Imap_Client_Fetch_Query();
        $query->fullText();

        $typemap = $structure->contentTypeMap();
        foreach ($typemap as $part => $type) {
            // The body of the part - attempt to decode it on the server.
            $query->bodyPart($part, array(
                'decode' => true,
                'peek' => true,
            ));
            $query->bodyPartSize($part);
        }

        $id = new Horde_Imap_Client_Ids($message->getUid());
        $messagedata = $oClient->fetch($mailbox, $query, array('ids' => $id))->first();
        $msgdata = new StdClass;
        $msgdata->id = $id;
        $msgdata->contentplain = '';
        $msgdata->contenthtml  = '';
        $msgdata->attachments  = array(
            'inline'     => array(),
            'attachment' => array(),
        );

        $plainpartid = $structure->findBody('plain');
        $htmlpartid  = $structure->findBody('html');

        foreach ($typemap as $part => $type) {
            // Get the message data from the body part, and combine it with the structure to give a fully-formed output.
            $stream = $messagedata->getBodyPart($part, true);
            $partdata = $structure->getPart($part);
            $partdata->setContents($stream, array('usestream' => true));
            if ($part == $plainpartid) {
                $msgdata->contentplain = $partdata->getContents();
            } else if ($part == $htmlpartid) {
                $msgdata->contenthtml = $partdata->getContents();
            } else if ($filename = $partdata->getName($part)) {
                $disposition = $partdata->getDisposition();
                $disposition = ($disposition == 'inline') ? 'inline' : 'attachment';
                $attachment = new StdClass;
                $attachment->name    = $filename;
                $attachment->type    = $partdata->getType();
                $attachment->content = $partdata->getContents();
                $attachment->size    = strlen($attachment->content);
                $msgdata->attachments[$disposition][] = $attachment;
            }
        }


        $data = [
            'uid' => implode("",$id->ids),
            'from' => implode(",",$msghdr->senders),
            'cc' => implode(",",$msghdr->cc),
            'bcc' => implode(",",$msghdr->bcc),
            'to' => implode(",",$msghdr->recipients),
            'date' => $msghdr->timestamp,
            'subject' => $envelope->subject,
            'hasAttachments' => $structure->getDisposition(),
            'folder' => $mailbox,
            'messageId' =>  $envelope->message_id,
            'attachment' => $msgdata->attachments
        ];

        $data['body'] = empty($msgdata->contenthtml) ? $msgdata->contenttext: $msgdata->contenthtml;    


        array_push($results,$data);



    }