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");
1150 ReThrow(WrtDeviceApis::Commons::PlatformException);
1155 void Mms::createSendMessage()
1157 LoggerD("convert m_id= " << convertId(getIdRef()));
1159 //prepare for add sms to draft folder
1160 if (!m_messageData) {
1161 //error if platform message not exists
1162 LoggerE("message can not be updated");
1163 Throw(WrtDeviceApis::Commons::PlatformException);
1166 //update all sms data
1167 if (getCurrentFolder() == DRAFTBOX) {
1168 LoggerD("update all mms data");
1170 updateBodyAndAttachments();
1171 updateRecipientList();
1178 // MSG_SENDINGOPT_S option = { false, false, false };
1179 // option.option.smsSendOpt.bReplyPath = true;
1180 // trying to get message from platform
1182 // msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1183 // msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
1186 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
1188 // msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1189 // msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, 4);
1190 // msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
1192 setId(convertId(msgId));
1193 setFolderType(DRAFTBOX);
1194 setMessageStatus(MESSAGE_STATUS_DRAFT);
1196 Catch(WrtDeviceApis::Commons::PlatformException) {
1197 LoggerE("remove message error");
1198 if (m_messageData) {
1199 //releasing platform message structure
1200 // msg_release_message(&m_messageData);
1201 msg_release_struct(&m_messageData);
1208 void Mms::addMessageToDraft()
1210 LoggerD("convert m_id= " << convertId(getIdRef()));
1212 msg_struct_t sendOpt = NULL;
1214 //prepare for add sms to draft folder
1215 if (!m_messageData) {
1216 //error if platform message not exists
1217 LoggerE("message can not be updated");
1218 Throw(WrtDeviceApis::Commons::PlatformException);
1221 //update all mms data
1222 if (getCurrentFolder() == DRAFTBOX) {
1224 updateBodyAndAttachments();
1225 updateRecipientList();
1232 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1234 // trying to add message
1235 LoggerD("add message");
1236 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
1237 if (ret < MSG_SUCCESS) {
1238 LoggerE("msg_add_message failed, error code=" << ret);
1239 Throw(WrtDeviceApis::Commons::PlatformException);
1246 LoggerD("Message ID : " << msgId);
1249 LoggerD("Message ID is invailded ");
1250 Throw(WrtDeviceApis::Commons::PlatformException);
1253 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1255 setId(convertId(msgId));
1258 msg_release_struct(&sendOpt);
1261 Catch(WrtDeviceApis::Commons::PlatformException) {
1262 LoggerE("add draft message error");
1263 msg_release_struct(&sendOpt);
1269 void Mms::loadDraftMessage()
1273 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
1275 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
1278 msg_release_struct(&m_messageData);
1279 m_messageData = NULL;
1280 msg_struct_t sendOpt = NULL;
1284 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1285 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1287 // trying to get message from platform
1288 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
1290 LoggerE("get message error");
1291 Throw(WrtDeviceApis::Commons::PlatformException);
1293 LoggerD("message found with msgId=" << getIdRef());
1295 // read all mms dat to abstraction layer
1296 readConversationId(m_messageData);
1297 readPriority(m_messageData);
1298 readSubject(m_messageData);
1299 readFolder(m_messageData);
1300 readDateTime(m_messageData);
1301 readReadStatus(m_messageData);
1302 readMessageStatus(m_messageData);
1303 readBody(m_messageData);
1305 msg_release_struct(&sendOpt);
1307 Catch(WrtDeviceApis::Commons::PlatformException) {
1308 LoggerE("exception");
1310 msg_release_struct(&sendOpt);
1315 void Mms::readAllData()
1319 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
1321 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
1324 msg_release_struct(&m_messageData);
1325 m_messageData = NULL;
1326 msg_struct_t sendOpt = NULL;
1330 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1331 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1333 // trying to get message from platform
1334 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
1336 LoggerE("get message error");
1337 Throw(WrtDeviceApis::Commons::PlatformException);
1339 LoggerD("message found with msgId=" << getIdRef());
1341 // read all mms dat to abstraction layer
1342 readConversationId(m_messageData);
1343 // readRecipientList(m_messageData);
1344 readPriority(m_messageData);
1345 readSubject(m_messageData);
1346 readBodyAndAttachments(m_messageData);
1347 readFolder(m_messageData);
1348 readDateTime(m_messageData);
1349 readReadStatus(m_messageData);
1350 readMessageStatus(m_messageData);
1352 msg_release_struct(&sendOpt);
1354 Catch(WrtDeviceApis::Commons::PlatformException) {
1355 LoggerE("exception");
1357 msg_release_struct(&sendOpt);
1362 void Mms::moveToFolder(const FolderType newFolder)
1369 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1372 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1373 platfromFolderId) != MSG_SUCCESS) {
1374 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error during movinf message");
1378 Catch(WrtDeviceApis::Commons::PlatformException) {
1379 LoggerE("remove message error");
1385 void Mms::moveToFolder(const string& newFolder)
1392 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1395 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1396 platfromFolderId) != MSG_SUCCESS) {
1397 LoggerE("msg_move_msg_to_folder error");
1398 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_move_msg_to_folder error");
1402 Catch(WrtDeviceApis::Commons::PlatformException) {
1403 LoggerE("remove message error");
1409 void Mms::copyToFolder(const FolderType newFolder)
1414 msg_message_t msg = msg_new_message();
1418 MSG_SENDINGOPT_S option = { false, false, false };
1419 option.option.smsSendOpt.bReplyPath = true;
1421 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1423 const msg_folder_id_t platfromFolderId =
1424 Messaging::convertFolderToPlatform(newFolder);
1425 msg_set_message_id(msg, 0);
1426 msg_set_folder_id(msg, platfromFolderId);
1428 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1429 if (error != MSG_SUCCESS) {
1430 LoggerE("msg_add_message failed, error code=" << error);
1431 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1435 msg_release_message(&msg);
1439 Catch(WrtDeviceApis::Commons::PlatformException) {
1440 LoggerE("remove message error");
1442 msg_release_message(&msg);
1449 void Mms::copyToFolder(const string& newFolder)
1454 msg_message_t msg = msg_new_message();
1458 MSG_SENDINGOPT_S option = { false, false, false };
1459 option.option.smsSendOpt.bReplyPath = true;
1461 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1463 const msg_folder_id_t platfromFolderId =
1464 Messaging::convertFolderToPlatform(newFolder);
1465 msg_set_message_id(msg, 0);
1466 msg_set_folder_id(msg, platfromFolderId);
1468 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1469 if (error != MSG_SUCCESS) {
1470 LoggerE("msg_add_message failed, error code=" << error);
1471 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1475 msg_release_message(&msg);
1479 Catch(WrtDeviceApis::Commons::PlatformException) {
1480 LoggerE("remove message error");
1482 msg_release_message(&msg);
1491 LoggerD("delete m_id=" << getIdRef());
1495 if (this->getIdRef().empty()) {
1496 LoggerE("existing msgId is zero, remove msg not done");
1497 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1498 "existing msgId is zero, remove msg not done");
1502 msg_delete_message(MsgGetCommonHandle(),
1503 convertId(getIdRef()))) {
1504 LoggerE("Failed to delete Message");
1505 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
1509 Catch(WrtDeviceApis::Commons::PlatformException) {
1510 LoggerE("platform error occurs");
1516 LoggerD("sending message, id=" << getIdRef());
1519 //prepare for sending sms/mms
1522 LoggerD("Start Sending Message...");
1524 LoggerD("trying to send mms");
1525 msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
1527 if (err != MSG_SUCCESS)
1529 LoggerE("Sending Message (submit request) failed!!! err=" << err);
1530 setMessageStatus(MESSAGE_STATUS_FAILED);
1531 Throw(WrtDeviceApis::Commons::PlatformException);
1534 setMessageStatus(MESSAGE_STATUS_SENDING);
1536 LoggerD("Sending Message request is submitted!");
1538 Catch(WrtDeviceApis::Commons::PlatformException) {
1539 LoggerE("message is not send, manually run callback");
1540 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1541 if (requestReceiver) {
1542 LoggerE("send Error");
1543 EventMessagingServicePtr event = getMessagingServiceEvent();
1544 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1545 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
1552 void Mms::sendingCallback(msg_struct_t sent_status)
1554 // LoggerI("sendingCallback callback received. Req id = " <<
1555 // sent_status->reqId << " Status = " << (int)sent_status->status);
1556 // msg_struct_t request_data = NULL;
1557 // msg_get_struct_handle(sent_status, MSG_STRUCT_REQUEST_INFO, (void **)request_data);
1558 // msg_get_int_value(request_data, MSG_REQUEST_REQUESTID_INT, &tempInt);
1559 int status = MSG_NETWORK_SEND_FAIL;
1560 msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
1562 LoggerD("status : " << status);
1564 if (MSG_NETWORK_SEND_SUCCESS == status) {
1565 LoggerD("sending ok");
1566 setSendingStatusOk();
1567 setMessageStatus(MESSAGE_STATUS_SENT);
1569 LoggerE("sending failed: " << static_cast<unsigned int>(status));
1570 setSendingStatusFailed();
1571 setMessageStatus(MESSAGE_STATUS_FAILED);
1575 void Mms::sendCancel(int handle)
1577 LoggerD("sending message, id=" << getIdRef());
1579 LoggerD("handle =" << handle);
1582 void Mms::setSendingStatusOk()
1584 //success callback should be executed here
1585 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1586 msg_struct_list_s *addr_list = NULL;
1587 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1590 if (requestReceiver) {
1591 LoggerI("calling JS success callback");
1592 EventMessagingServicePtr event = getMessagingServiceEvent();
1593 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
1595 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1597 nToCnt = addr_list->nCount;
1599 for ( int index=0; index < nToCnt; index++)
1601 msg_get_str_value(addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1602 event->m_successRecipients.push_back(strNumber);
1605 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1609 void Mms::setSendingStatusFailed()
1611 //error callback should be executed here
1612 EventOnSendingFailedEmitterPtr emitter = getEmitter();
1613 msg_struct_list_s *addr_list = NULL;
1614 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1619 EventOnSendingFailedPtr event(new EventOnSendingFailed);
1620 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
1621 emitter->emit(event);
1625 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1626 EventMessagingServicePtr event = getMessagingServiceEvent();
1627 if (requestReceiver)
1629 LoggerE("calling JS error callback");
1630 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1631 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1632 nToCnt = addr_list->nCount;
1634 LoggerD("nToCnt : " << nToCnt);
1636 for ( int index=0; index < nToCnt; index++)
1638 msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1639 event->m_failRecipients.push_back(strNumber);
1642 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1647 FolderType Mms::toFolder(const std::string &folder)
1649 if (folder == "INBOX") {
1651 } else if (folder == "OUTBOX") {
1653 } else if (folder == "SENTBOX") {
1655 } else if (folder == "DRAFTBOX") {
1658 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
1661 MimeType Mms::mimeTypeStringToIndexInt(std::string inputString)
1663 const char* szMimeStr = inputString.c_str();
1664 MimeType retInt = MIME_UNKNOWN;
1666 LoggerD("szMimeStr " << szMimeStr);
1668 for(int idx =0; mimeTable[idx].szMIME != NULL ; idx++)
1670 if (!strcmp(mimeTable[idx].szMIME, szMimeStr)) {
1671 retInt = mimeTable[idx].mime;
1679 std::string Mms::indexIntToMimeTypeString(MimeType inputIndex)
1681 std::string retString;
1683 for (int idx=0; mimeTable[idx].szMIME != NULL; idx++) {
1684 if (inputIndex == mimeTable[idx].mime) {
1685 retString = (char *)mimeTable[idx].szMIME;
1691 msg_struct_t Mms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
1693 int tempInt, nCount, ret;
1695 msg_struct_list_s *addr_list;
1696 msg_struct_list_s *new_addr_list;
1698 msg_struct_t mms_struct = NULL;
1699 msg_struct_t mms_struct_dummy = NULL;
1701 msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1703 msg_set_int_value(msg, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
1705 char strSubject[MAX_SUBJECT_LEN] = {0};
1706 msg_get_str_value(src, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
1707 msg_set_str_value(msg, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
1709 msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1710 msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1712 msg_get_int_value(src, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
1713 msg_set_int_value(msg, MSG_MESSAGE_THREAD_ID_INT, tempInt);
1715 msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1716 msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1718 // msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1719 // char tempStr[tempInt+1];
1720 // memset(tempStr, 0, tempInt+1);
1722 // msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1723 // msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1724 // copy mms body and attachment
1725 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
1726 mms_struct_dummy = msg_create_struct(MSG_STRUCT_MMS);
1727 ret = msg_get_mms_struct(src, mms_struct);
1728 if (ret != MSG_SUCCESS)
1730 LoggerE("cannot get mms struct");
1731 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
1734 msg_set_mms_struct(src, mms_struct_dummy);
1735 msg_set_mms_struct(msg, mms_struct);
1737 msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1738 msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1740 // msg_set_network_status(msg, msg_get_network_status(src));
1741 msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1742 msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
1744 // msg_set_encode_type(msg, msg_get_encode_type(src));
1745 msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1746 msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT, tempInt);
1748 // msg_set_read_status(msg, msg_is_read(src));
1749 msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1750 msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1752 // msg_set_protect_status(msg, msg_is_protected(src));
1753 msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1754 msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1756 // msg_set_priority_info(msg, msg_get_priority_info(src));
1757 msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1758 msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT, tempInt);
1760 // msg_set_direction_info(msg, msg_get_direction_info(src));
1761 msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1762 msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT, tempInt);
1764 // msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1765 msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1766 msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT, tempInt);
1767 msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1768 msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT, tempInt);
1771 msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1772 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
1774 new_addr_list->nCount = addr_list->nCount;
1776 for(int i=0; i<addr_list->nCount; i++)
1778 msg_struct_t addr_info = NULL;
1779 msg_struct_t new_addr_info = NULL;
1780 char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
1782 //get original address
1783 addr_info = addr_list->msg_struct_info[i];
1784 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1785 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
1787 //copy original address
1788 new_addr_info = new_addr_list->msg_struct_info[i];
1789 msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1790 msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);
1793 msg_release_struct(&mms_struct_dummy);
1794 msg_release_struct(&mms_struct);