2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
21 #include <Commons/Exception.h>
22 #include "ReqReceiverMessage.h"
23 #include "Messaging.h"
24 #include "CallbackMgr.h"
25 #include "MsgServiceHandleMgr.h"
30 #include <msg_storage.h>
35 const char* TEXT_AREA = "Text";
36 const char* TEXT_FILE_EXTENSION = ".txt";
37 const char* TEXT_DIR_PREFIX = "/tmp/";
38 const int WHITE_COLOR = 0xffffff;
39 const int BLACK_COLOR = 0x000000;
40 const int ROOT_LAYOUT_WIDTH = 100;
41 const int ROOT_LAYOUT_HEIGHT = 100;
42 const char* EMPTY_ID = "0";
50 Mms::Mms(const string& id) :
52 // m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
55 LoggerD("m_id=" << getIdRef());
56 LoggerD("m_msgType=" << getMessageType());
58 char buf[] = "XXXXXX";
59 mode_t mask = umask(S_IWGRP | S_IWOTH);
61 LoggerD("buf : " << buf << " i : " << i);
64 m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
66 LoggerD("m_bodyFilePath : " << m_bodyFilePath);
68 if (getIdRef().empty()) {
69 LoggerD("create new message");
72 LoggerD("read existing message");
73 readExistingMessage();
77 Mms::Mms(const string& id, const msg_struct_t msg_data) :
79 // m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
80 m_messageData(msg_data)
82 LoggerD("m_id=" << getIdRef());
83 LoggerD("m_msgType=" << getMessageType());
85 char buf[] = "XXXXXX";
86 mode_t mask = umask(S_IWGRP | S_IWOTH);
88 LoggerD("buf : " << buf << " i : " << i);
91 m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
93 LoggerD("m_bodyFilePath : " << m_bodyFilePath);
95 readConversationId(m_messageData);
96 readRecipientList(m_messageData);
97 readPriority(m_messageData);
98 readSubject(m_messageData);
99 readBodyAndAttachments(m_messageData);
100 readFolder(m_messageData);
101 readDateTime(m_messageData);
102 readReadStatus(m_messageData);
103 readMessageStatus(m_messageData);
104 // setMessageStatus(MESSAGE_STATUS_LOADED);
113 // release platform message structure
114 // msg_release_message(&m_messageData);
115 msg_release_struct(&m_messageData);
119 //trying to remove file, return value is skipped
120 if (!m_bodyFilePath.empty()) {
121 LoggerD("remove tmp file=" << m_bodyFilePath);
122 (void) ::remove(m_bodyFilePath.c_str());
126 void Mms::createNewMessage()
129 msg_release_struct(&m_messageData);
130 m_messageData = NULL;
133 char strSubject[MAX_SUBJECT_LEN] = {0,};
135 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
136 msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
137 // msg_struct_t option = NULL;
139 // initialize platform message structure
140 msg_set_int_value(m_messageData, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
141 msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
142 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
144 setMmsType(MULTIPART_MIXED);
145 setReadStatus(false);
146 setMessageStatus(MESSAGE_STATUS_CREATED);
148 msg_release_struct(&sendOpt);
149 LoggerD("Message created successfully, Id: " << getIdRef());
152 void Mms::readExistingMessage()
156 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
158 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
161 msg_release_struct(&m_messageData);
162 m_messageData = NULL;
163 msg_struct_t sendOpt = NULL;
167 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
168 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
170 // trying to get message from platform
171 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
173 LoggerE("get message error");
174 Throw(WrtDeviceApis::Commons::PlatformException);
176 LoggerD("message found with msgId=" << getIdRef());
178 // read all mms dat to abstraction layer
179 readConversationId(m_messageData);
180 readRecipientList(m_messageData);
181 readPriority(m_messageData);
182 readSubject(m_messageData);
183 readBodyAndAttachments(m_messageData);
184 readFolder(m_messageData);
185 readDateTime(m_messageData);
186 readReadStatus(m_messageData);
187 readMessageStatus(m_messageData);
189 msg_release_struct(&sendOpt);
191 Catch(WrtDeviceApis::Commons::PlatformException) {
192 LoggerE("exception");
194 msg_release_struct(&sendOpt);
198 void Mms::readDateTime(msg_struct_t& messageData)
200 // tm* time = localtime(msg_get_time(messageData));
201 // tm dateT = getDateTime();
203 msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
205 LoggerE("readDateTime : " <<tempInt);
207 tm* time = localtime((time_t*)&tempInt);
209 LoggerE("localtime failed");
210 Throw(WrtDeviceApis::Commons::PlatformException);
215 void Mms::readReadStatus(msg_struct_t& messageData)
218 msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
219 setReadStatus(tempBool);
222 void Mms::readFolder(msg_struct_t& messageData)
225 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
229 setFolderType(INBOX);
232 setFolderType(OUTBOX);
235 setFolderType(SENTBOX);
238 setFolderType(DRAFTBOX);
241 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
245 void Mms::readMessageStatus(msg_struct_t& messageData)
248 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
250 LoggerD("readMessageStatus folder : " << tempValue);
254 setMessageStatus(MESSAGE_STATUS_LOADED);
257 setMessageStatus(MESSAGE_STATUS_SENDING);
260 setMessageStatus(MESSAGE_STATUS_SENT);
263 setMessageStatus(MESSAGE_STATUS_DRAFT);
266 setMessageStatus(MESSAGE_STATUS_LOADED);
271 void Mms::readPriority(msg_struct_t& messageData)
273 // switch (msg_get_priority_info(messageData)) {
275 msg_get_int_value(messageData, MSG_MESSAGE_PRIORITY_INT, &tempInt);
277 case MSG_MESSAGE_PRIORITY_LOW:
278 setPriority(MessagePriority::LOW);
280 case MSG_MESSAGE_PRIORITY_NORMAL:
281 setPriority(MessagePriority::NORMAL);
283 case MSG_MESSAGE_PRIORITY_HIGH:
284 setPriority(MessagePriority::HIGH);
287 LoggerE("Wrong priority type");
288 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong priority type");
292 void Mms::readConversationId(msg_struct_t& messageData)
295 msg_get_int_value(messageData, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
296 LoggerD("conversationID : " <<tempInt);
300 void Mms::readRecipientList(msg_struct_t& messageData)
302 std::string phoneNumber;
303 // int recipientCount = msg_get_address_count(messageData);
304 // LoggerD("Recipient count " << recipientCount);
306 msg_list_handle_t addr_list = NULL;
307 msg_struct_t addr_info = NULL;
309 msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
312 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
314 int recipientCount = msg_list_length(addr_list);
315 LoggerD("Recipient count " << recipientCount);
317 for (int i = 0; i < recipientCount; ++i)
319 // int type = msg_get_direction_info(messageData);
320 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
322 LoggerD("Direction: " << type);
324 if (MSG_DIRECTION_TYPE_MT == type)
326 addr_info = (msg_struct_t)msg_list_nth_data(addr_list, i);
327 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
328 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
329 phoneNumber = strNumber;
331 if (validatePhoneNumber(phoneNumber))
333 setSourceAddress(phoneNumber);
334 setFrom(phoneNumber);
336 LoggerD("MT number: " << phoneNumber);
338 else if (MSG_DIRECTION_TYPE_MO == type)
340 addr_info = (msg_struct_t)msg_list_nth_data(addr_list, i);
341 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
342 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
343 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
344 LoggerD("MO number: " << strNumber);
345 LoggerD("Type : " << tempInt);
348 case MSG_RECIPIENTS_TYPE_TO:
349 appendToRecipients(strNumber);
351 case MSG_RECIPIENTS_TYPE_CC:
352 appendCcRecipients(strNumber);
354 case MSG_RECIPIENTS_TYPE_BCC:
355 appendBccRecipients(strNumber);
358 LoggerE("Wrong type of recipient");
363 LoggerE("Wrong type of recipient");
364 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
369 void Mms::readSubject(msg_struct_t& messageData)
371 char strTemp[MAX_SUBJECT_LEN] = {0};
372 msg_get_str_value(messageData, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
373 // setSubject(msg_get_subject(messageData));
374 LoggerE("readSubject : " << strTemp);
378 void Mms::readBodyAndAttachments(msg_struct_t& messageData)
381 int pageLen, mediaLen, attachLen, tempInt, ret;
383 msg_struct_t mms_struct = NULL;
385 msg_list_handle_t page_list = NULL;
386 msg_list_handle_t media_list = NULL;
387 msg_list_handle_t attach_list = NULL;
389 msg_struct_t page = NULL;
390 msg_struct_t media = NULL;
391 msg_struct_t attach = NULL;
393 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
394 ret = msg_get_mms_struct(messageData, mms_struct);
396 if (ret != MSG_SUCCESS)
398 LoggerE("cannot get mms struct");
399 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
402 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
403 char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
405 msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
406 pageLen = msg_list_length(page_list);
409 setMmsType(MULTIPART_RELATED);
411 setMmsType(MULTIPART_MIXED);
414 LoggerD("page count: " << pageLen);
416 for (int p = 0; p < pageLen; ++p)
418 LoggerD("page " << p);
419 page = (msg_struct_t)msg_list_nth_data(page_list, p);
422 LoggerE("returned page is null, continue");
426 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
427 mediaLen = msg_list_length(media_list);
429 for (int m = 0; m < mediaLen; ++m)
431 LoggerD("media file " << m);
432 media = (msg_struct_t)msg_list_nth_data(media_list, m);
435 LoggerE("returned media is null, continue");
439 msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
441 memset(szFilePath, 0, sizeof(szFilePath));
442 msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
444 if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt))
446 //text value on first page goes to body attribute
447 LoggerD("setting body from " << szFilePath);
450 f = fopen(szFilePath, "r");
453 LoggerE("cannot read file with body" << szFilePath);
454 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
456 fseek(f, 0, SEEK_END);
457 long int size = ftell(f);
458 fseek(f, 0, SEEK_SET);
459 char* data = new (nothrow) char[size + 1];
462 memset(data, 0, size + 1);
463 error = fread(data, 1, size, f);
467 LoggerE("body is not set");
469 LoggerD("message body: '" << getBody() << "'");
474 LoggerD("adding attachment " << szFilePath);
476 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
477 //attachment->setMessage(this); //set IMessagePtr
479 memset(szFileName, 0, sizeof(szFileName));
480 msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
481 if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0))
483 LoggerD("renaming to " << szFileName);
484 attachment->rename(szFileName);
486 else if (MMS_SMIL_MEDIA_TEXT == tempInt)
488 std::stringstream newName;
489 newName << "body_page_" << p + 1 << ".txt";
490 LoggerD("renaming to " << newName.str());
491 attachment->rename(newName.str());
497 msg_get_list_handle(mms_struct, MSG_MMS_ATTACH_LIST_HND, (void **)&attach_list);
499 attachLen= msg_list_length(attach_list);
501 LoggerD("attachment count: " << attachLen);
502 for (int a = 0; a < attachLen; ++a)
504 attach = (msg_struct_t)msg_list_nth_data(attach_list, a);
507 LoggerE("attachment is null, continue");
511 memset(szFilePath, 0, sizeof(szFilePath));
512 memset(szFileName, 0, sizeof(szFileName));
514 msg_get_str_value(attach, MSG_MMS_ATTACH_FILEPATH_STR, szFilePath, sizeof(szFilePath));
515 msg_get_str_value(attach, MSG_MMS_ATTACH_FILENAME_STR, szFileName, sizeof(szFileName));
517 IAttachmentPtr att = appendAttachment(szFilePath, false);
518 if ((szFileName[0] =! '\0') &&
519 strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0) {
520 LoggerD("renaming to " << szFileName);
521 att->rename(szFileName);
524 msg_release_struct(&mms_struct);
527 bool Mms::hasAttachment()
529 std::size_t attachmentSize = getAttachmentsCount();
530 if ( attachmentSize > 0)
536 void Mms::update(bool draftsOnly)
538 LoggerD("updating m_id=" << getIdRef());
540 if (!m_messageData) {
541 //error if platform message not exists
542 LoggerE("message can not be updated");
543 Throw(WrtDeviceApis::Commons::PlatformException);
546 //update mms data from abstraction
547 if (!draftsOnly || getCurrentFolder() == DRAFTBOX) {
549 updateBodyAndAttachments();
550 updateRecipientList();
556 void Mms::updatePriority()
558 if (isPriorityValid()) {
562 LoggerI("MMS updating priority");
564 //set priority in platform
565 switch (getPriority()) {
566 case MessagePriority::LOW:
567 priority = MSG_MESSAGE_PRIORITY_LOW;
569 case MessagePriority::NORMAL:
570 priority = MSG_MESSAGE_PRIORITY_NORMAL;
572 case MessagePriority::HIGH:
573 priority = MSG_MESSAGE_PRIORITY_HIGH;
576 LoggerE("Wrong priority");
577 Throw(WrtDeviceApis::Commons::PlatformException);
579 LoggerI("priority : " << priority);
582 msg_set_int_value(m_messageData, MSG_MESSAGE_PRIORITY_INT, priority)){
584 LoggerE("Error during setting priority");
585 Throw(WrtDeviceApis::Commons::PlatformException);
589 void Mms::updateRecipientList()
591 // check if abstraction recipient value has been changed
592 if (getToRecipients().isValid() &&
593 getBccRecipients().isValid() &&
594 getCcRecipients().isValid()) {
598 LoggerI("MMS updating platform recipients");
602 msg_list_clear(m_messageData, MSG_MESSAGE_ADDR_LIST_HND);
604 vector<string> to = getToRecipients().getRecipients();
605 vector<string> cc = getCcRecipients().getRecipients();
606 vector<string> bcc = getBccRecipients().getRecipients();
608 // update addresses in platform structure
611 LoggerI("updating to");
612 for (size_t i = 0; i < to.size(); i++)
614 msg_struct_t tmpAddr;
616 if (i >= MAX_TO_ADDRESS_CNT)
618 LoggerE("max number of recipient exceeded");
621 LoggerD("adding to[" << i << "]=" << to[i]);
623 msg_list_add_item(m_messageData, MSG_MESSAGE_ADDR_LIST_HND, &tmpAddr);
625 msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
627 if (msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
628 MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
630 LoggerE("problem with adding to address");
631 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
634 if(msg_set_str_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
635 const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
637 LoggerE("problem with adding to address");
638 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
642 LoggerE("nToCnt : " << nToCnt);
648 LoggerI("updating cc");
649 for (size_t i = 0; i < cc.size(); i++)
651 msg_struct_t tmpAddr;
653 if (nToCnt >= MAX_TO_ADDRESS_CNT)
655 LoggerE("max number of recipient exceeded");
658 LoggerD("adding cc[" << i << "]=" << cc[i]);
660 msg_list_add_item(m_messageData, MSG_MESSAGE_ADDR_LIST_HND, &tmpAddr);
662 msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
664 if (msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
665 MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS)
667 LoggerE("problem with adding cc address");
668 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
671 if(msg_set_str_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
672 const_cast<char*>(cc[i].c_str()), cc[i].size()) != MSG_SUCCESS)
674 LoggerE("problem with adding cc address");
675 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
679 LoggerE("nToCnt : " << nToCnt);
685 LoggerI("updating bcc");
686 for (size_t i = 0; i < bcc.size(); i++)
688 msg_struct_t tmpAddr;
690 if (nToCnt >= MAX_TO_ADDRESS_CNT)
692 LoggerE("max number of recipient exceeded");
695 LoggerD("adding bcc[" << i << "]=" << bcc[i]);
697 msg_list_add_item(m_messageData, MSG_MESSAGE_ADDR_LIST_HND, &tmpAddr);
699 msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
701 if (msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
702 MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS)
704 LoggerE("problem with adding bcc address");
705 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
708 if(msg_set_str_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
709 const_cast<char*>(bcc[i].c_str()), bcc[i].size()) != MSG_SUCCESS)
711 LoggerE("problem with adding bcc address");
712 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
716 LoggerE("nToCnt : " << nToCnt);
721 setBccValidity(true);
724 void Mms::updateSubject()
726 // check if abstraction subject value has been changed
727 if (isSubjectValid()) {
730 LoggerI("updating platform subject: " << getSubjectRef());
732 // msg_set_subject(m_messageData, getSubjectRef().c_str())) {
733 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, const_cast<char*>(getSubjectRef().c_str()), MAX_SUBJECT_LEN)) {
735 LoggerE("problem with setting subject");
736 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
738 setSubjectValidity(true);
741 void Mms::updateBodyAndAttachments()
743 // check if attachment or body source address value has been changed
744 if (isAttachmentsValid() && isBodyValid()) {
748 // MMS_MESSAGE_DATA_S *mmsData = NULL;
749 msg_struct_t mms_struct = NULL;
750 // msg_struct_t old_mms_struct = NULL;// THIS
753 LoggerI("updating platform body and attachment");
757 msg_struct_t region[1];
758 msg_struct_t page[1];
759 msg_struct_t media[1];
760 msg_struct_t smil_text[1];
762 if (getMessageType() != MMS) {
763 LoggerE("Wrong msg type");
764 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong msg type");
766 // mmsData = msg_mms_create_message();
767 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
768 // old_mms_struct = msg_create_struct(MSG_STRUCT_MMS);// THIS
770 // ret = msg_get_mms_struct(m_messageData, old_mms_struct);// THIS
771 // LoggerE("ret " << ret);// THIS
772 // ret = msg_release_struct(&old_mms_struct);// THIS
773 // LoggerE("ret " << ret);// THIS
776 LoggerE("create message body failed");
777 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "create message body failed");
781 if (!getBodyRef().empty()) {
783 f = fopen(m_bodyFilePath.c_str(), "w");
785 LoggerE("cannot create file with body" << m_bodyFilePath);
786 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
787 "cannot create file with body");
789 LoggerD("body file: " << m_bodyFilePath);
790 fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
794 LoggerD("getBodyRef(): " << getBodyRef());
796 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_INT, ROOT_LAYOUT_WIDTH);
797 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
798 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_BGCOLOR_INT, WHITE_COLOR);
799 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL, true);
800 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL, true);
802 msg_list_add_item(mms_struct, MSG_STRUCT_MMS_REGION, ®ion[0]);
803 msg_set_str_value(region[0], MSG_MMS_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
804 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
805 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_TOP_INT, 0);
806 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_INT, ROOT_LAYOUT_WIDTH);
807 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
808 msg_set_int_value(region[0], MSG_MMS_REGION_BGCOLOR_INT, WHITE_COLOR);
810 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL, true);
811 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL, true);
812 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL, true);
813 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL, true);
815 msg_list_add_item(mms_struct, MSG_STRUCT_MMS_PAGE, &page[0]);
816 msg_set_int_value(page[0], MSG_MMS_PAGE_PAGE_DURATION_INT, 0);
818 msg_list_add_item(page[0], MSG_STRUCT_MMS_MEDIA, &media[0]);
819 msg_set_int_value(media[0], MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT);
820 msg_set_str_value(media[0], MSG_MMS_MEDIA_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
822 error = msg_set_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, const_cast<char*>(m_bodyFilePath.c_str()),MSG_FILEPATH_LEN_MAX);
823 LoggerD("bodyFile Path= " << m_bodyFilePath);
824 LoggerD("error= " << error);
825 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
826 memset(szFilePath, 0, sizeof(szFilePath));
827 msg_get_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
828 LoggerD("bodyFile Path= " << m_bodyFilePath);
830 msg_get_struct_handle(media[0], MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text[0]);
831 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_COLOR_INT, BLACK_COLOR);
832 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_SIZE_INT, MMS_SMIL_FONT_SIZE_NORMAL);
833 msg_set_bool_value(smil_text[0], MSG_MMS_SMIL_TEXT_BOLD_BOOL, true);
841 msg_struct_t attachment[20];
843 for (size_t i = 0; i < getAttachmentsRef().size(); ++i) {
844 IAttachmentPtr att = getAttachment(i);
849 LoggerD("Add attachment=" << att->getFullPath());
851 errnum = stat(att->getFullPath().c_str(), &buffer);
852 LoggerD("errnum=" << errnum);
855 LoggerE("Opening file: " << att->getFullPath().c_str());
856 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
857 "cannot open attachment file");
860 //this function should return valid pointer
862 msg_list_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[i]);
863 msg_set_str_value(attachment[i], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
865 LoggerD("Attachment added");
871 if (MSG_SUCCESS !=msg_set_mms_struct(m_messageData, mms_struct))
873 LoggerE("set message body error");
874 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set message body error");
877 msg_release_struct(&mms_struct);
879 setAttachmentsValidity(true);
880 setBodyValidity(true);
883 Catch(WrtDeviceApis::Commons::PlatformException) {
884 LoggerE("Platform error");
885 msg_release_struct(&mms_struct);
891 void Mms::updateReadStatus()
893 if (isReadStatusValid()) {
897 LoggerI("updating platform read status: " << isRead());
898 // if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
899 if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
900 LoggerE("problem with setting subject");
901 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
904 setReadStatusValidity(true);
907 void Mms::updateIsRead()
909 LoggerD("updating m_id=" << getIdRef());
911 if (!m_messageData) {
912 //error if platform message not exists
913 LoggerE("message can not be updated");
914 Throw(WrtDeviceApis::Commons::PlatformException);
917 // check if abstraction from m_isReadChange value has been changed
918 if (isReadChangeStatusValid()) {
919 // do not update if not changed
925 if (this->getIdRef().empty()) {
926 LoggerE("existing msgId is zero, remove msg not done");
927 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
928 "existing msgId is zero, remove msg not done");
932 msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
934 LoggerE("Failed to update isRead");
935 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
938 Catch(WrtDeviceApis::Commons::PlatformException) {
939 LoggerE("platform error occurs");
941 setisReadChangeStatusValidity(true);
945 void Mms::updateMessage()
947 LoggerD("updating m_id=" << getIdRef());
948 msg_error_t err = MSG_SUCCESS;
949 msg_struct_t msg = NULL;
950 msg_struct_t sendOpt = NULL;
952 if (!m_messageData) {
953 //error if platform message not exists
954 LoggerE("message can not be updated");
955 Throw(WrtDeviceApis::Commons::PlatformException);
961 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
962 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
964 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
966 if (err != MSG_SUCCESS)
968 LoggerE("Get Message Failed!");
969 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
972 if (this->getIdRef().empty()) {
973 LoggerE("existing msgId is zero, update msg not done");
974 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
975 "existing msgId is zero, update msg not done");
980 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
982 LoggerE("Failed to update message");
983 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
985 msg_release_struct(&msg);
986 msg_release_struct(&sendOpt);
988 Catch(WrtDeviceApis::Commons::PlatformException) {
989 msg_release_struct(&msg);
990 msg_release_struct(&sendOpt);
991 LoggerE("platform error occurs");
996 void Mms::createSendMessage()
998 LoggerD("convert m_id= " << convertId(getIdRef()));
1000 //prepare for add sms to draft folder
1001 if (!m_messageData) {
1002 //error if platform message not exists
1003 LoggerE("message can not be updated");
1004 Throw(WrtDeviceApis::Commons::PlatformException);
1007 //update all sms data
1008 if (getCurrentFolder() == DRAFTBOX) {
1009 LoggerD("update all mms data");
1011 updateBodyAndAttachments();
1012 updateRecipientList();
1019 // MSG_SENDINGOPT_S option = { false, false, false };
1020 // option.option.smsSendOpt.bReplyPath = true;
1021 // trying to get message from platform
1023 // msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1024 // msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
1027 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
1029 // msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1030 // msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, 4);
1031 // msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
1033 setId(convertId(msgId));
1034 setFolderType(DRAFTBOX);
1035 setMessageStatus(MESSAGE_STATUS_DRAFT);
1037 Catch(WrtDeviceApis::Commons::PlatformException) {
1038 LoggerE("remove message error");
1039 if (m_messageData) {
1040 //releasing platform message structure
1041 // msg_release_message(&m_messageData);
1042 msg_release_struct(&m_messageData);
1049 void Mms::addMessageToDraft()
1051 LoggerD("convert m_id= " << convertId(getIdRef()));
1053 msg_struct_t sendOpt = NULL;
1055 //prepare for add sms to draft folder
1056 if (!m_messageData) {
1057 //error if platform message not exists
1058 LoggerE("message can not be updated");
1059 Throw(WrtDeviceApis::Commons::PlatformException);
1062 //update all mms data
1063 if (getCurrentFolder() == DRAFTBOX) {
1065 updateBodyAndAttachments();
1066 updateRecipientList();
1073 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1075 // trying to add message
1076 LoggerD("add message");
1077 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
1078 if (ret < MSG_SUCCESS) {
1079 LoggerE("msg_add_message failed, error code=" << ret);
1080 Throw(WrtDeviceApis::Commons::PlatformException);
1087 LoggerD("Message ID : " << msgId);
1090 LoggerD("Message ID is invailded ");
1091 Throw(WrtDeviceApis::Commons::PlatformException);
1094 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1096 setId(convertId(msgId));
1097 setFolderType(DRAFTBOX);
1098 setMessageStatus(MESSAGE_STATUS_DRAFT);
1100 msg_release_struct(&sendOpt);
1103 Catch(WrtDeviceApis::Commons::PlatformException) {
1104 LoggerE("add draft message error");
1105 msg_release_struct(&sendOpt);
1111 void Mms::readAllData()
1113 readExistingMessage();
1116 void Mms::moveToFolder(const FolderType newFolder)
1123 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1126 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1127 platfromFolderId) != MSG_SUCCESS) {
1128 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error during movinf message");
1132 Catch(WrtDeviceApis::Commons::PlatformException) {
1133 LoggerE("remove message error");
1139 void Mms::moveToFolder(const string& newFolder)
1146 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1149 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1150 platfromFolderId) != MSG_SUCCESS) {
1151 LoggerE("msg_move_msg_to_folder error");
1152 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_move_msg_to_folder error");
1156 Catch(WrtDeviceApis::Commons::PlatformException) {
1157 LoggerE("remove message error");
1163 void Mms::copyToFolder(const FolderType newFolder)
1168 msg_message_t msg = msg_new_message();
1172 MSG_SENDINGOPT_S option = { false, false, false };
1173 option.option.smsSendOpt.bReplyPath = true;
1175 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1177 const msg_folder_id_t platfromFolderId =
1178 Messaging::convertFolderToPlatform(newFolder);
1179 msg_set_message_id(msg, 0);
1180 msg_set_folder_id(msg, platfromFolderId);
1182 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1183 if (error != MSG_SUCCESS) {
1184 LoggerE("msg_add_message failed, error code=" << error);
1185 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1189 msg_release_message(&msg);
1193 Catch(WrtDeviceApis::Commons::PlatformException) {
1194 LoggerE("remove message error");
1196 msg_release_message(&msg);
1203 void Mms::copyToFolder(const string& newFolder)
1208 msg_message_t msg = msg_new_message();
1212 MSG_SENDINGOPT_S option = { false, false, false };
1213 option.option.smsSendOpt.bReplyPath = true;
1215 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1217 const msg_folder_id_t platfromFolderId =
1218 Messaging::convertFolderToPlatform(newFolder);
1219 msg_set_message_id(msg, 0);
1220 msg_set_folder_id(msg, platfromFolderId);
1222 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1223 if (error != MSG_SUCCESS) {
1224 LoggerE("msg_add_message failed, error code=" << error);
1225 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1229 msg_release_message(&msg);
1233 Catch(WrtDeviceApis::Commons::PlatformException) {
1234 LoggerE("remove message error");
1236 msg_release_message(&msg);
1245 LoggerD("delete m_id=" << getIdRef());
1249 if (this->getIdRef().empty()) {
1250 LoggerE("existing msgId is zero, remove msg not done");
1251 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1252 "existing msgId is zero, remove msg not done");
1256 msg_delete_message(MsgGetCommonHandle(),
1257 convertId(getIdRef()))) {
1258 LoggerE("Failed to delete Message");
1259 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
1263 Catch(WrtDeviceApis::Commons::PlatformException) {
1264 LoggerE("platform error occurs");
1270 LoggerD("sending message, id=" << getIdRef());
1273 //prepare for sending sms/mms
1276 LoggerD("Start Sending Message...");
1278 LoggerD("trying to send mms");
1279 msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
1281 if (err != MSG_SUCCESS)
1283 LoggerE("Sending Message (submit request) failed!!! err=" << err);
1284 setMessageStatus(MESSAGE_STATUS_FAILED);
1288 setMessageStatus(MESSAGE_STATUS_SENDING);
1290 LoggerD("Sending Message request is submitted!");
1292 Catch(WrtDeviceApis::Commons::PlatformException) {
1293 LoggerE("message is not send, manually run callback");
1300 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1301 if (requestReceiver) {
1302 LoggerE("send Error");
1303 EventMessagingServicePtr event = getMessagingServiceEvent();
1304 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1305 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
1310 void Mms::sendingCallback(msg_struct_t sent_status)
1312 // LoggerI("sendingCallback callback received. Req id = " <<
1313 // sent_status->reqId << " Status = " << (int)sent_status->status);
1314 // msg_struct_t request_data = NULL;
1315 // msg_get_struct_handle(sent_status, MSG_STRUCT_REQUEST_INFO, (void **)request_data);
1316 // msg_get_int_value(request_data, MSG_REQUEST_REQUESTID_INT, &tempInt);
1317 int status = MSG_NETWORK_SEND_FAIL;
1318 msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
1320 LoggerD("status : " << status);
1322 if (MSG_NETWORK_SEND_SUCCESS == status) {
1323 LoggerD("sending ok");
1324 setSendingStatusOk();
1325 setMessageStatus(MESSAGE_STATUS_SENT);
1327 LoggerE("sending failed: " << static_cast<unsigned int>(status));
1328 setSendingStatusFailed();
1329 setMessageStatus(MESSAGE_STATUS_FAILED);
1333 void Mms::sendCancel(int handle)
1335 LoggerD("sending message, id=" << getIdRef());
1337 LoggerD("handle =" << handle);
1340 void Mms::setSendingStatusOk()
1342 //success callback should be executed here
1343 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1344 msg_list_handle_t addr_list = NULL;
1345 msg_struct_t addr_info = NULL;
1347 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1350 if (requestReceiver) {
1351 LoggerI("calling JS success callback");
1352 EventMessagingServicePtr event = getMessagingServiceEvent();
1353 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
1355 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
1357 nToCnt = msg_list_length(addr_list);
1359 for ( int index=0; index < nToCnt; index++)
1361 addr_info = (msg_struct_t)msg_list_nth_data(addr_list, index);
1362 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1363 event->m_successRecipients.push_back(strNumber);
1366 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1370 void Mms::setSendingStatusFailed()
1372 //error callback should be executed here
1373 EventOnSendingFailedEmitterPtr emitter = getEmitter();
1374 msg_list_handle_t addr_list = NULL;
1375 msg_struct_t addr_info = NULL;
1377 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1382 EventOnSendingFailedPtr event(new EventOnSendingFailed);
1383 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
1384 emitter->emit(event);
1388 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1389 EventMessagingServicePtr event = getMessagingServiceEvent();
1390 if (requestReceiver)
1392 LoggerE("calling JS error callback");
1393 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1395 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
1396 nToCnt = msg_list_length(addr_list);
1398 LoggerD("nToCnt : " << nToCnt);
1400 for ( int index=0; index < nToCnt; index++)
1402 addr_info = (msg_struct_t)msg_list_nth_data(addr_list, index);
1403 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1404 event->m_failRecipients.push_back(strNumber);
1407 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1412 FolderType Mms::toFolder(const std::string &folder)
1414 if (folder == "INBOX") {
1416 } else if (folder == "OUTBOX") {
1418 } else if (folder == "SENTBOX") {
1420 } else if (folder == "DRAFTBOX") {
1423 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");