Update change log and spec for wrt-plugins-tizen_0.2.73
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Messaging / MailSync.cpp
index 8f84890..fa1b65f 100644 (file)
@@ -399,32 +399,31 @@ int MailSync::syncFolderInternal(const Api::Messaging::IMessagingServicePtr& mes
 // TODO Copied from former solution, refactor it.
 void MailSync::OnEventReceived(const DBus::MessageEvent& event)
 {
-    LogDebug("OnEventReceived");
-    SyncNetworkStatusPtr syncNetworkStatus(new SyncNetworkStatus(event.GetArg0()));
-    int mailId = syncNetworkStatus->getMailId();       //if email body download mode.
-    int status = syncNetworkStatus->getStatus();
-    int handle = syncNetworkStatus->getHandle();
+       LogDebug("OnEventReceived");
+       SyncNetworkStatusPtr syncNetworkStatus(new SyncNetworkStatus(event.GetArg0()));
+       int mailId = syncNetworkStatus->getMailId();    //if email body download mode.
+       int status = syncNetworkStatus->getStatus();
+       int handle = syncNetworkStatus->getHandle();
 
        // if Attachment Load
-       if ( status == NOTI_DOWNLOAD_ATTACH_FINISH ||
-       status == NOTI_DOWNLOAD_ATTACH_FAIL )
-       {       
+       if ( status == NOTI_DOWNLOAD_ATTACH_FINISH ||status == NOTI_DOWNLOAD_ATTACH_FAIL )
+       {
                int nth = handle;
                LogDebug(" Debus mailID = " <<  mailId <<  " , Nth = " << nth );
-               
+
                SyncRequestIterator it = m_SyncRequests.begin();
                for ( ; it != m_SyncRequests.end(); it++ )
                {
                        const Api::Messaging::IEmailPtr& mail = it->second.mail;
-                       
+
                        LogDebug(" request mailID = " <<  mail->getUID() <<  " , Nth = " << (it->second.attachment)->getNth() );
                        if ( mail->getUID() == mailId && nth == (it->second.attachment)->getNth())
-                       {       
+                       {
                                Api::Messaging::EventMessagingServiceReqReceiver* requestReceiver = mail->getRequestReceiver();
                                if ( mail && requestReceiver )
                                {
                                        Api::Messaging::EventMessagingServicePtr event = mail->getMessagingServiceEvent();
-                               
+
                                        if (status == NOTI_DOWNLOAD_ATTACH_FINISH)
                                        {
                                                LogDebug(" Attachment Finish " );
@@ -444,7 +443,7 @@ void MailSync::OnEventReceived(const DBus::MessageEvent& event)
                                                        email_attachment_data_t* attachment_data = NULL;
                                                        int attachmentId = attachment->getAttachmentID();
                                                        LogDebug("Attachment ID = " << attachmentId);
-                                                       
+
                                                        int err = email_get_attachment_data(attachmentId, &attachment_data);
                                                        if (err == EMAIL_ERROR_NONE) {
                                                                LogDebug("attachment Name : " << attachment_data->attachment_name);
@@ -455,88 +454,86 @@ void MailSync::OnEventReceived(const DBus::MessageEvent& event)
                                                        {
                                                                LogDebug("fail to email_get_attachment_data - err : " << err);
                                                        }
-                                                       
+
                                                }
-                                               
+
                                        }
-                                       else 
-                                       {       
+                                       else
+                                       {
                                                event->setExceptionCode( WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
                                                LogDebug(" Attachment Failed " );
                                        }
 
                                        requestReceiver->ManualAnswer(event);
-                                       m_SyncRequests.erase( handle );         
-                               
-                               }
+                                       m_SyncRequests.erase( handle );
 
-                       break;
+                               }
+                               break;
                        }
                } 
        }
-       else if ( status == NOTI_DOWNLOAD_ATTACH_START ) 
+       else if ( status == NOTI_DOWNLOAD_ATTACH_START )
        {
                LogDebug("DownLoading... attachment : size = " << syncNetworkStatus->getErrorCode());
                return;
        }
 
-    SyncRequestIterator it = m_SyncRequests.find(handle);
-    if ( m_SyncRequests.end() != it)
-    {  
+       SyncRequestIterator it = m_SyncRequests.find(handle);
+       if ( m_SyncRequests.end() != it)
+       {
                int syncType = it->second.syncType;
                LogDebug(" Sync ... handle : " << handle << " status : " << status << " SyncType: " << syncType);
 
                switch(syncType)
                {
                        case MESSAGING_SERVICE_SYNC_TYPE_SYNC:
-                       {       
+                       {
                                LogDebug(" Sync Account");
                                const Api::Messaging::IMessagingServicePtr& messagingService = it->second.messagingService;
                                Api::Messaging::EventMessagingServiceReqReceiver* requestReceiver = messagingService->getRequestReceiver();
-                               
+
                                if ( messagingService && requestReceiver)
-                               {       
+                               {
                                        Api::Messaging::EventMessagingServicePtr event = messagingService->getMessagingServiceEvent();
                                        if ( status == NOTI_DOWNLOAD_FINISH )
-                                       {       
+                                       {
                                                LogDebug("Sync Success");
-                                               requestReceiver->ManualAnswer(event);
-                                               m_SyncRequests.erase( handle );                                                         
+                                               requestReceiver->ManualAnswer(event);
+                                               m_SyncRequests.erase( handle );
                                        }
                                        else if ( status == NOTI_DOWNLOAD_FAIL )
-                                       {       
+                                       {
                                                LogDebug("Sync Fail");
-                                       event->setExceptionCode( WrtDeviceApis::Commons::ExceptionCodes::UnknownException );
+                                               event->setExceptionCode( WrtDeviceApis::Commons::ExceptionCodes::UnknownException );
                                                requestReceiver->ManualAnswer(event);
                                                m_SyncRequests.erase( handle );
-                                       }       
+                                       }
                                }
                                else
                                {
                                        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "request Receiver is NULL. ");
                                }
-                               
                                break;
                        }
                        case MESSAGING_SERVICE_SYNC_TYPE_SYNC_FOLDER:
-                       {       
+                       {
                                LogDebug("Sync Folder");
                                const Api::Messaging::IMessagingServicePtr& messagingService = it->second.messagingService;
                                Api::Messaging::EventMessagingServiceReqReceiver* requestReceiver = messagingService->getRequestReceiver();
-                               
+
                                if ( messagingService && requestReceiver)
-                               {       
+                               {
                                        Api::Messaging::EventMessagingServicePtr event = messagingService->getMessagingServiceEvent();
                                        if ( status == NOTI_DOWNLOAD_FINISH )
-                                       {       
+                                       {
                                                LogDebug("Sync Success");
-                                               requestReceiver->ManualAnswer(event);
-                                               m_SyncRequests.erase( handle );                                                         
+                                                       requestReceiver->ManualAnswer(event);
+                                               m_SyncRequests.erase( handle );
                                        }
                                        else if ( status == NOTI_DOWNLOAD_FAIL )
-                                       {       
+                                       {
                                                LogDebug("Sync Fail");
-                                       event->setExceptionCode( WrtDeviceApis::Commons::ExceptionCodes::UnknownException );
+                                               event->setExceptionCode( WrtDeviceApis::Commons::ExceptionCodes::UnknownException );
                                                requestReceiver->ManualAnswer(event);
                                                m_SyncRequests.erase( handle );
                                        }
@@ -548,7 +545,7 @@ void MailSync::OnEventReceived(const DBus::MessageEvent& event)
                                break;
                        }
                        case MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_BODY:
-                       {       
+                       {
                                LogDebug(" DownLoad Body");
                                const Api::Messaging::IEmailPtr& mail = it->second.mail;        // IEmailPtr
                                Api::Messaging::EventMessagingServiceReqReceiver* requestReceiver = mail->getRequestReceiver();
@@ -556,6 +553,7 @@ void MailSync::OnEventReceived(const DBus::MessageEvent& event)
                                        Api::Messaging::EventMessagingServicePtr event = mail->getMessagingServiceEvent();
                                        if ( status == NOTI_DOWNLOAD_BODY_FINISH )
                                        {
+                                               event->m_message->readAllData();
                                                requestReceiver->ManualAnswer(event);
                                                m_SyncRequests.erase( handle );
                                        }
@@ -564,21 +562,16 @@ void MailSync::OnEventReceived(const DBus::MessageEvent& event)
                                                event->setExceptionCode( WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
                                                requestReceiver->ManualAnswer(event);
                                                m_SyncRequests.erase( handle );
-                                       }              
-                       }
+                                       }
+                               }
                                else
                                {
                                        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "request Receiver is NULL. ");
                                }
-                               
                                break;
                        }
-                       
                }
-
-               
        }
-                               
 }
 
 int MailSync::downloadBodyInternal( const Api::Messaging::IEmailPtr& mail, int account_id)
@@ -620,10 +613,10 @@ int MailSync::downloadAttachmentInternal(const Api::Messaging::IEmailPtr& mail,
        int mailId = mail->convertId(mail->getIdRef());
        unsigned email_handle = 0;
        
-//     email_mail_data_t* result = NULL;
+       email_mail_data_t* result = NULL;
 
        int error;
-//     error = email_get_mail_data(mailId, &result);
+       error = email_get_mail_data(mailId, &result);
        if (EMAIL_ERROR_NONE != error) {
                        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
                                 "Couldn't find message " << mailId << ". [" << error << "]");
@@ -661,14 +654,14 @@ int MailSync::downloadAttachmentInternal(const Api::Messaging::IEmailPtr& mail,
        {
                LogDebug("Insert downloadAttachment request");
                LogDebug("handle : " << email_handle);
-               SyncRequestData data = SyncRequestData( email_handle,   
+               SyncRequestData data = SyncRequestData( email_handle,
                        MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_ATTACHMENT, mail, attachment );
-               m_SyncRequests.insert(std::make_pair(email_handle, data));              
+               m_SyncRequests.insert(std::make_pair(email_handle, data));
        }
 
-//     if ( result )
-//             if  (  EMAIL_ERROR_NONE != email_free_mail_data( &result , 1) )
-//                     LogDebug("fail to email_free_mail_data - err ");
+       if ( result )
+               if  (  EMAIL_ERROR_NONE != email_free_mail_data( &result , 1) )
+                       LogDebug("fail to email_free_mail_data - err ");
        
        return email_handle;
 }