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 <dpl/log/log.h>
22 #include <Commons/Exception.h>
23 #include "ReqReceiverMessage.h"
24 #include "Messaging.h"
25 #include "CallbackMgr.h"
26 #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 LogDebug("m_id=" << getIdRef());
56 LogDebug("m_msgType=" << getMessageType());
58 char buf[] = "XXXXXX";
59 mode_t mask = umask(S_IWGRP | S_IWOTH);
61 LogDebug("buf : " << buf << " i : " << i);
64 m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
66 LogDebug("m_bodyFilePath : " << m_bodyFilePath);
68 if (getIdRef().empty()) {
69 LogDebug("create new message");
72 LogDebug("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 LogDebug("m_id=" << getIdRef());
83 LogDebug("m_msgType=" << getMessageType());
85 char buf[] = "XXXXXX";
86 mode_t mask = umask(S_IWGRP | S_IWOTH);
88 LogDebug("buf : " << buf << " i : " << i);
91 m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
93 LogDebug("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 LogDebug("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 LogDebug("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 LogError("get message error");
174 Throw(WrtDeviceApis::Commons::PlatformException);
176 LogDebug("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 LogError("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 LogError("readDateTime : " <<tempInt);
207 tm* time = localtime((time_t*)&tempInt);
209 LogError("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 LogDebug("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 LogError("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 LogDebug("conversationID : " <<tempInt);
300 void Mms::readRecipientList(msg_struct_t& messageData)
302 std::string phoneNumber;
303 // int recipientCount = msg_get_address_count(messageData);
304 // LogDebug("Recipient count " << recipientCount);
306 msg_struct_list_s *addr_list;
307 msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
310 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
312 int recipientCount = addr_list->nCount;
313 LogDebug("Recipient count " << recipientCount);
315 for (int i = 0; i < recipientCount; ++i)
317 // int type = msg_get_direction_info(messageData);
318 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
320 LogDebug("Direction: " << type);
322 if (MSG_DIRECTION_TYPE_MT == type)
324 msg_struct_t addr_info = addr_list->msg_struct_info[i];
325 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
326 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
327 phoneNumber = strNumber;
329 if (validatePhoneNumber(phoneNumber))
331 setSourceAddress(phoneNumber);
332 setFrom(phoneNumber);
334 LogDebug("MT number: " << phoneNumber);
336 else if (MSG_DIRECTION_TYPE_MO == type)
338 msg_struct_t addr_info = addr_list->msg_struct_info[i];
339 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
340 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
341 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
342 LogDebug("MO number: " << strNumber);
343 LogDebug("Type : " << tempInt);
346 case MSG_RECIPIENTS_TYPE_TO:
347 appendToRecipients(strNumber);
349 case MSG_RECIPIENTS_TYPE_CC:
350 appendCcRecipients(strNumber);
352 case MSG_RECIPIENTS_TYPE_BCC:
353 appendBccRecipients(strNumber);
356 LogError("Wrong type of recipient");
361 LogError("Wrong type of recipient");
362 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
367 void Mms::readSubject(msg_struct_t& messageData)
369 char strTemp[MAX_SUBJECT_LEN] = {0};
370 msg_get_str_value(messageData, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
371 // setSubject(msg_get_subject(messageData));
372 LogError("readSubject : " << strTemp);
376 void Mms::readBodyAndAttachments(msg_struct_t& messageData)
379 int pageLen, mediaLen, attachLen, tempInt, ret;
381 msg_struct_t mms_struct = NULL;
383 msg_list_handle_t page_list = NULL;
384 msg_list_handle_t media_list = NULL;
385 msg_list_handle_t attach_list = NULL;
387 msg_struct_t page = NULL;
388 msg_struct_t media = NULL;
389 msg_struct_t attach = NULL;
391 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
392 ret = msg_get_mms_struct(messageData, mms_struct);
394 if (ret != MSG_SUCCESS)
396 LogError("cannot get mms struct");
397 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
400 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
401 char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
403 msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
404 pageLen = msg_list_length(page_list);
407 setMmsType(MULTIPART_RELATED);
409 setMmsType(MULTIPART_MIXED);
412 LogDebug("page count: " << pageLen);
414 for (int p = 0; p < pageLen; ++p)
416 LogDebug("page " << p);
417 page = (msg_struct_t)msg_list_nth_data(page_list, p);
420 LogError("returned page is null, continue");
424 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
425 mediaLen = msg_list_length(media_list);
427 for (int m = 0; m < mediaLen; ++m)
429 LogDebug("media file " << m);
430 media = (msg_struct_t)msg_list_nth_data(media_list, m);
433 LogError("returned media is null, continue");
437 msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
439 memset(szFilePath, 0, sizeof(szFilePath));
440 msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
442 if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt))
444 //text value on first page goes to body attribute
445 LogDebug("setting body from " << szFilePath);
448 f = fopen(szFilePath, "r");
451 LogError("cannot read file with body" << szFilePath);
452 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
454 fseek(f, 0, SEEK_END);
455 long int size = ftell(f);
456 fseek(f, 0, SEEK_SET);
457 char* data = new (nothrow) char[size + 1];
460 memset(data, 0, size + 1);
461 error = fread(data, 1, size, f);
465 LogError("body is not set");
467 LogDebug("message body: '" << getBody() << "'");
472 LogDebug("adding attachment " << szFilePath);
474 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
475 //attachment->setMessage(this); //set IMessagePtr
477 memset(szFileName, 0, sizeof(szFileName));
478 msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
479 if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0))
481 LogDebug("renaming to " << szFileName);
482 attachment->rename(szFileName);
484 else if (MMS_SMIL_MEDIA_TEXT == tempInt)
486 std::stringstream newName;
487 newName << "body_page_" << p + 1 << ".txt";
488 LogDebug("renaming to " << newName.str());
489 attachment->rename(newName.str());
495 msg_get_list_handle(mms_struct, MSG_MMS_ATTACH_LIST_HND, (void **)&attach_list);
497 attachLen= msg_list_length(attach_list);
499 LogDebug("attachment count: " << attachLen);
500 for (int a = 0; a < attachLen; ++a)
502 attach = (msg_struct_t)msg_list_nth_data(attach_list, a);
505 LogError("attachment is null, continue");
509 memset(szFilePath, 0, sizeof(szFilePath));
510 memset(szFileName, 0, sizeof(szFileName));
512 msg_get_str_value(attach, MSG_MMS_ATTACH_FILEPATH_STR, szFilePath, sizeof(szFilePath));
513 msg_get_str_value(attach, MSG_MMS_ATTACH_FILENAME_STR, szFileName, sizeof(szFileName));
515 IAttachmentPtr att = appendAttachment(szFilePath, false);
516 if ((szFileName[0] =! '\0') &&
517 strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0) {
518 LogDebug("renaming to " << szFileName);
519 att->rename(szFileName);
522 msg_release_struct(&mms_struct);
525 bool Mms::hasAttachment()
527 std::size_t attachmentSize = getAttachmentsCount();
528 if ( attachmentSize > 0)
534 void Mms::update(bool draftsOnly)
536 LogDebug("updating m_id=" << getIdRef());
538 if (!m_messageData) {
539 //error if platform message not exists
540 LogError("message can not be updated");
541 Throw(WrtDeviceApis::Commons::PlatformException);
544 //update mms data from abstraction
545 if (!draftsOnly || getCurrentFolder() == DRAFTBOX) {
547 updateBodyAndAttachments();
548 updateRecipientList();
554 void Mms::updatePriority()
556 if (isPriorityValid()) {
560 LogInfo("MMS updating priority");
562 //set priority in platform
563 switch (getPriority()) {
564 case MessagePriority::LOW:
565 priority = MSG_MESSAGE_PRIORITY_LOW;
567 case MessagePriority::NORMAL:
568 priority = MSG_MESSAGE_PRIORITY_NORMAL;
570 case MessagePriority::HIGH:
571 priority = MSG_MESSAGE_PRIORITY_HIGH;
574 LogError("Wrong priority");
575 Throw(WrtDeviceApis::Commons::PlatformException);
577 LogInfo("priority : " << priority);
580 msg_set_int_value(m_messageData, MSG_MESSAGE_PRIORITY_INT, priority)){
582 LogError("Error during setting priority");
583 Throw(WrtDeviceApis::Commons::PlatformException);
587 void Mms::updateRecipientList()
589 // check if abstraction recipient value has been changed
590 if (getToRecipients().isValid() &&
591 getBccRecipients().isValid() &&
592 getCcRecipients().isValid()) {
596 LogInfo("MMS updating platform recipients");
598 // reset addresses in platform structure
599 // msg_reset_address(m_messageData);
600 msg_struct_list_s *addr_list = NULL;
601 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
603 nToCnt = addr_list->nCount;
605 LogInfo("addr_list->nCount" << addr_list->nCount);
609 for (int i = 0; i < nToCnt; i++) {
610 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, (char *)"", 0);
611 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, (char *)"", 0);
612 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
613 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
614 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
617 addr_list->nCount = nToCnt;
620 LogInfo("addr_list->nCount" << addr_list->nCount);
622 vector<string> to = getToRecipients().getRecipients();
623 vector<string> cc = getCcRecipients().getRecipients();
624 vector<string> bcc = getBccRecipients().getRecipients();
626 // update addresses in platform structure
629 LogInfo("updating to");
630 for (size_t i = 0; i < to.size(); i++)
632 if (i >= MAX_TO_ADDRESS_CNT)
634 LogError("max number of recipient exceeded");
637 LogDebug("adding to[" << i << "]=" << to[i]);
639 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
641 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
642 MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
644 LogError("problem with adding to address");
645 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
648 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
649 const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
651 LogError("problem with adding to address");
652 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
656 addr_list->nCount = nToCnt;
657 LogError("nToCnt : " << nToCnt);
658 LogError("addr_list->nCount: " <<addr_list->nCount);
662 LogInfo("addr_list->nCount" << addr_list->nCount);
666 LogInfo("updating cc");
667 for (size_t i = 0; i < cc.size(); i++)
669 if (nToCnt >= MAX_TO_ADDRESS_CNT)
671 LogError("max number of recipient exceeded");
674 LogDebug("adding cc[" << i << "]=" << cc[i]);
676 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
678 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
679 MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS)
681 LogError("problem with adding cc address");
682 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
685 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
686 const_cast<char*>(cc[i].c_str()), cc[i].size()) != MSG_SUCCESS)
688 LogError("problem with adding cc address");
689 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
693 addr_list->nCount = nToCnt;
694 LogError("nToCnt : " << nToCnt);
695 LogError("addr_list->nCount: " <<addr_list->nCount);
698 LogInfo("addr_list->nCount" << addr_list->nCount);
702 LogInfo("updating bcc");
703 for (size_t i = 0; i < bcc.size(); i++)
705 if (nToCnt >= MAX_TO_ADDRESS_CNT)
707 LogError("max number of recipient exceeded");
710 LogDebug("adding bcc[" << i << "]=" << bcc[i]);
712 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
714 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
715 MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS)
717 LogError("problem with adding bcc address");
718 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
721 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
722 const_cast<char*>(bcc[i].c_str()), bcc[i].size()) != MSG_SUCCESS)
724 LogError("problem with adding bcc address");
725 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
729 addr_list->nCount = nToCnt;
730 LogError("nToCnt : " << nToCnt);
731 LogError("addr_list->nCount: " <<addr_list->nCount);
734 LogInfo("addr_list->nCount" << addr_list->nCount);
737 setBccValidity(true);
740 void Mms::updateSubject()
742 // check if abstraction subject value has been changed
743 if (isSubjectValid()) {
746 LogInfo("updating platform subject: " << getSubjectRef());
748 // msg_set_subject(m_messageData, getSubjectRef().c_str())) {
749 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, const_cast<char*>(getSubjectRef().c_str()), MAX_SUBJECT_LEN)) {
751 LogError("problem with setting subject");
752 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
754 setSubjectValidity(true);
757 void Mms::updateBodyAndAttachments()
759 // check if attachment or body source address value has been changed
760 if (isAttachmentsValid() && isBodyValid()) {
764 // MMS_MESSAGE_DATA_S *mmsData = NULL;
765 msg_struct_t mms_struct = NULL;
766 // msg_struct_t old_mms_struct = NULL;// THIS
769 LogInfo("updating platform body and attachment");
773 msg_struct_t region[1];
774 msg_struct_t page[1];
775 msg_struct_t media[1];
776 msg_struct_t smil_text[1];
778 if (getMessageType() != MMS) {
779 LogError("Wrong msg type");
780 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong msg type");
782 // mmsData = msg_mms_create_message();
783 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
784 // old_mms_struct = msg_create_struct(MSG_STRUCT_MMS);// THIS
786 // ret = msg_get_mms_struct(m_messageData, old_mms_struct);// THIS
787 // LogError("ret " << ret);// THIS
788 // ret = msg_release_struct(&old_mms_struct);// THIS
789 // LogError("ret " << ret);// THIS
792 LogError("create message body failed");
793 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "create message body failed");
797 if (!getBodyRef().empty()) {
799 f = fopen(m_bodyFilePath.c_str(), "w");
801 LogError("cannot create file with body" << m_bodyFilePath);
802 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
803 "cannot create file with body");
805 LogDebug("body file: " << m_bodyFilePath);
806 fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
810 LogDebug("getBodyRef(): " << getBodyRef());
812 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_INT, ROOT_LAYOUT_WIDTH);
813 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
814 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_BGCOLOR_INT, WHITE_COLOR);
815 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL, true);
816 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL, true);
818 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_REGION, ®ion[0]);
819 msg_set_str_value(region[0], MSG_MMS_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
820 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
821 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_TOP_INT, 0);
822 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_INT, ROOT_LAYOUT_WIDTH);
823 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
824 msg_set_int_value(region[0], MSG_MMS_REGION_BGCOLOR_INT, WHITE_COLOR);
826 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL, true);
827 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL, true);
828 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL, true);
829 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL, true);
831 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_PAGE, &page[0]);
832 msg_set_int_value(page[0], MSG_MMS_PAGE_PAGE_DURATION_INT, 0);
834 msg_mms_add_item(page[0], MSG_STRUCT_MMS_MEDIA, &media[0]);
835 msg_set_int_value(media[0], MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT);
836 msg_set_str_value(media[0], MSG_MMS_MEDIA_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
838 error = msg_set_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, const_cast<char*>(m_bodyFilePath.c_str()),MSG_FILEPATH_LEN_MAX);
839 LogDebug("bodyFile Path= " << m_bodyFilePath);
840 LogDebug("error= " << error);
841 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
842 memset(szFilePath, 0, sizeof(szFilePath));
843 msg_get_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
844 LogDebug("bodyFile Path= " << m_bodyFilePath);
846 msg_get_struct_handle(media[0], MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text[0]);
847 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_COLOR_INT, BLACK_COLOR);
848 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_SIZE_INT, MMS_SMIL_FONT_SIZE_NORMAL);
849 msg_set_bool_value(smil_text[0], MSG_MMS_SMIL_TEXT_BOLD_BOOL, true);
857 msg_struct_t attachment[20];
859 for (size_t i = 0; i < getAttachmentsRef().size(); ++i) {
860 IAttachmentPtr att = getAttachment(i);
865 LogDebug("Add attachment=" << att->getFullPath());
867 errnum = stat(att->getFullPath().c_str(), &buffer);
868 LogDebug("errnum=" << errnum);
871 LogError("Opening file: " << att->getFullPath().c_str());
872 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
873 "cannot open attachment file");
876 //this function should return valid pointer
878 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[i]);
879 msg_set_str_value(attachment[i], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
881 LogDebug("Attachment added");
887 if (MSG_SUCCESS !=msg_set_mms_struct(m_messageData, mms_struct))
889 LogError("set message body error");
890 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set message body error");
893 msg_release_struct(&mms_struct);
895 setAttachmentsValidity(true);
896 setBodyValidity(true);
899 Catch(WrtDeviceApis::Commons::PlatformException) {
900 LogError("Platform error");
901 msg_release_struct(&mms_struct);
907 void Mms::updateReadStatus()
909 if (isReadStatusValid()) {
913 LogInfo("updating platform read status: " << isRead());
914 // if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
915 if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
916 LogError("problem with setting subject");
917 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
920 setReadStatusValidity(true);
923 void Mms::updateIsRead()
925 LogDebug("updating m_id=" << getIdRef());
927 if (!m_messageData) {
928 //error if platform message not exists
929 LogError("message can not be updated");
930 Throw(WrtDeviceApis::Commons::PlatformException);
933 // check if abstraction from m_isReadChange value has been changed
934 if (isReadChangeStatusValid()) {
935 // do not update if not changed
941 if (this->getIdRef().empty()) {
942 LogError("existing msgId is zero, remove msg not done");
943 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
944 "existing msgId is zero, remove msg not done");
948 msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
950 LogError("Failed to update isRead");
951 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
954 Catch(WrtDeviceApis::Commons::PlatformException) {
955 LogError("platform error occurs");
957 setisReadChangeStatusValidity(true);
961 void Mms::updateMessage()
963 LogDebug("updating m_id=" << getIdRef());
964 msg_error_t err = MSG_SUCCESS;
965 msg_struct_t msg = NULL;
966 msg_struct_t sendOpt = NULL;
968 if (!m_messageData) {
969 //error if platform message not exists
970 LogError("message can not be updated");
971 Throw(WrtDeviceApis::Commons::PlatformException);
977 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
978 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
980 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
982 if (err != MSG_SUCCESS)
984 LogError("Get Message Failed!");
985 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
988 if (this->getIdRef().empty()) {
989 LogError("existing msgId is zero, update msg not done");
990 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
991 "existing msgId is zero, update msg not done");
996 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
998 LogError("Failed to update message");
999 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
1001 msg_release_struct(&msg);
1002 msg_release_struct(&sendOpt);
1004 Catch(WrtDeviceApis::Commons::PlatformException) {
1005 msg_release_struct(&msg);
1006 msg_release_struct(&sendOpt);
1007 LogError("platform error occurs");
1012 void Mms::createSendMessage()
1014 LogDebug("convert m_id= " << convertId(getIdRef()));
1016 //prepare for add sms to draft folder
1017 if (!m_messageData) {
1018 //error if platform message not exists
1019 LogError("message can not be updated");
1020 Throw(WrtDeviceApis::Commons::PlatformException);
1023 //update all sms data
1024 if (getCurrentFolder() == DRAFTBOX) {
1025 LogDebug("update all mms data");
1027 updateBodyAndAttachments();
1028 updateRecipientList();
1035 // MSG_SENDINGOPT_S option = { false, false, false };
1036 // option.option.smsSendOpt.bReplyPath = true;
1037 // trying to get message from platform
1039 // msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1040 // msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
1043 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
1045 // msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1046 // msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, 4);
1047 // msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
1049 setId(convertId(msgId));
1050 setFolderType(DRAFTBOX);
1051 setMessageStatus(MESSAGE_STATUS_DRAFT);
1053 Catch(WrtDeviceApis::Commons::PlatformException) {
1054 LogError("remove message error");
1055 if (m_messageData) {
1056 //releasing platform message structure
1057 // msg_release_message(&m_messageData);
1058 msg_release_struct(&m_messageData);
1065 void Mms::addMessageToDraft()
1067 LogDebug("convert m_id= " << convertId(getIdRef()));
1069 msg_struct_t sendOpt = NULL;
1071 //prepare for add sms to draft folder
1072 if (!m_messageData) {
1073 //error if platform message not exists
1074 LogError("message can not be updated");
1075 Throw(WrtDeviceApis::Commons::PlatformException);
1078 //update all mms data
1079 if (getCurrentFolder() == DRAFTBOX) {
1081 updateBodyAndAttachments();
1082 updateRecipientList();
1089 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1091 // trying to add message
1092 LogDebug("add message");
1093 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
1094 if (ret < MSG_SUCCESS) {
1095 LogError("msg_add_message failed, error code=" << ret);
1096 Throw(WrtDeviceApis::Commons::PlatformException);
1103 LogDebug("Message ID : " << msgId);
1106 LogDebug("Message ID is invailded ");
1107 Throw(WrtDeviceApis::Commons::PlatformException);
1110 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1112 setId(convertId(msgId));
1113 setFolderType(DRAFTBOX);
1114 setMessageStatus(MESSAGE_STATUS_DRAFT);
1116 msg_release_struct(&sendOpt);
1119 Catch(WrtDeviceApis::Commons::PlatformException) {
1120 LogError("add draft message error");
1121 msg_release_struct(&sendOpt);
1127 void Mms::readAllData()
1129 readExistingMessage();
1132 void Mms::moveToFolder(const FolderType newFolder)
1139 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1142 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1143 platfromFolderId) != MSG_SUCCESS) {
1144 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error during movinf message");
1148 Catch(WrtDeviceApis::Commons::PlatformException) {
1149 LogError("remove message error");
1155 void Mms::moveToFolder(const string& newFolder)
1162 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1165 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1166 platfromFolderId) != MSG_SUCCESS) {
1167 LogError("msg_move_msg_to_folder error");
1168 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_move_msg_to_folder error");
1172 Catch(WrtDeviceApis::Commons::PlatformException) {
1173 LogError("remove message error");
1179 void Mms::copyToFolder(const FolderType newFolder)
1184 msg_message_t msg = msg_new_message();
1188 MSG_SENDINGOPT_S option = { false, false, false };
1189 option.option.smsSendOpt.bReplyPath = true;
1191 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1193 const msg_folder_id_t platfromFolderId =
1194 Messaging::convertFolderToPlatform(newFolder);
1195 msg_set_message_id(msg, 0);
1196 msg_set_folder_id(msg, platfromFolderId);
1198 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1199 if (error != MSG_SUCCESS) {
1200 LogError("msg_add_message failed, error code=" << error);
1201 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1205 msg_release_message(&msg);
1209 Catch(WrtDeviceApis::Commons::PlatformException) {
1210 LogError("remove message error");
1212 msg_release_message(&msg);
1219 void Mms::copyToFolder(const string& newFolder)
1224 msg_message_t msg = msg_new_message();
1228 MSG_SENDINGOPT_S option = { false, false, false };
1229 option.option.smsSendOpt.bReplyPath = true;
1231 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1233 const msg_folder_id_t platfromFolderId =
1234 Messaging::convertFolderToPlatform(newFolder);
1235 msg_set_message_id(msg, 0);
1236 msg_set_folder_id(msg, platfromFolderId);
1238 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1239 if (error != MSG_SUCCESS) {
1240 LogError("msg_add_message failed, error code=" << error);
1241 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1245 msg_release_message(&msg);
1249 Catch(WrtDeviceApis::Commons::PlatformException) {
1250 LogError("remove message error");
1252 msg_release_message(&msg);
1261 LogDebug("delete m_id=" << getIdRef());
1265 if (this->getIdRef().empty()) {
1266 LogError("existing msgId is zero, remove msg not done");
1267 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1268 "existing msgId is zero, remove msg not done");
1272 msg_delete_message(MsgGetCommonHandle(),
1273 convertId(getIdRef()))) {
1274 LogError("Failed to delete Message");
1275 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
1279 Catch(WrtDeviceApis::Commons::PlatformException) {
1280 LogError("platform error occurs");
1286 LogDebug("sending message, id=" << getIdRef());
1289 //prepare for sending sms/mms
1292 LogDebug("Start Sending Message...");
1294 LogDebug("trying to send mms");
1295 msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
1297 if (err != MSG_SUCCESS)
1299 LogError("Sending Message (submit request) failed!!! err=" << err);
1300 setMessageStatus(MESSAGE_STATUS_FAILED);
1304 setMessageStatus(MESSAGE_STATUS_SENDING);
1306 LogDebug("Sending Message request is submitted!");
1308 Catch(WrtDeviceApis::Commons::PlatformException) {
1309 LogError("message is not send, manually run callback");
1316 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1317 if (requestReceiver) {
1318 LogError("send Error");
1319 EventMessagingServicePtr event = getMessagingServiceEvent();
1320 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1321 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
1326 void Mms::sendingCallback(msg_struct_t sent_status)
1328 // LogInfo("sendingCallback callback received. Req id = " <<
1329 // sent_status->reqId << " Status = " << (int)sent_status->status);
1330 // msg_struct_t request_data = NULL;
1331 // msg_get_struct_handle(sent_status, MSG_STRUCT_REQUEST_INFO, (void **)request_data);
1332 // msg_get_int_value(request_data, MSG_REQUEST_REQUESTID_INT, &tempInt);
1333 int status = MSG_NETWORK_SEND_FAIL;
1334 msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
1336 LogDebug("status : " << status);
1338 if (MSG_NETWORK_SEND_SUCCESS == status) {
1339 LogDebug("sending ok");
1340 setSendingStatusOk();
1341 setMessageStatus(MESSAGE_STATUS_SENT);
1343 LogError("sending failed: " << static_cast<unsigned int>(status));
1344 setSendingStatusFailed();
1345 setMessageStatus(MESSAGE_STATUS_FAILED);
1349 void Mms::sendCancel(int handle)
1351 LogDebug("sending message, id=" << getIdRef());
1353 LogDebug("handle =" << handle);
1356 void Mms::setSendingStatusOk()
1358 //success callback should be executed here
1359 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1360 msg_struct_list_s *addr_list = NULL;
1361 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1364 if (requestReceiver) {
1365 LogInfo("calling JS success callback");
1366 EventMessagingServicePtr event = getMessagingServiceEvent();
1367 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
1369 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1371 nToCnt = addr_list->nCount;
1373 for ( int index=0; index < nToCnt; index++)
1375 msg_get_str_value(addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1376 event->m_successRecipients.push_back(strNumber);
1379 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1383 void Mms::setSendingStatusFailed()
1385 //error callback should be executed here
1386 EventOnSendingFailedEmitterPtr emitter = getEmitter();
1387 msg_struct_list_s *addr_list = NULL;
1388 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1393 EventOnSendingFailedPtr event(new EventOnSendingFailed);
1394 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
1395 emitter->emit(event);
1399 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1400 EventMessagingServicePtr event = getMessagingServiceEvent();
1401 if (requestReceiver)
1403 LogError("calling JS error callback");
1404 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1405 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1406 nToCnt = addr_list->nCount;
1408 LogDebug("nToCnt : " << nToCnt);
1410 for ( int index=0; index < nToCnt; index++)
1412 msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1413 event->m_failRecipients.push_back(strNumber);
1416 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1421 FolderType Mms::toFolder(const std::string &folder)
1423 if (folder == "INBOX") {
1425 } else if (folder == "OUTBOX") {
1427 } else if (folder == "SENTBOX") {
1429 } else if (folder == "DRAFTBOX") {
1432 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");