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;
    }