Ensure message exists.

@param int $messageNumber
544542
protected function assertMessageExists(int $messageNumber): void
    {
        if (true === $this->messageNumberVerified) {
            return;
        }
        $this->messageNumberVerified = true;

        $msgno = \imap_msgno($this->resource->getStream(), $messageNumber);
        if (\is_numeric($msgno) && $msgno > 0) {
            $this->imapMsgNo = $msgno;

            return;
        }

        throw new MessageDoesNotExistException(\sprintf(
            'Message "%s" does not exist',
            $messageNumber
        ));
    }
1032909
public function matches(MessageReceived $message): bool
    {
        $haystack = $this->values;

        if ($haystack instanceof Collection) {
            $haystack = $haystack->toArray();
        }

        return in_array($message->getText(), $haystack, false);
    }
376626
public function checkMessage(MessageInterface $message) {
        if (!$message->isBinary()) {
            if (!$this->checkUtf8($message->getPayload())) {
                return Frame::CLOSE_BAD_PAYLOAD;
            }
        }

        return true;
    }
187493
public function add($key, $message)
	{
		if ($this->unique($key, $message)) $this->messages[$key][] = $message;
	}
600388
public function move($numbers, MailboxInterface $mailbox): void
    {
        if (!\imap_mail_move($this->resource->getStream(), $this->prepareMessageIds($numbers), $mailbox->getEncodedName(), \CP_UID)) {
            throw new MessageMoveException(\sprintf('Messages cannot be moved to "%s"', $mailbox->getName()));
        }
    }
228325
public function setPhoneNumber(PhoneNumber $phoneNumber)
    {
        if (!is_a($phoneNumber, PhoneNumber::class, false))
        {
            throw new InvalidArgumentException("The phone number is not an instance of the PhoneNumber class.");
        }

        $this->phoneNumbers[$phoneNumber->getType()] = $phoneNumber;
    }
854962
protected function isUnique($key, $message)
    {
        $messages = (array) $this->messages;

        return !isset($messages[$key]) || !in_array($message, $messages[$key], true);
    }
1181667
public static function hasMessageForError($value)
    {
        if (self::isValidName($value)) {
            $value = self::getNameValue($value);
        }

        return isset(self::$messages[$value]);
    }
1305831
protected function _setLineNumber($lineNumber)
    {
        if ($lineNumber !== null) {
            try {
                $lineNumber = $this->_normalizeInt($lineNumber);
            } catch (RootException $e) {
                throw $this->_createInvalidArgumentException($this->__('Invalid line number'), null, $e, $lineNumber);
            }

            if ($lineNumber < 1) {
                throw $this->_createInvalidArgumentException($this->__('Line number must be positive'), null, null, $lineNumber);
            }
        }

        $this->lineNumber = $lineNumber;
    }
811419
public function updateFailedMessage($number, $message = null)
    {
        if (Lang::has('resource-controller.updatefailed')) {
            return trans(
                'resource-controller.updatefailed', [
                    'number' => $number,
                    'message' => $message
                ]
            );
        }

        return 'Operation failed while updating the record '.$number.' with message: '.$message;
    }
68308
public function sendAsync($mobileNumber, $message, $messageId = null)
    {
        return $this->app['chikka.sender']->sendAsync($mobileNumber, $message, $messageId);
    }
688219
public function setMessage($value)
    {
        $this->_validateNotNull('Message', $value);
        $this->_validateString('Message', $value);

        if ($this->data['message'] === $value) {
            return;
        }

        $this->data['message'] = $value;

        $this->_setModified('message');
    }
1284997
public function send($mobileNumber, $message, $messageId = null)
    {
        return $this->sendAsync($mobileNumber, $message, $messageId)
        ->then(
            function (ResponseInterface $response) {
                return new SentResponse($response, $this->requestForm);
            },
            function ($exception) {
                return $this->throwError($exception);
            }
        )->wait();
    }
298673
public function isValid(Message $message)
    {
        try {
            $this->validate($message);
            return true;
        } catch (InvalidSnsMessageException $e) {
            return false;
        }
    }
236668
public static function legacy_messages_exist($userid) {
        global $DB;

        $sql = "SELECT id
                  FROM {message} m
                 WHERE useridfrom = ?
                    OR useridto = ?";
        $messageexists = $DB->record_exists_sql($sql, [$userid, $userid]);

        $sql = "SELECT id
                  FROM {message_read} m
                 WHERE useridfrom = ?
                    OR useridto = ?";
        $messagereadexists = $DB->record_exists_sql($sql, [$userid, $userid]);

        return $messageexists || $messagereadexists;
    }
839935
public function addError($errorMessage)
    {
        if (is_array($errorMessage)) {
            if (count($errorMessage)) {
                foreach ($errorMessage as $message) {
                    $this->errors[] = $message;
                }
            }
        } else {
            $this->errors[] = $errorMessage;
        }
    }
79583
protected function uniqueMessages($messageBag, $messageBagFromCustom = null)
    {
        if (is_null($messageBagFromCustom)) {
            return $messageBag;
        }
        $messages = $messageBagFromCustom->getMessages();
        foreach ($messages as $key => $value) {
            if (empty($value)) {
                continue;
            }
            foreach ($value as $messageName) {
                if ($messageBag->has($key, $messageName)) {
                    continue;
                }
                $messageBag->add($key, $messageName);
            }
        }
        return $messageBag;
    }