2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 * @author Pawel Misiak (p.misiak@samsung.com)
29 #include <dpl/log/log.h>
30 #include <Commons/Exception.h>
31 #include <API/Messaging/ReqReceiverMessage.h>
32 #include "Messaging.h"
33 #include "CallbackMgr.h"
34 #include "MsgServiceHandleMgr.h"
37 #include <MapiControl.h>
38 #include <MapiMessage.h>
39 #include <MapiStorage.h>
43 const char* TEXT_AREA = "Text";
44 const char* TEXT_FILE_EXTENSION = ".txt";
45 const int WHITE_COLOR = 0xffffff;
46 const int BLACK_COLOR = 0x000000;
47 const int ROOT_LAYOUT_WIDTH = 100;
48 const int ROOT_LAYOUT_HEIGHT = 100;
49 const char* EMPTY_ID = "0";
53 using namespace TizenApis::Api::Messaging;
59 Mms::Mms(const string& id) :
61 m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
65 LogDebug("m_id=" << getIdRef());
66 LogDebug("m_msgType=" << getMessageType());
67 if (getIdRef().empty()) {
70 readExistingMessage();
79 // release platform message structure
80 msg_release_message(&m_messageData);
84 //trying to remove file, return value is skipped
85 if (!m_bodyFilePath.empty()) {
86 LogDebug("remove tmp file=" << m_bodyFilePath);
87 (void) ::remove(m_bodyFilePath.c_str());
91 void Mms::createNewMessage()
94 msg_release_message(&m_messageData);
97 m_messageData = msg_new_message();
99 MSG_SENDINGOPT_S sendOpt = { 0 };
100 sendOpt.bSetting = false;
102 // initialize platform message structure
103 msg_set_message_id(m_messageData, 0); // It should be set 0
104 msg_set_folder_id(m_messageData, MSG_DRAFT_ID);
105 msg_set_message_type(m_messageData, MSG_TYPE_MMS);
106 msg_set_storage_id(m_messageData, MSG_STORAGE_PHONE);
107 msg_set_subject(m_messageData, "");
108 msg_set_read_status(m_messageData, false);
109 msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
110 msg_set_direction_info(m_messageData, MSG_DIRECTION_TYPE_MO);
111 msg_set_priority_info(m_messageData, MSG_MESSAGE_PRIORITY_NORMAL);
113 tm dateT = getDateTime();
114 msg_set_time(m_messageData, mktime(&dateT));
116 setMmsType(MULTIPART_MIXED);
117 setReadStatus(false);
118 setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
120 LogDebug("Message created successfully, Id: " << getIdRef());
123 void Mms::readExistingMessage()
127 if (getIdRef().empty() || (EMPTY_ID == getIdRef())) {
128 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
132 MSG_SENDINGOPT_S option;
133 option.bSetting = false;
136 msg_release_message(&m_messageData);
137 m_messageData = NULL;
138 // crate new structure
139 m_messageData = msg_new_message();
141 // trying to get message from platform
142 if (MSG_SUCCESS != msg_get_message(
143 MsgGetCommonHandle(), convertId(getIdRef()), m_messageData,
145 LogError("get message error");
146 Throw(WrtDeviceApis::Commons::PlatformException);
148 LogDebug("message found with msgId=" << getIdRef());
150 // read all mms dat to abstraction layer
151 readRecipientList(m_messageData);
152 readPriority(m_messageData);
153 readSubject(m_messageData);
154 readBodyAndAttachments(m_messageData);
155 readFolder(m_messageData);
156 readDateTime(m_messageData);
157 readReadStatus(m_messageData);
159 Catch(WrtDeviceApis::Commons::Exception) {
164 void Mms::readDateTime(msg_message_t& messageData)
166 tm* time = localtime(msg_get_time(messageData));
168 LogError("localtime failed");
169 Throw(WrtDeviceApis::Commons::PlatformException);
174 void Mms::readReadStatus(msg_message_t& messageData)
176 setReadStatus(msg_is_read(messageData));
179 void Mms::readFolder(msg_message_t& messageData)
181 switch (msg_get_folder_id(messageData)) {
183 setFolderType(Api::Messaging::INBOX);
186 setFolderType(Api::Messaging::OUTBOX);
189 setFolderType(Api::Messaging::SENTBOX);
192 setFolderType(Api::Messaging::DRAFTBOX);
195 setFolderType(Api::Messaging::SPAMBOX);
198 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
202 void Mms::readPriority(msg_message_t& messageData)
204 switch (msg_get_priority_info(messageData)) {
205 case MSG_MESSAGE_PRIORITY_LOW:
206 setPriority(MessagePriority::LOW);
208 case MSG_MESSAGE_PRIORITY_NORMAL:
209 setPriority(MessagePriority::NORMAL);
211 case MSG_MESSAGE_PRIORITY_HIGH:
212 setPriority(MessagePriority::HIGH);
215 LogError("Wrong priority type");
216 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong priority type");
220 void Mms::readRecipientList(msg_message_t& messageData)
222 std::string phoneNumber;
223 int recipientCount = msg_get_address_count(messageData);
224 LogDebug("Recipient count " << recipientCount);
225 for (int i = 0; i < recipientCount; ++i) {
226 int type = msg_get_direction_info(messageData);
228 if (MSG_DIRECTION_TYPE_MT == type) {
229 phoneNumber = msg_get_ith_address(messageData, i);
230 if (validatePhoneNumber(phoneNumber)) {
231 setSourceAddress(phoneNumber);
232 setFrom(phoneNumber);
234 LogDebug("phone number: " << phoneNumber);
235 } else if (MSG_DIRECTION_TYPE_MO == type) {
236 switch (msg_get_ith_recipient_type(messageData, i)) {
237 case MSG_RECIPIENTS_TYPE_TO:
238 appendToRecipients(msg_get_ith_address(messageData, i));
240 case MSG_RECIPIENTS_TYPE_CC:
241 appendCcRecipients(msg_get_ith_address(messageData, i));
243 case MSG_RECIPIENTS_TYPE_BCC:
244 appendBccRecipients(msg_get_ith_address(messageData, i));
247 LogError("Wrong type of recipient");
248 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
251 LogError("Wrong type of recipient");
252 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
257 void Mms::readSubject(msg_message_t& messageData)
259 setSubject(msg_get_subject(messageData));
262 void Mms::readBodyAndAttachments(msg_message_t& messageData)
265 MMS_MESSAGE_DATA_S msgBody = {};
266 msg_mms_get_message_body(messageData, &msgBody);
268 //if any page then multipart is related type
269 if (msgBody.pageCnt > 0) {
270 setMmsType(MULTIPART_RELATED);
272 setMmsType(MULTIPART_MIXED);
275 LogDebug("page count: " << msgBody.pageCnt);
277 for (int p = 0; p < msgBody.pageCnt; ++p) {
278 LogDebug("page " << p);
279 MMS_PAGE_S *page = msg_mms_get_page(p);
281 LogError("returned page is null, continue");
284 for (int m = 0; m < page->mediaCnt; ++m) {
285 LogDebug("media file " << m);
286 MMS_MEDIA_S* media = msg_mms_get_media(page, m);
288 LogError("returned media is null, continue");
291 if (0 == p && MMS_SMIL_MEDIA_TEXT == media->mediatype) {
292 //text value on first page goes to body attribute
293 LogDebug("setting body from " << media->szFilePath);
295 f = fopen(media->szFilePath, "r");
297 LogError("cannot read file with body" << media->szFilePath);
298 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
299 "Cannot read file with body");
301 fseek(f, 0, SEEK_END);
302 long int size = ftell(f);
303 fseek(f, 0, SEEK_SET);
304 char* data = new (nothrow) char[size + 1];
306 memset(data, 0, size + 1);
307 fread(data, 1, size, f);
311 LogError("body is not set");
313 LogDebug("message body: '" << getBody() << "'");
316 LogDebug("adding attachment " << media->szFilePath);
318 IAttachmentPtr attachment = appendAttachment(media->szFilePath,
320 //attachment->setMessage(this); //set IMessagePtr
321 if (NULL != media->szFileName &&
322 strnlen(media->szFileName, MSG_FILENAME_LEN_MAX) > 0) {
323 LogDebug("renaming to " << media->szFileName);
324 attachment->rename(media->szFileName);
325 } else if (MMS_SMIL_MEDIA_TEXT == media->mediatype) {
326 std::stringstream newName;
327 newName << "body_page_" << p + 1 << ".txt";
328 LogDebug("renaming to " << newName.str());
329 attachment->rename(newName.str());
336 LogDebug("attachment count: " << msgBody.attachCnt);
337 for (int a = 0; a < msgBody.attachCnt; ++a) {
338 MMS_ATTACH_S* attachment = msg_mms_get_attachment(a);
340 LogError("attachment is null, continue");
343 IAttachmentPtr att = appendAttachment(attachment->szFilePath, false);
344 if (NULL != attachment->szFileName &&
345 strnlen(attachment->szFileName, MSG_FILENAME_LEN_MAX) > 0) {
346 LogDebug("renaming to " << attachment->szFileName);
347 att->rename(attachment->szFileName);
354 void Mms::update(bool draftsOnly)
356 LogDebug("updating m_id=" << getIdRef());
358 if (!m_messageData) {
359 //error if platform message not exists
360 LogError("message can not be updated");
361 Throw(WrtDeviceApis::Commons::PlatformException);
364 //update mms data from abstraction
365 if (!draftsOnly || getCurrentFolder() == Api::Messaging::DRAFTBOX) {
367 updateBodyAndAttachments();
368 updateRecipientList();
374 void Mms::updatePriority()
376 if (isPriorityValid()) {
380 LogInfo("MMS updating priority");
382 //set priority in platform
383 switch (getPriority()) {
384 case MessagePriority::LOW:
385 priority = MSG_MESSAGE_PRIORITY_LOW;
387 case MessagePriority::NORMAL:
388 priority = MSG_MESSAGE_PRIORITY_NORMAL;
390 case MessagePriority::HIGH:
391 priority = MSG_MESSAGE_PRIORITY_HIGH;
394 LogError("Wrong priority");
395 Throw(WrtDeviceApis::Commons::PlatformException);
398 msg_set_priority_info(m_messageData, MSG_MESSAGE_PRIORITY_LOW)) {
399 LogError("Error during setting priority");
400 Throw(WrtDeviceApis::Commons::PlatformException);
404 void Mms::updateRecipientList()
406 // check if abstraction recipient value has been changed
407 if (getToRecipients().isValid() &&
408 getBccRecipients().isValid() &&
409 getCcRecipients().isValid()) {
413 LogInfo("MMS updating platform recipients");
415 // reset addresses in platform structure
416 msg_reset_address(m_messageData);
418 vector<string> to = getToRecipients().getRecipients();
419 vector<string> cc = getCcRecipients().getRecipients();
420 vector<string> bcc = getBccRecipients().getRecipients();
422 // update addresses in platform structure
424 LogInfo("updating to");
425 for (size_t i = 0; i < to.size(); i++) {
426 if (msg_get_address_count(m_messageData) >= MAX_TO_ADDRESS_CNT) {
427 LogError("max number of recipient exceeded");
430 LogDebug("adding to[" << i << "]=" << to[i]);
431 if (msg_add_address(m_messageData, to[i].c_str(),
432 MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS) {
433 LogError("problem with adding to address");
434 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
435 "Problem with adding to address");
441 LogInfo("updating cc");
442 for (size_t i = 0; i < cc.size(); i++) {
443 if (msg_get_address_count(m_messageData) >= MAX_TO_ADDRESS_CNT) {
444 LogError("max number of recipient exceeded");
447 LogDebug("adding cc[" << i << "]=" << cc[i]);
448 if (msg_add_address(m_messageData, cc[i].c_str(),
449 MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS) {
450 LogError("problem with adding cc address");
451 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
452 "Problem with adding cc address");
458 LogInfo("updating bcc");
459 for (size_t i = 0; i < bcc.size(); i++) {
460 if (msg_get_address_count(m_messageData) >= MAX_TO_ADDRESS_CNT) {
461 LogError("max number of recipient exceeded");
464 LogDebug("adding bcc[" << i << "]=" << bcc[i]);
465 if (msg_add_address(m_messageData, bcc[i].c_str(),
466 MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS) {
467 LogError("problem with adding bcc address");
468 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
469 "Problem with adding bcc address");
476 setBccValidity(true);
479 void Mms::updateSubject()
481 // check if abstraction subject value has been changed
482 if (isSubjectValid()) {
485 LogInfo("updating platform subject: " << getSubjectRef());
487 msg_set_subject(m_messageData, getSubjectRef().c_str())) {
488 LogError("problem with setting subject");
489 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
491 setSubjectValidity(true);
494 void Mms::updateBodyAndAttachments()
497 // check if attachment or body source address value has been changed
498 if (isAttachmentsValid() && isBodyValid()) {
502 MMS_MESSAGE_DATA_S *mmsData = NULL;
503 LogInfo("updating platform body and attachment");
507 if (getMessageType() != MMS) {
508 LogError("Wrong msg type");
509 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong msg type");
511 mmsData = msg_mms_create_message();
513 LogError("create message body failed");
514 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "create message body failed");
518 if (!getBodyRef().empty()) {
520 f = fopen(m_bodyFilePath.c_str(), "w");
522 LogError("cannot create file with body" << m_bodyFilePath);
523 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
524 "cannot create file with body");
526 LogDebug("body file: " << m_bodyFilePath);
527 fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
530 if (!msg_mms_set_rootlayout(mmsData, ROOT_LAYOUT_WIDTH,
531 ROOT_LAYOUT_HEIGHT, WHITE_COLOR)) {
532 LogError("cannot create root layout");
533 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
534 "cannot create root layout");
536 if (!msg_mms_add_region(mmsData, TEXT_AREA, 0, 0, ROOT_LAYOUT_WIDTH,
537 ROOT_LAYOUT_HEIGHT, WHITE_COLOR)) {
538 LogError("cannot create region");
539 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot create region");
541 MMS_PAGE_S* page = msg_mms_add_page(mmsData, 0);
543 LogError("cannot create page");
544 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot create page");
546 MMS_MEDIA_S* media = msg_mms_add_media(page,
550 m_bodyFilePath.c_str()));
552 LogError("cannot create media");
553 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot create media");
555 media->sMedia.sText.nColor = BLACK_COLOR;
556 media->sMedia.sText.nSize = MMS_SMIL_FONT_SIZE_NORMAL;
562 for (size_t i = 0; i < getAttachmentsRef().size(); ++i) {
563 Api::Messaging::IAttachmentPtr att = getAttachment(i);
568 LogDebug("Add attachment=" << att->getFullPath());
570 errnum = stat(att->getFullPath().c_str(), &buffer);
572 LogError("Opening file: " <<
573 att->getFullPath().c_str() <<
574 " " << strerror(errnum));
575 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
576 "cannot open attachment file");
579 //this function should return valid pointer
580 if (!msg_mms_add_attachment(mmsData,
581 const_cast<char*>(att->getFullPath().
583 LogError("add attachment failed");
584 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "add attachment failed");
586 LogDebug("Attachment added");
592 if (MSG_SUCCESS != msg_mms_set_message_body(m_messageData, mmsData)) {
593 LogError("set message body error");
594 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set message body error");
597 msg_mms_destroy_message(mmsData);
599 setAttachmentsValidity(true);
600 setBodyValidity(true);
603 Catch(WrtDeviceApis::Commons::PlatformException) {
604 LogError("Platform error");
606 msg_mms_destroy_message(mmsData);
615 void Mms::updateReadStatus()
617 if (isReadStatusValid()) {
621 LogInfo("updating platform read status: " << isRead());
622 if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
623 LogError("problem with setting subject");
624 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
627 setReadStatusValidity(true);
630 void Mms::updateIsRead()
632 LogDebug("updating m_id=" << getIdRef());
634 if (!m_messageData) {
635 //error if platform message not exists
636 LogError("message can not be updated");
637 Throw(WrtDeviceApis::Commons::PlatformException);
640 // check if abstraction from m_isReadChange value has been changed
641 if (isReadChangeStatusValid()) {
642 // do not update if not changed
648 if (this->getIdRef().empty()) {
649 LogError("existing msgId is zero, remove msg not done");
650 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
651 "existing msgId is zero, remove msg not done");
655 msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
657 LogError("Failed to update isRead");
658 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
661 Catch(WrtDeviceApis::Commons::PlatformException) {
662 LogError("platform error occurs");
664 setisReadChangeStatusValidity(true);
668 void Mms::addMessageToDraft()
670 LogDebug("convert m_id= " << convertId(getIdRef()));
672 //prepare for add sms to draft folder
673 if (!m_messageData) {
674 //error if platform message not exists
675 LogError("message can not be updated");
676 Throw(WrtDeviceApis::Commons::PlatformException);
679 //update all sms data
680 if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
682 updateBodyAndAttachments();
683 updateRecipientList();
689 MSG_SENDINGOPT_S option = { false, false, false };
690 option.option.smsSendOpt.bReplyPath = true;
691 // trying to get message from platform
693 const MSG_FOLDER_ID_T platfromFolderId =
694 Messaging::convertFolderToPlatform(DRAFTBOX);
696 msg_set_message_id(m_messageData, 0);
697 msg_set_folder_id(m_messageData, platfromFolderId);
698 msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
700 // trying to add message
701 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, &option);
702 if (ret < MSG_SUCCESS) {
703 LogError("msg_add_message failed, error code=" << ret);
704 Throw(WrtDeviceApis::Commons::PlatformException);
707 //releasing platform message structure
708 msg_release_message(&m_messageData);
710 Catch(WrtDeviceApis::Commons::PlatformException) {
711 LogError("remove message error");
713 //releasing platform message structure
714 msg_release_message(&m_messageData);
721 void Mms::readAllData()
723 readExistingMessage();
726 void Mms::moveToFolder(const FolderType newFolder)
732 MSG_FOLDER_ID_T platfromFolderId = Messaging::convertFolderToPlatform(
735 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
736 platfromFolderId) != MSG_SUCCESS) {
737 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error during movinf message");
741 Catch(WrtDeviceApis::Commons::PlatformException) {
742 LogError("remove message error");
747 void Mms::moveToFolder(const string& newFolder)
753 MSG_FOLDER_ID_T platfromFolderId = Messaging::convertFolderToPlatform(
756 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
757 platfromFolderId) != MSG_SUCCESS) {
758 LogError("msg_move_msg_to_folder error");
759 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_move_msg_to_folder error");
763 Catch(WrtDeviceApis::Commons::PlatformException) {
764 LogError("remove message error");
769 void Mms::copyToFolder(const FolderType newFolder)
773 msg_message_t msg = msg_new_message();
777 MSG_SENDINGOPT_S option = { false, false, false };
778 option.option.smsSendOpt.bReplyPath = true;
780 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
782 const MSG_FOLDER_ID_T platfromFolderId =
783 Messaging::convertFolderToPlatform(newFolder);
784 msg_set_message_id(msg, 0);
785 msg_set_folder_id(msg, platfromFolderId);
787 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
788 if (error != MSG_SUCCESS) {
789 LogError("msg_add_message failed, error code=" << error);
790 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
794 msg_release_message(&msg);
798 Catch(WrtDeviceApis::Commons::PlatformException) {
799 LogError("remove message error");
801 msg_release_message(&msg);
807 void Mms::copyToFolder(const string& newFolder)
811 msg_message_t msg = msg_new_message();
815 MSG_SENDINGOPT_S option = { false, false, false };
816 option.option.smsSendOpt.bReplyPath = true;
818 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
820 const MSG_FOLDER_ID_T platfromFolderId =
821 Messaging::convertFolderToPlatform(newFolder);
822 msg_set_message_id(msg, 0);
823 msg_set_folder_id(msg, platfromFolderId);
825 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
826 if (error != MSG_SUCCESS) {
827 LogError("msg_add_message failed, error code=" << error);
828 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
832 msg_release_message(&msg);
836 Catch(WrtDeviceApis::Commons::PlatformException) {
837 LogError("remove message error");
839 msg_release_message(&msg);
847 LogDebug("delete m_id=" << getIdRef());
851 if (this->getIdRef().empty()) {
852 LogError("existing msgId is zero, remove msg not done");
853 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
854 "existing msgId is zero, remove msg not done");
858 msg_delete_message(MsgGetCommonHandle(),
859 convertId(getIdRef()))) {
860 LogError("Failed to delete Message");
861 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
865 Catch(WrtDeviceApis::Commons::PlatformException) {
866 LogError("platform error occurs");
872 LogDebug("sending message, id=" << getIdRef());
875 //prepare for sending sms/mms
878 LogDebug("Start Sending Message...");
879 LogDebug("msgId=" << msg_get_message_id(m_messageData));
880 LogDebug("subject: " << msg_get_subject(m_messageData));
881 LogDebug("recipient count: " << msg_get_address_count(m_messageData));
882 LogDebug("body size : " << msg_get_message_body_size( m_messageData ));
884 for (int i = 0; i < msg_get_address_count(m_messageData); ++i) {
885 LogDebug("recipient[" << i << "]: " <<
886 msg_get_ith_address(m_messageData, i));
889 LogDebug("trying to send mms");
890 MSG_ERROR_T err = CallbackMgrSingleton::Instance().registerAndSend(
891 msg_mms_send_message,
895 if (err != MSG_SUCCESS) {
896 LogError("Sending Message (submit request) failed!!! err=" << err);
897 setMessageStatus(MESSAGE_STATUS_FAILED);
901 setMessageStatus(MESSAGE_STATUS_SENDING);
903 LogDebug("Sending Message request is submitted!");
905 Catch(WrtDeviceApis::Commons::PlatformException) {
906 LogError("message is not send, manually run callback");
912 ReqReceiverMessage *requestReceiver = getRequestReceiver();
913 if (requestReceiver) {
914 LogError("send Error");
915 EventSendMessagePtr event = getSendMessageEvent();
916 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
917 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventSendMessage >::ManualAnswer(event);
922 void Mms::sendingCallback(MSG_SENT_STATUS_S *sent_status)
925 "sendingCallback callback received. Req id = " <<
926 sent_status->reqId << " Status = " << (int)sent_status->status);
927 if (MSG_NETWORK_SEND_SUCCESS == sent_status->status) {
928 LogDebug("sending ok");
929 setSendingStatusOk();
930 setMessageStatus(MESSAGE_STATUS_SENT);
932 LogError("sending failed: " <<
933 static_cast<unsigned int>(sent_status->status));
934 setSendingStatusFailed();
935 setMessageStatus(MESSAGE_STATUS_FAILED);
939 void Mms::sendCancel(int handle)
941 LogDebug("sending message, id=" << getIdRef());
943 LogDebug("handle =" << handle);
946 void Mms::setSendingStatusOk()
948 //success callback should be executed here
949 ReqReceiverMessage *requestReceiver = getRequestReceiver();
950 if (requestReceiver) {
951 LogInfo("calling JS success callback");
952 EventSendMessagePtr event = getSendMessageEvent();
953 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
955 for ( int index=0; index < msg_get_address_count(m_messageData); index++)
957 LogDebug( "Address :" << msg_get_ith_address(m_messageData, index));
958 event->m_successRecipients.push_back(msg_get_ith_address(m_messageData, index));
961 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventSendMessage >::ManualAnswer(event);
966 void Mms::setSendingStatusFailed()
968 //error callback should be executed here
969 EventOnSendingFailedEmitterPtr emitter = getEmitter();
971 EventOnSendingFailedPtr event(new EventOnSendingFailed);
972 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
973 emitter->emit(event);
975 ReqReceiverMessage *requestReceiver = getRequestReceiver();
976 if (requestReceiver) {
977 LogError("calling JS error callback");
978 EventSendMessagePtr event = getSendMessageEvent();
979 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
981 for ( int index=0; index < msg_get_address_count(m_messageData); index++)
983 LogDebug( "Address :" << msg_get_ith_address(m_messageData, index));
984 event->m_failRecipients.push_back(msg_get_ith_address(m_messageData, index));
991 Api::Messaging::FolderType Mms::toFolder(const std::string &folder)
993 if (folder == "INBOX") {
995 } else if (folder == "OUTBOX") {
997 } else if (folder == "SENTBOX") {
999 } else if (folder == "DRAFTBOX") {
1002 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");