2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
21 #include <Commons/Exception.h>
22 #include "ReqReceiverMessage.h"
23 #include "Messaging.h"
24 #include "CallbackMgr.h"
25 #include "MsgServiceHandleMgr.h"
30 #include <msg_storage.h>
35 const char* TEXT_AREA = "Text";
36 const char* TEXT_FILE_EXTENSION = ".txt";
37 const char* TEXT_DIR_PREFIX = "/tmp/";
38 const int WHITE_COLOR = 0xffffff;
39 const int BLACK_COLOR = 0x000000;
40 const int ROOT_LAYOUT_WIDTH = 100;
41 const int ROOT_LAYOUT_HEIGHT = 100;
42 const char* EMPTY_ID = "0";
50 Mms::Mms(const string& id) :
52 // m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
55 LoggerD("m_id=" << getIdRef());
56 LoggerD("m_msgType=" << getMessageType());
58 char buf[] = "XXXXXX";
59 mode_t mask = umask(S_IWGRP | S_IWOTH);
61 LoggerD("buf : " << buf << " i : " << i);
64 m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
66 LoggerD("m_bodyFilePath : " << m_bodyFilePath);
68 if (getIdRef().empty()) {
69 LoggerD("create new message");
72 LoggerD("read existing message");
73 readExistingMessage();
77 Mms::Mms(const string& id, const msg_struct_t msg_data) :
79 // m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
80 m_messageData(msg_data)
82 LoggerD("m_id=" << getIdRef());
83 LoggerD("m_msgType=" << getMessageType());
85 char buf[] = "XXXXXX";
86 mode_t mask = umask(S_IWGRP | S_IWOTH);
88 LoggerD("buf : " << buf << " i : " << i);
91 m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
93 LoggerD("m_bodyFilePath : " << m_bodyFilePath);
95 readConversationId(m_messageData);
96 readRecipientList(m_messageData);
97 readPriority(m_messageData);
98 readSubject(m_messageData);
99 readBodyAndAttachments(m_messageData);
100 readFolder(m_messageData);
101 readDateTime(m_messageData);
102 readReadStatus(m_messageData);
103 readMessageStatus(m_messageData);
104 // setMessageStatus(MESSAGE_STATUS_LOADED);
113 // release platform message structure
114 // msg_release_message(&m_messageData);
115 msg_release_struct(&m_messageData);
119 //trying to remove file, return value is skipped
120 if (!m_bodyFilePath.empty()) {
121 LoggerD("remove tmp file=" << m_bodyFilePath);
122 (void) ::remove(m_bodyFilePath.c_str());
126 void Mms::createNewMessage()
129 msg_release_struct(&m_messageData);
130 m_messageData = NULL;
133 char strSubject[MAX_SUBJECT_LEN] = {0,};
135 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
136 msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
137 // msg_struct_t option = NULL;
139 // initialize platform message structure
140 msg_set_int_value(m_messageData, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
141 msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
142 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
144 setMmsType(MULTIPART_MIXED);
145 setReadStatus(false);
146 setMessageStatus(MESSAGE_STATUS_CREATED);
148 msg_release_struct(&sendOpt);
149 LoggerD("Message created successfully, Id: " << getIdRef());
152 void Mms::readExistingMessage()
156 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
158 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
161 msg_release_struct(&m_messageData);
162 m_messageData = NULL;
163 msg_struct_t sendOpt = NULL;
167 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
168 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
170 // trying to get message from platform
171 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
173 LoggerE("get message error");
174 Throw(WrtDeviceApis::Commons::PlatformException);
176 LoggerD("message found with msgId=" << getIdRef());
178 // read all mms dat to abstraction layer
179 readConversationId(m_messageData);
180 readRecipientList(m_messageData);
181 readPriority(m_messageData);
182 readSubject(m_messageData);
183 readBodyAndAttachments(m_messageData);
184 readFolder(m_messageData);
185 readDateTime(m_messageData);
186 readReadStatus(m_messageData);
187 readMessageStatus(m_messageData);
189 msg_release_struct(&sendOpt);
191 Catch(WrtDeviceApis::Commons::PlatformException) {
192 LoggerE("exception");
194 msg_release_struct(&sendOpt);
198 void Mms::readDateTime(msg_struct_t& messageData)
200 // tm* time = localtime(msg_get_time(messageData));
201 // tm dateT = getDateTime();
203 msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
205 LoggerE("readDateTime : " <<tempInt);
207 tm* time = localtime((time_t*)&tempInt);
209 LoggerE("localtime failed");
210 Throw(WrtDeviceApis::Commons::PlatformException);
215 void Mms::readReadStatus(msg_struct_t& messageData)
218 msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
219 setReadStatus(tempBool);
222 void Mms::readFolder(msg_struct_t& messageData)
225 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
229 setFolderType(INBOX);
232 setFolderType(OUTBOX);
235 setFolderType(SENTBOX);
238 setFolderType(DRAFTBOX);
241 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
245 void Mms::readMessageStatus(msg_struct_t& messageData)
248 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
250 LoggerD("readMessageStatus folder : " << tempValue);
254 setMessageStatus(MESSAGE_STATUS_LOADED);
257 setMessageStatus(MESSAGE_STATUS_SENDING);
260 setMessageStatus(MESSAGE_STATUS_SENT);
263 setMessageStatus(MESSAGE_STATUS_DRAFT);
266 setMessageStatus(MESSAGE_STATUS_LOADED);
271 void Mms::readPriority(msg_struct_t& messageData)
273 // switch (msg_get_priority_info(messageData)) {
275 msg_get_int_value(messageData, MSG_MESSAGE_PRIORITY_INT, &tempInt);
277 case MSG_MESSAGE_PRIORITY_LOW:
278 setPriority(MessagePriority::LOW);
280 case MSG_MESSAGE_PRIORITY_NORMAL:
281 setPriority(MessagePriority::NORMAL);
283 case MSG_MESSAGE_PRIORITY_HIGH:
284 setPriority(MessagePriority::HIGH);
287 LoggerE("Wrong priority type");
288 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong priority type");
292 void Mms::readConversationId(msg_struct_t& messageData)
295 msg_get_int_value(messageData, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
296 LoggerD("conversationID : " <<tempInt);
300 void Mms::readRecipientList(msg_struct_t& messageData)
302 std::string phoneNumber;
303 // int recipientCount = msg_get_address_count(messageData);
304 // LoggerD("Recipient count " << recipientCount);
306 msg_struct_list_s *addr_list;
307 msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
310 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
312 int recipientCount = addr_list->nCount;
313 LoggerD("Recipient count " << recipientCount);
315 for (int i = 0; i < recipientCount; ++i)
317 // int type = msg_get_direction_info(messageData);
318 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
320 LoggerD("Direction: " << type);
322 if (MSG_DIRECTION_TYPE_MT == type)
324 msg_struct_t addr_info = addr_list->msg_struct_info[i];
325 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
326 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
327 phoneNumber = strNumber;
329 if (validatePhoneNumber(phoneNumber))
331 setSourceAddress(phoneNumber);
332 setFrom(phoneNumber);
334 LoggerD("MT number: " << phoneNumber);
336 else if (MSG_DIRECTION_TYPE_MO == type)
338 msg_struct_t addr_info = addr_list->msg_struct_info[i];
339 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
340 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
341 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
342 LoggerD("MO number: " << strNumber);
343 LoggerD("Type : " << tempInt);
346 case MSG_RECIPIENTS_TYPE_TO:
347 appendToRecipients(strNumber);
349 case MSG_RECIPIENTS_TYPE_CC:
350 appendCcRecipients(strNumber);
352 case MSG_RECIPIENTS_TYPE_BCC:
353 appendBccRecipients(strNumber);
356 LoggerE("Wrong type of recipient");
361 LoggerE("Wrong type of recipient");
362 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
367 void Mms::readSubject(msg_struct_t& messageData)
369 char strTemp[MAX_SUBJECT_LEN] = {0};
370 msg_get_str_value(messageData, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
371 // setSubject(msg_get_subject(messageData));
372 LoggerE("readSubject : " << strTemp);
376 void Mms::readBodyAndAttachments(msg_struct_t& messageData)
379 int pageLen, mediaLen, attachLen, tempInt, ret;
381 msg_struct_t mms_struct = NULL;
383 msg_list_handle_t page_list = NULL;
384 msg_list_handle_t media_list = NULL;
385 msg_list_handle_t attach_list = NULL;
387 msg_struct_t page = NULL;
388 msg_struct_t media = NULL;
389 msg_struct_t attach = NULL;
391 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
392 ret = msg_get_mms_struct(messageData, mms_struct);
394 if (ret != MSG_SUCCESS)
396 LoggerE("cannot get mms struct");
397 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
400 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
401 char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
403 msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
404 pageLen = msg_list_length(page_list);
407 setMmsType(MULTIPART_RELATED);
409 setMmsType(MULTIPART_MIXED);
412 LoggerD("page count: " << pageLen);
414 for (int p = 0; p < pageLen; ++p)
416 LoggerD("page " << p);
417 page = (msg_struct_t)msg_list_nth_data(page_list, p);
420 LoggerE("returned page is null, continue");
424 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
425 mediaLen = msg_list_length(media_list);
427 for (int m = 0; m < mediaLen; ++m)
429 LoggerD("media file " << m);
430 media = (msg_struct_t)msg_list_nth_data(media_list, m);
433 LoggerE("returned media is null, continue");
437 msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
439 memset(szFilePath, 0, sizeof(szFilePath));
440 msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
442 if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt))
444 //text value on first page goes to body attribute
445 LoggerD("setting body from " << szFilePath);
448 f = fopen(szFilePath, "r");
451 LoggerE("cannot read file with body" << szFilePath);
452 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
454 fseek(f, 0, SEEK_END);
455 long int size = ftell(f);
456 fseek(f, 0, SEEK_SET);
457 char* data = new (nothrow) char[size + 1];
460 memset(data, 0, size + 1);
461 error = fread(data, 1, size, f);
465 LoggerE("body is not set");
467 LoggerD("message body: '" << getBody() << "'");
472 LoggerD("adding attachment " << szFilePath);
474 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
475 //attachment->setMessage(this); //set IMessagePtr
477 memset(szFileName, 0, sizeof(szFileName));
478 msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
479 if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0))
481 LoggerD("renaming to " << szFileName);
482 attachment->rename(szFileName);
484 else if (MMS_SMIL_MEDIA_TEXT == tempInt)
486 std::stringstream newName;
487 newName << "body_page_" << p + 1 << ".txt";
488 LoggerD("renaming to " << newName.str());
489 attachment->rename(newName.str());
495 msg_get_list_handle(mms_struct, MSG_MMS_ATTACH_LIST_HND, (void **)&attach_list);
497 attachLen= msg_list_length(attach_list);
499 LoggerD("attachment count: " << attachLen);
500 for (int a = 0; a < attachLen; ++a)
502 std::string tempString;
505 attach = (msg_struct_t)msg_list_nth_data(attach_list, a);
508 LoggerE("attachment is null, continue");
512 memset(szFilePath, 0, sizeof(szFilePath));
513 memset(szFileName, 0, sizeof(szFileName));
515 msg_get_str_value(attach, MSG_MMS_ATTACH_FILEPATH_STR, szFilePath, sizeof(szFilePath));
516 msg_get_str_value(attach, MSG_MMS_ATTACH_FILENAME_STR, szFileName, sizeof(szFileName));
518 msg_get_int_value(attach, MSG_MMS_ATTACH_MIME_TYPE_INT, &tempInt);
519 tempString = indexIntToMimeTypeString((MimeType)tempInt);
521 IAttachmentPtr att = appendAttachment(szFilePath, false);
522 if ((szFileName[0] =! '\0') &&
523 strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0) {
524 LoggerD("renaming to " << szFileName);
525 att->rename(szFileName);
527 att->setMimeType(tempString);
528 att->setAttachmentID((int)a);
529 att->setDownloaded(true);
531 msg_release_struct(&mms_struct);
534 void Mms::readBody(msg_struct_t& messageData)
537 int pageLen, mediaLen, attachLen, tempInt, ret;
539 msg_struct_t mms_struct = NULL;
541 msg_list_handle_t page_list = NULL;
542 msg_list_handle_t media_list = NULL;
543 msg_list_handle_t attach_list = NULL;
545 msg_struct_t page = NULL;
546 msg_struct_t media = NULL;
548 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
549 ret = msg_get_mms_struct(messageData, mms_struct);
551 if (ret != MSG_SUCCESS)
553 LoggerE("cannot get mms struct");
554 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
557 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
558 char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
560 msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
561 pageLen = msg_list_length(page_list);
564 setMmsType(MULTIPART_RELATED);
566 setMmsType(MULTIPART_MIXED);
569 LoggerD("page count: " << pageLen);
571 for (int p = 0; p < pageLen; ++p)
573 LoggerD("page " << p);
574 page = (msg_struct_t)msg_list_nth_data(page_list, p);
577 LoggerE("returned page is null, continue");
581 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
582 mediaLen = msg_list_length(media_list);
584 for (int m = 0; m < mediaLen; ++m)
586 LoggerD("media file " << m);
587 media = (msg_struct_t)msg_list_nth_data(media_list, m);
590 LoggerE("returned media is null, continue");
594 msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
596 memset(szFilePath, 0, sizeof(szFilePath));
597 msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
599 if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt))
601 //text value on first page goes to body attribute
602 LoggerD("setting body from " << szFilePath);
605 f = fopen(szFilePath, "r");
608 LoggerE("cannot read file with body" << szFilePath);
609 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
611 fseek(f, 0, SEEK_END);
612 long int size = ftell(f);
613 fseek(f, 0, SEEK_SET);
614 char* data = new (nothrow) char[size + 1];
617 memset(data, 0, size + 1);
618 error = fread(data, 1, size, f);
622 LoggerE("body is not set");
624 LoggerD("message body: '" << getBody() << "'");
629 LoggerD("adding attachment " << szFilePath);
631 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
632 //attachment->setMessage(this); //set IMessagePtr
634 memset(szFileName, 0, sizeof(szFileName));
635 msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
636 if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0))
638 LoggerD("renaming to " << szFileName);
639 attachment->rename(szFileName);
641 else if (MMS_SMIL_MEDIA_TEXT == tempInt)
643 std::stringstream newName;
644 newName << "body_page_" << p + 1 << ".txt";
645 LoggerD("renaming to " << newName.str());
646 attachment->rename(newName.str());
651 msg_release_struct(&mms_struct);
655 bool Mms::hasAttachment()
657 std::size_t attachmentSize = getAttachmentsCount();
658 if ( attachmentSize > 0)
664 void Mms::update(bool draftsOnly)
666 LoggerD("updating m_id=" << getIdRef());
668 if (!m_messageData) {
669 //error if platform message not exists
670 LoggerE("message can not be updated");
671 Throw(WrtDeviceApis::Commons::PlatformException);
674 //update mms data from abstraction
675 if (!draftsOnly || getCurrentFolder() == DRAFTBOX) {
677 updateBodyAndAttachments();
678 updateRecipientList();
684 void Mms::updatePriority()
686 if (isPriorityValid()) {
690 LoggerI("MMS updating priority");
692 //set priority in platform
693 switch (getPriority()) {
694 case MessagePriority::LOW:
695 priority = MSG_MESSAGE_PRIORITY_LOW;
697 case MessagePriority::NORMAL:
698 priority = MSG_MESSAGE_PRIORITY_NORMAL;
700 case MessagePriority::HIGH:
701 priority = MSG_MESSAGE_PRIORITY_HIGH;
704 LoggerE("Wrong priority");
705 Throw(WrtDeviceApis::Commons::PlatformException);
707 LoggerI("priority : " << priority);
710 msg_set_int_value(m_messageData, MSG_MESSAGE_PRIORITY_INT, priority)){
712 LoggerE("Error during setting priority");
713 Throw(WrtDeviceApis::Commons::PlatformException);
717 void Mms::updateRecipientList()
719 // check if abstraction recipient value has been changed
720 if (getToRecipients().isValid() &&
721 getBccRecipients().isValid() &&
722 getCcRecipients().isValid()) {
726 LoggerI("MMS updating platform recipients");
728 // reset addresses in platform structure
729 // msg_reset_address(m_messageData);
730 msg_struct_list_s *addr_list = NULL;
731 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
733 nToCnt = addr_list->nCount;
735 LoggerI("addr_list->nCount" << addr_list->nCount);
739 for (int i = 0; i < nToCnt; i++) {
740 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, (char *)"", 0);
741 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, (char *)"", 0);
742 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
743 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
744 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
747 addr_list->nCount = nToCnt;
750 LoggerI("addr_list->nCount" << addr_list->nCount);
752 vector<string> to = getToRecipients().getRecipients();
753 vector<string> cc = getCcRecipients().getRecipients();
754 vector<string> bcc = getBccRecipients().getRecipients();
756 // update addresses in platform structure
759 LoggerI("updating to");
760 for (size_t i = 0; i < to.size(); i++)
762 if (i >= MAX_TO_ADDRESS_CNT)
764 LoggerE("max number of recipient exceeded");
767 LoggerD("adding to[" << i << "]=" << to[i]);
769 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
771 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
772 MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
774 LoggerE("problem with adding to address");
775 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
778 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
779 const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
781 LoggerE("problem with adding to address");
782 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
786 addr_list->nCount = nToCnt;
787 LoggerE("nToCnt : " << nToCnt);
788 LoggerE("addr_list->nCount: " <<addr_list->nCount);
792 LoggerI("addr_list->nCount" << addr_list->nCount);
796 LoggerI("updating cc");
797 for (size_t i = 0; i < cc.size(); i++)
799 if (nToCnt >= MAX_TO_ADDRESS_CNT)
801 LoggerE("max number of recipient exceeded");
804 LoggerD("adding cc[" << i << "]=" << cc[i]);
806 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
808 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
809 MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS)
811 LoggerE("problem with adding cc address");
812 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
815 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
816 const_cast<char*>(cc[i].c_str()), cc[i].size()) != MSG_SUCCESS)
818 LoggerE("problem with adding cc address");
819 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
823 addr_list->nCount = nToCnt;
824 LoggerE("nToCnt : " << nToCnt);
825 LoggerE("addr_list->nCount: " <<addr_list->nCount);
828 LoggerI("addr_list->nCount" << addr_list->nCount);
832 LoggerI("updating bcc");
833 for (size_t i = 0; i < bcc.size(); i++)
835 if (nToCnt >= MAX_TO_ADDRESS_CNT)
837 LoggerE("max number of recipient exceeded");
840 LoggerD("adding bcc[" << i << "]=" << bcc[i]);
842 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
844 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
845 MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS)
847 LoggerE("problem with adding bcc address");
848 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
851 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
852 const_cast<char*>(bcc[i].c_str()), bcc[i].size()) != MSG_SUCCESS)
854 LoggerE("problem with adding bcc address");
855 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
859 addr_list->nCount = nToCnt;
860 LoggerE("nToCnt : " << nToCnt);
861 LoggerE("addr_list->nCount: " <<addr_list->nCount);
864 LoggerI("addr_list->nCount" << addr_list->nCount);
867 setBccValidity(true);
870 void Mms::updateSubject()
872 // check if abstraction subject value has been changed
873 if (isSubjectValid()) {
876 LoggerI("updating platform subject: " << getSubjectRef());
878 // msg_set_subject(m_messageData, getSubjectRef().c_str())) {
879 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, const_cast<char*>(getSubjectRef().c_str()), MAX_SUBJECT_LEN)) {
881 LoggerE("problem with setting subject");
882 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
884 setSubjectValidity(true);
887 void Mms::updateBodyAndAttachments()
889 // check if attachment or body source address value has been changed
890 if (isAttachmentsValid() && isBodyValid()) {
894 // MMS_MESSAGE_DATA_S *mmsData = NULL;
895 msg_struct_t mms_struct = NULL;
896 // msg_struct_t old_mms_struct = NULL;// THIS
899 LoggerI("updating platform body and attachment");
903 msg_struct_t region[1];
904 msg_struct_t page[1];
905 msg_struct_t media[1];
906 msg_struct_t smil_text[1];
908 if (getMessageType() != MMS) {
909 LoggerE("Wrong msg type");
910 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong msg type");
912 // mmsData = msg_mms_create_message();
913 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
914 // old_mms_struct = msg_create_struct(MSG_STRUCT_MMS);// THIS
916 // ret = msg_get_mms_struct(m_messageData, old_mms_struct);// THIS
917 // LoggerE("ret " << ret);// THIS
918 // ret = msg_release_struct(&old_mms_struct);// THIS
919 // LoggerE("ret " << ret);// THIS
922 LoggerE("create message body failed");
923 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "create message body failed");
927 if (!getBodyRef().empty()) {
929 f = fopen(m_bodyFilePath.c_str(), "w");
931 LoggerE("cannot create file with body" << m_bodyFilePath);
932 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
933 "cannot create file with body");
935 LoggerD("body file: " << m_bodyFilePath);
936 fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
940 LoggerD("getBodyRef(): " << getBodyRef());
942 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_INT, ROOT_LAYOUT_WIDTH);
943 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
944 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_BGCOLOR_INT, WHITE_COLOR);
945 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL, true);
946 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL, true);
948 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_REGION, ®ion[0]);
949 msg_set_str_value(region[0], MSG_MMS_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
950 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
951 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_TOP_INT, 0);
952 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_INT, ROOT_LAYOUT_WIDTH);
953 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
954 msg_set_int_value(region[0], MSG_MMS_REGION_BGCOLOR_INT, WHITE_COLOR);
956 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL, true);
957 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL, true);
958 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL, true);
959 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL, true);
961 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_PAGE, &page[0]);
962 msg_set_int_value(page[0], MSG_MMS_PAGE_PAGE_DURATION_INT, 0);
964 msg_mms_add_item(page[0], MSG_STRUCT_MMS_MEDIA, &media[0]);
965 msg_set_int_value(media[0], MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT);
966 msg_set_str_value(media[0], MSG_MMS_MEDIA_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
968 error = msg_set_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, const_cast<char*>(m_bodyFilePath.c_str()),MSG_FILEPATH_LEN_MAX);
969 LoggerD("bodyFile Path= " << m_bodyFilePath);
970 LoggerD("error= " << error);
971 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
972 memset(szFilePath, 0, sizeof(szFilePath));
973 msg_get_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
974 LoggerD("bodyFile Path= " << m_bodyFilePath);
976 msg_get_struct_handle(media[0], MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text[0]);
977 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_COLOR_INT, BLACK_COLOR);
978 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_SIZE_INT, MMS_SMIL_FONT_SIZE_NORMAL);
979 msg_set_bool_value(smil_text[0], MSG_MMS_SMIL_TEXT_BOLD_BOOL, true);
987 msg_struct_t attachment[20];
989 for (size_t idx = 0; idx < getAttachmentsRef().size(); ++idx) {
990 IAttachmentPtr att = getAttachment(idx);
995 LoggerD("Add attachment=" << att->getFullPath());
997 errnum = stat(att->getFullPath().c_str(), &buffer);
998 LoggerD("errnum=" << errnum);
1001 LoggerE("Opening file: " << att->getFullPath().c_str());
1002 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1003 "cannot open attachment file");
1006 //this function should return valid pointer
1007 att->setMessage(SharedFromThis()); // setMessage to setMessageId
1008 att->setAttachmentID((int)idx);
1009 att->setDownloaded(true);
1011 int ret = mimeTypeStringToIndexInt(att->getMimeType());
1013 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[idx]);
1014 msg_set_str_value(attachment[idx], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
1016 if(ret != MIME_UNKNOWN)
1018 msg_set_int_value(attachment[idx], MSG_MMS_ATTACH_MIME_TYPE_INT, ret);
1021 LoggerD("Attachment added");
1027 if (MSG_SUCCESS !=msg_set_mms_struct(m_messageData, mms_struct))
1029 LoggerE("set message body error");
1030 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set message body error");
1033 msg_release_struct(&mms_struct);
1035 setAttachmentsValidity(true);
1036 setBodyValidity(true);
1039 Catch(WrtDeviceApis::Commons::PlatformException) {
1040 LoggerE("Platform error");
1041 msg_release_struct(&mms_struct);
1047 void Mms::updateReadStatus()
1049 if (isReadStatusValid()) {
1053 LoggerI("updating platform read status: " << isRead());
1054 // if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
1055 if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
1056 LoggerE("problem with setting subject");
1057 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
1060 setReadStatusValidity(true);
1063 void Mms::updateIsRead()
1065 LoggerD("updating m_id=" << getIdRef());
1067 if (!m_messageData) {
1068 //error if platform message not exists
1069 LoggerE("message can not be updated");
1070 Throw(WrtDeviceApis::Commons::PlatformException);
1073 // check if abstraction from m_isReadChange value has been changed
1074 if (isReadChangeStatusValid()) {
1075 // do not update if not changed
1081 if (this->getIdRef().empty()) {
1082 LoggerE("existing msgId is zero, remove msg not done");
1083 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1084 "existing msgId is zero, remove msg not done");
1088 msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
1090 LoggerE("Failed to update isRead");
1091 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
1094 Catch(WrtDeviceApis::Commons::PlatformException) {
1095 LoggerE("platform error occurs");
1097 setisReadChangeStatusValidity(true);
1101 void Mms::updateMessage()
1103 LoggerD("updating m_id=" << getIdRef());
1104 msg_error_t err = MSG_SUCCESS;
1105 msg_struct_t msg = NULL;
1106 msg_struct_t sendOpt = NULL;
1108 if (!m_messageData) {
1109 //error if platform message not exists
1110 LoggerE("message can not be updated");
1111 Throw(WrtDeviceApis::Commons::PlatformException);
1117 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1118 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1120 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
1122 if (err != MSG_SUCCESS)
1124 LoggerE("Get Message Failed!");
1125 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
1128 if (this->getIdRef().empty()) {
1129 LoggerE("existing msgId is zero, update msg not done");
1130 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1131 "existing msgId is zero, update msg not done");
1136 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
1138 LoggerE("Failed to update message");
1139 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
1141 msg_release_struct(&msg);
1142 msg_release_struct(&sendOpt);
1144 Catch(WrtDeviceApis::Commons::PlatformException) {
1145 msg_release_struct(&msg);
1146 msg_release_struct(&sendOpt);
1147 LoggerE("platform error occurs");
1152 void Mms::createSendMessage()
1154 LoggerD("convert m_id= " << convertId(getIdRef()));
1156 //prepare for add sms to draft folder
1157 if (!m_messageData) {
1158 //error if platform message not exists
1159 LoggerE("message can not be updated");
1160 Throw(WrtDeviceApis::Commons::PlatformException);
1163 //update all sms data
1164 if (getCurrentFolder() == DRAFTBOX) {
1165 LoggerD("update all mms data");
1167 updateBodyAndAttachments();
1168 updateRecipientList();
1175 // MSG_SENDINGOPT_S option = { false, false, false };
1176 // option.option.smsSendOpt.bReplyPath = true;
1177 // trying to get message from platform
1179 // msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1180 // msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
1183 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
1185 // msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1186 // msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, 4);
1187 // msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
1189 setId(convertId(msgId));
1190 setFolderType(DRAFTBOX);
1191 setMessageStatus(MESSAGE_STATUS_DRAFT);
1193 Catch(WrtDeviceApis::Commons::PlatformException) {
1194 LoggerE("remove message error");
1195 if (m_messageData) {
1196 //releasing platform message structure
1197 // msg_release_message(&m_messageData);
1198 msg_release_struct(&m_messageData);
1205 void Mms::addMessageToDraft()
1207 LoggerD("convert m_id= " << convertId(getIdRef()));
1209 msg_struct_t sendOpt = NULL;
1211 //prepare for add sms to draft folder
1212 if (!m_messageData) {
1213 //error if platform message not exists
1214 LoggerE("message can not be updated");
1215 Throw(WrtDeviceApis::Commons::PlatformException);
1218 //update all mms data
1219 if (getCurrentFolder() == DRAFTBOX) {
1221 updateBodyAndAttachments();
1222 updateRecipientList();
1229 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1231 // trying to add message
1232 LoggerD("add message");
1233 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
1234 if (ret < MSG_SUCCESS) {
1235 LoggerE("msg_add_message failed, error code=" << ret);
1236 Throw(WrtDeviceApis::Commons::PlatformException);
1243 LoggerD("Message ID : " << msgId);
1246 LoggerD("Message ID is invailded ");
1247 Throw(WrtDeviceApis::Commons::PlatformException);
1250 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1252 setId(convertId(msgId));
1255 msg_release_struct(&sendOpt);
1258 Catch(WrtDeviceApis::Commons::PlatformException) {
1259 LoggerE("add draft message error");
1260 msg_release_struct(&sendOpt);
1266 void Mms::loadDraftMessage()
1270 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
1272 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
1275 msg_release_struct(&m_messageData);
1276 m_messageData = NULL;
1277 msg_struct_t sendOpt = NULL;
1281 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1282 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1284 // trying to get message from platform
1285 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
1287 LoggerE("get message error");
1288 Throw(WrtDeviceApis::Commons::PlatformException);
1290 LoggerD("message found with msgId=" << getIdRef());
1292 // read all mms dat to abstraction layer
1293 readConversationId(m_messageData);
1294 readPriority(m_messageData);
1295 readSubject(m_messageData);
1296 readFolder(m_messageData);
1297 readDateTime(m_messageData);
1298 readReadStatus(m_messageData);
1299 readMessageStatus(m_messageData);
1300 readBody(m_messageData);
1302 msg_release_struct(&sendOpt);
1304 Catch(WrtDeviceApis::Commons::PlatformException) {
1305 LoggerE("exception");
1307 msg_release_struct(&sendOpt);
1312 void Mms::readAllData()
1316 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
1318 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
1321 msg_release_struct(&m_messageData);
1322 m_messageData = NULL;
1323 msg_struct_t sendOpt = NULL;
1327 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1328 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1330 // trying to get message from platform
1331 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
1333 LoggerE("get message error");
1334 Throw(WrtDeviceApis::Commons::PlatformException);
1336 LoggerD("message found with msgId=" << getIdRef());
1338 // read all mms dat to abstraction layer
1339 readConversationId(m_messageData);
1340 // readRecipientList(m_messageData);
1341 readPriority(m_messageData);
1342 readSubject(m_messageData);
1343 readBodyAndAttachments(m_messageData);
1344 readFolder(m_messageData);
1345 readDateTime(m_messageData);
1346 readReadStatus(m_messageData);
1347 readMessageStatus(m_messageData);
1349 msg_release_struct(&sendOpt);
1351 Catch(WrtDeviceApis::Commons::PlatformException) {
1352 LoggerE("exception");
1354 msg_release_struct(&sendOpt);
1359 void Mms::moveToFolder(const FolderType newFolder)
1366 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1369 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1370 platfromFolderId) != MSG_SUCCESS) {
1371 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error during movinf message");
1375 Catch(WrtDeviceApis::Commons::PlatformException) {
1376 LoggerE("remove message error");
1382 void Mms::moveToFolder(const string& newFolder)
1389 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1392 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1393 platfromFolderId) != MSG_SUCCESS) {
1394 LoggerE("msg_move_msg_to_folder error");
1395 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_move_msg_to_folder error");
1399 Catch(WrtDeviceApis::Commons::PlatformException) {
1400 LoggerE("remove message error");
1406 void Mms::copyToFolder(const FolderType newFolder)
1411 msg_message_t msg = msg_new_message();
1415 MSG_SENDINGOPT_S option = { false, false, false };
1416 option.option.smsSendOpt.bReplyPath = true;
1418 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1420 const msg_folder_id_t platfromFolderId =
1421 Messaging::convertFolderToPlatform(newFolder);
1422 msg_set_message_id(msg, 0);
1423 msg_set_folder_id(msg, platfromFolderId);
1425 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1426 if (error != MSG_SUCCESS) {
1427 LoggerE("msg_add_message failed, error code=" << error);
1428 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1432 msg_release_message(&msg);
1436 Catch(WrtDeviceApis::Commons::PlatformException) {
1437 LoggerE("remove message error");
1439 msg_release_message(&msg);
1446 void Mms::copyToFolder(const string& newFolder)
1451 msg_message_t msg = msg_new_message();
1455 MSG_SENDINGOPT_S option = { false, false, false };
1456 option.option.smsSendOpt.bReplyPath = true;
1458 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1460 const msg_folder_id_t platfromFolderId =
1461 Messaging::convertFolderToPlatform(newFolder);
1462 msg_set_message_id(msg, 0);
1463 msg_set_folder_id(msg, platfromFolderId);
1465 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1466 if (error != MSG_SUCCESS) {
1467 LoggerE("msg_add_message failed, error code=" << error);
1468 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1472 msg_release_message(&msg);
1476 Catch(WrtDeviceApis::Commons::PlatformException) {
1477 LoggerE("remove message error");
1479 msg_release_message(&msg);
1488 LoggerD("delete m_id=" << getIdRef());
1492 if (this->getIdRef().empty()) {
1493 LoggerE("existing msgId is zero, remove msg not done");
1494 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1495 "existing msgId is zero, remove msg not done");
1499 msg_delete_message(MsgGetCommonHandle(),
1500 convertId(getIdRef()))) {
1501 LoggerE("Failed to delete Message");
1502 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
1506 Catch(WrtDeviceApis::Commons::PlatformException) {
1507 LoggerE("platform error occurs");
1513 LoggerD("sending message, id=" << getIdRef());
1516 //prepare for sending sms/mms
1519 LoggerD("Start Sending Message...");
1521 LoggerD("trying to send mms");
1522 msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
1524 if (err != MSG_SUCCESS)
1526 LoggerE("Sending Message (submit request) failed!!! err=" << err);
1527 setMessageStatus(MESSAGE_STATUS_FAILED);
1531 setMessageStatus(MESSAGE_STATUS_SENDING);
1533 LoggerD("Sending Message request is submitted!");
1535 Catch(WrtDeviceApis::Commons::PlatformException) {
1536 LoggerE("message is not send, manually run callback");
1543 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1544 if (requestReceiver) {
1545 LoggerE("send Error");
1546 EventMessagingServicePtr event = getMessagingServiceEvent();
1547 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1548 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
1553 void Mms::sendingCallback(msg_struct_t sent_status)
1555 // LoggerI("sendingCallback callback received. Req id = " <<
1556 // sent_status->reqId << " Status = " << (int)sent_status->status);
1557 // msg_struct_t request_data = NULL;
1558 // msg_get_struct_handle(sent_status, MSG_STRUCT_REQUEST_INFO, (void **)request_data);
1559 // msg_get_int_value(request_data, MSG_REQUEST_REQUESTID_INT, &tempInt);
1560 int status = MSG_NETWORK_SEND_FAIL;
1561 msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
1563 LoggerD("status : " << status);
1565 if (MSG_NETWORK_SEND_SUCCESS == status) {
1566 LoggerD("sending ok");
1567 setSendingStatusOk();
1568 setMessageStatus(MESSAGE_STATUS_SENT);
1570 LoggerE("sending failed: " << static_cast<unsigned int>(status));
1571 setSendingStatusFailed();
1572 setMessageStatus(MESSAGE_STATUS_FAILED);
1576 void Mms::sendCancel(int handle)
1578 LoggerD("sending message, id=" << getIdRef());
1580 LoggerD("handle =" << handle);
1583 void Mms::setSendingStatusOk()
1585 //success callback should be executed here
1586 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1587 msg_struct_list_s *addr_list = NULL;
1588 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1591 if (requestReceiver) {
1592 LoggerI("calling JS success callback");
1593 EventMessagingServicePtr event = getMessagingServiceEvent();
1594 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
1596 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1598 nToCnt = addr_list->nCount;
1600 for ( int index=0; index < nToCnt; index++)
1602 msg_get_str_value(addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1603 event->m_successRecipients.push_back(strNumber);
1606 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1610 void Mms::setSendingStatusFailed()
1612 //error callback should be executed here
1613 EventOnSendingFailedEmitterPtr emitter = getEmitter();
1614 msg_struct_list_s *addr_list = NULL;
1615 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1620 EventOnSendingFailedPtr event(new EventOnSendingFailed);
1621 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
1622 emitter->emit(event);
1626 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1627 EventMessagingServicePtr event = getMessagingServiceEvent();
1628 if (requestReceiver)
1630 LoggerE("calling JS error callback");
1631 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1632 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1633 nToCnt = addr_list->nCount;
1635 LoggerD("nToCnt : " << nToCnt);
1637 for ( int index=0; index < nToCnt; index++)
1639 msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1640 event->m_failRecipients.push_back(strNumber);
1643 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1648 FolderType Mms::toFolder(const std::string &folder)
1650 if (folder == "INBOX") {
1652 } else if (folder == "OUTBOX") {
1654 } else if (folder == "SENTBOX") {
1656 } else if (folder == "DRAFTBOX") {
1659 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
1662 MimeType Mms::mimeTypeStringToIndexInt(std::string inputString)
1664 const char* szMimeStr = inputString.c_str();
1665 MimeType retInt = MIME_UNKNOWN;
1667 LoggerD("szMimeStr " << szMimeStr);
1669 for(int idx =0; mimeTable[idx].szMIME != NULL ; idx++)
1671 if (!strcmp(mimeTable[idx].szMIME, szMimeStr)) {
1672 retInt = mimeTable[idx].mime;
1680 std::string Mms::indexIntToMimeTypeString(MimeType inputIndex)
1682 std::string retString;
1684 for (int idx=0; mimeTable[idx].szMIME != NULL; idx++) {
1685 if (inputIndex == mimeTable[idx].mime) {
1686 retString = (char *)mimeTable[idx].szMIME;