Skip to content

how to fetch mails headers ? #17

Open
@darkworks

Description

@darkworks

am trying to fetch mails headers
so after connecting to mail box like

$imap = imap2_open($mailbox, $username, $accessToken, OP_XOAUTH2);

when i call imap2_headers like

imap2_headers($this->mail_box_handle);

i get error

Fatal error: Uncaught ArgumentCountError: Too few arguments to function Javanile\Imap2\Message::headers(), 1 passed in 
vendor\javanile\php-imap2\bootstrap.php on line 745 and at least 2 expected in vendor\javanile\php-imap2\src\Message.php:90 Stack trace: #0 vendor\javanile\php-imap2\bootstrap.php(745): Javanile\Imap2\Message::headers(Array) #1 F:\index.php(119): imap2_headers(Array) 

so after checking lib source
bootstrap.php

if (!function_exists('imap2_headers')) {
    function imap2_headers($imap)
    {
        return Message::headers($imap);
    }
}

then in Message.php definition of headers() method

    public static function headers($imap, $messageNum, $fromLength = 0, $subjectLength = 0, $defaultHost = null)
    {
        if (is_a($imap, Connection::class)) {
            $client = $imap->getClient();
            #$client->setDebug(true);

            $messages = $client->fetch($imap->getMailboxName(), $messageNum, false, ['BODY['.$section.']']);

            if ($section) {
                return $messages[$messageNum]->bodypart[$section];
            }

            return $messages[$messageNum]->body;
        }

        return imap_headerinfo($imap, $messageNum, $fromLength = 0, $subjectLength = 0);
    }

looks like headers method need at least two parameters however in bootstrap its declared incorrect. although original php imap_headers(); function would work ok with single parameter.

Metadata

Metadata

Labels

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions