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"
31 #include <msg_storage.h>
36 const char* TEXT_AREA = "Text";
37 const char* TEXT_FILE_EXTENSION = ".txt";
38 const char* TEXT_DIR_PREFIX = "/tmp/";
39 const int WHITE_COLOR = 0xffffff;
40 const int BLACK_COLOR = 0x000000;
41 const int ROOT_LAYOUT_WIDTH = 100;
42 const int ROOT_LAYOUT_HEIGHT = 100;
43 const char* EMPTY_ID = "0";
51 Mms::Mms(const string& id) :
53 // m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
56 LoggerD("m_id=" << getIdRef());
57 LoggerD("m_msgType=" << getMessageType());
59 char buf[] = "XXXXXX";
60 mode_t mask = umask(S_IWGRP | S_IWOTH);
62 LoggerD("buf : " << buf << " i : " << i);
65 m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
67 LoggerD("m_bodyFilePath : " << m_bodyFilePath);
69 if (getIdRef().empty()) {
70 LoggerD("create new message");
73 LoggerD("read existing message");
74 readExistingMessage();
78 Mms::Mms(const string& id, const msg_struct_t msg_data) :
82 LoggerD("m_id=" << getIdRef());
83 LoggerD("m_msgType=" << getMessageType());
85 LoggerD("created msg_data : " << msg_data);
86 m_messageData = createNewCopyOfPLatformMsgWithAddressList(msg_data);
87 LoggerD("created m_messageData : " << m_messageData);
89 char buf[] = "XXXXXX";
90 mode_t mask = umask(S_IWGRP | S_IWOTH);
92 LoggerD("buf : " << buf << " i : " << i);
95 m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
97 LoggerD("m_bodyFilePath : " << m_bodyFilePath);
99 readConversationId(m_messageData);
100 readRecipientList(m_messageData);
101 readPriority(m_messageData);
102 readSubject(m_messageData);
103 readBodyAndAttachments(m_messageData);
104 readFolder(m_messageData);
105 readDateTime(m_messageData);
106 readReadStatus(m_messageData);
107 readMessageStatus(m_messageData);
108 // setMessageStatus(MESSAGE_STATUS_LOADED);
117 // release platform message structure
118 // msg_release_message(&m_messageData);
119 msg_release_struct(&m_messageData);
123 //trying to remove file, return value is skipped
124 if (!m_bodyFilePath.empty()) {
125 LoggerD("remove tmp file=" << m_bodyFilePath);
126 (void) ::remove(m_bodyFilePath.c_str());
130 void Mms::createNewMessage()
133 msg_release_struct(&m_messageData);
134 m_messageData = NULL;
137 char strSubject[MAX_SUBJECT_LEN] = {0,};
139 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
140 msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
141 // msg_struct_t option = NULL;
143 // initialize platform message structure
144 msg_set_int_value(m_messageData, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
145 msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
146 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
148 setMmsType(MULTIPART_MIXED);
149 setReadStatus(false);
150 setMessageStatus(MESSAGE_STATUS_CREATED);
152 msg_release_struct(&sendOpt);
153 LoggerD("Message created successfully, Id: " << getIdRef());
156 void Mms::readExistingMessage()
160 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
162 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
165 msg_release_struct(&m_messageData);
166 m_messageData = NULL;
167 msg_struct_t sendOpt = NULL;
171 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
172 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
174 // trying to get message from platform
175 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
177 LoggerE("get message error");
178 Throw(WrtDeviceApis::Commons::PlatformException);
180 LoggerD("message found with msgId=" << getIdRef());
182 // read all mms dat to abstraction layer
183 readConversationId(m_messageData);
184 readRecipientList(m_messageData);
185 readPriority(m_messageData);
186 readSubject(m_messageData);
187 readBodyAndAttachments(m_messageData);
188 readFolder(m_messageData);
189 readDateTime(m_messageData);
190 readReadStatus(m_messageData);
191 readMessageStatus(m_messageData);
193 msg_release_struct(&sendOpt);
195 Catch(WrtDeviceApis::Commons::PlatformException) {
196 LoggerE("exception");
198 msg_release_struct(&sendOpt);
202 void Mms::readDateTime(msg_struct_t& messageData)
204 // tm* time = localtime(msg_get_time(messageData));
205 // tm dateT = getDateTime();
207 msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
209 LoggerE("readDateTime : " <<tempInt);
211 tm* time = localtime((time_t*)&tempInt);
213 LoggerE("localtime failed");
214 Throw(WrtDeviceApis::Commons::PlatformException);
219 void Mms::readReadStatus(msg_struct_t& messageData)
222 msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
223 setReadStatus(tempBool);
226 void Mms::readFolder(msg_struct_t& messageData)
229 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
233 setFolderType(INBOX);
236 setFolderType(OUTBOX);
239 setFolderType(SENTBOX);
242 setFolderType(DRAFTBOX);
245 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
249 void Mms::readMessageStatus(msg_struct_t& messageData)
252 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
254 LoggerD("readMessageStatus folder : " << tempValue);
258 setMessageStatus(MESSAGE_STATUS_LOADED);
261 setMessageStatus(MESSAGE_STATUS_SENDING);
264 setMessageStatus(MESSAGE_STATUS_SENT);
267 setMessageStatus(MESSAGE_STATUS_DRAFT);
270 setMessageStatus(MESSAGE_STATUS_LOADED);
275 void Mms::readPriority(msg_struct_t& messageData)
277 // switch (msg_get_priority_info(messageData)) {
279 msg_get_int_value(messageData, MSG_MESSAGE_PRIORITY_INT, &tempInt);
281 case MSG_MESSAGE_PRIORITY_LOW:
282 setPriority(MessagePriority::LOW);
284 case MSG_MESSAGE_PRIORITY_NORMAL:
285 setPriority(MessagePriority::NORMAL);
287 case MSG_MESSAGE_PRIORITY_HIGH:
288 setPriority(MessagePriority::HIGH);
291 LoggerE("Wrong priority type");
292 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong priority type");
296 void Mms::readConversationId(msg_struct_t& messageData)
299 msg_get_int_value(messageData, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
300 LoggerD("conversationID : " <<tempInt);
304 void Mms::readRecipientList(msg_struct_t& messageData)
306 std::string phoneNumber;
307 // int recipientCount = msg_get_address_count(messageData);
308 // LoggerD("Recipient count " << recipientCount);
310 msg_struct_list_s *addr_list;
311 msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
314 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
316 int recipientCount = addr_list->nCount;
317 LoggerD("Recipient count " << recipientCount);
319 for (int i = 0; i < recipientCount; ++i)
321 // int type = msg_get_direction_info(messageData);
322 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
324 LoggerD("Direction: " << type);
326 if (MSG_DIRECTION_TYPE_MT == type)
328 msg_struct_t addr_info = addr_list->msg_struct_info[i];
329 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
330 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
331 phoneNumber = strNumber;
333 if (validatePhoneNumber(phoneNumber))
335 setSourceAddress(phoneNumber);
336 setFrom(phoneNumber);
338 LoggerD("MT number: " << phoneNumber);
340 else if (MSG_DIRECTION_TYPE_MO == type)
342 msg_struct_t addr_info = addr_list->msg_struct_info[i];
343 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
344 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
345 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
346 LoggerD("MO number: " << strNumber);
347 LoggerD("Type : " << tempInt);
350 case MSG_RECIPIENTS_TYPE_TO:
351 appendToRecipients(strNumber);
353 case MSG_RECIPIENTS_TYPE_CC:
354 appendCcRecipients(strNumber);
356 case MSG_RECIPIENTS_TYPE_BCC:
357 appendBccRecipients(strNumber);
360 LoggerE("Wrong type of recipient");
365 LoggerE("Wrong type of recipient");
366 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
371 void Mms::readSubject(msg_struct_t& messageData)
373 char strTemp[MAX_SUBJECT_LEN] = {0};
374 msg_get_str_value(messageData, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
375 // setSubject(msg_get_subject(messageData));
376 LoggerE("readSubject : " << strTemp);
380 void Mms::readBodyAndAttachments(msg_struct_t& messageData)
383 int pageLen, mediaLen, attachLen, tempInt, ret;
385 msg_struct_t mms_struct = NULL;
387 msg_list_handle_t page_list = NULL;
388 msg_list_handle_t media_list = NULL;
389 msg_list_handle_t attach_list = NULL;
391 msg_struct_t page = NULL;
392 msg_struct_t media = NULL;
393 msg_struct_t attach = NULL;
395 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
396 ret = msg_get_mms_struct(messageData, mms_struct);
398 if (ret != MSG_SUCCESS)
400 LoggerE("cannot get mms struct");
401 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
404 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
405 char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
407 msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
408 pageLen = msg_list_length(page_list);
411 setMmsType(MULTIPART_RELATED);
413 setMmsType(MULTIPART_MIXED);
416 LoggerD("page count: " << pageLen);
418 for (int p = 0; p < pageLen; ++p)
420 LoggerD("page " << p);
421 page = (msg_struct_t)msg_list_nth_data(page_list, p);
424 LoggerE("returned page is null, continue");
428 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
429 mediaLen = msg_list_length(media_list);
431 for (int m = 0; m < mediaLen; ++m)
433 LoggerD("media file " << m);
434 media = (msg_struct_t)msg_list_nth_data(media_list, m);
437 LoggerE("returned media is null, continue");
441 msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
443 memset(szFilePath, 0, sizeof(szFilePath));
444 msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
446 if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt))
448 //text value on first page goes to body attribute
449 LoggerD("setting body from " << szFilePath);
452 f = fopen(szFilePath, "r");
455 LoggerE("cannot read file with body" << szFilePath);
456 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
458 fseek(f, 0, SEEK_END);
459 long int size = ftell(f);
460 fseek(f, 0, SEEK_SET);
461 char* data = new (nothrow) char[size + 1];
464 memset(data, 0, size + 1);
465 error = fread(data, 1, size, f);
469 LoggerE("body is not set");
471 LoggerD("message body: '" << getBody() << "'");
476 LoggerD("adding attachment " << szFilePath);
478 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
479 //attachment->setMessage(this); //set IMessagePtr
481 memset(szFileName, 0, sizeof(szFileName));
482 msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
483 if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0))
485 LoggerD("renaming to " << szFileName);
486 attachment->rename(szFileName);
488 else if (MMS_SMIL_MEDIA_TEXT == tempInt)
490 std::stringstream newName;
491 newName << "body_page_" << p + 1 << ".txt";
492 LoggerD("renaming to " << newName.str());
493 attachment->rename(newName.str());
499 msg_get_list_handle(mms_struct, MSG_MMS_ATTACH_LIST_HND, (void **)&attach_list);
501 attachLen= msg_list_length(attach_list);
503 LoggerD("attachment count: " << attachLen);
504 for (int a = 0; a < attachLen; ++a)
506 std::string tempString;
509 attach = (msg_struct_t)msg_list_nth_data(attach_list, a);
512 LoggerE("attachment is null, continue");
516 memset(szFilePath, 0, sizeof(szFilePath));
517 memset(szFileName, 0, sizeof(szFileName));
519 msg_get_str_value(attach, MSG_MMS_ATTACH_FILEPATH_STR, szFilePath, sizeof(szFilePath));
520 msg_get_str_value(attach, MSG_MMS_ATTACH_FILENAME_STR, szFileName, sizeof(szFileName));
522 msg_get_int_value(attach, MSG_MMS_ATTACH_MIME_TYPE_INT, &tempInt);
523 tempString = indexIntToMimeTypeString((MimeType)tempInt);
525 IAttachmentPtr att = appendAttachment(szFilePath, false);
526 if ((szFileName[0] =! '\0') &&
527 strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0) {
528 LoggerD("renaming to " << szFileName);
529 att->rename(szFileName);
531 att->setMimeType(tempString);
532 att->setAttachmentID((int)a);
533 att->setDownloaded(true);
535 msg_release_struct(&mms_struct);
538 void Mms::readBody(msg_struct_t& messageData)
541 int pageLen, mediaLen, tempInt, ret;
543 msg_struct_t mms_struct = NULL;
545 msg_list_handle_t page_list = NULL;
546 msg_list_handle_t media_list = NULL;
548 msg_struct_t page = NULL;
549 msg_struct_t media = NULL;
551 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
552 ret = msg_get_mms_struct(messageData, mms_struct);
554 if (ret != MSG_SUCCESS)
556 LoggerE("cannot get mms struct");
557 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
560 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
561 char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
563 msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
564 pageLen = msg_list_length(page_list);
567 setMmsType(MULTIPART_RELATED);
569 setMmsType(MULTIPART_MIXED);
572 LoggerD("page count: " << pageLen);
574 for (int p = 0; p < pageLen; ++p)
576 LoggerD("page " << p);
577 page = (msg_struct_t)msg_list_nth_data(page_list, p);
580 LoggerE("returned page is null, continue");
584 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
585 mediaLen = msg_list_length(media_list);
587 for (int m = 0; m < mediaLen; ++m)
589 LoggerD("media file " << m);
590 media = (msg_struct_t)msg_list_nth_data(media_list, m);
593 LoggerE("returned media is null, continue");
597 msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
599 memset(szFilePath, 0, sizeof(szFilePath));
600 msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
602 if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt))
604 //text value on first page goes to body attribute
605 LoggerD("setting body from " << szFilePath);
608 f = fopen(szFilePath, "r");
611 LoggerE("cannot read file with body" << szFilePath);
612 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
614 fseek(f, 0, SEEK_END);
615 long int size = ftell(f);
616 fseek(f, 0, SEEK_SET);
617 char* data = new (nothrow) char[size + 1];
620 memset(data, 0, size + 1);
621 error = fread(data, 1, size, f);
625 LoggerE("body is not set");
627 LoggerD("message body: '" << getBody() << "'");
632 LoggerD("adding attachment " << szFilePath);
634 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
635 //attachment->setMessage(this); //set IMessagePtr
637 memset(szFileName, 0, sizeof(szFileName));
638 msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
639 if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0))
641 LoggerD("renaming to " << szFileName);
642 attachment->rename(szFileName);
644 else if (MMS_SMIL_MEDIA_TEXT == tempInt)
646 std::stringstream newName;
647 newName << "body_page_" << p + 1 << ".txt";
648 LoggerD("renaming to " << newName.str());
649 attachment->rename(newName.str());
654 msg_release_struct(&mms_struct);
658 bool Mms::hasAttachment()
660 std::size_t attachmentSize = getAttachmentsCount();
661 if ( attachmentSize > 0)
667 void Mms::update(bool draftsOnly)
669 LoggerD("updating m_id=" << getIdRef());
671 if (!m_messageData) {
672 //error if platform message not exists
673 LoggerE("message can not be updated");
674 Throw(WrtDeviceApis::Commons::PlatformException);
677 //update mms data from abstraction
678 if (!draftsOnly || getCurrentFolder() == DRAFTBOX) {
680 updateBodyAndAttachments();
681 updateRecipientList();
687 void Mms::updatePriority()
689 if (isPriorityValid()) {
693 LoggerI("MMS updating priority");
695 //set priority in platform
696 switch (getPriority()) {
697 case MessagePriority::LOW:
698 priority = MSG_MESSAGE_PRIORITY_LOW;
700 case MessagePriority::NORMAL:
701 priority = MSG_MESSAGE_PRIORITY_NORMAL;
703 case MessagePriority::HIGH:
704 priority = MSG_MESSAGE_PRIORITY_HIGH;
707 LoggerE("Wrong priority");
708 Throw(WrtDeviceApis::Commons::PlatformException);
710 LoggerI("priority : " << priority);
713 msg_set_int_value(m_messageData, MSG_MESSAGE_PRIORITY_INT, priority)){
715 LoggerE("Error during setting priority");
716 Throw(WrtDeviceApis::Commons::PlatformException);
720 void Mms::updateRecipientList()
722 // check if abstraction recipient value has been changed
723 if (getToRecipients().isValid() &&
724 getBccRecipients().isValid() &&
725 getCcRecipients().isValid()) {
729 LoggerI("MMS updating platform recipients");
731 // reset addresses in platform structure
732 // msg_reset_address(m_messageData);
733 msg_struct_list_s *addr_list = NULL;
734 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
736 nToCnt = addr_list->nCount;
738 LoggerI("addr_list->nCount" << addr_list->nCount);
742 for (int i = 0; i < nToCnt; i++) {
743 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, (char *)"", 0);
744 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, (char *)"", 0);
745 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
746 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
747 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
750 addr_list->nCount = nToCnt;
753 LoggerI("addr_list->nCount" << addr_list->nCount);
755 vector<string> to = getToRecipients().getRecipients();
756 vector<string> cc = getCcRecipients().getRecipients();
757 vector<string> bcc = getBccRecipients().getRecipients();
759 // update addresses in platform structure
762 LoggerI("updating to");
763 for (size_t i = 0; i < to.size(); i++)
765 if (i >= MAX_TO_ADDRESS_CNT)
767 LoggerE("max number of recipient exceeded");
770 LoggerD("adding to[" << i << "]=" << to[i]);
772 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
774 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
775 MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
777 LoggerE("problem with adding to address");
778 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
781 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
782 const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
784 LoggerE("problem with adding to address");
785 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
789 addr_list->nCount = nToCnt;
790 LoggerE("nToCnt : " << nToCnt);
791 LoggerE("addr_list->nCount: " <<addr_list->nCount);
795 LoggerI("addr_list->nCount" << addr_list->nCount);
799 LoggerI("updating cc");
800 for (size_t i = 0; i < cc.size(); i++)
802 if (nToCnt >= MAX_TO_ADDRESS_CNT)
804 LoggerE("max number of recipient exceeded");
807 LoggerD("adding cc[" << i << "]=" << cc[i]);
809 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
811 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
812 MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS)
814 LoggerE("problem with adding cc address");
815 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
818 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
819 const_cast<char*>(cc[i].c_str()), cc[i].size()) != MSG_SUCCESS)
821 LoggerE("problem with adding cc address");
822 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
826 addr_list->nCount = nToCnt;
827 LoggerE("nToCnt : " << nToCnt);
828 LoggerE("addr_list->nCount: " <<addr_list->nCount);
831 LoggerI("addr_list->nCount" << addr_list->nCount);
835 LoggerI("updating bcc");
836 for (size_t i = 0; i < bcc.size(); i++)
838 if (nToCnt >= MAX_TO_ADDRESS_CNT)
840 LoggerE("max number of recipient exceeded");
843 LoggerD("adding bcc[" << i << "]=" << bcc[i]);
845 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
847 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
848 MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS)
850 LoggerE("problem with adding bcc address");
851 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
854 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
855 const_cast<char*>(bcc[i].c_str()), bcc[i].size()) != MSG_SUCCESS)
857 LoggerE("problem with adding bcc address");
858 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
862 addr_list->nCount = nToCnt;
863 LoggerE("nToCnt : " << nToCnt);
864 LoggerE("addr_list->nCount: " <<addr_list->nCount);
867 LoggerI("addr_list->nCount" << addr_list->nCount);
870 setBccValidity(true);
873 void Mms::updateSubject()
875 // check if abstraction subject value has been changed
876 if (isSubjectValid()) {
879 LoggerI("updating platform subject: " << getSubjectRef());
881 // msg_set_subject(m_messageData, getSubjectRef().c_str())) {
882 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, const_cast<char*>(getSubjectRef().c_str()), MAX_SUBJECT_LEN)) {
884 LoggerE("problem with setting subject");
885 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
887 setSubjectValidity(true);
890 void Mms::updateBodyAndAttachments()
892 // check if attachment or body source address value has been changed
893 if (isAttachmentsValid() && isBodyValid()) {
897 // MMS_MESSAGE_DATA_S *mmsData = NULL;
898 msg_struct_t mms_struct = NULL;
899 // msg_struct_t old_mms_struct = NULL;// THIS
902 LoggerI("updating platform body and attachment");
906 msg_struct_t region[1];
907 msg_struct_t page[1];
908 msg_struct_t media[1];
909 msg_struct_t smil_text[1];
911 if (getMessageType() != MMS) {
912 LoggerE("Wrong msg type");
913 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong msg type");
915 // mmsData = msg_mms_create_message();
916 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
917 // old_mms_struct = msg_create_struct(MSG_STRUCT_MMS);// THIS
919 // ret = msg_get_mms_struct(m_messageData, old_mms_struct);// THIS
920 // LoggerE("ret " << ret);// THIS
921 // ret = msg_release_struct(&old_mms_struct);// THIS
922 // LoggerE("ret " << ret);// THIS
925 LoggerE("create message body failed");
926 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "create message body failed");
930 if (!getBodyRef().empty()) {
932 f = fopen(m_bodyFilePath.c_str(), "w");
934 LoggerE("cannot create file with body" << m_bodyFilePath);
935 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
936 "cannot create file with body");
938 LoggerD("body file: " << m_bodyFilePath);
939 fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
943 LoggerD("getBodyRef(): " << getBodyRef());
945 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_INT, ROOT_LAYOUT_WIDTH);
946 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
947 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_BGCOLOR_INT, WHITE_COLOR);
948 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL, true);
949 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL, true);
951 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_REGION, ®ion[0]);
952 msg_set_str_value(region[0], MSG_MMS_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
953 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
954 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_TOP_INT, 0);
955 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_INT, ROOT_LAYOUT_WIDTH);
956 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
957 msg_set_int_value(region[0], MSG_MMS_REGION_BGCOLOR_INT, WHITE_COLOR);
959 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL, true);
960 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL, true);
961 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL, true);
962 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL, true);
964 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_PAGE, &page[0]);
965 msg_set_int_value(page[0], MSG_MMS_PAGE_PAGE_DURATION_INT, 0);
967 msg_mms_add_item(page[0], MSG_STRUCT_MMS_MEDIA, &media[0]);
968 msg_set_int_value(media[0], MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT);
969 msg_set_str_value(media[0], MSG_MMS_MEDIA_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
971 error = msg_set_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, const_cast<char*>(m_bodyFilePath.c_str()),MSG_FILEPATH_LEN_MAX);
972 LoggerD("bodyFile Path= " << m_bodyFilePath);
973 LoggerD("error= " << error);
974 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
975 memset(szFilePath, 0, sizeof(szFilePath));
976 msg_get_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
977 LoggerD("bodyFile Path= " << m_bodyFilePath);
979 msg_get_struct_handle(media[0], MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text[0]);
980 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_COLOR_INT, BLACK_COLOR);
981 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_SIZE_INT, MMS_SMIL_FONT_SIZE_NORMAL);
982 msg_set_bool_value(smil_text[0], MSG_MMS_SMIL_TEXT_BOLD_BOOL, true);
990 msg_struct_t attachment[20];
992 for (size_t idx = 0; idx < getAttachmentsRef().size(); ++idx) {
993 IAttachmentPtr att = getAttachment(idx);
998 LoggerD("Add attachment=" << att->getFullPath());
1000 errnum = stat(att->getFullPath().c_str(), &buffer);
1001 LoggerD("errnum=" << errnum);
1004 LoggerE("Opening file: " << att->getFullPath().c_str());
1005 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1006 "cannot open attachment file");
1009 //this function should return valid pointer
1010 att->setMessage(SharedFromThis()); // setMessage to setMessageId
1011 att->setAttachmentID((int)idx);
1012 att->setDownloaded(true);
1014 int ret = mimeTypeStringToIndexInt(att->getMimeType());
1016 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[idx]);
1017 msg_set_str_value(attachment[idx], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
1019 if(ret != MIME_UNKNOWN)
1021 msg_set_int_value(attachment[idx], MSG_MMS_ATTACH_MIME_TYPE_INT, ret);
1024 LoggerD("Attachment added");
1030 if (MSG_SUCCESS !=msg_set_mms_struct(m_messageData, mms_struct))
1032 LoggerE("set message body error");
1033 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set message body error");
1036 msg_release_struct(&mms_struct);
1038 setAttachmentsValidity(true);
1039 setBodyValidity(true);
1042 Catch(WrtDeviceApis::Commons::PlatformException) {
1043 LoggerE("Platform error");
1044 msg_release_struct(&mms_struct);
1050 void Mms::updateReadStatus()
1052 if (isReadStatusValid()) {
1056 LoggerI("updating platform read status: " << isRead());
1057 // if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
1058 if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
1059 LoggerE("problem with setting subject");
1060 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
1063 setReadStatusValidity(true);
1066 void Mms::updateIsRead()
1068 LoggerD("updating m_id=" << getIdRef());
1070 if (!m_messageData) {
1071 //error if platform message not exists
1072 LoggerE("message can not be updated");
1073 Throw(WrtDeviceApis::Commons::PlatformException);
1076 // check if abstraction from m_isReadChange value has been changed
1077 if (isReadChangeStatusValid()) {
1078 // do not update if not changed
1084 if (this->getIdRef().empty()) {
1085 LoggerE("existing msgId is zero, remove msg not done");
1086 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1087 "existing msgId is zero, remove msg not done");
1091 msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
1093 LoggerE("Failed to update isRead");
1094 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
1097 Catch(WrtDeviceApis::Commons::PlatformException) {
1098 LoggerE("platform error occurs");
1100 setisReadChangeStatusValidity(true);
1104 void Mms::updateMessage()
1106 LoggerD("updating m_id=" << getIdRef());
1107 msg_error_t err = MSG_SUCCESS;
1110 msg_struct_t msg = NULL;
1111 msg_struct_t sendOpt = NULL;
1113 if (!m_messageData) {
1114 //error if platform message not exists
1115 LoggerE("message can not be updated");
1116 Throw(WrtDeviceApis::Commons::PlatformException);
1122 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1123 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1125 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
1127 if (err != MSG_SUCCESS)
1129 LoggerE("msg_get_message() Failed!");
1130 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to get message for update");
1133 if (this->getIdRef().empty()) {
1134 LoggerE("existing msgId is zero, update msg not done");
1135 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1136 "existing msgId is zero, update msg not done");
1139 err = msg_get_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1140 if(err == MSG_SUCCESS)
1142 msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
1145 err = msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1146 if(err == MSG_SUCCESS)
1148 msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1153 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
1155 LoggerE("msg_update_message() Failed!");
1156 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
1158 msg_release_struct(&msg);
1159 msg_release_struct(&sendOpt);
1161 Catch(WrtDeviceApis::Commons::PlatformException) {
1162 msg_release_struct(&msg);
1163 msg_release_struct(&sendOpt);
1164 LoggerE("platform error occurs");
1165 ReThrow(WrtDeviceApis::Commons::PlatformException);
1170 void Mms::createSendMessage()
1172 LoggerD("convert m_id= " << convertId(getIdRef()));
1174 msg_struct_t sendOpt = NULL;
1176 //prepare for add sms to draft folder
1177 if (!m_messageData) {
1178 //error if platform message not exists
1179 LoggerE("message can not be updated");
1180 Throw(WrtDeviceApis::Commons::PlatformException);
1183 //update all mms data
1184 if (getCurrentFolder() == DRAFTBOX) {
1185 LoggerD("update all mms data");
1187 updateBodyAndAttachments();
1188 updateRecipientList();
1195 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1196 // trying to add message
1198 // msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
1200 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
1201 if (ret < MSG_SUCCESS) {
1202 LoggerE("msg_add_message failed, error code=" << ret);
1203 Throw(WrtDeviceApis::Commons::PlatformException);
1210 LoggerD("Message ID : " << msgId);
1212 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1214 setId(convertId(msgId));
1217 setFolderType(OUTBOX);
1218 setMessageStatus(MESSAGE_STATUS_DRAFT);
1220 msg_release_struct(&sendOpt);
1222 Catch(WrtDeviceApis::Commons::PlatformException) {
1223 LoggerE("remove message error");
1224 msg_release_struct(&sendOpt);
1229 void Mms::addMessageToDraft()
1231 LoggerD("convert m_id= " << convertId(getIdRef()));
1233 msg_struct_t sendOpt = NULL;
1235 //prepare for add sms to draft folder
1236 if (!m_messageData) {
1237 //error if platform message not exists
1238 LoggerE("message can not be updated");
1239 Throw(WrtDeviceApis::Commons::PlatformException);
1242 //update all mms data
1243 if (getCurrentFolder() == DRAFTBOX) {
1245 updateBodyAndAttachments();
1246 updateRecipientList();
1253 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1255 // trying to add message
1256 LoggerD("add message");
1257 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
1258 if (ret < MSG_SUCCESS) {
1259 LoggerE("msg_add_message failed, error code=" << ret);
1260 Throw(WrtDeviceApis::Commons::PlatformException);
1267 LoggerD("Message ID : " << msgId);
1270 LoggerD("Message ID is invailded ");
1271 Throw(WrtDeviceApis::Commons::PlatformException);
1274 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1276 setId(convertId(msgId));
1279 msg_release_struct(&sendOpt);
1282 Catch(WrtDeviceApis::Commons::PlatformException) {
1283 LoggerE("add draft message error");
1284 msg_release_struct(&sendOpt);
1290 void Mms::loadDraftMessage()
1294 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
1296 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
1299 msg_release_struct(&m_messageData);
1300 m_messageData = NULL;
1301 msg_struct_t sendOpt = NULL;
1305 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1306 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1308 // trying to get message from platform
1309 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
1311 LoggerE("get message error");
1312 Throw(WrtDeviceApis::Commons::PlatformException);
1314 LoggerD("message found with msgId=" << getIdRef());
1316 // read all mms dat to abstraction layer
1317 readConversationId(m_messageData);
1318 readPriority(m_messageData);
1319 readSubject(m_messageData);
1320 readFolder(m_messageData);
1321 readDateTime(m_messageData);
1322 readReadStatus(m_messageData);
1323 readMessageStatus(m_messageData);
1324 readBody(m_messageData);
1326 msg_release_struct(&sendOpt);
1328 Catch(WrtDeviceApis::Commons::PlatformException) {
1329 LoggerE("exception");
1331 msg_release_struct(&sendOpt);
1336 void Mms::readAllData()
1340 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
1342 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
1345 msg_release_struct(&m_messageData);
1346 m_messageData = NULL;
1347 msg_struct_t sendOpt = NULL;
1351 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1352 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1354 // trying to get message from platform
1355 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
1357 LoggerE("get message error");
1358 Throw(WrtDeviceApis::Commons::PlatformException);
1360 LoggerD("message found with msgId=" << getIdRef());
1362 // read all mms dat to abstraction layer
1363 readConversationId(m_messageData);
1364 // readRecipientList(m_messageData);
1365 readPriority(m_messageData);
1366 readSubject(m_messageData);
1367 readBodyAndAttachments(m_messageData);
1368 readFolder(m_messageData);
1369 readDateTime(m_messageData);
1370 readReadStatus(m_messageData);
1371 readMessageStatus(m_messageData);
1373 msg_release_struct(&sendOpt);
1375 Catch(WrtDeviceApis::Commons::PlatformException) {
1376 LoggerE("exception");
1378 msg_release_struct(&sendOpt);
1383 void Mms::moveToFolder(const FolderType newFolder)
1390 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1393 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1394 platfromFolderId) != MSG_SUCCESS) {
1395 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error during movinf message");
1399 Catch(WrtDeviceApis::Commons::PlatformException) {
1400 LoggerE("remove message error");
1406 void Mms::moveToFolder(const string& newFolder)
1413 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1416 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1417 platfromFolderId) != MSG_SUCCESS) {
1418 LoggerE("msg_move_msg_to_folder error");
1419 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_move_msg_to_folder error");
1423 Catch(WrtDeviceApis::Commons::PlatformException) {
1424 LoggerE("remove message error");
1430 void Mms::copyToFolder(const FolderType newFolder)
1435 msg_message_t msg = msg_new_message();
1439 MSG_SENDINGOPT_S option = { false, false, false };
1440 option.option.smsSendOpt.bReplyPath = true;
1442 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1444 const msg_folder_id_t platfromFolderId =
1445 Messaging::convertFolderToPlatform(newFolder);
1446 msg_set_message_id(msg, 0);
1447 msg_set_folder_id(msg, platfromFolderId);
1449 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1450 if (error != MSG_SUCCESS) {
1451 LoggerE("msg_add_message failed, error code=" << error);
1452 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1456 msg_release_message(&msg);
1460 Catch(WrtDeviceApis::Commons::PlatformException) {
1461 LoggerE("remove message error");
1463 msg_release_message(&msg);
1470 void Mms::copyToFolder(const string& newFolder)
1475 msg_message_t msg = msg_new_message();
1479 MSG_SENDINGOPT_S option = { false, false, false };
1480 option.option.smsSendOpt.bReplyPath = true;
1482 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1484 const msg_folder_id_t platfromFolderId =
1485 Messaging::convertFolderToPlatform(newFolder);
1486 msg_set_message_id(msg, 0);
1487 msg_set_folder_id(msg, platfromFolderId);
1489 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1490 if (error != MSG_SUCCESS) {
1491 LoggerE("msg_add_message failed, error code=" << error);
1492 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1496 msg_release_message(&msg);
1500 Catch(WrtDeviceApis::Commons::PlatformException) {
1501 LoggerE("remove message error");
1503 msg_release_message(&msg);
1512 LoggerD("delete m_id=" << getIdRef());
1516 if (this->getIdRef().empty()) {
1517 LoggerE("existing msgId is zero, remove msg not done");
1518 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1519 "existing msgId is zero, remove msg not done");
1523 msg_delete_message(MsgGetCommonHandle(),
1524 convertId(getIdRef()))) {
1525 LoggerE("Failed to delete Message");
1526 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
1530 Catch(WrtDeviceApis::Commons::PlatformException) {
1531 LoggerE("platform error occurs");
1537 LoggerD("sending message, id=" << getIdRef());
1538 msg_error_t err = MSG_SUCCESS;
1542 //prepare for sending sms/mms
1545 LoggerD("trying to send mms");
1546 if (!getCellularOn())
1548 err = MSG_ERR_TRANSPORT_ERROR;
1549 LoggerW("MMS send error. No transport possible over network");
1553 err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
1556 if (err != MSG_SUCCESS)
1558 LoggerE("Sending Message (submit request) failed!!! err=" << err);
1559 setMessageStatus(MESSAGE_STATUS_FAILED);
1560 Throw(WrtDeviceApis::Commons::PlatformException);
1563 setMessageStatus(MESSAGE_STATUS_SENDING);
1565 LoggerD("Sending Message request is submitted!");
1567 Catch(WrtDeviceApis::Commons::PlatformException) {
1568 LoggerE("message is not send, manually run callback");
1569 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1570 if (requestReceiver) {
1571 LoggerE("send Error");
1572 EventMessagingServicePtr event = getMessagingServiceEvent();
1573 if(err == MSG_ERR_TRANSPORT_ERROR)
1575 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::PlatformWrongStateException);
1579 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1581 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
1588 void Mms::sendingCallback(msg_struct_t sent_status)
1590 int status = MSG_NETWORK_SEND_FAIL;
1591 msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
1593 LoggerD("status : " << status);
1595 if (MSG_NETWORK_SEND_SUCCESS == status) {
1596 LoggerD("sending ok");
1597 setSendingStatusOk();
1598 setMessageStatus(MESSAGE_STATUS_SENT);
1600 LoggerE("sending failed: " << static_cast<unsigned int>(status));
1601 setSendingStatusFailed();
1602 setMessageStatus(MESSAGE_STATUS_FAILED);
1606 void Mms::sendCancel(int handle)
1608 LoggerD("sending message, id=" << getIdRef());
1610 LoggerD("handle =" << handle);
1613 void Mms::setSendingStatusOk()
1615 //success callback should be executed here
1616 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1617 msg_struct_list_s *addr_list = NULL;
1618 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1621 if (requestReceiver) {
1622 LoggerI("calling JS success callback");
1623 EventMessagingServicePtr event = getMessagingServiceEvent();
1624 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
1626 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1628 nToCnt = addr_list->nCount;
1630 for ( int index=0; index < nToCnt; index++)
1632 msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1633 event->m_successRecipients.push_back(strNumber);
1636 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1640 void Mms::setSendingStatusFailed()
1642 //error callback should be executed here
1643 EventOnSendingFailedEmitterPtr emitter = getEmitter();
1644 msg_struct_list_s *addr_list = NULL;
1645 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1650 EventOnSendingFailedPtr event(new EventOnSendingFailed);
1651 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
1652 emitter->emit(event);
1656 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1657 EventMessagingServicePtr event = getMessagingServiceEvent();
1658 if (requestReceiver)
1660 LoggerE("calling JS error callback");
1661 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1662 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1663 nToCnt = addr_list->nCount;
1665 LoggerD("nToCnt : " << nToCnt);
1667 for ( int index=0; index < nToCnt; index++)
1669 msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1670 event->m_failRecipients.push_back(strNumber);
1673 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1678 FolderType Mms::toFolder(const std::string &folder)
1680 if (folder == "INBOX") {
1682 } else if (folder == "OUTBOX") {
1684 } else if (folder == "SENTBOX") {
1686 } else if (folder == "DRAFTBOX") {
1689 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
1692 bool Mms::getCellularOn()
1694 auto cellularOn = true;
1698 vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &tempInt);
1699 vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &tempbool);
1700 if(tempInt <= VCONFKEY_TELEPHONY_SVCTYPE_SEARCH || tempbool == TRUE)
1702 LoggerE("VCONFKEY_TELEPHONY_SVCTYPE error " << tempInt);
1703 LoggerE("VCONFKEY_TELEPHONY_FLIGHT_MODE error " << tempbool);
1708 vconf_get_bool(VCONFKEY_3G_ENABLE, &tempbool);
1709 vconf_get_int(VCONFKEY_TELEPHONY_SVC_PS, &tempInt);
1710 if(tempbool == FALSE || tempInt != VCONFKEY_TELEPHONY_SVC_PS_ON)
1712 LoggerE("VCONFKEY_3G_ENABLE error " << tempbool);
1713 LoggerE("VCONFKEY_TELEPHONY_SVC_PS_ON error " << tempInt);
1720 MimeType Mms::mimeTypeStringToIndexInt(std::string inputString)
1722 const char* szMimeStr = inputString.c_str();
1723 MimeType retInt = MIME_UNKNOWN;
1725 LoggerD("szMimeStr " << szMimeStr);
1727 for(int idx =0; strcmp(mimeTable[idx].szMIME, "") != 0; idx++)
1729 if (!strcmp(mimeTable[idx].szMIME, szMimeStr)) {
1730 retInt = mimeTable[idx].mime;
1738 std::string Mms::indexIntToMimeTypeString(MimeType inputIndex)
1740 std::string retString;
1742 for (int idx=0; mimeTable[idx].szMIME != NULL; idx++) {
1743 if (inputIndex == mimeTable[idx].mime) {
1744 retString = (char *)mimeTable[idx].szMIME;
1750 msg_struct_t Mms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
1752 int tempInt, nCount, ret;
1754 msg_struct_list_s *addr_list;
1755 msg_struct_list_s *new_addr_list;
1757 msg_struct_t mms_struct = NULL;
1758 msg_struct_t mms_struct_dummy = NULL;
1760 msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1762 msg_set_int_value(msg, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
1764 char strSubject[MAX_SUBJECT_LEN] = {0};
1765 msg_get_str_value(src, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
1766 msg_set_str_value(msg, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
1768 msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1769 msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1771 msg_get_int_value(src, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
1772 msg_set_int_value(msg, MSG_MESSAGE_THREAD_ID_INT, tempInt);
1774 msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1775 msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1777 // msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1778 // char tempStr[tempInt+1];
1779 // memset(tempStr, 0, tempInt+1);
1781 // msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1782 // msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1783 // copy mms body and attachment
1784 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
1785 mms_struct_dummy = msg_create_struct(MSG_STRUCT_MMS);
1786 ret = msg_get_mms_struct(src, mms_struct);
1787 if (ret != MSG_SUCCESS)
1789 LoggerE("cannot get mms struct");
1790 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
1793 msg_set_mms_struct(src, mms_struct_dummy);
1794 msg_set_mms_struct(msg, mms_struct);
1796 msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1797 msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1799 // msg_set_network_status(msg, msg_get_network_status(src));
1800 msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1801 msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
1803 // msg_set_encode_type(msg, msg_get_encode_type(src));
1804 msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1805 msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT, tempInt);
1807 // msg_set_read_status(msg, msg_is_read(src));
1808 msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1809 msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1811 // msg_set_protect_status(msg, msg_is_protected(src));
1812 msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1813 msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1815 // msg_set_priority_info(msg, msg_get_priority_info(src));
1816 msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1817 msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT, tempInt);
1819 // msg_set_direction_info(msg, msg_get_direction_info(src));
1820 msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1821 msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT, tempInt);
1823 // msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1824 msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1825 msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT, tempInt);
1826 msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1827 msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT, tempInt);
1830 msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1831 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
1833 new_addr_list->nCount = addr_list->nCount;
1835 for(int i=0; i<addr_list->nCount; i++)
1837 msg_struct_t addr_info = NULL;
1838 msg_struct_t new_addr_info = NULL;
1839 char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
1841 //get original address
1842 addr_info = addr_list->msg_struct_info[i];
1843 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1844 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
1846 //copy original address
1847 new_addr_info = new_addr_list->msg_struct_info[i];
1848 msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1849 msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);
1852 msg_release_struct(&mms_struct_dummy);
1853 msg_release_struct(&mms_struct);