protected function getMail($matches = [], $new = false, $index = null, $store = 'default')
    {
        $mail = $this->getMailManager()->getMail($store);
        $previousMailCount = $this->getMailCount($store);
        $this->mailCount[$store] = count($mail);

        // Ignore previously seen mail.
        if ($new) {
            $mail = array_slice($mail, $previousMailCount);
        }

        // Filter mail based on $matches; keep only mail where each field mentioned
        // in $matches contains the value specified for that field.
        $mail = array_values(array_filter($mail, function ($singleMail) use ($matches) {
            return ($this->matchesMail($singleMail, $matches));
        }));

        // Return an individual mail if specified by an index.
        if (is_null($index) || count($mail) === 0) {
            return $mail;
        } else {
            return array_slice($mail, $index, 1)[0];
        }
    }