Converts message identifiers array into sequence-set syntax

@param array $messages Message identifiers
@param bool  $force    Forces compression of any size

@return string Compressed sequence-set
558992
public static function compressMessageSet($messages, $force=false)
    {
        // given a comma delimited list of independent mid's,
        // compresses by grouping sequences together
        if (!is_array($messages)) {
            // if less than 255 bytes long, let's not bother
            if (!$force && strlen($messages) < 255) {
                return preg_match('/[^0-9:,*]/', $messages) ? 'INVALID' : $messages;
            }

            // see if it's already been compressed
            if (strpos($messages, ':') !== false) {
                return preg_match('/[^0-9:,*]/', $messages) ? 'INVALID' : $messages;
            }

            // separate, then sort
            $messages = explode(',', $messages);
        }

        sort($messages);

        $result = array();
        $start  = $prev = $messages[0];

        foreach ($messages as $id) {
            $incr = $id - $prev;
            if ($incr > 1) { // found a gap
                if ($start == $prev) {
                    $result[] = $prev; // push single id
                }
                else {
                    $result[] = $start . ':' . $prev; // push sequence as start_id:end_id
                }
                $start = $id; // start of new sequence
            }
            $prev = $id;
        }

        // handle the last sequence/id
        if ($start == $prev) {
            $result[] = $prev;
        }
        else {
            $result[] = $start.':'.$prev;
        }

        // return as comma separated string
        $result = implode(',', $result);

        return preg_match('/[^0-9:,*]/', $result) ? 'INVALID' : $result;
    }
79238
public static function expandToTree(array $messages)
    {
        $tree = [];

        foreach ($messages as $id => $value) {
            $referenceToElement = &self::getElementByPath($tree, explode('.', $id));

            $referenceToElement = $value;

            unset($referenceToElement);
        }

        return $tree;
    }
599505
public static function messages($messages = [], $append = true)
    {
        if (func_num_args()) {
            static::$_messages = $append ? array_merge(static::$_messages, $messages) : $messages + ['_default_' => 'is invalid'];
        }
        return static::$_messages;
    }
674299
protected function getFormMessages(array $fields)
    {
        // Each message is defined by field and its own rules.
        // In our case, we need to prepend the field name (attribute)
        // using a "dot" notation. Ex.: email.required
        $messages = [];

        foreach ($fields as $field) {
            /** @var FieldTypeInterface $field */
            foreach ($field->getOption('messages') as $attr => $message) {
                $messages[$field->getName().'.'.$attr] = $message;
            }
        }

        return $messages;
    }
921835
public function setMessages($messages)
	{
		if (!is_array($messages))
		{
			throw new InvalidArgumentException(sprintf(
				'Messages must be an array. Type of "%s" passed.',
				gettype($messages)
			));
		}

		$this->_messages = $messages;

		return $this;
	}
1112847
protected function denormaliseMessages($messages)
    {
        // Sort prior to denormalisation
        ksort($messages);
        $entities = [];
        foreach ($messages as $entity => $value) {
            // Skip un-namespaced keys
            $value = $this->denormaliseValue($value);

            // Non-nested key
            if (strstr($entity, '.') === false) {
                $entities[$entity] = $value;
                continue;
            }

            // Get key nested within class
            list($class, $key) = $this->getClassKey($entity);
            if (!isset($entities[$class])) {
                $entities[$class] = [];
            }

            $entities[$class][$key] = $value;
        }
        return $entities;
    }
983205
protected function formatMessages($messages, $format, $type = '')
    {

        if ($format === self::Format_Array) {
            $result = $messages;
        } else {
            $result = array();
            foreach ($messages as $message) {
                if (is_array($message)) {
                    $messagePart = "{$message['code']}: ";
                    $messagePart .= $this->t($message['message']);
                    if ($message['codetag']) {
                        $messagePart .= " ({$message['codetag']})";
                    }
                    $message = $this->t($type) . ' ' . $messagePart;
                }
                if ($format === self::Format_FormattedText) {
                    $message = "* $message\n\n";
                } elseif ($format === self::Format_Html) {
                    $message = "<li>" . nl2br(htmlspecialchars($message, ENT_NOQUOTES)) . "</li>\n";
                }
                $result[] = $message;
            }
            if ($format === self::Format_FormattedText) {
                $result = implode('', $result);
            } elseif ($format === self::Format_Html) {
                $result = "<ul>\n" . implode('', $result) . "</ul>\n";
            }
        }
        return $result;
    }
858122
public function formatMessage(array $message): string
    {
        [$level, $text, $context] = $message;
        $category = $context['category'];
        $timestamp = $context['time'];
        $level = Logger::getLevelName($level);
        $traces = [];
        if (isset($context['trace'])) {
            foreach ($context['trace'] as $trace) {
                $traces[] = "in {$trace['file']}:{$trace['line']}";
            }
        }

        $prefix = $this->getMessagePrefix($message);

        return $this->getTime($timestamp) . " {$prefix}[$level][$category] $text"
            . (empty($traces) ? '' : "\n    " . implode("\n    ", $traces));
    }
620321
public function transformMessages(array $messages)
    {
        $transformed = null;

        if(count($messages))
        {
            $transformed = [];

            foreach ($messages as $message)
            {
                $attributes = (object) $message->getAttributes();

                $attributes->timestamp = $attributes->t;

                unset($attributes->t);
                
                // Add encryption check 
                $child = is_null($message->getChild(1)) ? $message->getChild(0) : $message->getChild(1);

                $node = new stdClass();
                $node->tag = $child->getTag();
                $node->attributes = (object) $child->getAttributes();
                $node->data = $child->getData();

                $attributes->body = $node;

                if($attributes->type == 'media')
                {
                    if($attributes->body->attributes->type == 'vcard')
                    {
                        $vcard = new VCardReader(null, $child->getChild(0)->getData());

                        if(count($vcard) == 1)
                        {
                            $attributes->body->vcard[] = $vcard->parse($vcard);
                        }
                        else
                        {
                            foreach ($vcard as $card)
                            {
                                $attributes->body->vcard[] = $vcard->parse($card);
                            }
                        }
                    }
                    else
                    {
                        $tmp = $this->media->link($attributes);
                    
                        $attributes->body->file = $tmp->file;
                        $attributes->body->html = $tmp->html;
                        $attributes->body->attributes2 = $node->attributes;
                    }           
                }

                $transformed[] = $attributes;
            }
        }

        return $transformed;
    }
869926
public function errors(array $messages): string
    {
        if (!$messages) {
            return ''; // No error messages.
        }
        $messages      = $this->c::markdown($messages, ['no_p' => true]);
        return $markup = '<ul><li>'.implode('</li><li>', $messages).'</li></ul>';
    }
172823
private static function processParams(array $message): string
    {
        $msg_type = count($message);
        if($msg_type==1) {
            return (string) $message[0];
        } else if($msg_type<1) {
            return "";
        } else {
            $params = $message;
            $message = array_shift($params);
            return sprintf($message, ...$params);
        }
    }
1296276
public function message($force_full_length = false)
	{
		if (is_null($this->is_trimmed) && !$force_full_length)
		{
			$this->is_trimmed = $this->trim();
		}

		return ($this->is_trimmed && !$force_full_length) ? $this->trimmed_message : $this->message;
	}
586502
public function copy($messages, $from, $to)
    {
        // Clear last COPYUID data
        unset($this->data['COPYUID']);

        if (!$this->select($from)) {
            return false;
        }

        // Clear internal status cache
        unset($this->data['STATUS:'.$to]);

        $result = $this->execute('UID COPY', array(
            $this->compressMessageSet($messages), $this->escape($to)),
            self::COMMAND_NORESPONSE);

        return $result == self::ERROR_OK;
    }
948286
protected function resolveErrorKey($messages = [])
	{
		// if there is no error key defined leave messages as they were
		if(empty($this->errorKey))
		{
			return $messages;
		}

		// keys are divided on every .
		$keys = explode('.', $this->errorKey);

		// we need to reverse this array for sorting
		$keys = array_reverse($keys);

		foreach ($keys as $errorKey) {
			$messages = array($errorKey => $messages);
		}

		return $messages;
	}
780270
public function configureDefaults(array $defaults, $force = false)
    {
        if ($force || empty($this->toArray())) {
            $attachmentDefaults = $this->attachmentDefaults;

            foreach (MessageDefaults::allKeys() as $key) {
                if (isset($defaults[$key]) && ! is_null($value = $defaults[$key])) {
                    if (strpos($key, 'attachment_') !== false) {
                        if ($key = substr($key, strlen('attachment_'))) {
                            $attachmentDefaults[$key] = $value;
                        }
                    } else {
                        $this->fillDefaults($key, $value);
                    }
                }
            }

            $this->setAttachmentDefaults($attachmentDefaults);
        }

        return $this;
    }
65620
public function getMessageSequence(string $sequence): MessageIteratorInterface
    {
        \imap_errors();

        $overview = \imap_fetch_overview($this->resource->getStream(), $sequence, \FT_UID);
        if (\is_array($overview) && [] !== $overview) {
            $messageNumbers = \array_column($overview, 'uid');
        } else {
            if (false !== \imap_last_error()) {
                throw new InvalidSearchCriteriaException(\sprintf('Invalid sequence [%s]', $sequence));
            }

            $messageNumbers = [];
        }

        return new MessageIterator($this->resource, $messageNumbers);
    }
670993
protected function formatMessages($messages, string $prefix): array
    {
        $result = [];

        // Convert single messages to array
        if (is_string($messages)) {
            $messages = [$messages];
        }

        // Prefix all messages
        foreach ($messages as $message) {
            $result[] = sprintf("[%s][%s] %s : %s", $this->module, $this->configType, $prefix, $message);
        }

        return $result;
    }