@param MessageStructure $structure
@param RawMessage       $rawMessage

@return FailureMessage
961701
public function convertStructureToFailureMessage(MessageStructure $structure, RawMessage $rawMessage)
    {
        $message = new FailureMessage($structure->getElements()[0]);
        $message->setSerialization($rawMessage->getBytes());

        return $message;
    }
519721
public function log($level, $rawMessage, array $context = array())
    {
        $message = $this->initMessage($level, $rawMessage, $context);

        // add exception data if present
        if (isset($context['exception'])
           && $context['exception'] instanceof Exception
        ) {
            $this->initExceptionData($message, $context['exception']);
        }

        $this->publisher->publish($message);
    }
1232400
protected function makeMessages($rawMessages)
    {
        $incomingMessages = [];
        foreach ($rawMessages as $rawMessage) {
            $incomingMessages[] = $this->processReceive($rawMessage);
        }

        return $incomingMessages;
    }
468758
protected static function addStructure(array $structure, vfsStreamDirectory $baseDir): vfsStreamDirectory
    {
        foreach ($structure as $name => $data) {
            $name = (string) $name;
            if (is_array($data) === true) {
                self::addStructure($data, self::newDirectory($name)->at($baseDir));
            } elseif (is_string($data) === true) {
                $matches = null;
                preg_match('/^\[(.*)\]$/', $name, $matches);
                if ($matches !== []) {
                    self::newBlock($matches[1])->withContent($data)->at($baseDir);
                } else {
                    self::newFile($name)->withContent($data)->at($baseDir);
                }
            } elseif ($data instanceof FileContent) {
                self::newFile($name)->withContent($data)->at($baseDir);
            } elseif ($data instanceof vfsStreamFile) {
                $baseDir->addChild($data);
            }
        }

        return $baseDir;
    }
119908
private function lazyParseStructure(): void
    {
        if (true === $this->structureParsed) {
            return;
        }
        $this->structureParsed = true;

        $this->lazyLoadStructure();

        $this->type = self::$typesMap[$this->structure->type] ?? self::TYPE_UNKNOWN;

        // In our context, \ENCOTHER is as useful as an uknown encoding
        $this->encoding = self::$encodingsMap[$this->structure->encoding] ?? self::ENCODING_UNKNOWN;
        $this->subtype  = $this->structure->subtype;

        if (isset($this->structure->bytes)) {
            $this->bytes = $this->structure->bytes;
        }
        if ($this->structure->ifdisposition) {
            $this->disposition = $this->structure->disposition;
        }
        if ($this->structure->ifdescription) {
            $this->description = $this->structure->description;
        }

        $this->parameters = new Parameters();
        if ($this->structure->ifparameters) {
            $this->parameters->add($this->structure->parameters);
        }

        if ($this->structure->ifdparameters) {
            $this->parameters->add($this->structure->dparameters);
        }

        // When the message is not multipart and the body is the attachment content
        // Prevents infinite recursion
        if (self::isAttachment($this->structure) && !$this instanceof Attachment) {
            $this->parts[] = new Attachment($this->resource, $this->getNumber(), '1', $this->structure);
        }

        if (isset($this->structure->parts)) {
            $parts = $this->structure->parts;
            // https://secure.php.net/manual/en/function.imap-fetchbody.php#89002
            if ($this instanceof Attachment && $this->isEmbeddedMessage() && 1 === \count($parts) && \TYPEMULTIPART === $parts[0]->type) {
                $parts = $parts[0]->parts;
            }
            foreach ($parts as $key => $partStructure) {
                $partNumber = (!$this instanceof Message) ? $this->partNumber . '.' : '';
                $partNumber .= (string) ($key + 1);

                $newPartClass = self::isAttachment($partStructure)
                    ? Attachment::class
                    : SimplePart::class
                ;

                $this->parts[] = new $newPartClass($this->resource, $this->getNumber(), $partNumber, $partStructure);
            }
        }
    }
995542
private function prepareStructure($structure)
    {
        $newStructure = [];
        foreach ($structure as $path => $element) {
            $position = &$newStructure;
            foreach (explode('/', $path) as $part) {
                $position[$part] = [];
                $position = &$position[$part];
            }
            $position = strpos($path, DIRECTORY_SEPARATOR) === false ? [] : $position;
            $position = is_array($element) ? $this->prepareStructure($element) : (string) $element;
        }
        return $newStructure;
    }
264176
public function createViewProxy(StructureInterface $structure, array $data)
    {
        return $this->proxyFactory->createProxy(
            \ArrayObject::class,
            function (
                &$wrappedObject,
                LazyLoadingInterface $proxy,
                $method,
                array $parameters,
                &$initializer
            ) use ($structure, $data) {
                $initializer = null;
                $wrappedObject = new \ArrayObject($this->resolveView($structure, $data));

                return true;
            }
        );
    }
989852
protected function _send($message, &$failedRecipients = null)
    {
        $swiftMessage = new \Swift_Message();

        if ($charset = $message->getCharset()) {
            $swiftMessage->setCharset($charset);
        }

        $swiftMessage->setFrom($message->getFrom() ?: $this->_from);

        if ($replyTo = $message->getReplyTo()) {
            $swiftMessage->setReplyTo($replyTo);
        }

        $swiftMessage->setTo($message->getTo() ?: $this->_to);

        if ($cc = $message->getCc()) {
            $swiftMessage->setCc($cc);
        }

        if ($bcc = $message->getBcc()) {
            $swiftMessage->setBcc($bcc);
        }

        $swiftMessage->setSubject($message->getSubject());
        $swiftMessage->setBody($message->getHtmlBody());

        if ($priority = $message->getPriority()) {
            $swiftMessage->setPriority($priority);
        }

        foreach ($message->getAttachments() as $attachment) {
            $swiftMessage->attach(
                (new \Swift_Attachment($attachment['data'], $attachment['file'], $attachment['contentType']))->setId($attachment['cid']));
        }

        return $this->_swift->send($swiftMessage, $failedRecipients);
    }
476745
private function addStructureProperties(
        StructureMetadata $structureMetadata,
        StructureBehavior $document,
        VisitorInterface $visitor
    ) {
        /** @var ManagedStructure $structure */
        $structure = $document->getStructure();
        $data = $structure->toArray();
        foreach ($structureMetadata->getProperties() as $name => $property) {
            if ('title' === $name || !array_key_exists($name, $data) || $property->hasTag('sulu.rlp')) {
                continue;
            }

            $visitor->addData($name, $data[$name]);
        }
    }
1262553
protected function _send($message, &$failedRecipients = null)
    {
        $this->_message = $message;

        return count($message->getTo()) + count($message->getCc()) + count($message->getBcc());
    }
1267099
public function send($message, $raw=false)
    {
        if(!$raw && $this->parser){
            $message = call_user_func([$this->parser, 'encode'], $message, $this);
        }
        
        if($message === false || $message === null) {
            return false;
        }
        
        $message = (string)$message;
        
        if($this->isUDP() ) {
            return stream_socket_sendto($this->socket, $message);
        }
        
        if ($this->bufferIsFull()) {
            if($this->_pipe) {
                $this->_pipe->pauseRecv();
            }
            $this->trigger(Server::ON_BUFFER_FULL, new IOEvent());
            return false;
        }
        
        if(!$this->isConnnected()) {
            $this->sendBuffer .= $message;
            return ;
        }
        
        if($this->sendBuffer === ''){
            $len = fwrite($this->socket, $message);
            if ($len === strlen($message)) {
                return true;
            }else if($len >0) {
                $this->sendBuffer = substr($message, $len);
                Yii::$app->eventLooper->add($this->socket, EventLooper::EV_WRITE, [$this, 'baseWrite']);
            } else {
                $error = error_get_last();
                
                $event = new ErrorEvent([
                    'code' => $error['type'],
                    'errstr' => $error['message'],
                ]);
                
                $this->trigger(Server::ON_ERROR, $event);
                
                if(!is_resource($this->socket) || feof($this->socket)){
                    
                    $this->status = static::STATUS_CLOSED;
                    
                    $this->removeEventLooper();
                    
                    $event = new CloseEvent([
                        'by' => CloseEvent::BY_PEER,
                    ]);
                    $this->trigger(Server::ON_CLOSE, $event);
                    $this->destroy();
                    return false;
                }
            }
            
            return $len;
        }else{
            if ($this->bufferIsFull()) {
                $this->trigger(Server::ON_BUFFER_FULL, new IOEvent());
                return false;
            }
            
            $this->sendBuffer .= $message;
            
            return strlen($message);
        }
    }
1359468
public function buildClassMethods(StructureInterface $structure, TypeInterface $source_type, TypeInterface $target_type, array &$result)
    {
        $namespace = $structure->getNamespace();

        if ($namespace) {
            $namespace = '\\' . ltrim($namespace, '\\');
        }

        $this->buildGetFinderMethod($structure, $source_type, $target_type, $namespace, $result);

        $result[] = '';
        $result[] = '    /**';
        $result[] = '     * Return ' . Inflector::singularize($source_type->getName()) . ' ' . $this->getName() . '.';
        $result[] = '     *';
        $result[] = '     * @return ' . $this->getInstanceClassFrom($namespace, $target_type) . '[]';
        $result[] = '     */';
        $result[] = "    public function get{$this->getClassifiedAssociationName()}()";
        $result[] = '    {';
        $result[] = '        return $this->' . $this->getFinderMethodName() . '()->all();';
        $result[] = '    }';

        $result[] = '';
        $result[] = '    /**';
        $result[] = '     * Return ' . Inflector::singularize($source_type->getName()) . ' ' . Inflector::singularize($this->getName()) . ' ID-s.';
        $result[] = '     *';
        $result[] = '     * @return int[]';
        $result[] = '     */';
        $result[] = '    public function get' . Inflector::classify(Inflector::singularize($this->getName())) . 'Ids()';
        $result[] = '    {';
        $result[] = '        return $this->' . $this->getFinderMethodName() . '()->ids();';
        $result[] = '    }';

        $result[] = '';
        $result[] = '    /**';
        $result[] = '     * Return number of ' . Inflector::singularize($source_type->getName()) . ' ' . $this->getName() . '.';
        $result[] = '     *';
        $result[] = '     * @return int';
        $result[] = '     */';
        $result[] = "    public function count{$this->getClassifiedAssociationName()}()";
        $result[] = '    {';
        $result[] = '        return $this->' . $this->getFinderMethodName() . '()->count();';
        $result[] = '    }';

        $this->buildAddRelatedObjectMethod($structure, $source_type, $target_type, $namespace, $result);
        $this->buildRemoveRelatedObjectMethod($structure, $source_type, $target_type, $namespace, $result);
        $this->buildClearRelatedObjectsMethod($structure, $source_type, $target_type, $namespace, $result);
    }
501499
public static void showStructure(Structure structure)
			throws ClassNotFoundException, NoSuchMethodException,
			InvocationTargetException, IllegalAccessException, InstantiationException{

		Class<?> structureAlignmentJmol = Class.forName(strucAligJmol);

		Object strucAligJ = structureAlignmentJmol.newInstance();

		Method setS = structureAlignmentJmol.getMethod("setStructure", new Class[] {Structure.class});

		setS.invoke(strucAligJ,structure);
	}
1253170
public function setStructurePrototype( $structurePrototype )
    {
        if ( $structurePrototype instanceof MapperAwareInterface )
        {
            $structurePrototype->setMapper( $this );
        }

        $this->structurePrototype = $structurePrototype;
        return $this;
    }
148768
function get_message($uid, $raw = null)
    {
        if ( $this->stream !== null && $this->stream !== false ) {

            if ( $raw === null ) {
                $raw = $this->options['raw'];
            }

            $raw_header  = imap_fetchheader($this->stream, $uid, FT_UID);
            $raw_body    = imap_body($this->stream, $uid, FT_UID);
            $raw_message = $raw_header . $raw_body;

            if ( $raw ) {
                return $raw_message;
            } else {
                if ( class_exists('Email_Parser') ) {
                    return new Email_Parser($raw_message);
                }
            }

        }
    }
392620
public function save( & $structure )
    {
        if ( ! $structure instanceof Structure\ProxyAbstract ||
             empty( $structure->type ) )
        {
            return 0;
        }

        $data   = ArrayUtils::iteratorToArray( $structure->getBaseIterator() );
        $result = parent::save( $data );

        if ( $result > 0 )
        {
            if ( empty( $structure->id ) )
            {
                $structure->setOption( 'id', $id = $data['id'] );
            }
            else
            {
                $id = $structure->id;
            }

            foreach ( $structure->getPropertiesIterator() as $property => $value )
            {
                $result += $this->saveProperty(
                    $id, $structure::isPropertyLocaleAware( $property ),
                    $property, $value
                );
            }

            $tags = (array) $structure->getTags();
            $result += $this->deleteTagsNotIn( $id, $tags );

            foreach ( $tags as $tag )
            {
                $result += $this->setTagFor( $id, $tag );
            }
        }

        foreach ( $structure->getDependentStructures() as $depStruct )
        {
            if ( empty( $depStruct ) )
            {
                continue;
            }

            if ( $depStruct instanceof MapperAwareAbstract )
            {
                $result += $depStruct->save();
            }
            else if ( $depStruct instanceof MapperAwareInterface )
            {
                $result += $depStruct->getMapper()
                                     ->save( $depStruct );
            }
        }

        return $result;
    }
1204973
public function inherits(RowStructure $structure)
    {
        foreach ($structure->getDefinition() as $field => $type) {
            $this->addField($field, $type);
        }

        return $this;
    }