Coverity fix: check return type
[platform/core/messaging/msg-service.git] / framework / submit-handler / MsgSubmitHandler.cpp
index 2c45925..14ac522 100755 (executable)
- /*
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
-  *    http://www.tizenopensource.org/license
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
-  */
+/*
* Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
 
 #include <stdio.h>
 #include <string.h>
 
 #include "MsgDebug.h"
 #include "MsgUtilFile.h"
+#include "MsgUtilStorage.h"
 #include "MsgException.h"
 #include "MsgGconfWrapper.h"
 #include "MsgPluginManager.h"
 #include "MsgStorageHandler.h"
 #include "MsgSubmitHandler.h"
+#include "MsgUtilFunction.h"
 
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
-MSG_ERROR_T MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
+msg_error_t MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
 {
-       MSG_ERROR_T err = MSG_SUCCESS;
-
+       msg_error_t err = MSG_SUCCESS;
        static int reqId = 1;
 
        pReqInfo->reqId = reqId;
        reqId++;
 
+       if (msg_check_dpm_policy(pReqInfo->msgInfo.msgType.mainType) == false) {
+               MSG_DEBUG("Messaging is restricted by DPM policy.");
+               MsgDbHandler *dbHandle = getDbHandle();
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+               if (pReqInfo->msgInfo.msgType.subType != MSG_RETRIEVE_MMS)
+                       /* sending popup */
+                       msg_syspopup_message(true);
+               else
+                       /* retrieving popup */
+                       msg_syspopup_message(false);
+
+               return MSG_ERR_DPM_RESTRICT;
+       }
+
        MSG_DEBUG("==== Msg ID = [%d] ====", pReqInfo->msgInfo.msgId);
        MSG_DEBUG("==== Folder ID = [%d] ====", pReqInfo->msgInfo.folderId);
-       MSG_DEBUG("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
-       MSG_DEBUG("==== Sub Type = [%d] ====", pReqInfo->msgInfo.msgType.subType);
+       MSG_INFO("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
+       MSG_INFO("==== Sub Type = [%d] ====", pReqInfo->msgInfo.msgType.subType);
        MSG_DEBUG("==== Class Type = [%d] ====", pReqInfo->msgInfo.msgType.classType);
        MSG_DEBUG("==== Message Data = [%s] ====", pReqInfo->msgInfo.msgData);
-       MSG_DEBUG("==== Message Text = [%s] ====", pReqInfo->msgInfo.msgText);
+       MSG_SEC_DEBUG("==== Message Text = [%s] ====", pReqInfo->msgInfo.msgText);
+       MSG_INFO("==== SIM Index = [%d] ====", pReqInfo->msgInfo.sim_idx);
 
        MSG_DEBUG("==== bSetting = [%d] ====", pReqInfo->sendOptInfo.bSetting);
 
-       if (pReqInfo->msgInfo.msgType.mainType == MSG_SMS_TYPE)
-       {
+       if (pReqInfo->msgInfo.msgType.mainType == MSG_SMS_TYPE) {
                MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
                MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
                MSG_DEBUG("==== bReplyPath = [%d] ====", pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath);
 
                err = MsgSubmitReqSMS(pReqInfo);
-       }
-       else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE)
-       {
+       } else if (pReqInfo->msgInfo.msgType.mainType == MSG_MMS_TYPE) {
                MSG_DEBUG("==== deliver = [%d] ====", pReqInfo->sendOptInfo.bDeliverReq);
                MSG_DEBUG("==== keepcopy = [%d] ====", pReqInfo->sendOptInfo.bKeepCopy);
                MSG_DEBUG("==== bReadReq = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.bReadReq);
                MSG_DEBUG("==== priority = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.priority);
                MSG_DEBUG("==== expiryTime = [%d] ====", pReqInfo->sendOptInfo.option.mmsSendOptInfo.expiryTime.time);
 
-               err = MsgSubmitReqMMS(pReqInfo, bScheduled);
+               err = MsgSubmitReqMMS(pReqInfo);
        }
 
        return err;
 }
 
 
-MSG_ERROR_T MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
+msg_error_t MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
 {
-       MSG_ERROR_T err = MSG_SUCCESS;
+       msg_error_t err = MSG_SUCCESS;
 
-       // submit request based on msgType;
+       /* submit request based on msgType; */
        MSG_MAIN_TYPE_T mainType = pReqInfo->msgInfo.msgType.mainType;
        MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
 
-       if (plg == NULL)
-       {
-               THROW(MsgException::PLUGIN_ERROR, "No plugin for %d type", mainType);
+       if (plg == NULL) {
+               MsgDbHandler *dbHandle = getDbHandle();
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+               MSG_ERR("No plugin for %d type", mainType);
+               return MSG_ERR_INVALID_PLUGIN_HANDLE;
        }
 
-       MSG_REQUEST_INFO_S tmpInfo = {};
-
-       bool bReqSentStatus = false;
-
-       for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++)
-       {
-               MsgCopyReqInfo(pReqInfo, i, &tmpInfo);
-
-               // If MSG ID > 0 -> MSG in DRAFT
-               // Move Folder to OUTBOX
-               if (pReqInfo->msgInfo.msgPort.valid == false)
-               {
-                       pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
-
-                       if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID))
-                       {
-                               err = MsgStoUpdateMessage(&(tmpInfo.msgInfo), &(tmpInfo.sendOptInfo));
-                       }
+       /* If MSG ID > 0 -> MSG in DRAFT */
+       /* Move Folder to OUTBOX */
+       if (pReqInfo->msgInfo.msgPort.valid == false) {
+               pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
 
+               if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
+                       err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
                        if (err != MSG_SUCCESS)
-                       {
-                               MSG_DEBUG("MsgStoUpdateMessage() Fail");
-                               continue;
-                       }
-               }
-
-               if (i == (pReqInfo->msgInfo.nAddressCnt -1))
-               {
-                       // Request Sent Status Callback
-                       bReqSentStatus = true;
-               }
-
-               err = plg->submitReq(&tmpInfo, bReqSentStatus);
-
-               if (err != MSG_SUCCESS)
-               {
-                       break;
-               }
-
-               if (i == (pReqInfo->msgInfo.nAddressCnt -1))
-               {
-                       // Copy MSG ID
-                       pReqInfo->msgInfo.msgId = tmpInfo.msgInfo.msgId;
+                               return err;
                }
        }
 
+       err = plg->submitReq(pReqInfo);
+
        return err;
 }
 
-
-MSG_ERROR_T MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
+msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
 {
-       MSG_ERROR_T err = MSG_SUCCESS;
-
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
        MSG_RECIPIENTS_LIST_S pRecipientList;
 
+       MsgPlugin *sms_plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
+
+       if (sms_plg == NULL) {
+               MsgDbHandler *dbHandle = getDbHandle();
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+               MSG_ERR("No plugin for %d type", MSG_SMS_TYPE);
+               return MSG_ERR_INVALID_PLUGIN_HANDLE;
+       }
+
+       int defaultNetworkSimId = 0;
+
+       err = sms_plg->getDefaultNetworkSimId(&defaultNetworkSimId);
+       if (err != MSG_SUCCESS) {
+               MSG_ERR("getDefaultNetworkSimId is failed=[%d]", err);
+               return err;
+       } else if (pReqInfo->msgInfo.sim_idx != defaultNetworkSimId) {
+               MSG_ERR("It is not default network SIM ID, request SIM=[%d], activated SIM=[%d]", pReqInfo->msgInfo.sim_idx, defaultNetworkSimId);
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
        MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
        MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
 
-       if(!plg)
-       {
-               MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+       if(!plg) {
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
                MSG_DEBUG("No Plugin for %d type", msgMainType);
 
                return MSG_ERR_INVALID_PLUGIN_HANDLE;
        }
 
-       //      If MSG ID > 0 -> MSG in DRAFT
-       // Move Folder to OUTBOX
+       /*      If MSG ID > 0 -> MSG in DRAFT */
+       /* Move Folder to OUTBOX */
        /* reject_msg_support */
-       if(!bScheduled)
-       {
-               if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS)
-               {
-                       char fileName[MAX_COMMON_INFO_SIZE+1] = {0};
+       MSG_DEBUG("Not scheduled MMS, pReqInfo->msgInfo.msgType.subType [%d]", pReqInfo->msgInfo.msgType.subType);
 
-                       // copy whole of MMS PDU filepath to msgData
-                       strncpy(fileName, pReqInfo->msgInfo.msgData, MAX_COMMON_INFO_SIZE);
-                       memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
-                       snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_IPC_DATA_PATH"%s", fileName);
+       if(pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_JAVA_MMS) {
+               char fileName[MSG_FILENAME_LEN_MAX+1] = {0};
 
-                       MSG_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
+               /* copy whole of MMS PDU filepath to msgData */
+               strncpy(fileName, pReqInfo->msgInfo.msgData, MSG_FILENAME_LEN_MAX);
+               memset(pReqInfo->msgInfo.msgData, 0x00, sizeof(pReqInfo->msgInfo.msgData));
+               int wrn = snprintf(pReqInfo->msgInfo.msgData, sizeof(pReqInfo->msgInfo.msgData), "%s%s", MSG_IPC_DATA_PATH, fileName);
+               if(wrn<0)
+                       MSG_DEBUG("snprintf was failed");
 
-                       // submit request
-                       plg->submitReq(pReqInfo, false);
+               MSG_SEC_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
 
-                       if(err != MSG_SUCCESS)
-                       {
-                               MSG_DEBUG("Update Network Status : [%d]", err);
-                               MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
-                       }
+               /* submit request */
+               err = plg->submitReq(pReqInfo);
 
-                       return err;
+               if(err != MSG_SUCCESS) {
+                       MSG_DEBUG("Update Network Status : [%d]", err);
+                       MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
                }
-               else if((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS))
-               {
-                       // update address list in the ase of existing message
-                       if(pReqInfo->msgInfo.msgId > 0)
-                       {
-                               err = MsgStoGetOrgAddressList(&(pReqInfo->msgInfo));
-
-                               if(err != MSG_SUCCESS)
-                                       MSG_DEBUG("[WARNING]MsgStoGetOrgAddressList returned not a MSG_SUCCESS");
-                       }
-
-                       if(pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
-                               MSG_ADDRESS_INFO_S addrInfo = {0,};
-                               int addrIdx = 0;
-
-                               err = MsgStoGetAddrInfo(pReqInfo->msgInfo.msgId, &addrInfo);
-
-                               if (err == MSG_SUCCESS) {
-                                       for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
-                                               //if (pReqInfo->msgInfo.addressList[i].threadId == addrInfo.threadId) {
-                                               if (!strcmp(pReqInfo->msgInfo.addressList[i].addressVal, addrInfo.addressVal)) {
-                                                       addrIdx = i;
-                                                       MSG_DEBUG("addrIdx = %d, address = [%s]", addrIdx, pReqInfo->msgInfo.addressList[i].addressVal);
-                                                       break;
-                                               }
-                                       }
-                               } else {
-                                       MSG_DEBUG("[Error]MsgStoGetAddrInfo is failed");
-                               }
-
-                               pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
-                               err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo), addrIdx);
-
-                               MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
-                       } else {
-                               //new message case
-                               MSG_DEBUG("New Message");
-                               for(int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
-                                       pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
-                                       err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo), i);
-                                       //pReqInfo->msgInfo.msgId = 0;
-                               }
-
-                               if (pReqInfo->msgInfo.msgId != pReqInfo->msgInfo.referenceId) {
-                                       MSG_DEBUG("Add Multi-recipient Message");
-                                       //multi-recipient mms case
-                                       pReqInfo->msgInfo.msgId = pReqInfo->msgInfo.referenceId;
-                               }
-                       }
-               //      pReqInfo->msgInfo.msgId = pReqInfo->msgInfo.referenceId;
+
+               return err;
+       } else if ((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS)) {
+               MSG_SEC_DEBUG("msgdata file path = [%s]", pReqInfo->msgInfo.msgData);
+
+               if (pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
+                       MSG_DEBUG("Not New Message.");
+                       pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
+                       err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
+               } else {
+                       MSG_DEBUG("New Message.");
+                       pReqInfo->msgInfo.msgId = 0;
+                       pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
+                       err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
                }
-               else if(pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS)
-               {
-                       err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
-                       if(err != MSG_SUCCESS)
-                               return err;
+       } else if (pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS) {
+               msg_read_report_status_t readStatus;
 
-                       err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
-                       if(err != MSG_SUCCESS)
-                               return MSG_ERR_PLUGIN_STORAGE;
+               err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
+               if(err != MSG_SUCCESS) {
+                       MSG_INFO("msg id [%d], read report could NOT send [%d]", pReqInfo->msgInfo.msgId, err);
+                       return err;
+               }
 
-                       pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
+               memcpy(&readStatus, pReqInfo->msgInfo.msgData, sizeof(msg_read_report_status_t));
+               if (readStatus == MSG_READ_REPORT_REJECT_BY_USER) {
+                       MSG_INFO("msg id [%d], read report reject by user", pReqInfo->msgInfo.msgId);
 
-                       for(int i = 0; i < pRecipientList.recipientCnt; i++)
-                       {
-                               pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
-                               pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
-                               pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
-                               strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
-                       }
+                       err = MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_NO_SENT);
 
-                       char subject[MAX_SUBJECT_LEN+1];
+                       return err;
+               }
 
-                       err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
-                       if(err != MSG_SUCCESS)
-                               MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
+               err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
+               if(err != MSG_SUCCESS)
+                       return MSG_ERR_PLUGIN_STORAGE;
 
-                       strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
+               pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
+               pReqInfo->msgInfo.addressList = pRecipientList.recipientAddr;
 
-                       err = plg->composeReadReport(&(pReqInfo->msgInfo));
-               }
-               else if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
+               /*
+               for(int i = 0; i < pRecipientList.recipientCnt; i++)
                {
-                       MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
+                       pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
+                       pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
+                       pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
+                       strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
                }
+               */
+
+               char subject[MAX_SUBJECT_LEN+1];
+
+               err = MsgStoGetSubject(pReqInfo->msgInfo.msgId, subject);
+               if (err != MSG_SUCCESS)
+                       MSG_DEBUG("Getting subject returned not a MSG_SUCCESS");
+
+               strncpy(pReqInfo->msgInfo.subject, subject, MAX_SUBJECT_LEN);
+
+               err = plg->composeReadReport(&(pReqInfo->msgInfo));
+       } else if (pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS) {
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
        }
 
        /* reject_msg_support */
 
-       if(err != MSG_SUCCESS)
-       {
+       if(err != MSG_SUCCESS) {
                MSG_DEBUG("Fail to Add/Update Message : MsgStoMoveMessageToFolder()/MsgStoAddMessage()");
                return err;
        }
 
-       switch(pReqInfo->msgInfo.msgType.subType)
-       {
+       switch (pReqInfo->msgInfo.msgType.subType) {
                case MSG_SENDREQ_MMS:
                case MSG_FORWARD_MMS:
                        MsgDeleteFile(pReqInfo->msgInfo.msgData);
                        memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
-                       snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pReqInfo->msgInfo.referenceId);
+                       snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, "%s%d.mms", MSG_DATA_PATH, pReqInfo->msgInfo.msgId);
                        break;
 
                case MSG_READREPLY_MMS:
                case MSG_READRECIND_MMS:
-                       memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
-                       snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pReqInfo->msgInfo.msgId);
                        break;
                default:
                        break;
        }
 
-       // update content location from db
+       /* update content location from db */
        if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
                err = MsgStoGetContentLocation(&(pReqInfo->msgInfo));
        /* reject_msg_support */
-       else if(pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
+       else if (pReqInfo->msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS)
                err = plg->updateRejectStatus(&(pReqInfo->msgInfo));
-       /* reject_msg_support */
 
-       // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
+       /* Check SIM is present or not */
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, pReqInfo->msgInfo.sim_idx);
+       int tmpval = 0;
+       if (MsgSettingGetInt(keyName, &tmpval) != MSG_SUCCESS) {
+               MSG_INFO("MsgSettingGetInt() is failed");
+       }
+       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)tmpval;
 
-       if(simStatus == MSG_SIM_STATUS_NOT_FOUND)
-       {
+       if(simStatus == MSG_SIM_STATUS_NOT_FOUND) {
                MSG_DEBUG("SIM is not present...");
-               MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
 
                return MSG_ERR_NO_SIM;
        }
 
-       if(err == MSG_SUCCESS)
-               err = plg->submitReq(pReqInfo, false);
+       if (err == MSG_SUCCESS)
+               err = plg->submitReq(pReqInfo);
 
-       if(err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
+       if (err == MSG_SUCCESS && ( pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS || pReqInfo->msgInfo.msgType.subType == MSG_READRECIND_MMS ))
                MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_SENT);
 
-       if (err != MSG_SUCCESS)
-       {
-               if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
-                       MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
+       if (err != MSG_SUCCESS) {
+               if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
+                       MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
                else
-                       MsgStoUpdateNetworkStatus(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+                       MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
        }
 
-
        return err;
 }
 
 
-MSG_ERROR_T MsgCancelReq(MSG_REQUEST_ID_T reqId)
+msg_error_t MsgUpdateSentMsg(msg_message_id_t MsgId, msg_network_status_t Status)
 {
-       MSG_ERROR_T err = MSG_SUCCESS;
-
-       return err;
-}
+       msg_error_t err = MSG_SUCCESS;
 
+       bool bKeepCopy = true;
 
-MSG_ERROR_T MsgUpdateSentMsg(MSG_MESSAGE_ID_T MsgId, MSG_NETWORK_STATUS_T Status)
-{
-       MSG_ERROR_T err = MSG_SUCCESS;
+#ifdef MSG_MMS_KEEPCOPY
+       MSG_SENDINGOPT_INFO_S sendOpt = {};
 
-       bool bKeepCopy = true;
+       if (msgType.mainType == MSG_MMS_TYPE) {
+               if (MsgStoGetMmsSendOpt(MsgId, &sendOpt) == MSG_SUCCESS)
+                       bKeepCopy = sendOpt.bKeepCopy;
+               else
+                       err = MsgSettingGetBool(MSG_KEEP_COPY, &bKeepCopy);
+       }
 
-       // Move Msg to SENTBOX
-       if (Status == MSG_NETWORK_SEND_SUCCESS)
-       {
-               MSG_DEBUG(" In Status == MSG_NETWORK_SEND_SUCCESS and  bKeepCopy is [%d]", bKeepCopy);
+       /* Move Msg to SENTBOX */
+       if (Status == MSG_NETWORK_SEND_SUCCESS) {
+               MSG_DEBUG("In Status == MSG_NETWORK_SEND_SUCCESS and  bKeepCopy is [%d]", bKeepCopy);
                if (bKeepCopy == true)
                        err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
                else
                        err = MsgStoDeleteMessage(MsgId, false);
        }
-
+#else
+       /* Move Msg to SENTBOX */
+       if (Status == MSG_NETWORK_SEND_SUCCESS) {
+               MSG_DEBUG("In Status == MSG_NETWORK_SEND_SUCCESS and  bKeepCopy is [%d]", bKeepCopy);
+               if (bKeepCopy == true)
+                       err = MsgStoMoveMessageToFolder(MsgId, MSG_SENTBOX_ID);
+       }
+#endif
        return err;
 }
 
@@ -361,16 +342,17 @@ void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *p
 {
        MSG_BEGIN();
 
-       memset(pDest, 0x00, sizeof(pDest));
+       memset(pDest, 0x00, sizeof(MSG_REQUEST_INFO_S));
 
-       // Copy Request ID
+       /* Copy Request ID */
        pDest->reqId = pSrc->reqId;
 
-       // Copy Msg Info
+       /* Copy Msg Info */
        pDest->msgInfo.msgId = pSrc->msgInfo.msgId;
-       pDest->msgInfo.folderId = pSrc->msgInfo.folderId;
 
-       pDest->msgInfo.referenceId = pSrc->msgInfo.referenceId;
+       pDest->msgInfo.threadId = pSrc->msgInfo.threadId;
+
+       pDest->msgInfo.folderId = pSrc->msgInfo.folderId;
 
        pDest->msgInfo.msgType.mainType = pSrc->msgInfo.msgType.mainType;
        pDest->msgInfo.msgType.subType = pSrc->msgInfo.msgType.subType;
@@ -380,7 +362,6 @@ void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *p
 
        pDest->msgInfo.nAddressCnt = 1;
 
-       pDest->msgInfo.addressList[0].threadId = pSrc->msgInfo.addressList[addrIdx].threadId;
        pDest->msgInfo.addressList[0].addressType = pSrc->msgInfo.addressList[addrIdx].addressType;
        pDest->msgInfo.addressList[0].recipientType = pSrc->msgInfo.addressList[addrIdx].recipientType;
        pDest->msgInfo.addressList[0].contactId = pSrc->msgInfo.addressList[addrIdx].contactId;
@@ -390,7 +371,6 @@ void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *p
        strncpy(pDest->msgInfo.replyAddress, pSrc->msgInfo.replyAddress, MAX_PHONE_NUMBER_LEN);
        strncpy(pDest->msgInfo.subject, pSrc->msgInfo.subject, MAX_SUBJECT_LEN);
 
-       pDest->msgInfo.scheduledTime = pSrc->msgInfo.scheduledTime;
        pDest->msgInfo.displayTime = pSrc->msgInfo.displayTime;
        pDest->msgInfo.networkStatus = pSrc->msgInfo.networkStatus;
        pDest->msgInfo.encodeType = pSrc->msgInfo.encodeType;
@@ -401,8 +381,7 @@ void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *p
 
        pDest->msgInfo.msgPort.valid = pSrc->msgInfo.msgPort.valid;
 
-       if (pDest->msgInfo.msgPort.valid == true)
-       {
+       if (pDest->msgInfo.msgPort.valid == true) {
                pDest->msgInfo.msgPort.dstPort = pSrc->msgInfo.msgPort.dstPort;
                pDest->msgInfo.msgPort.srcPort = pSrc->msgInfo.msgPort.srcPort;
        }
@@ -412,26 +391,21 @@ void MsgCopyReqInfo(MSG_REQUEST_INFO_S *pSrc, int addrIdx, MSG_REQUEST_INFO_S *p
 
        strncpy(pDest->msgInfo.msgData, pSrc->msgInfo.msgData, MAX_MSG_DATA_LEN);
 
-       if (pDest->msgInfo.bTextSms == true)
-       {
+       if (pDest->msgInfo.bTextSms == true) {
                memcpy(pDest->msgInfo.msgText, pSrc->msgInfo.msgText, pDest->msgInfo.dataSize);
                pDest->msgInfo.msgText[pDest->msgInfo.dataSize] = '\0';
        }
 
-       // Set Sending Info
+       /* Set Sending Info */
        pDest->sendOptInfo.bSetting = pSrc->sendOptInfo.bSetting;
 
-       if (pDest->sendOptInfo.bSetting == true)
-       {
+       if (pDest->sendOptInfo.bSetting == true) {
                pDest->sendOptInfo.bDeliverReq = pSrc->sendOptInfo.bDeliverReq;
                pDest->sendOptInfo.bKeepCopy = pSrc->sendOptInfo.bKeepCopy;
 
-               if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE)
-               {
+               if (pDest->msgInfo.msgType.mainType == MSG_SMS_TYPE) {
                        pDest->sendOptInfo.option.smsSendOptInfo.bReplyPath = pSrc->sendOptInfo.option.smsSendOptInfo.bReplyPath;
-               }
-               else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE)
-               {
+               } else if (pDest->msgInfo.msgType.mainType == MSG_MMS_TYPE) {
                        pDest->sendOptInfo.option.mmsSendOptInfo.priority = pSrc->sendOptInfo.option.mmsSendOptInfo.priority;
                        pDest->sendOptInfo.option.mmsSendOptInfo.bReadReq = pSrc->sendOptInfo.option.mmsSendOptInfo.bReadReq;