<?php


namespace Heanup\App\Api\Controller;


use Heanup\App\Api\RestfulController;
use PhpImap\Exceptions\InvalidParameterException;
use PhpImap\Mailbox;

class Imap extends RestfulController
{

    /**
     * Get Method|获取数据
     * @return void
     * @throws InvalidParameterException
     */
    protected function getData()
    {
        // Create PhpImap\Mailbox instance for all further actions
        $mailbox = new Mailbox(
            '{mail.97admin.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
            'chendeben@a4sky.com', // Username for the before configured mailbox
            '6485882', // Password for the before configured username
            __DIR__, // Directory, where attachments will be saved (optional)
            'UTF-8' // Server encoding (optional)
        );

        // Get all emails (messages)
        // PHP.net imap_search criteria: http://php.net/manual/en/function.imap-search.php
        $mailsIds = $mailbox->searchMailbox('ALL');

// Get the first message
// If '__DIR__' was defined in the first line, it will automatically
// save all attachments to the specified directory
        $mail = $mailbox->getMail(26);

// Show, if $mail has one or more attachments
//        echo "\nMail has attachments? ";
//        if ($mail->hasAttachments()) {
//            echo "Yes\n";
//        } else {
//            echo "No\n";
//        }

        echo ($mail->textHtml);
// Print all information of $mail
//        print_r($mail);

// Print all attachements of $mail
//        echo "\n\nAttachments:\n";
//        print_r($mail->getAttachments());
    }

    /**
     * Post Method|新增数据
     * @return void
     */
    protected function postData()
    {
        // TODO: 需要实现 postData() 方法.
    }

    /**
     * Put Method|更新数据
     * @return void
     */
    protected function putData()
    {
        // TODO: 需要实现 putData() 方法.
    }

    /**
     * Delete Method|删除数据
     * @return void
     */
    protected function deleteData()
    {
        // TODO: 需要实现 deleteData() 方法.
    }
}