Skip to content

Method Webklex\PHPIMAP\Address::__toString() must return a string value #83

@vesper8

Description

@vesper8

I am running into a new bug as a result of your latest update. I will try to detail it as best I can so you can fix it

It occurs when I run a search for emails containing a certain string in the past 3 years. Note that this doesn't occur if I search for a smaller period. Also note that this was working fine before the 2.4.0 update. I don't think it has anything to do with the length of the search but rather is blowing up because of an edge case in an old email

This is the block of code where it occurs

        $messages = new MessageCollection();

        $this->client->getFolders(false)->each(function ($folder) use (&$messages, $searchInclude) {
            $query = $folder
            ->query()
            ->leaveUnread()
            ->since($this->since)
            ->setFetchFlags(true)
            ->setFetchBody(true)
            ->text($searchInclude);

            if ($this->ignoreRepliesAndForwards) {
                $query->notText('Re:')->notText('Fwd:')->notText('Fw:');
            }

            if ($query->count() > 0) {
                // dd($query->get()->reverse());

                $messages = $messages->merge(
                    $query->get()->reverse()
                );
            }
        });

The line that triggers it is $query->get()->reverse(), more specifically it's $query->get()

The error is

Method Webklex\PHPIMAP\Address::__toString() must return a string value

I added a try/catch inside the method that causes the fatal error:

    /**
     * Return the stringified attribute
     *
     * @return string
     */
    public function __toString()
    {
        try {
            $return = implode(', ', $this->values);
        } catch (\Throwable $th) {
            dd($this->values);
        }
        return $return;
    }

When successful, the following dd($this->values, $return); prints out:

array:1 [
  0 => Webklex\PHPIMAP\Address^ {#2112
    +personal: "Redacted"
    +mailbox: "office"
    +host: "Redacted.com"
    +mail: "office@Redacted.com"
    +full: "Redacted <office@Redacted.com>"
  }
]
"Redacted <office@Redacted.com>"

When it fails, $this->values contains:

array:1 [
  0 => Webklex\PHPIMAP\Address^ {#3658
    +personal: ""
    +mailbox: "07854482402"
    +host: null
    +mail: false
    +full: false
  }
]

I hope that's enough for you to figure out what's going wrong. Ask me anything if I can be of more assistance

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions