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) :
81 LoggerD("m_id=" << getIdRef());
82 LoggerD("m_msgType=" << getMessageType());
84 LoggerD("created msg_data : " << msg_data);
85 m_messageData = createNewCopyOfPLatformMsgWithAddressList(msg_data);
86 LoggerD("created m_messageData : " << m_messageData);
88 char buf[] = "XXXXXX";
89 mode_t mask = umask(S_IWGRP | S_IWOTH);
91 LoggerD("buf : " << buf << " i : " << i);
94 m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
96 LoggerD("m_bodyFilePath : " << m_bodyFilePath);
98 readConversationId(m_messageData);
99 readRecipientList(m_messageData);
100 readPriority(m_messageData);
101 readSubject(m_messageData);
102 readBodyAndAttachments(m_messageData);
103 readFolder(m_messageData);
104 readDateTime(m_messageData);
105 readReadStatus(m_messageData);
106 readMessageStatus(m_messageData);
107 // setMessageStatus(MESSAGE_STATUS_LOADED);
116 // release platform message structure
117 // msg_release_message(&m_messageData);
118 msg_release_struct(&m_messageData);
122 //trying to remove file, return value is skipped
123 if (!m_bodyFilePath.empty()) {
124 LoggerD("remove tmp file=" << m_bodyFilePath);
125 (void) ::remove(m_bodyFilePath.c_str());
129 void Mms::createNewMessage()
132 msg_release_struct(&m_messageData);
133 m_messageData = NULL;
136 char strSubject[MAX_SUBJECT_LEN] = {0,};
138 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
139 msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
140 // msg_struct_t option = NULL;
142 // initialize platform message structure
143 msg_set_int_value(m_messageData, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
144 msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
145 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
147 setMmsType(MULTIPART_MIXED);
148 setReadStatus(false);
149 setMessageStatus(MESSAGE_STATUS_CREATED);
151 msg_release_struct(&sendOpt);
152 LoggerD("Message created successfully, Id: " << getIdRef());
155 void Mms::readExistingMessage()
159 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
161 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
164 msg_release_struct(&m_messageData);
165 m_messageData = NULL;
166 msg_struct_t sendOpt = NULL;
170 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
171 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
173 // trying to get message from platform
174 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
176 LoggerE("get message error");
177 Throw(WrtDeviceApis::Commons::PlatformException);
179 LoggerD("message found with msgId=" << getIdRef());
181 // read all mms dat to abstraction layer
182 readConversationId(m_messageData);
183 readRecipientList(m_messageData);
184 readPriority(m_messageData);
185 readSubject(m_messageData);
186 readBodyAndAttachments(m_messageData);
187 readFolder(m_messageData);
188 readDateTime(m_messageData);
189 readReadStatus(m_messageData);
190 readMessageStatus(m_messageData);
192 msg_release_struct(&sendOpt);
194 Catch(WrtDeviceApis::Commons::PlatformException) {
195 LoggerE("exception");
197 msg_release_struct(&sendOpt);
201 void Mms::readDateTime(msg_struct_t& messageData)
203 // tm* time = localtime(msg_get_time(messageData));
204 // tm dateT = getDateTime();
206 msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
208 LoggerE("readDateTime : " <<tempInt);
210 tm* time = localtime((time_t*)&tempInt);
212 LoggerE("localtime failed");
213 Throw(WrtDeviceApis::Commons::PlatformException);
218 void Mms::readReadStatus(msg_struct_t& messageData)
221 msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
222 setReadStatus(tempBool);
225 void Mms::readFolder(msg_struct_t& messageData)
228 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
232 setFolderType(INBOX);
235 setFolderType(OUTBOX);
238 setFolderType(SENTBOX);
241 setFolderType(DRAFTBOX);
244 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
248 void Mms::readMessageStatus(msg_struct_t& messageData)
251 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
253 LoggerD("readMessageStatus folder : " << tempValue);
257 setMessageStatus(MESSAGE_STATUS_LOADED);
260 setMessageStatus(MESSAGE_STATUS_SENDING);
263 setMessageStatus(MESSAGE_STATUS_SENT);
266 setMessageStatus(MESSAGE_STATUS_DRAFT);
269 setMessageStatus(MESSAGE_STATUS_LOADED);
274 void Mms::readPriority(msg_struct_t& messageData)
276 // switch (msg_get_priority_info(messageData)) {
278 msg_get_int_value(messageData, MSG_MESSAGE_PRIORITY_INT, &tempInt);
280 case MSG_MESSAGE_PRIORITY_LOW:
281 setPriority(MessagePriority::LOW);
283 case MSG_MESSAGE_PRIORITY_NORMAL:
284 setPriority(MessagePriority::NORMAL);
286 case MSG_MESSAGE_PRIORITY_HIGH:
287 setPriority(MessagePriority::HIGH);
290 LoggerE("Wrong priority type");
291 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong priority type");
295 void Mms::readConversationId(msg_struct_t& messageData)
298 msg_get_int_value(messageData, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
299 LoggerD("conversationID : " <<tempInt);
303 void Mms::readRecipientList(msg_struct_t& messageData)
305 std::string phoneNumber;
306 // int recipientCount = msg_get_address_count(messageData);
307 // LoggerD("Recipient count " << recipientCount);
309 msg_struct_list_s *addr_list;
310 msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
313 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
315 int recipientCount = addr_list->nCount;
316 LoggerD("Recipient count " << recipientCount);
318 for (int i = 0; i < recipientCount; ++i)
320 // int type = msg_get_direction_info(messageData);
321 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
323 LoggerD("Direction: " << type);
325 if (MSG_DIRECTION_TYPE_MT == type)
327 msg_struct_t addr_info = addr_list->msg_struct_info[i];
328 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
329 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
330 phoneNumber = strNumber;
332 if (validatePhoneNumber(phoneNumber))
334 setSourceAddress(phoneNumber);
335 setFrom(phoneNumber);
337 LoggerD("MT number: " << phoneNumber);
339 else if (MSG_DIRECTION_TYPE_MO == type)
341 msg_struct_t addr_info = addr_list->msg_struct_info[i];
342 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
343 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
344 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
345 LoggerD("MO number: " << strNumber);
346 LoggerD("Type : " << tempInt);
349 case MSG_RECIPIENTS_TYPE_TO:
350 appendToRecipients(strNumber);
352 case MSG_RECIPIENTS_TYPE_CC:
353 appendCcRecipients(strNumber);
355 case MSG_RECIPIENTS_TYPE_BCC:
356 appendBccRecipients(strNumber);
359 LoggerE("Wrong type of recipient");
364 LoggerE("Wrong type of recipient");
365 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
370 void Mms::readSubject(msg_struct_t& messageData)
372 char strTemp[MAX_SUBJECT_LEN] = {0};
373 msg_get_str_value(messageData, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
374 // setSubject(msg_get_subject(messageData));
375 LoggerE("readSubject : " << strTemp);
379 void Mms::readBodyAndAttachments(msg_struct_t& messageData)
382 int pageLen, mediaLen, attachLen, tempInt, ret;
384 msg_struct_t mms_struct = NULL;
386 msg_list_handle_t page_list = NULL;
387 msg_list_handle_t media_list = NULL;
388 msg_list_handle_t attach_list = NULL;
390 msg_struct_t page = NULL;
391 msg_struct_t media = NULL;
392 msg_struct_t attach = NULL;
394 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
395 ret = msg_get_mms_struct(messageData, mms_struct);
397 if (ret != MSG_SUCCESS)
399 LoggerE("cannot get mms struct");
400 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
403 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
404 char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
406 msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
407 pageLen = msg_list_length(page_list);
410 setMmsType(MULTIPART_RELATED);
412 setMmsType(MULTIPART_MIXED);
415 LoggerD("page count: " << pageLen);
417 for (int p = 0; p < pageLen; ++p)
419 LoggerD("page " << p);
420 page = (msg_struct_t)msg_list_nth_data(page_list, p);
423 LoggerE("returned page is null, continue");
427 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
428 mediaLen = msg_list_length(media_list);
430 for (int m = 0; m < mediaLen; ++m)
432 LoggerD("media file " << m);
433 media = (msg_struct_t)msg_list_nth_data(media_list, m);
436 LoggerE("returned media is null, continue");
440 msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
442 memset(szFilePath, 0, sizeof(szFilePath));
443 msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
445 if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt))
447 //text value on first page goes to body attribute
448 LoggerD("setting body from " << szFilePath);
451 f = fopen(szFilePath, "r");
454 LoggerE("cannot read file with body" << szFilePath);
455 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
457 fseek(f, 0, SEEK_END);
458 long int size = ftell(f);
459 fseek(f, 0, SEEK_SET);
460 char* data = new (nothrow) char[size + 1];
463 memset(data, 0, size + 1);
464 error = fread(data, 1, size, f);
468 LoggerE("body is not set");
470 LoggerD("message body: '" << getBody() << "'");
475 LoggerD("adding attachment " << szFilePath);
477 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
478 //attachment->setMessage(this); //set IMessagePtr
480 memset(szFileName, 0, sizeof(szFileName));
481 msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
482 if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0))
484 LoggerD("renaming to " << szFileName);
485 attachment->rename(szFileName);
487 else if (MMS_SMIL_MEDIA_TEXT == tempInt)
489 std::stringstream newName;
490 newName << "body_page_" << p + 1 << ".txt";
491 LoggerD("renaming to " << newName.str());
492 attachment->rename(newName.str());
498 msg_get_list_handle(mms_struct, MSG_MMS_ATTACH_LIST_HND, (void **)&attach_list);
500 attachLen= msg_list_length(attach_list);
502 LoggerD("attachment count: " << attachLen);
503 for (int a = 0; a < attachLen; ++a)
505 std::string tempString;
508 attach = (msg_struct_t)msg_list_nth_data(attach_list, a);
511 LoggerE("attachment is null, continue");
515 memset(szFilePath, 0, sizeof(szFilePath));
516 memset(szFileName, 0, sizeof(szFileName));
518 msg_get_str_value(attach, MSG_MMS_ATTACH_FILEPATH_STR, szFilePath, sizeof(szFilePath));
519 msg_get_str_value(attach, MSG_MMS_ATTACH_FILENAME_STR, szFileName, sizeof(szFileName));
521 msg_get_int_value(attach, MSG_MMS_ATTACH_MIME_TYPE_INT, &tempInt);
522 tempString = indexIntToMimeTypeString((MimeType)tempInt);
524 IAttachmentPtr att = appendAttachment(szFilePath, false);
525 if ((szFileName[0] =! '\0') &&
526 strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0) {
527 LoggerD("renaming to " << szFileName);
528 att->rename(szFileName);
530 att->setMimeType(tempString);
531 att->setAttachmentID((int)a);
532 att->setDownloaded(true);
534 msg_release_struct(&mms_struct);
537 void Mms::readBody(msg_struct_t& messageData)
540 int pageLen, mediaLen, tempInt, ret;
542 msg_struct_t mms_struct = NULL;
544 msg_list_handle_t page_list = NULL;
545 msg_list_handle_t media_list = NULL;
547 msg_struct_t page = NULL;
548 msg_struct_t media = NULL;
550 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
551 ret = msg_get_mms_struct(messageData, mms_struct);
553 if (ret != MSG_SUCCESS)
555 LoggerE("cannot get mms struct");
556 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
559 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
560 char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
562 msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
563 pageLen = msg_list_length(page_list);
566 setMmsType(MULTIPART_RELATED);
568 setMmsType(MULTIPART_MIXED);
571 LoggerD("page count: " << pageLen);
573 for (int p = 0; p < pageLen; ++p)
575 LoggerD("page " << p);
576 page = (msg_struct_t)msg_list_nth_data(page_list, p);
579 LoggerE("returned page is null, continue");
583 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
584 mediaLen = msg_list_length(media_list);
586 for (int m = 0; m < mediaLen; ++m)
588 LoggerD("media file " << m);
589 media = (msg_struct_t)msg_list_nth_data(media_list, m);
592 LoggerE("returned media is null, continue");
596 msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
598 memset(szFilePath, 0, sizeof(szFilePath));
599 msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
601 if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt))
603 //text value on first page goes to body attribute
604 LoggerD("setting body from " << szFilePath);
607 f = fopen(szFilePath, "r");
610 LoggerE("cannot read file with body" << szFilePath);
611 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
613 fseek(f, 0, SEEK_END);
614 long int size = ftell(f);
615 fseek(f, 0, SEEK_SET);
616 char* data = new (nothrow) char[size + 1];
619 memset(data, 0, size + 1);
620 error = fread(data, 1, size, f);
624 LoggerE("body is not set");
626 LoggerD("message body: '" << getBody() << "'");
631 LoggerD("adding attachment " << szFilePath);
633 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
634 //attachment->setMessage(this); //set IMessagePtr
636 memset(szFileName, 0, sizeof(szFileName));
637 msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
638 if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0))
640 LoggerD("renaming to " << szFileName);
641 attachment->rename(szFileName);
643 else if (MMS_SMIL_MEDIA_TEXT == tempInt)
645 std::stringstream newName;
646 newName << "body_page_" << p + 1 << ".txt";
647 LoggerD("renaming to " << newName.str());
648 attachment->rename(newName.str());
653 msg_release_struct(&mms_struct);
657 bool Mms::hasAttachment()
659 std::size_t attachmentSize = getAttachmentsCount();
660 if ( attachmentSize > 0)
666 void Mms::update(bool draftsOnly)
668 LoggerD("updating m_id=" << getIdRef());
670 if (!m_messageData) {
671 //error if platform message not exists
672 LoggerE("message can not be updated");
673 Throw(WrtDeviceApis::Commons::PlatformException);
676 //update mms data from abstraction
677 if (!draftsOnly || getCurrentFolder() == DRAFTBOX) {
679 updateBodyAndAttachments();
680 updateRecipientList();
686 void Mms::updatePriority()
688 if (isPriorityValid()) {
692 LoggerI("MMS updating priority");
694 //set priority in platform
695 switch (getPriority()) {
696 case MessagePriority::LOW:
697 priority = MSG_MESSAGE_PRIORITY_LOW;
699 case MessagePriority::NORMAL:
700 priority = MSG_MESSAGE_PRIORITY_NORMAL;
702 case MessagePriority::HIGH:
703 priority = MSG_MESSAGE_PRIORITY_HIGH;
706 LoggerE("Wrong priority");
707 Throw(WrtDeviceApis::Commons::PlatformException);
709 LoggerI("priority : " << priority);
712 msg_set_int_value(m_messageData, MSG_MESSAGE_PRIORITY_INT, priority)){
714 LoggerE("Error during setting priority");
715 Throw(WrtDeviceApis::Commons::PlatformException);
719 void Mms::updateRecipientList()
721 // check if abstraction recipient value has been changed
722 if (getToRecipients().isValid() &&
723 getBccRecipients().isValid() &&
724 getCcRecipients().isValid()) {
728 LoggerI("MMS updating platform recipients");
730 // reset addresses in platform structure
731 // msg_reset_address(m_messageData);
732 msg_struct_list_s *addr_list = NULL;
733 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
735 nToCnt = addr_list->nCount;
737 LoggerI("addr_list->nCount" << addr_list->nCount);
741 for (int i = 0; i < nToCnt; i++) {
742 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, (char *)"", 0);
743 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, (char *)"", 0);
744 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
745 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
746 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
749 addr_list->nCount = nToCnt;
752 LoggerI("addr_list->nCount" << addr_list->nCount);
754 vector<string> to = getToRecipients().getRecipients();
755 vector<string> cc = getCcRecipients().getRecipients();
756 vector<string> bcc = getBccRecipients().getRecipients();
758 // update addresses in platform structure
761 LoggerI("updating to");
762 for (size_t i = 0; i < to.size(); i++)
764 if (i >= MAX_TO_ADDRESS_CNT)
766 LoggerE("max number of recipient exceeded");
769 LoggerD("adding to[" << i << "]=" << to[i]);
771 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
773 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
774 MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
776 LoggerE("problem with adding to address");
777 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
780 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
781 const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
783 LoggerE("problem with adding to address");
784 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
788 addr_list->nCount = nToCnt;
789 LoggerE("nToCnt : " << nToCnt);
790 LoggerE("addr_list->nCount: " <<addr_list->nCount);
794 LoggerI("addr_list->nCount" << addr_list->nCount);
798 LoggerI("updating cc");
799 for (size_t i = 0; i < cc.size(); i++)
801 if (nToCnt >= MAX_TO_ADDRESS_CNT)
803 LoggerE("max number of recipient exceeded");
806 LoggerD("adding cc[" << i << "]=" << cc[i]);
808 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
810 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
811 MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS)
813 LoggerE("problem with adding cc address");
814 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
817 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
818 const_cast<char*>(cc[i].c_str()), cc[i].size()) != MSG_SUCCESS)
820 LoggerE("problem with adding cc address");
821 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
825 addr_list->nCount = nToCnt;
826 LoggerE("nToCnt : " << nToCnt);
827 LoggerE("addr_list->nCount: " <<addr_list->nCount);
830 LoggerI("addr_list->nCount" << addr_list->nCount);
834 LoggerI("updating bcc");
835 for (size_t i = 0; i < bcc.size(); i++)
837 if (nToCnt >= MAX_TO_ADDRESS_CNT)
839 LoggerE("max number of recipient exceeded");
842 LoggerD("adding bcc[" << i << "]=" << bcc[i]);
844 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
846 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
847 MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS)
849 LoggerE("problem with adding bcc address");
850 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
853 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
854 const_cast<char*>(bcc[i].c_str()), bcc[i].size()) != MSG_SUCCESS)
856 LoggerE("problem with adding bcc address");
857 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
861 addr_list->nCount = nToCnt;
862 LoggerE("nToCnt : " << nToCnt);
863 LoggerE("addr_list->nCount: " <<addr_list->nCount);
866 LoggerI("addr_list->nCount" << addr_list->nCount);
869 setBccValidity(true);
872 void Mms::updateSubject()
874 // check if abstraction subject value has been changed
875 if (isSubjectValid()) {
878 LoggerI("updating platform subject: " << getSubjectRef());
880 // msg_set_subject(m_messageData, getSubjectRef().c_str())) {
881 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, const_cast<char*>(getSubjectRef().c_str()), MAX_SUBJECT_LEN)) {
883 LoggerE("problem with setting subject");
884 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
886 setSubjectValidity(true);
889 void Mms::updateBodyAndAttachments()
891 // check if attachment or body source address value has been changed
892 if (isAttachmentsValid() && isBodyValid()) {
896 // MMS_MESSAGE_DATA_S *mmsData = NULL;
897 msg_struct_t mms_struct = NULL;
898 // msg_struct_t old_mms_struct = NULL;// THIS
901 LoggerI("updating platform body and attachment");
905 msg_struct_t region[1];
906 msg_struct_t page[1];
907 msg_struct_t media[1];
908 msg_struct_t smil_text[1];
910 if (getMessageType() != MMS) {
911 LoggerE("Wrong msg type");
912 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong msg type");
914 // mmsData = msg_mms_create_message();
915 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
916 // old_mms_struct = msg_create_struct(MSG_STRUCT_MMS);// THIS
918 // ret = msg_get_mms_struct(m_messageData, old_mms_struct);// THIS
919 // LoggerE("ret " << ret);// THIS
920 // ret = msg_release_struct(&old_mms_struct);// THIS
921 // LoggerE("ret " << ret);// THIS
924 LoggerE("create message body failed");
925 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "create message body failed");
929 if (!getBodyRef().empty()) {
931 f = fopen(m_bodyFilePath.c_str(), "w");
933 LoggerE("cannot create file with body" << m_bodyFilePath);
934 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
935 "cannot create file with body");
937 LoggerD("body file: " << m_bodyFilePath);
938 fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
942 LoggerD("getBodyRef(): " << getBodyRef());
944 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_INT, ROOT_LAYOUT_WIDTH);
945 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
946 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_BGCOLOR_INT, WHITE_COLOR);
947 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL, true);
948 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL, true);
950 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_REGION, ®ion[0]);
951 msg_set_str_value(region[0], MSG_MMS_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
952 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
953 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_TOP_INT, 0);
954 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_INT, ROOT_LAYOUT_WIDTH);
955 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
956 msg_set_int_value(region[0], MSG_MMS_REGION_BGCOLOR_INT, WHITE_COLOR);
958 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL, true);
959 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL, true);
960 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL, true);
961 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL, true);
963 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_PAGE, &page[0]);
964 msg_set_int_value(page[0], MSG_MMS_PAGE_PAGE_DURATION_INT, 0);
966 msg_mms_add_item(page[0], MSG_STRUCT_MMS_MEDIA, &media[0]);
967 msg_set_int_value(media[0], MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT);
968 msg_set_str_value(media[0], MSG_MMS_MEDIA_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
970 error = msg_set_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, const_cast<char*>(m_bodyFilePath.c_str()),MSG_FILEPATH_LEN_MAX);
971 LoggerD("bodyFile Path= " << m_bodyFilePath);
972 LoggerD("error= " << error);
973 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
974 memset(szFilePath, 0, sizeof(szFilePath));
975 msg_get_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
976 LoggerD("bodyFile Path= " << m_bodyFilePath);
978 msg_get_struct_handle(media[0], MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text[0]);
979 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_COLOR_INT, BLACK_COLOR);
980 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_SIZE_INT, MMS_SMIL_FONT_SIZE_NORMAL);
981 msg_set_bool_value(smil_text[0], MSG_MMS_SMIL_TEXT_BOLD_BOOL, true);
989 msg_struct_t attachment[20];
991 for (size_t idx = 0; idx < getAttachmentsRef().size(); ++idx) {
992 IAttachmentPtr att = getAttachment(idx);
997 LoggerD("Add attachment=" << att->getFullPath());
999 errnum = stat(att->getFullPath().c_str(), &buffer);
1000 LoggerD("errnum=" << errnum);
1003 LoggerE("Opening file: " << att->getFullPath().c_str());
1004 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1005 "cannot open attachment file");
1008 //this function should return valid pointer
1009 att->setMessage(SharedFromThis()); // setMessage to setMessageId
1010 att->setAttachmentID((int)idx);
1011 att->setDownloaded(true);
1013 int ret = mimeTypeStringToIndexInt(att->getMimeType());
1015 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[idx]);
1016 msg_set_str_value(attachment[idx], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
1018 if(ret != MIME_UNKNOWN)
1020 msg_set_int_value(attachment[idx], MSG_MMS_ATTACH_MIME_TYPE_INT, ret);
1023 LoggerD("Attachment added");
1029 if (MSG_SUCCESS !=msg_set_mms_struct(m_messageData, mms_struct))
1031 LoggerE("set message body error");
1032 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set message body error");
1035 msg_release_struct(&mms_struct);
1037 setAttachmentsValidity(true);
1038 setBodyValidity(true);
1041 Catch(WrtDeviceApis::Commons::PlatformException) {
1042 LoggerE("Platform error");
1043 msg_release_struct(&mms_struct);
1049 void Mms::updateReadStatus()
1051 if (isReadStatusValid()) {
1055 LoggerI("updating platform read status: " << isRead());
1056 // if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
1057 if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
1058 LoggerE("problem with setting subject");
1059 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
1062 setReadStatusValidity(true);
1065 void Mms::updateIsRead()
1067 LoggerD("updating m_id=" << getIdRef());
1069 if (!m_messageData) {
1070 //error if platform message not exists
1071 LoggerE("message can not be updated");
1072 Throw(WrtDeviceApis::Commons::PlatformException);
1075 // check if abstraction from m_isReadChange value has been changed
1076 if (isReadChangeStatusValid()) {
1077 // do not update if not changed
1083 if (this->getIdRef().empty()) {
1084 LoggerE("existing msgId is zero, remove msg not done");
1085 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1086 "existing msgId is zero, remove msg not done");
1090 msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
1092 LoggerE("Failed to update isRead");
1093 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
1096 Catch(WrtDeviceApis::Commons::PlatformException) {
1097 LoggerE("platform error occurs");
1099 setisReadChangeStatusValidity(true);
1103 void Mms::updateMessage()
1105 LoggerD("updating m_id=" << getIdRef());
1106 msg_error_t err = MSG_SUCCESS;
1107 msg_struct_t msg = NULL;
1108 msg_struct_t sendOpt = NULL;
1110 if (!m_messageData) {
1111 //error if platform message not exists
1112 LoggerE("message can not be updated");
1113 Throw(WrtDeviceApis::Commons::PlatformException);
1119 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1120 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1122 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
1124 if (err != MSG_SUCCESS)
1126 LoggerE("Get Message Failed!");
1127 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
1130 if (this->getIdRef().empty()) {
1131 LoggerE("existing msgId is zero, update msg not done");
1132 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1133 "existing msgId is zero, update msg not done");
1138 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
1140 LoggerE("Failed to update message");
1141 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
1143 msg_release_struct(&msg);
1144 msg_release_struct(&sendOpt);
1146 Catch(WrtDeviceApis::Commons::PlatformException) {
1147 msg_release_struct(&msg);
1148 msg_release_struct(&sendOpt);
1149 LoggerE("platform error occurs");
1154 void Mms::createSendMessage()
1156 LoggerD("convert m_id= " << convertId(getIdRef()));
1158 //prepare for add sms to draft folder
1159 if (!m_messageData) {
1160 //error if platform message not exists
1161 LoggerE("message can not be updated");
1162 Throw(WrtDeviceApis::Commons::PlatformException);
1165 //update all sms data
1166 if (getCurrentFolder() == DRAFTBOX) {
1167 LoggerD("update all mms data");
1169 updateBodyAndAttachments();
1170 updateRecipientList();
1177 // MSG_SENDINGOPT_S option = { false, false, false };
1178 // option.option.smsSendOpt.bReplyPath = true;
1179 // trying to get message from platform
1181 // msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1182 // msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
1185 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
1187 // msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1188 // msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, 4);
1189 // msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
1191 setId(convertId(msgId));
1192 setFolderType(DRAFTBOX);
1193 setMessageStatus(MESSAGE_STATUS_DRAFT);
1195 Catch(WrtDeviceApis::Commons::PlatformException) {
1196 LoggerE("remove message error");
1197 if (m_messageData) {
1198 //releasing platform message structure
1199 // msg_release_message(&m_messageData);
1200 msg_release_struct(&m_messageData);
1207 void Mms::addMessageToDraft()
1209 LoggerD("convert m_id= " << convertId(getIdRef()));
1211 msg_struct_t sendOpt = NULL;
1213 //prepare for add sms to draft folder
1214 if (!m_messageData) {
1215 //error if platform message not exists
1216 LoggerE("message can not be updated");
1217 Throw(WrtDeviceApis::Commons::PlatformException);
1220 //update all mms data
1221 if (getCurrentFolder() == DRAFTBOX) {
1223 updateBodyAndAttachments();
1224 updateRecipientList();
1231 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1233 // trying to add message
1234 LoggerD("add message");
1235 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
1236 if (ret < MSG_SUCCESS) {
1237 LoggerE("msg_add_message failed, error code=" << ret);
1238 Throw(WrtDeviceApis::Commons::PlatformException);
1245 LoggerD("Message ID : " << msgId);
1248 LoggerD("Message ID is invailded ");
1249 Throw(WrtDeviceApis::Commons::PlatformException);
1252 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1254 setId(convertId(msgId));
1257 msg_release_struct(&sendOpt);
1260 Catch(WrtDeviceApis::Commons::PlatformException) {
1261 LoggerE("add draft message error");
1262 msg_release_struct(&sendOpt);
1268 void Mms::loadDraftMessage()
1272 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
1274 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
1277 msg_release_struct(&m_messageData);
1278 m_messageData = NULL;
1279 msg_struct_t sendOpt = NULL;
1283 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1284 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1286 // trying to get message from platform
1287 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
1289 LoggerE("get message error");
1290 Throw(WrtDeviceApis::Commons::PlatformException);
1292 LoggerD("message found with msgId=" << getIdRef());
1294 // read all mms dat to abstraction layer
1295 readConversationId(m_messageData);
1296 readPriority(m_messageData);
1297 readSubject(m_messageData);
1298 readFolder(m_messageData);
1299 readDateTime(m_messageData);
1300 readReadStatus(m_messageData);
1301 readMessageStatus(m_messageData);
1302 readBody(m_messageData);
1304 msg_release_struct(&sendOpt);
1306 Catch(WrtDeviceApis::Commons::PlatformException) {
1307 LoggerE("exception");
1309 msg_release_struct(&sendOpt);
1314 void Mms::readAllData()
1318 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
1320 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
1323 msg_release_struct(&m_messageData);
1324 m_messageData = NULL;
1325 msg_struct_t sendOpt = NULL;
1329 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1330 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1332 // trying to get message from platform
1333 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
1335 LoggerE("get message error");
1336 Throw(WrtDeviceApis::Commons::PlatformException);
1338 LoggerD("message found with msgId=" << getIdRef());
1340 // read all mms dat to abstraction layer
1341 readConversationId(m_messageData);
1342 // readRecipientList(m_messageData);
1343 readPriority(m_messageData);
1344 readSubject(m_messageData);
1345 readBodyAndAttachments(m_messageData);
1346 readFolder(m_messageData);
1347 readDateTime(m_messageData);
1348 readReadStatus(m_messageData);
1349 readMessageStatus(m_messageData);
1351 msg_release_struct(&sendOpt);
1353 Catch(WrtDeviceApis::Commons::PlatformException) {
1354 LoggerE("exception");
1356 msg_release_struct(&sendOpt);
1361 void Mms::moveToFolder(const FolderType newFolder)
1368 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1371 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1372 platfromFolderId) != MSG_SUCCESS) {
1373 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error during movinf message");
1377 Catch(WrtDeviceApis::Commons::PlatformException) {
1378 LoggerE("remove message error");
1384 void Mms::moveToFolder(const string& newFolder)
1391 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1394 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1395 platfromFolderId) != MSG_SUCCESS) {
1396 LoggerE("msg_move_msg_to_folder error");
1397 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_move_msg_to_folder error");
1401 Catch(WrtDeviceApis::Commons::PlatformException) {
1402 LoggerE("remove message error");
1408 void Mms::copyToFolder(const FolderType newFolder)
1413 msg_message_t msg = msg_new_message();
1417 MSG_SENDINGOPT_S option = { false, false, false };
1418 option.option.smsSendOpt.bReplyPath = true;
1420 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1422 const msg_folder_id_t platfromFolderId =
1423 Messaging::convertFolderToPlatform(newFolder);
1424 msg_set_message_id(msg, 0);
1425 msg_set_folder_id(msg, platfromFolderId);
1427 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1428 if (error != MSG_SUCCESS) {
1429 LoggerE("msg_add_message failed, error code=" << error);
1430 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1434 msg_release_message(&msg);
1438 Catch(WrtDeviceApis::Commons::PlatformException) {
1439 LoggerE("remove message error");
1441 msg_release_message(&msg);
1448 void Mms::copyToFolder(const string& newFolder)
1453 msg_message_t msg = msg_new_message();
1457 MSG_SENDINGOPT_S option = { false, false, false };
1458 option.option.smsSendOpt.bReplyPath = true;
1460 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1462 const msg_folder_id_t platfromFolderId =
1463 Messaging::convertFolderToPlatform(newFolder);
1464 msg_set_message_id(msg, 0);
1465 msg_set_folder_id(msg, platfromFolderId);
1467 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1468 if (error != MSG_SUCCESS) {
1469 LoggerE("msg_add_message failed, error code=" << error);
1470 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1474 msg_release_message(&msg);
1478 Catch(WrtDeviceApis::Commons::PlatformException) {
1479 LoggerE("remove message error");
1481 msg_release_message(&msg);
1490 LoggerD("delete m_id=" << getIdRef());
1494 if (this->getIdRef().empty()) {
1495 LoggerE("existing msgId is zero, remove msg not done");
1496 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1497 "existing msgId is zero, remove msg not done");
1501 msg_delete_message(MsgGetCommonHandle(),
1502 convertId(getIdRef()))) {
1503 LoggerE("Failed to delete Message");
1504 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
1508 Catch(WrtDeviceApis::Commons::PlatformException) {
1509 LoggerE("platform error occurs");
1515 LoggerD("sending message, id=" << getIdRef());
1518 //prepare for sending sms/mms
1521 LoggerD("Start Sending Message...");
1523 LoggerD("trying to send mms");
1524 msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
1526 if (err != MSG_SUCCESS)
1528 LoggerE("Sending Message (submit request) failed!!! err=" << err);
1529 setMessageStatus(MESSAGE_STATUS_FAILED);
1530 Throw(WrtDeviceApis::Commons::PlatformException);
1533 setMessageStatus(MESSAGE_STATUS_SENDING);
1535 LoggerD("Sending Message request is submitted!");
1537 Catch(WrtDeviceApis::Commons::PlatformException) {
1538 LoggerE("message is not send, manually run callback");
1539 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1540 if (requestReceiver) {
1541 LoggerE("send Error");
1542 EventMessagingServicePtr event = getMessagingServiceEvent();
1543 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1544 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
1551 void Mms::sendingCallback(msg_struct_t sent_status)
1553 // LoggerI("sendingCallback callback received. Req id = " <<
1554 // sent_status->reqId << " Status = " << (int)sent_status->status);
1555 // msg_struct_t request_data = NULL;
1556 // msg_get_struct_handle(sent_status, MSG_STRUCT_REQUEST_INFO, (void **)request_data);
1557 // msg_get_int_value(request_data, MSG_REQUEST_REQUESTID_INT, &tempInt);
1558 int status = MSG_NETWORK_SEND_FAIL;
1559 msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
1561 LoggerD("status : " << status);
1563 if (MSG_NETWORK_SEND_SUCCESS == status) {
1564 LoggerD("sending ok");
1565 setSendingStatusOk();
1566 setMessageStatus(MESSAGE_STATUS_SENT);
1568 LoggerE("sending failed: " << static_cast<unsigned int>(status));
1569 setSendingStatusFailed();
1570 setMessageStatus(MESSAGE_STATUS_FAILED);
1574 void Mms::sendCancel(int handle)
1576 LoggerD("sending message, id=" << getIdRef());
1578 LoggerD("handle =" << handle);
1581 void Mms::setSendingStatusOk()
1583 //success callback should be executed here
1584 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1585 msg_struct_list_s *addr_list = NULL;
1586 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1589 if (requestReceiver) {
1590 LoggerI("calling JS success callback");
1591 EventMessagingServicePtr event = getMessagingServiceEvent();
1592 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
1594 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1596 nToCnt = addr_list->nCount;
1598 for ( int index=0; index < nToCnt; index++)
1600 msg_get_str_value(addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1601 event->m_successRecipients.push_back(strNumber);
1604 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1608 void Mms::setSendingStatusFailed()
1610 //error callback should be executed here
1611 EventOnSendingFailedEmitterPtr emitter = getEmitter();
1612 msg_struct_list_s *addr_list = NULL;
1613 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1618 EventOnSendingFailedPtr event(new EventOnSendingFailed);
1619 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
1620 emitter->emit(event);
1624 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1625 EventMessagingServicePtr event = getMessagingServiceEvent();
1626 if (requestReceiver)
1628 LoggerE("calling JS error callback");
1629 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1630 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1631 nToCnt = addr_list->nCount;
1633 LoggerD("nToCnt : " << nToCnt);
1635 for ( int index=0; index < nToCnt; index++)
1637 msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1638 event->m_failRecipients.push_back(strNumber);
1641 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1646 FolderType Mms::toFolder(const std::string &folder)
1648 if (folder == "INBOX") {
1650 } else if (folder == "OUTBOX") {
1652 } else if (folder == "SENTBOX") {
1654 } else if (folder == "DRAFTBOX") {
1657 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
1660 MimeType Mms::mimeTypeStringToIndexInt(std::string inputString)
1662 const char* szMimeStr = inputString.c_str();
1663 MimeType retInt = MIME_UNKNOWN;
1665 LoggerD("szMimeStr " << szMimeStr);
1667 for(int idx =0; mimeTable[idx].szMIME != NULL ; idx++)
1669 if (!strcmp(mimeTable[idx].szMIME, szMimeStr)) {
1670 retInt = mimeTable[idx].mime;
1678 std::string Mms::indexIntToMimeTypeString(MimeType inputIndex)
1680 std::string retString;
1682 for (int idx=0; mimeTable[idx].szMIME != NULL; idx++) {
1683 if (inputIndex == mimeTable[idx].mime) {
1684 retString = (char *)mimeTable[idx].szMIME;
1690 msg_struct_t Mms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
1692 int tempInt, nCount;
1694 msg_struct_list_s *addr_list;
1695 msg_struct_list_s *new_addr_list;
1697 int pageLen, mediaLen, attachLen, ret;
1699 msg_struct_t mms_struct = NULL;
1700 msg_struct_t mms_struct_dummy = NULL;
1702 msg_list_handle_t page_list = NULL;
1703 msg_list_handle_t media_list = NULL;
1704 msg_list_handle_t attach_list = NULL;
1706 msg_struct_t page = NULL;
1707 msg_struct_t media = NULL;
1708 msg_struct_t attach = NULL;
1710 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
1711 char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
1713 msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1715 msg_set_int_value(msg, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
1717 char strSubject[MAX_SUBJECT_LEN] = {0};
1718 msg_get_str_value(src, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
1719 msg_set_str_value(msg, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
1721 msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1722 msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1724 msg_get_int_value(src, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
1725 msg_set_int_value(msg, MSG_MESSAGE_THREAD_ID_INT, tempInt);
1727 msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1728 msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1730 // msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1731 // char tempStr[tempInt+1];
1732 // memset(tempStr, 0, tempInt+1);
1734 // msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1735 // msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1736 // copy mms body and attachment
1737 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
1738 mms_struct_dummy = msg_create_struct(MSG_STRUCT_MMS);
1739 msg_get_mms_struct(src, mms_struct);
1741 msg_set_mms_struct(src, mms_struct_dummy);
1742 msg_set_mms_struct(msg, mms_struct);
1743 msg_release_struct(&mms_struct);
1745 msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1746 msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1748 // msg_set_network_status(msg, msg_get_network_status(src));
1749 msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1750 msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
1752 // msg_set_encode_type(msg, msg_get_encode_type(src));
1753 msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1754 msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT, tempInt);
1756 // msg_set_read_status(msg, msg_is_read(src));
1757 msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1758 msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1760 // msg_set_protect_status(msg, msg_is_protected(src));
1761 msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1762 msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1764 // msg_set_priority_info(msg, msg_get_priority_info(src));
1765 msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1766 msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT, tempInt);
1768 // msg_set_direction_info(msg, msg_get_direction_info(src));
1769 msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1770 msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT, tempInt);
1772 // msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1773 msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1774 msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT, tempInt);
1775 msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1776 msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT, tempInt);
1779 msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1780 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
1782 new_addr_list->nCount = addr_list->nCount;
1784 for(int i=0; i<addr_list->nCount; i++)
1786 msg_struct_t addr_info = NULL;
1787 msg_struct_t new_addr_info = NULL;
1788 char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
1790 //get original address
1791 addr_info = addr_list->msg_struct_info[i];
1792 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1793 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
1795 //copy original address
1796 new_addr_info = new_addr_list->msg_struct_info[i];
1797 msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1798 msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);