Update change log and spec for wrt-plugins-tizen_0.4.65
[platform/framework/web/wrt-plugins-tizen.git] / src / Messaging / Mms.cpp
index 7e62511..4fcffeb 100644 (file)
 #include "Mms.h"
 
 #include <vector>
-#include <dpl/log/log.h>
 #include <Commons/Exception.h>
 #include "ReqReceiverMessage.h"
 #include "Messaging.h"
 #include "CallbackMgr.h"
 #include "MsgServiceHandleMgr.h"
+#include "WidgetFilePathMgr.h"
+#include <Logger.h>
+#include <vconf.h>
 
 extern "C" {
 #include <msg.h>
@@ -34,7 +36,7 @@ extern "C" {
 namespace {
 const char* TEXT_AREA = "Text";
 const char* TEXT_FILE_EXTENSION = ".txt";
-const char* TEXT_DIR_PREFIX = "/tmp/";
+const char* TEXT_DIR_SEPERATOR = "/";
 const int WHITE_COLOR = 0xffffff;
 const int BLACK_COLOR = 0x000000;
 const int ROOT_LAYOUT_WIDTH = 100;
@@ -49,49 +51,41 @@ namespace Messaging {
 
 Mms::Mms(const string& id) :
     IMessage(MMS, id),
-//    m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
     m_messageData(NULL)
 {
-       LogDebug("m_id=" << getIdRef());
-       LogDebug("m_msgType=" << getMessageType());
+       LoggerD("m_id=" << getIdRef());
 
        char buf[] = "XXXXXX";
        mode_t mask = umask(S_IWGRP | S_IWOTH);
        int i = mkstemp(buf);
-       LogDebug("buf : " << buf << " i : " << i);
+       LoggerD("buf : " << buf << " i : " << i);
        umask(mask);
        m_bodyFilePath = buf;
-       m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
-
-       LogDebug("m_bodyFilePath : " << m_bodyFilePath);
+       m_bodyFilePath = getWidgetPath()+TEXT_DIR_SEPERATOR+m_bodyFilePath+TEXT_FILE_EXTENSION;
 
        if (getIdRef().empty()) {
-               LogDebug("create new message");
                createNewMessage();
        } else {
-               LogDebug("read existing message");
                readExistingMessage();
        }
 }
 
 Mms::Mms(const string& id, const msg_struct_t msg_data) :
        IMessage(MMS, id),
-//     m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
-       m_messageData(msg_data)
+       m_messageData(NULL)
 {
-       LogDebug("m_id=" << getIdRef());
-       LogDebug("m_msgType=" << getMessageType());
+       LoggerD("m_id=" << getIdRef());
+
+       m_messageData = createNewCopyOfPLatformMsgWithAddressList(msg_data);
 
        char buf[] = "XXXXXX";
        mode_t mask = umask(S_IWGRP | S_IWOTH);
        int i = mkstemp(buf);
-       LogDebug("buf : " << buf << " i : " << i);
+       LoggerD("buf : " << buf << " i : " << i);
        umask(mask);
        m_bodyFilePath = buf;
-       m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
-       
-       LogDebug("m_bodyFilePath : " << m_bodyFilePath);
-       
+       m_bodyFilePath = getWidgetPath()+TEXT_DIR_SEPERATOR+m_bodyFilePath+TEXT_FILE_EXTENSION;
+
        readConversationId(m_messageData);
        readRecipientList(m_messageData);
        readPriority(m_messageData);
@@ -101,13 +95,12 @@ Mms::Mms(const string& id, const msg_struct_t msg_data) :
        readDateTime(m_messageData);
        readReadStatus(m_messageData);
        readMessageStatus(m_messageData);
-//     setMessageStatus(MESSAGE_STATUS_LOADED);
 
 }
 
 Mms::~Mms()
 {
-    LogDebug("enter");
+    LoggerD("enter");
 
     if (m_messageData) {
         // release platform message structure
@@ -118,7 +111,7 @@ Mms::~Mms()
     //remove tmp file
     //trying to remove file, return value is skipped
     if (!m_bodyFilePath.empty()) {
-        LogDebug("remove tmp file=" << m_bodyFilePath);
+        LoggerD("remove tmp file=" << m_bodyFilePath);
         (void) ::remove(m_bodyFilePath.c_str());
     }
 }
@@ -146,12 +139,12 @@ void Mms::createNewMessage()
     setMessageStatus(MESSAGE_STATUS_CREATED);
 
        msg_release_struct(&sendOpt);
-    LogDebug("Message created successfully, Id: " << getIdRef());
+    LoggerD("Message created successfully, Id: " << getIdRef());
 }
 
 void Mms::readExistingMessage()
 {
-       LogDebug("entered");
+       LoggerD("entered");
 
        if (getIdRef().empty() || (EMPTY_ID == getIdRef())) 
        {
@@ -170,10 +163,10 @@ void Mms::readExistingMessage()
                // trying to get message from platform
                if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt)) 
                {
-                       LogError("get message error");
+                       LoggerE("get message error");
                        Throw(WrtDeviceApis::Commons::PlatformException);
                }
-               LogDebug("message found with msgId=" << getIdRef());
+               LoggerD("message found with msgId=" << getIdRef());
 
                // read all mms dat to abstraction layer
                readConversationId(m_messageData);
@@ -189,7 +182,7 @@ void Mms::readExistingMessage()
                msg_release_struct(&sendOpt);
        }
        Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("exception");
+               LoggerE("exception");
                // nothing to do
                msg_release_struct(&sendOpt);
        }
@@ -202,11 +195,11 @@ void Mms::readDateTime(msg_struct_t& messageData)
     int tempInt = 0;
     msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
 
-    LogError("readDateTime : " <<tempInt);
+    LoggerE("readDateTime : " <<tempInt);
 
     tm* time = localtime((time_t*)&tempInt);
     if (!time) {
-        LogError("localtime failed");
+        LoggerE("localtime failed");
         Throw(WrtDeviceApis::Commons::PlatformException);
     }
     setDateTime(*time);
@@ -247,7 +240,7 @@ void Mms::readMessageStatus(msg_struct_t& messageData)
        int tempValue = 0;
        msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
 
-       LogDebug("readMessageStatus folder : " << tempValue);
+       LoggerD("readMessageStatus folder : " << tempValue);
 
        switch (tempValue) {
                case MSG_INBOX_ID:
@@ -284,7 +277,7 @@ void Mms::readPriority(msg_struct_t& messageData)
         setPriority(MessagePriority::HIGH);
         break;
     default:
-        LogError("Wrong priority type");
+        LoggerE("Wrong priority type");
         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong priority type");
     }
 }
@@ -293,7 +286,7 @@ void Mms::readConversationId(msg_struct_t& messageData)
 {
        int tempInt = 0;
        msg_get_int_value(messageData, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
-       LogDebug("conversationID : " <<tempInt);
+       LoggerD("conversationID : " <<tempInt);
        setConvId(tempInt);
 }
 
@@ -301,7 +294,7 @@ void Mms::readRecipientList(msg_struct_t& messageData)
 {
        std::string phoneNumber;
 //     int recipientCount = msg_get_address_count(messageData);
-//     LogDebug("Recipient count " << recipientCount);
+//     LoggerD("Recipient count " << recipientCount);
 
        msg_struct_list_s *addr_list;
        msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
@@ -310,14 +303,14 @@ void Mms::readRecipientList(msg_struct_t& messageData)
        char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
 
        int recipientCount = addr_list->nCount;
-       LogDebug("Recipient count " << recipientCount);
+       LoggerD("Recipient count " << recipientCount);
 
        for (int i = 0; i < recipientCount; ++i) 
        {
 //        int type = msg_get_direction_info(messageData);
                msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
                int type = tempInt;
-               LogDebug("Direction: " << type);
+               LoggerD("Direction: " << type);
 
                if (MSG_DIRECTION_TYPE_MT == type) 
                {
@@ -331,7 +324,7 @@ void Mms::readRecipientList(msg_struct_t& messageData)
                                setSourceAddress(phoneNumber);
                                setFrom(phoneNumber);
                        }
-                       LogDebug("MT number: " << phoneNumber);
+                       LoggerD("MT number: " << phoneNumber);
                } 
                else if (MSG_DIRECTION_TYPE_MO == type) 
                {
@@ -339,8 +332,8 @@ void Mms::readRecipientList(msg_struct_t& messageData)
                        memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
                        msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
                        msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
-                       LogDebug("MO number: " << strNumber);
-                       LogDebug("Type : " << tempInt);
+                       LoggerD("MO number: " << strNumber);
+                       LoggerD("Type : " << tempInt);
                        switch (tempInt) 
                        {
                                case MSG_RECIPIENTS_TYPE_TO:
@@ -353,12 +346,12 @@ void Mms::readRecipientList(msg_struct_t& messageData)
                                        appendBccRecipients(strNumber);
                                        break;
                                default:
-                               LogError("Wrong type of recipient");
+                               LoggerE("Wrong type of recipient");
                        }
                } 
                else 
                {
-                       LogError("Wrong type of recipient");
+                       LoggerE("Wrong type of recipient");
                        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
                }
        }
@@ -369,7 +362,7 @@ void Mms::readSubject(msg_struct_t& messageData)
     char strTemp[MAX_SUBJECT_LEN] = {0};
     msg_get_str_value(messageData, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
 //    setSubject(msg_get_subject(messageData));
-    LogError("readSubject : " << strTemp);
+    LoggerE("readSubject : " << strTemp);
     setSubject(strTemp);
 }
 
@@ -393,7 +386,7 @@ void Mms::readBodyAndAttachments(msg_struct_t& messageData)
 
        if (ret != MSG_SUCCESS) 
        {
-               LogError("cannot get mms struct");
+               LoggerE("cannot get mms struct");
                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
        }
 
@@ -409,15 +402,15 @@ void Mms::readBodyAndAttachments(msg_struct_t& messageData)
                setMmsType(MULTIPART_MIXED);
        }
 
-       LogDebug("page count: " << pageLen);
+       LoggerD("page count: " << pageLen);
 
        for (int p = 0; p < pageLen; ++p) 
        {
-               LogDebug("page " << p);
+               LoggerD("page " << p);
                page = (msg_struct_t)msg_list_nth_data(page_list, p);
                
                if (NULL  == page) {
-                       LogError("returned page is null, continue");
+                       LoggerE("returned page is null, continue");
                        continue;
                }
                
@@ -426,11 +419,11 @@ void Mms::readBodyAndAttachments(msg_struct_t& messageData)
 
                for (int m = 0; m < mediaLen; ++m) 
                {
-                       LogDebug("media file " << m);
+                       LoggerD("media file " << m);
                        media = (msg_struct_t)msg_list_nth_data(media_list, m);
                        if (NULL == media) 
                        {
-                               LogError("returned media is null, continue");
+                               LoggerE("returned media is null, continue");
                                continue;
                        }
 
@@ -442,13 +435,13 @@ void Mms::readBodyAndAttachments(msg_struct_t& messageData)
                        if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt)) 
                        {
                                //text value on first page goes to body attribute
-                               LogDebug("setting body from " << szFilePath);
+                               LoggerD("setting body from " << szFilePath);
                                
                                FILE* f = NULL;
                                f = fopen(szFilePath, "r");
                                if (!f) 
                                {
-                                       LogError("cannot read file with body" << szFilePath);
+                                       LoggerE("cannot read file with body" << szFilePath);
                                        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
                                }
                                fseek(f, 0, SEEK_END);
@@ -462,14 +455,14 @@ void Mms::readBodyAndAttachments(msg_struct_t& messageData)
                                        setBody(data);
                                        delete[] data;
                                } else {
-                                       LogError("body is not set");
+                                       LoggerE("body is not set");
                                }
-                               LogDebug("message body: '" << getBody() << "'");
+                               LoggerD("message body: '" << getBody() << "'");
                                fclose(f);
                        } 
                        else 
                        {
-                               LogDebug("adding attachment " << szFilePath);
+                               LoggerD("adding attachment " << szFilePath);
 
                                IAttachmentPtr attachment = appendAttachment(szFilePath, false);
                                //attachment->setMessage(this); //set IMessagePtr
@@ -478,14 +471,14 @@ void Mms::readBodyAndAttachments(msg_struct_t& messageData)
                                msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
                                if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0)) 
                                {
-                                       LogDebug("renaming to " << szFileName);
+                                       LoggerD("renaming to " << szFileName);
                                        attachment->rename(szFileName);
                                }
                                else if (MMS_SMIL_MEDIA_TEXT == tempInt) 
                                {
                                        std::stringstream newName;
                                        newName << "body_page_" << p + 1 << ".txt";
-                                       LogDebug("renaming to " << newName.str());
+                                       LoggerD("renaming to " << newName.str());
                                        attachment->rename(newName.str());
                                }
                        }
@@ -496,13 +489,16 @@ void Mms::readBodyAndAttachments(msg_struct_t& messageData)
        
        attachLen= msg_list_length(attach_list);
 
-       LogDebug("attachment count: " << attachLen);
+       LoggerD("attachment count: " << attachLen);
        for (int a = 0; a < attachLen; ++a) 
        {
+               std::string tempString;
+               int tempInt;
+               
                attach = (msg_struct_t)msg_list_nth_data(attach_list, a);
                if (NULL == attach) 
                {
-                       LogError("attachment is null, continue");
+                       LoggerE("attachment is null, continue");
                        continue;
                }
 
@@ -511,17 +507,143 @@ void Mms::readBodyAndAttachments(msg_struct_t& messageData)
 
                msg_get_str_value(attach, MSG_MMS_ATTACH_FILEPATH_STR, szFilePath, sizeof(szFilePath));
                msg_get_str_value(attach, MSG_MMS_ATTACH_FILENAME_STR, szFileName, sizeof(szFileName));
+
+               msg_get_int_value(attach, MSG_MMS_ATTACH_MIME_TYPE_INT, &tempInt);
+               tempString = indexIntToMimeTypeString((MimeType)tempInt);
                
                IAttachmentPtr att = appendAttachment(szFilePath, false);
                if ((szFileName[0] =! '\0') &&
                        strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0) {
-                       LogDebug("renaming to " << szFileName);
+                       LoggerD("renaming to " << szFileName);
                        att->rename(szFileName);
                }
+               att->setMimeType(tempString);
+               att->setAttachmentID((int)a);
+               att->setDownloaded(true);
        }
        msg_release_struct(&mms_struct);
 }
 
+void Mms::readBody(msg_struct_t& messageData)
+{
+
+       int pageLen, mediaLen, tempInt, ret;
+
+       msg_struct_t mms_struct = NULL;
+
+       msg_list_handle_t page_list = NULL;
+       msg_list_handle_t media_list = NULL;
+       
+       msg_struct_t page = NULL;
+       msg_struct_t media = NULL;
+
+       mms_struct = msg_create_struct(MSG_STRUCT_MMS);
+       ret = msg_get_mms_struct(messageData, mms_struct);
+
+       if (ret != MSG_SUCCESS) 
+       {
+               LoggerE("cannot get mms struct");
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
+       }
+
+       char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
+       char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
+
+       msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
+       pageLen = msg_list_length(page_list);
+
+       if (pageLen > 0) {
+               setMmsType(MULTIPART_RELATED);
+       } else {
+               setMmsType(MULTIPART_MIXED);
+       }
+
+       LoggerD("page count: " << pageLen);
+
+       for (int p = 0; p < pageLen; ++p) 
+       {
+               LoggerD("page " << p);
+               page = (msg_struct_t)msg_list_nth_data(page_list, p);
+               
+               if (NULL  == page) {
+                       LoggerE("returned page is null, continue");
+                       continue;
+               }
+               
+               msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
+               mediaLen = msg_list_length(media_list);
+
+               for (int m = 0; m < mediaLen; ++m) 
+               {
+                       LoggerD("media file " << m);
+                       media = (msg_struct_t)msg_list_nth_data(media_list, m);
+                       if (NULL == media) 
+                       {
+                               LoggerE("returned media is null, continue");
+                               continue;
+                       }
+
+                       msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
+
+                       memset(szFilePath, 0, sizeof(szFilePath));
+                       msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
+                       
+                       if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt)) 
+                       {
+                               //text value on first page goes to body attribute
+                               LoggerD("setting body from " << szFilePath);
+                               
+                               FILE* f = NULL;
+                               f = fopen(szFilePath, "r");
+                               if (!f) 
+                               {
+                                       LoggerE("cannot read file with body" << szFilePath);
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
+                               }
+                               fseek(f, 0, SEEK_END);
+                               long int size = ftell(f);
+                               fseek(f, 0, SEEK_SET);
+                               char* data = new (nothrow) char[size + 1];
+                               size_t error;
+                               if (data) {
+                                       memset(data, 0, size + 1);
+                                       error = fread(data, 1, size, f);
+                                       setBody(data);
+                                       delete[] data;
+                               } else {
+                                       LoggerE("body is not set");
+                               }
+                               LoggerD("message body: '" << getBody() << "'");
+                               fclose(f);
+                       } 
+                       else 
+                       {
+                               LoggerD("adding attachment " << szFilePath);
+
+                               IAttachmentPtr attachment = appendAttachment(szFilePath, false);
+                               //attachment->setMessage(this); //set IMessagePtr
+
+                               memset(szFileName, 0, sizeof(szFileName));
+                               msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
+                               if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0)) 
+                               {
+                                       LoggerD("renaming to " << szFileName);
+                                       attachment->rename(szFileName);
+                               }
+                               else if (MMS_SMIL_MEDIA_TEXT == tempInt) 
+                               {
+                                       std::stringstream newName;
+                                       newName << "body_page_" << p + 1 << ".txt";
+                                       LoggerD("renaming to " << newName.str());
+                                       attachment->rename(newName.str());
+                               }
+                       }
+               }
+       }
+       msg_release_struct(&mms_struct);
+}
+
+
 bool Mms::hasAttachment()
 {
        std::size_t attachmentSize = getAttachmentsCount();
@@ -533,11 +655,11 @@ bool Mms::hasAttachment()
 
 void Mms::update(bool draftsOnly)
 {
-    LogDebug("updating m_id=" << getIdRef());
+    LoggerD("updating m_id=" << getIdRef());
 
     if (!m_messageData) {
         //error if platform message not exists
-        LogError("message can not be updated");
+        LoggerE("message can not be updated");
         Throw(WrtDeviceApis::Commons::PlatformException);
     }
 
@@ -557,7 +679,7 @@ void Mms::updatePriority()
         return;
     }
     int priority = -1;
-    LogInfo("MMS updating priority");
+    LoggerI("MMS updating priority");
 
     //set priority in platform
     switch (getPriority()) {
@@ -571,15 +693,15 @@ void Mms::updatePriority()
         priority = MSG_MESSAGE_PRIORITY_HIGH;
         break;
     default:
-        LogError("Wrong priority");
+        LoggerE("Wrong priority");
         Throw(WrtDeviceApis::Commons::PlatformException);
     }
-    LogInfo("priority : " << priority);
+    LoggerI("priority : " << priority);
 
     if (MSG_SUCCESS !=
        msg_set_int_value(m_messageData, MSG_MESSAGE_PRIORITY_INT, priority)){
         
-        LogError("Error during setting priority");
+        LoggerE("Error during setting priority");
         Throw(WrtDeviceApis::Commons::PlatformException);
     }
 }
@@ -593,7 +715,7 @@ void Mms::updateRecipientList()
         return;
     }
 
-    LogInfo("MMS updating platform recipients");
+    LoggerI("MMS updating platform recipients");
 
     // reset addresses in platform structure
 //    msg_reset_address(m_messageData);
@@ -602,7 +724,7 @@ void Mms::updateRecipientList()
        int nToCnt = 0;
        nToCnt = addr_list->nCount;
 
-       LogInfo("addr_list->nCount" << addr_list->nCount);
+       LoggerI("addr_list->nCount" << addr_list->nCount);
        
        if (nToCnt > 0)         
        {               
@@ -617,7 +739,7 @@ void Mms::updateRecipientList()
                addr_list->nCount = nToCnt;
        }               
 
-       LogInfo("addr_list->nCount" << addr_list->nCount);
+       LoggerI("addr_list->nCount" << addr_list->nCount);
 
        vector<string> to = getToRecipients().getRecipients();
        vector<string> cc = getCcRecipients().getRecipients();
@@ -626,112 +748,112 @@ void Mms::updateRecipientList()
        // update addresses in platform structure
        if (to.size()) 
        {
-               LogInfo("updating to");
+               LoggerI("updating to");
                for (size_t i = 0; i < to.size(); i++) 
                {
                        if (i >= MAX_TO_ADDRESS_CNT) 
                        {
-                               LogError("max number of recipient exceeded");
+                               LoggerE("max number of recipient exceeded");
                                break;
                        }
-                       LogDebug("adding to[" << i << "]=" << to[i]);
+                       LoggerD("adding to[" << i << "]=" << to[i]);
 
                        msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
 
                        if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, 
                                MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS) 
                        {
-                               LogError("problem with adding to address");
+                               LoggerE("problem with adding to address");
                                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
                        }
                        
                        if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, 
                                const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS) 
                        {
-                               LogError("problem with adding to address");
+                               LoggerE("problem with adding to address");
                                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
                        }
                        nToCnt ++;
                }
                addr_list->nCount = nToCnt;
-               LogError("nToCnt : " << nToCnt);
-               LogError("addr_list->nCount: " <<addr_list->nCount);
+               LoggerE("nToCnt : " << nToCnt);
+               LoggerE("addr_list->nCount: " <<addr_list->nCount);
                
        }
        
-       LogInfo("addr_list->nCount" << addr_list->nCount);
+       LoggerI("addr_list->nCount" << addr_list->nCount);
 
        if (cc.size()) 
        {
-               LogInfo("updating cc");
+               LoggerI("updating cc");
                for (size_t i = 0; i < cc.size(); i++) 
                {
                        if (nToCnt >= MAX_TO_ADDRESS_CNT) 
                        {
-                               LogError("max number of recipient exceeded");
+                               LoggerE("max number of recipient exceeded");
                                break;
                        }
-                       LogDebug("adding cc[" << i << "]=" << cc[i]);
+                       LoggerD("adding cc[" << i << "]=" << cc[i]);
 
                        msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
 
                        if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, 
                                MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS) 
                        {
-                               LogError("problem with adding cc address");
+                               LoggerE("problem with adding cc address");
                                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
                        }
                        
                        if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, 
                                const_cast<char*>(cc[i].c_str()), cc[i].size()) != MSG_SUCCESS) 
                        {
-                               LogError("problem with adding cc address");
+                               LoggerE("problem with adding cc address");
                                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
                        }
                        nToCnt ++;
                }
                addr_list->nCount = nToCnt;
-               LogError("nToCnt : " << nToCnt);
-               LogError("addr_list->nCount: " <<addr_list->nCount);
+               LoggerE("nToCnt : " << nToCnt);
+               LoggerE("addr_list->nCount: " <<addr_list->nCount);
        }
 
-       LogInfo("addr_list->nCount" << addr_list->nCount);
+       LoggerI("addr_list->nCount" << addr_list->nCount);
 
        if (bcc.size()) 
        {
-               LogInfo("updating bcc");
+               LoggerI("updating bcc");
                for (size_t i = 0; i < bcc.size(); i++) 
                {
                        if (nToCnt >= MAX_TO_ADDRESS_CNT) 
                        {
-                               LogError("max number of recipient exceeded");
+                               LoggerE("max number of recipient exceeded");
                                break;
                        }
-                       LogDebug("adding bcc[" << i << "]=" << bcc[i]);
+                       LoggerD("adding bcc[" << i << "]=" << bcc[i]);
 
                        msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
 
                        if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, 
                                MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS) 
                        {
-                               LogError("problem with adding bcc address");
+                               LoggerE("problem with adding bcc address");
                                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
                        }
                        
                        if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, 
                                const_cast<char*>(bcc[i].c_str()), bcc[i].size()) != MSG_SUCCESS) 
                        {
-                               LogError("problem with adding bcc address");
+                               LoggerE("problem with adding bcc address");
                                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
                        }
                        nToCnt ++;
                }
                addr_list->nCount = nToCnt;
-               LogError("nToCnt : " << nToCnt);
-               LogError("addr_list->nCount: " <<addr_list->nCount);
+               LoggerE("nToCnt : " << nToCnt);
+               LoggerE("addr_list->nCount: " <<addr_list->nCount);
        }
 
-       LogInfo("addr_list->nCount" << addr_list->nCount);              
+       LoggerI("addr_list->nCount" << addr_list->nCount);              
        setToValidity(true);
        setCcValidity(true);
        setBccValidity(true);
@@ -743,12 +865,12 @@ void Mms::updateSubject()
     if (isSubjectValid()) {
         return;
     }
-    LogInfo("updating platform subject: " << getSubjectRef());
+    LoggerI("updating platform subject: " << getSubjectRef());
     if (MSG_SUCCESS !=
 //        msg_set_subject(m_messageData, getSubjectRef().c_str())) {
        msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, const_cast<char*>(getSubjectRef().c_str()), MAX_SUBJECT_LEN)) {
 
-        LogError("problem with setting subject");
+        LoggerE("problem with setting subject");
         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
     }
     setSubjectValidity(true);
@@ -766,7 +888,7 @@ void Mms::updateBodyAndAttachments()
 //             msg_struct_t old_mms_struct = NULL;// THIS
 //             int ret;// THIS
 
-               LogInfo("updating platform body and attachment");
+               LoggerI("updating platform body and attachment");
        
                Try
                {
@@ -776,7 +898,7 @@ void Mms::updateBodyAndAttachments()
                        msg_struct_t smil_text[1];
                        
                        if (getMessageType() != MMS) {
-                               LogError("Wrong msg type");
+                               LoggerE("Wrong msg type");
                                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong msg type");
                        }
 //                     mmsData = msg_mms_create_message();
@@ -784,12 +906,12 @@ void Mms::updateBodyAndAttachments()
 //                     old_mms_struct = msg_create_struct(MSG_STRUCT_MMS);// THIS
 
 //                     ret = msg_get_mms_struct(m_messageData, old_mms_struct);// THIS
-//                     LogError("ret " << ret);// THIS
+//                     LoggerE("ret " << ret);// THIS
 //                     ret = msg_release_struct(&old_mms_struct);// THIS
-//                     LogError("ret " << ret);// THIS
+//                     LoggerE("ret " << ret);// THIS
 
                        if (!mms_struct) {
-                               LogError("create message body failed");
+                               LoggerE("create message body failed");
                                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "create message body failed");
                        }
        
@@ -798,16 +920,16 @@ void Mms::updateBodyAndAttachments()
                                FILE* f = NULL;
                                f = fopen(m_bodyFilePath.c_str(), "w");
                                if (!f) {
-                                       LogError("cannot create file with body" << m_bodyFilePath);
+                                       LoggerE("cannot create file with body" << m_bodyFilePath);
                                        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
                                                         "cannot create file with body");
                                }
-                               LogDebug("body file: " << m_bodyFilePath);
+                               LoggerD("body file: " << m_bodyFilePath);
                                fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
                         
                                fclose(f);
 
-                               LogDebug("getBodyRef(): " << getBodyRef());
+                               LoggerD("getBodyRef(): " << getBodyRef());
 
                                msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_INT, ROOT_LAYOUT_WIDTH);
                                msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
@@ -836,12 +958,12 @@ void Mms::updateBodyAndAttachments()
                                msg_set_str_value(media[0], MSG_MMS_MEDIA_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
                                int error;
                                error = msg_set_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, const_cast<char*>(m_bodyFilePath.c_str()),MSG_FILEPATH_LEN_MAX);
-                               LogDebug("bodyFile Path= " << m_bodyFilePath);
-                               LogDebug("error= " << error);
+                               LoggerD("bodyFile Path= " << m_bodyFilePath);
+                               LoggerD("error= " << error);
                                char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
                                memset(szFilePath, 0, sizeof(szFilePath));
                                msg_get_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
-                               LogDebug("bodyFile Path= " << m_bodyFilePath);
+                               LoggerD("bodyFile Path= " << m_bodyFilePath);
 
                                msg_get_struct_handle(media[0], MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text[0]);
                                msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_COLOR_INT, BLACK_COLOR);
@@ -856,29 +978,39 @@ void Mms::updateBodyAndAttachments()
 
                        msg_struct_t attachment[20];                    
                        
-                       for (size_t i = 0; i < getAttachmentsRef().size(); ++i) {
-                               IAttachmentPtr att = getAttachment(i);
+                       for (size_t idx = 0; idx < getAttachmentsRef().size(); ++idx) {
+                               IAttachmentPtr att = getAttachment(idx);
                                if (!att) {
                                        continue;
                                }
        
-                               LogDebug("Add attachment=" << att->getFullPath());
+                               LoggerD("Add attachment=" << att->getFullPath());
                                //checking file
                                errnum = stat(att->getFullPath().c_str(), &buffer);
-                               LogDebug("errnum=" << errnum);
+                               LoggerD("errnum=" << errnum);
 
                                if (errnum != 0) {
-                                       LogError("Opening file: " << att->getFullPath().c_str());
+                                       LoggerE("Opening file: " << att->getFullPath().c_str());
                                        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
                                                         "cannot open attachment file");
                                }
        
                                //this function should return valid pointer
+                               att->setMessage(SharedFromThis());      // setMessage to setMessageId
+                               att->setAttachmentID((int)idx);
+                               att->setDownloaded(true);
+
+                               int ret = mimeTypeStringToIndexInt(att->getMimeType());
+
+                               msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[idx]);
+                               msg_set_str_value(attachment[idx], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
 
-                               msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[i]);
-                               msg_set_str_value(attachment[i], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
+                               if(ret != MIME_UNKNOWN)
+                               {
+                                       msg_set_int_value(attachment[idx], MSG_MMS_ATTACH_MIME_TYPE_INT, ret);
+                               }
                                
-                               LogDebug("Attachment added");
+                               LoggerD("Attachment added");
        
                                //reset errno
                                errnum = 0;
@@ -886,7 +1018,7 @@ void Mms::updateBodyAndAttachments()
        
                if (MSG_SUCCESS !=msg_set_mms_struct(m_messageData, mms_struct))
                {
-                       LogError("set message body error");
+                       LoggerE("set message body error");
                        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set message body error");
                }
 
@@ -897,7 +1029,7 @@ void Mms::updateBodyAndAttachments()
                
                }
                Catch(WrtDeviceApis::Commons::PlatformException) {
-                       LogError("Platform error");
+                       LoggerE("Platform error");
                        msg_release_struct(&mms_struct);
                        throw;
                }
@@ -910,10 +1042,10 @@ void Mms::updateReadStatus()
         return;
     }
 
-    LogInfo("updating platform read status: " << isRead());
+    LoggerI("updating platform read status: " << isRead());
 //    if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
     if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
-        LogError("problem with setting subject");
+        LoggerE("problem with setting subject");
         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
     }
 
@@ -922,11 +1054,11 @@ void Mms::updateReadStatus()
 
 void Mms::updateIsRead()
 {
-    LogDebug("updating m_id=" << getIdRef());
+    LoggerD("updating m_id=" << getIdRef());
 
     if (!m_messageData) {
         //error if platform message not exists
-        LogError("message can not be updated");
+        LoggerE("message can not be updated");
         Throw(WrtDeviceApis::Commons::PlatformException);
     }
        
@@ -939,7 +1071,7 @@ void Mms::updateIsRead()
     Try
     {
         if (this->getIdRef().empty()) {
-            LogError("existing msgId is zero, remove msg not done");
+            LoggerE("existing msgId is zero, remove msg not done");
             ThrowMsg(WrtDeviceApis::Commons::PlatformException,
                      "existing msgId is zero, remove msg not done");
         }
@@ -947,12 +1079,12 @@ void Mms::updateIsRead()
         if (MSG_SUCCESS !=
             msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
         {
-            LogError("Failed to update isRead");
+            LoggerE("Failed to update isRead");
             ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
         }
     }
     Catch(WrtDeviceApis::Commons::PlatformException) {
-        LogError("platform error occurs");
+        LoggerE("platform error occurs");
     }
     setisReadChangeStatusValidity(true);
 
@@ -960,14 +1092,16 @@ void Mms::updateIsRead()
 
 void Mms::updateMessage()
 {
-       LogDebug("updating m_id=" << getIdRef());
+       LoggerD("updating m_id=" << getIdRef());
        msg_error_t err = MSG_SUCCESS;
+       int tempInt = 0;
+
        msg_struct_t msg = NULL;
        msg_struct_t sendOpt = NULL;
        
        if (!m_messageData) {
                //error if platform message not exists
-               LogError("message can not be updated");
+               LoggerE("message can not be updated");
                Throw(WrtDeviceApis::Commons::PlatformException);
        }
 
@@ -981,21 +1115,33 @@ void Mms::updateMessage()
                
                if (err != MSG_SUCCESS)
                {
-                       LogError("Get Message Failed!");
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
+                       LoggerE("msg_get_message() Failed!");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to get message for update");
                }
        
                if (this->getIdRef().empty()) {
-                       LogError("existing msgId is zero, update msg not done");
+                       LoggerE("existing msgId is zero, update msg not done");
                        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
                                        "existing msgId is zero, update msg not done");
                }
-               
+
+               err = msg_get_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
+               if(err == MSG_SUCCESS)
+               {
+                       msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
+               }
+
+               err = msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
+               if(err == MSG_SUCCESS)
+               {
+                       msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
+               }
+
                update(TRUE);
                
                if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
                {
-                       LogError("Failed to update message");
+                       LoggerE("msg_update_message() Failed!");
                        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
                }
                msg_release_struct(&msg);
@@ -1004,25 +1150,28 @@ void Mms::updateMessage()
        Catch(WrtDeviceApis::Commons::PlatformException) {
                msg_release_struct(&msg);
                msg_release_struct(&sendOpt);
-               LogError("platform error occurs");
+               LoggerE("platform error occurs");
+               ReThrow(WrtDeviceApis::Commons::PlatformException);
        }
 }
 
 
 void Mms::createSendMessage()
 {
-    LogDebug("convert m_id= " << convertId(getIdRef()));       
+    LoggerD("convert m_id= " << convertId(getIdRef()));        
+
+    msg_struct_t sendOpt = NULL;
 
     //prepare for add sms to draft folder
     if (!m_messageData) {
         //error if platform message not exists
-        LogError("message can not be updated");
+        LoggerE("message can not be updated");
         Throw(WrtDeviceApis::Commons::PlatformException);
     }
 
-    //update all sms data
+    //update all mms data
     if (getCurrentFolder() == DRAFTBOX) {
-               LogDebug("update all mms data");
+               LoggerD("update all mms data");
         updateSubject();
         updateBodyAndAttachments();
         updateRecipientList();
@@ -1032,46 +1181,50 @@ void Mms::createSendMessage()
     Try
     {
         int msgId = 0;
-//        MSG_SENDINGOPT_S option = { false, false, false };
-//        option.option.smsSendOpt.bReplyPath = true;
-        // trying to get message from platform
+        sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+        // trying to add message
 
-//        msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
-//        msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
+//        msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
 
+        int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
+        if (ret < MSG_SUCCESS) {
+            LoggerE("msg_add_message failed, error code=" << ret);
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+        else
+        {
+            msgId = ret;
+        }
 
-//        const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
+        LoggerD("Message ID : " << msgId);
 
-//        msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
-//        msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, 4);
-//        msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
+        msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
 
         setId(convertId(msgId));
-        setFolderType(DRAFTBOX);
+        loadDraftMessage();
+
+        setFolderType(OUTBOX);
         setMessageStatus(MESSAGE_STATUS_DRAFT);
+
+        msg_release_struct(&sendOpt);
     }
     Catch(WrtDeviceApis::Commons::PlatformException) {
-        LogError("remove message error");
-        if (m_messageData) {
-            //releasing platform message structure
-//            msg_release_message(&m_messageData);
-            msg_release_struct(&m_messageData);                
-        }
+        LoggerE("remove message error");
+        msg_release_struct(&sendOpt);
         throw;
     }
-
 }      
 
 void Mms::addMessageToDraft()
 {
-       LogDebug("convert m_id= " << convertId(getIdRef()));
+       LoggerD("convert m_id= " << convertId(getIdRef()));
 
        msg_struct_t sendOpt = NULL;
 
        //prepare for add sms to draft folder
        if (!m_messageData) {
                //error if platform message not exists
-               LogError("message can not be updated");
+               LoggerE("message can not be updated");
                Throw(WrtDeviceApis::Commons::PlatformException);
        }
 
@@ -1089,10 +1242,10 @@ void Mms::addMessageToDraft()
                sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
 
                // trying to add message
-               LogDebug("add message");
+               LoggerD("add message");
                int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
                if (ret < MSG_SUCCESS) {
-                       LogError("msg_add_message failed, error code=" << ret);
+                       LoggerE("msg_add_message failed, error code=" << ret);
                        Throw(WrtDeviceApis::Commons::PlatformException);
                }
                else
@@ -1100,33 +1253,120 @@ void Mms::addMessageToDraft()
                        msgId = ret;
                }
 
-               LogDebug("Message ID : " << msgId);
+               LoggerD("Message ID : " << msgId);
                if (msgId < 0)
                {
-                       LogDebug("Message ID is invailded ");
+                       LoggerD("Message ID is invailded ");
                        Throw(WrtDeviceApis::Commons::PlatformException);
                }
 
                msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
 
                setId(convertId(msgId));
-               setFolderType(DRAFTBOX);
-               setMessageStatus(MESSAGE_STATUS_DRAFT);
+               loadDraftMessage();
 
                msg_release_struct(&sendOpt);
 
        }
        Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("add draft message error");
+               LoggerE("add draft message error");
                msg_release_struct(&sendOpt);
                throw;
        }
 
 }              
 
+void Mms::loadDraftMessage()
+{
+       LoggerD("entered");
+
+       if (getIdRef().empty() || (EMPTY_ID == getIdRef())) 
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
+       }
+
+       msg_release_struct(&m_messageData);
+       m_messageData = NULL;
+       msg_struct_t sendOpt = NULL;
+
+       Try {
+
+               m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+               sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+
+               // trying to get message from platform
+               if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt)) 
+               {
+                       LoggerE("get message error");
+                       Throw(WrtDeviceApis::Commons::PlatformException);
+               }
+               LoggerD("message found with msgId=" << getIdRef());
+
+               // read all mms dat to abstraction layer
+               readConversationId(m_messageData);
+               readPriority(m_messageData);
+               readSubject(m_messageData);
+               readFolder(m_messageData);
+               readDateTime(m_messageData);
+               readReadStatus(m_messageData);
+               readMessageStatus(m_messageData);
+               readBody(m_messageData);
+
+               msg_release_struct(&sendOpt);
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               LoggerE("exception");
+               // nothing to do
+               msg_release_struct(&sendOpt);
+       }
+
+}
+
 void Mms::readAllData()
 {
-    readExistingMessage();
+       LoggerD("entered");
+
+       if (getIdRef().empty() || (EMPTY_ID == getIdRef())) 
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
+       }
+
+       msg_release_struct(&m_messageData);
+       m_messageData = NULL;
+       msg_struct_t sendOpt = NULL;
+
+       Try {
+
+               m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+               sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+
+               // trying to get message from platform
+               if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt)) 
+               {
+                       LoggerE("get message error");
+                       Throw(WrtDeviceApis::Commons::PlatformException);
+               }
+               LoggerD("message found with msgId=" << getIdRef());
+
+               // read all mms dat to abstraction layer
+               readConversationId(m_messageData);
+//             readRecipientList(m_messageData);
+               readPriority(m_messageData);
+               readSubject(m_messageData);
+               readBodyAndAttachments(m_messageData);
+               readFolder(m_messageData);
+               readDateTime(m_messageData);
+               readReadStatus(m_messageData);
+               readMessageStatus(m_messageData);
+
+               msg_release_struct(&sendOpt);
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               LoggerE("exception");
+               // nothing to do
+               msg_release_struct(&sendOpt);
+       }
+
 }
 
 void Mms::moveToFolder(const FolderType newFolder)
@@ -1146,7 +1386,7 @@ void Mms::moveToFolder(const FolderType newFolder)
     }
 
     Catch(WrtDeviceApis::Commons::PlatformException) {
-        LogError("remove message error");
+        LoggerE("remove message error");
         throw;
     }
 */
@@ -1164,13 +1404,13 @@ void Mms::moveToFolder(const string& newFolder)
 
         if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
                                    platfromFolderId) != MSG_SUCCESS) {
-            LogError("msg_move_msg_to_folder error");
+            LoggerE("msg_move_msg_to_folder error");
             ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_move_msg_to_folder error");
         }
     }
 
     Catch(WrtDeviceApis::Commons::PlatformException) {
-        LogError("remove message error");
+        LoggerE("remove message error");
         throw;
     }
     */
@@ -1197,7 +1437,7 @@ void Mms::copyToFolder(const FolderType newFolder)
 
             int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
             if (error != MSG_SUCCESS) {
-                LogError("msg_add_message failed, error code=" << error);
+                LoggerE("msg_add_message failed, error code=" << error);
                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
             }
         }
@@ -1207,7 +1447,7 @@ void Mms::copyToFolder(const FolderType newFolder)
     }
 
     Catch(WrtDeviceApis::Commons::PlatformException) {
-        LogError("remove message error");
+        LoggerE("remove message error");
         if (msg) {
             msg_release_message(&msg);
         }
@@ -1237,7 +1477,7 @@ void Mms::copyToFolder(const string& newFolder)
 
             int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
             if (error != MSG_SUCCESS) {
-                LogError("msg_add_message failed, error code=" << error);
+                LoggerE("msg_add_message failed, error code=" << error);
                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
             }
         }
@@ -1247,7 +1487,7 @@ void Mms::copyToFolder(const string& newFolder)
     }
 
     Catch(WrtDeviceApis::Commons::PlatformException) {
-        LogError("remove message error");
+        LoggerE("remove message error");
         if (msg) {
             msg_release_message(&msg);
         }
@@ -1258,12 +1498,12 @@ void Mms::copyToFolder(const string& newFolder)
 
 void Mms::remove()
 {
-    LogDebug("delete m_id=" << getIdRef());
+    LoggerD("delete m_id=" << getIdRef());
 
     Try
     {
         if (this->getIdRef().empty()) {
-            LogError("existing msgId is zero, remove msg not done");
+            LoggerE("existing msgId is zero, remove msg not done");
             ThrowMsg(WrtDeviceApis::Commons::PlatformException,
                      "existing msgId is zero, remove msg not done");
         }
@@ -1271,76 +1511,82 @@ void Mms::remove()
         if (MSG_SUCCESS !=
             msg_delete_message(MsgGetCommonHandle(),
                                convertId(getIdRef()))) {
-            LogError("Failed to delete Message");
+            LoggerE("Failed to delete Message");
             ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
         }
     }
 
     Catch(WrtDeviceApis::Commons::PlatformException) {
-        LogError("platform error occurs");
+        LoggerE("platform error occurs");
     }
 }
 
 int Mms::send()
 {
-       LogDebug("sending message, id=" << getIdRef());
+       LoggerD("sending message, id=" << getIdRef());
+       msg_error_t err = MSG_SUCCESS;
+
        Try
        {
                //prepare for sending sms/mms
                update();
 
-               LogDebug("Start Sending Message...");
-
-               LogDebug("trying to send mms");
-               msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
+               LoggerD("trying to send mms");
+               if (!getCellularOn())
+               {
+                       err = MSG_ERR_TRANSPORT_ERROR;
+                       LoggerW("MMS send error. No transport possible over network");
+               }
+               else
+               {
+                       err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
+               }
 
                if (err != MSG_SUCCESS) 
                {
-                       LogError("Sending Message (submit request) failed!!! err=" << err);
+                       LoggerE("Sending Message (submit request) failed!!! err=" << err);
                        setMessageStatus(MESSAGE_STATUS_FAILED);
-                       goto ERROR;
+                       Throw(WrtDeviceApis::Commons::PlatformException);
                }
 
                setMessageStatus(MESSAGE_STATUS_SENDING);
 
-               LogDebug("Sending Message request is submitted!");
+               LoggerD("Sending Message request is submitted!");
        }
        Catch(WrtDeviceApis::Commons::PlatformException) {
-               LogError("message is not send, manually run callback");
-               goto ERROR;
+               LoggerE("message is not send, manually run callback");
+       ReqReceiverMessage *requestReceiver = getRequestReceiver();
+       if (requestReceiver) {
+               LoggerE("send Error");
+               EventMessagingServicePtr event = getMessagingServiceEvent();
+             if(err == MSG_ERR_TRANSPORT_ERROR)
+             {
+                 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::PlatformWrongStateException);
+             }
+             else
+             {
+                 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+             }
+               requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
+       }
        }
 
        return 0;
-
-       ERROR:
-       ReqReceiverMessage *requestReceiver = getRequestReceiver();
-       if (requestReceiver) {
-               LogError("send Error");
-               EventMessagingServicePtr event = getMessagingServiceEvent();
-               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
-               requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
-       }
-       return 0;
 }
 
 void Mms::sendingCallback(msg_struct_t sent_status)
 {
-//     LogInfo("sendingCallback callback received. Req id = " <<
-//     sent_status->reqId << " Status = " << (int)sent_status->status);
-//     msg_struct_t request_data = NULL;
-//     msg_get_struct_handle(sent_status, MSG_STRUCT_REQUEST_INFO, (void **)request_data);
-//     msg_get_int_value(request_data, MSG_REQUEST_REQUESTID_INT, &tempInt);
        int status = MSG_NETWORK_SEND_FAIL;
        msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
        
-       LogDebug("status : " << status);
+       LoggerD("status : " << status);
        
        if (MSG_NETWORK_SEND_SUCCESS == status) {
-               LogDebug("sending ok");
+               LoggerD("sending ok");
                setSendingStatusOk();
                setMessageStatus(MESSAGE_STATUS_SENT);
        } else {
-               LogError("sending failed: " << static_cast<unsigned int>(status));
+               LoggerE("sending failed: " << static_cast<unsigned int>(status));
                setSendingStatusFailed();
                setMessageStatus(MESSAGE_STATUS_FAILED);
        }
@@ -1348,9 +1594,9 @@ void Mms::sendingCallback(msg_struct_t sent_status)
 
 void Mms::sendCancel(int handle)
 {
-    LogDebug("sending message, id=" << getIdRef());
+    LoggerD("sending message, id=" << getIdRef());
     //#warning "TODO"
-    LogDebug("handle =" << handle);
+    LoggerD("handle =" << handle);
 }
 
 void Mms::setSendingStatusOk()
@@ -1362,7 +1608,7 @@ void Mms::setSendingStatusOk()
        int nToCnt;
        
        if (requestReceiver) {
-               LogInfo("calling JS success callback");
+               LoggerI("calling JS success callback");
                EventMessagingServicePtr event = getMessagingServiceEvent();
                event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
 
@@ -1372,7 +1618,7 @@ void Mms::setSendingStatusOk()
 
                for ( int index=0; index < nToCnt; index++)
                {
-                       msg_get_str_value(addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                       msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
                        event->m_successRecipients.push_back(strNumber);
                }
          
@@ -1400,12 +1646,12 @@ void Mms::setSendingStatusFailed()
                EventMessagingServicePtr event = getMessagingServiceEvent();
                if (requestReceiver) 
                {
-                       LogError("calling JS error callback");
+                       LoggerE("calling JS error callback");
                        event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
                        msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
                        nToCnt = addr_list->nCount;
 
-                       LogDebug("nToCnt : " << nToCnt);
+                       LoggerD("nToCnt : " << nToCnt);
 
                        for ( int index=0; index < nToCnt; index++)
                        {
@@ -1431,5 +1677,172 @@ FolderType Mms::toFolder(const std::string &folder)
     }
     ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
 }
+
+bool Mms::getCellularOn()
+{
+    auto cellularOn = true;
+    int tempInt;
+    int tempbool;
+
+    vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &tempInt);
+    vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &tempbool);
+    if(tempInt <= VCONFKEY_TELEPHONY_SVCTYPE_SEARCH || tempbool == TRUE)
+    {
+        LoggerE("VCONFKEY_TELEPHONY_SVCTYPE error " << tempInt);
+        LoggerE("VCONFKEY_TELEPHONY_FLIGHT_MODE error " << tempbool);
+        cellularOn = false;
+        return cellularOn;
+    }
+
+    vconf_get_bool(VCONFKEY_3G_ENABLE, &tempbool);
+    vconf_get_int(VCONFKEY_TELEPHONY_SVC_PS, &tempInt);
+    if(tempbool == FALSE || tempInt != VCONFKEY_TELEPHONY_SVC_PS_ON)
+    {
+        LoggerE("VCONFKEY_3G_ENABLE error " << tempbool);
+        LoggerE("VCONFKEY_TELEPHONY_SVC_PS_ON error " << tempInt);
+        cellularOn = false;
+    }
+    return cellularOn;
+}
+
+
+MimeType Mms::mimeTypeStringToIndexInt(std::string inputString)
+{
+       const char* szMimeStr = inputString.c_str();
+       MimeType retInt = MIME_UNKNOWN;
+
+       LoggerD("szMimeStr " << szMimeStr);
+
+       for(int idx =0; strcmp(mimeTable[idx].szMIME, "") != 0; idx++)
+       {
+               if (!strcmp(mimeTable[idx].szMIME, szMimeStr)) {
+                       retInt = mimeTable[idx].mime;
+                       break;
+               }
+       }
+       return retInt;
+
+}
+
+std::string Mms::indexIntToMimeTypeString(MimeType inputIndex)
+{
+       std::string retString;
+       
+       for (int idx=0; mimeTable[idx].szMIME != NULL; idx++) {
+               if (inputIndex == mimeTable[idx].mime) {
+                       retString = (char *)mimeTable[idx].szMIME;
+               }
+       }
+       return retString;
+}
+
+msg_struct_t Mms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
+{
+       int tempInt, nCount, ret;
+       bool tempBool;
+       msg_struct_list_s *addr_list;
+       msg_struct_list_s *new_addr_list;
+
+       msg_struct_t mms_struct = NULL;
+       msg_struct_t mms_struct_dummy = NULL;   
+
+       msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+
+       msg_set_int_value(msg, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
+
+       char strSubject[MAX_SUBJECT_LEN] = {0};
+       msg_get_str_value(src, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
+       msg_set_str_value(msg, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
+
+       msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
+
+       msg_get_int_value(src, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_THREAD_ID_INT, tempInt);
+
+       msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
+
+//     msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
+//     char tempStr[tempInt+1];
+//     memset(tempStr, 0, tempInt+1);
+
+//     msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
+//     msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
+//    copy mms body and attachment
+       mms_struct = msg_create_struct(MSG_STRUCT_MMS);
+       mms_struct_dummy = msg_create_struct(MSG_STRUCT_MMS);
+       ret = msg_get_mms_struct(src, mms_struct);
+       if (ret != MSG_SUCCESS)
+       {
+               LoggerE("cannot get mms struct");
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
+       }
+
+       msg_set_mms_struct(src, mms_struct_dummy);
+       msg_set_mms_struct(msg, mms_struct);
+
+       msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
+
+//    msg_set_network_status(msg, msg_get_network_status(src));
+       msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT,  tempInt);
+
+//    msg_set_encode_type(msg, msg_get_encode_type(src));
+       msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT,  tempInt);
+
+//    msg_set_read_status(msg, msg_is_read(src));
+       msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
+       msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
+
+//       msg_set_protect_status(msg, msg_is_protected(src));
+       msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
+       msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
+
+//       msg_set_priority_info(msg, msg_get_priority_info(src));
+       msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT,  tempInt);
+
+//       msg_set_direction_info(msg, msg_get_direction_info(src));
+       msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT,  tempInt);
+
+//       msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
+       msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT,  tempInt);
+       msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT,  tempInt);
+
+// copy addr list
+       msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+       msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
+
+       new_addr_list->nCount = addr_list->nCount;
+
+       for(int i=0; i<addr_list->nCount; i++)
+       {
+               msg_struct_t addr_info = NULL;
+               msg_struct_t new_addr_info = NULL;
+               char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
+               
+               //get original address
+               addr_info = addr_list->msg_struct_info[i];
+               msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
+               msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
+
+               //copy original address
+               new_addr_info = new_addr_list->msg_struct_info[i];
+               msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
+               msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);
+       }
+
+       msg_release_struct(&mms_struct_dummy);
+       msg_release_struct(&mms_struct);
+
+    return msg;
+}
+
 }
 }