Body.php 959 字节
<?php


namespace Lib\Imap\Request;

use Lib\Imap\Imap;

use Lib\Imap\Parse\Body as ParseBody;

/**
 * body邮件内容
 * @author:dc
 * @time 2024/9/20 14:53
 * Class Body
 * @package Lib\Imap\Request
 */
class Body extends Request {

    /**
     * @var Folder
     */
    protected Folder $folder;



    public function __construct(Imap $imap, Folder $folder)
    {
        parent::__construct($imap);

        $this->folder = $folder;
    }


    public function exec(): static{return $this;}


    /**
     * 读取邮件body
     * @param int $num
     * @param bool $is_uid
     * @return ParseBody
     * @author:dc
     * @time 2024/9/20 15:40
     */
    public function get(int $num, bool $is_uid = false):ParseBody {
        $this->folder->exec(); // 防止在其他文件夹下面
        $this->cmd("%sFETCH %s (RFC822.BODY)", $is_uid ? 'UID ' : '', $num);

        return (new ParseBody($this->result ? $this->result[0] : ''));
    }




}