merge wrt-plugins-tizen_0.2.0-12
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Messaging / Conversation.cpp
index a1deaa3..3606138 100755 (executable)
@@ -452,28 +452,34 @@ bool Conversation::makeConversationFromEmailThreadId(unsigned int emailTreadId)
 
        try 
        {
+
                // Todo : will be re-implemented as using email_get_thread_information_ex 
                if(email_get_thread_information_ex(emailTreadId, &resultMail) != EMF_ERROR_NONE) 
                {
                        ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get email thread fail" );
                }
 
+               if (!resultMail)
+               {
+                       return NULL;
+               }
                
                if (email_get_mail(&mailbox, resultMail->mail_id, &mail) != EMF_ERROR_NONE)
                {
                        ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get email data fail" );
                }
-
-
+               
                // account Id
                m_unreadMessages = 0;
-               
+
+               LogDebug("start email_get_mail_list_ex");
                if (email_get_mail_list_ex(accountId, NULL, emailTreadId, 0, resultMail->thread_item_count, 
                        EMF_SORT_DATETIME_HIGH, &mailList, &count) != EMF_ERROR_NONE)
                {
                        ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get email data fail" );
                }
-
+               LogDebug("end email_get_mail_list_ex");
+               
                // unread msg count
                accountId = resultMail->account_id;     
 
@@ -544,11 +550,10 @@ bool Conversation::makeConversationFromEmailThreadId(unsigned int emailTreadId)
                        LogDebug(mail->head->previewBodyText);
                        m_preview = mail->head->previewBodyText;
                }
-#endif         
+#endif 
                // read
                m_read = (bool)resultMail->flags_seen_field; 
 
-
                // from
                if (resultMail->from[0] != '\0')
                {
@@ -596,16 +601,17 @@ bool Conversation::makeConversationFromEmailThreadId(unsigned int emailTreadId)
                LogError("Exception: " << ex.GetMessage());
        }
 
-       if (resultMail != NULL)
+       if (mail != NULL)
        {
-               free(resultMail);
+               email_free_mail(&mail , 1);
        }
        
-       if (mail != NULL)
+       if (resultMail != NULL)
        {
-               email_free_mail(&mail , 1);
+               free(resultMail);
        }
 
+
        return m_result;
 
 }