Update change log and spec for wrt-plugins-tizen_0.4.55
[platform/framework/web/wrt-plugins-tizen.git] / src / Messaging / Mms.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include "Mms.h"
19
20 #include <vector>
21 #include <Commons/Exception.h>
22 #include "ReqReceiverMessage.h"
23 #include "Messaging.h"
24 #include "CallbackMgr.h"
25 #include "MsgServiceHandleMgr.h"
26 #include <Logger.h>
27
28 extern "C" {
29 #include <msg.h>
30 #include <msg_storage.h>
31 }
32
33
34 namespace {
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";
43 }
44
45 using namespace std;
46
47 namespace DeviceAPI {
48 namespace Messaging {
49
50 Mms::Mms(const string& id) :
51     IMessage(MMS, id),
52 //    m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
53     m_messageData(NULL)
54 {
55         LoggerD("m_id=" << getIdRef());
56         LoggerD("m_msgType=" << getMessageType());
57
58         char buf[] = "XXXXXX";
59         mode_t mask = umask(S_IWGRP | S_IWOTH);
60         int i = mkstemp(buf);
61         LoggerD("buf : " << buf << " i : " << i);
62         umask(mask);
63         m_bodyFilePath = buf;
64         m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
65
66         LoggerD("m_bodyFilePath : " << m_bodyFilePath);
67
68         if (getIdRef().empty()) {
69                 LoggerD("create new message");
70                 createNewMessage();
71         } else {
72                 LoggerD("read existing message");
73                 readExistingMessage();
74         }
75 }
76
77 Mms::Mms(const string& id, const msg_struct_t msg_data) :
78         IMessage(MMS, id),
79         m_messageData(NULL)
80 {
81         LoggerD("m_id=" << getIdRef());
82         LoggerD("m_msgType=" << getMessageType());
83
84         LoggerD("created msg_data : " << msg_data);
85         m_messageData = createNewCopyOfPLatformMsgWithAddressList(msg_data);
86         LoggerD("created m_messageData : " << m_messageData);
87
88         char buf[] = "XXXXXX";
89         mode_t mask = umask(S_IWGRP | S_IWOTH);
90         int i = mkstemp(buf);
91         LoggerD("buf : " << buf << " i : " << i);
92         umask(mask);
93         m_bodyFilePath = buf;
94         m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
95         
96         LoggerD("m_bodyFilePath : " << m_bodyFilePath);
97         
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);
108
109 }
110
111 Mms::~Mms()
112 {
113     LoggerD("enter");
114
115     if (m_messageData) {
116         // release platform message structure
117 //        msg_release_message(&m_messageData);
118         msg_release_struct(&m_messageData);
119     }
120
121     //remove tmp file
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());
126     }
127 }
128
129 void Mms::createNewMessage()
130 {
131     if (m_messageData) {
132         msg_release_struct(&m_messageData);
133         m_messageData = NULL;
134     }
135
136     char strSubject[MAX_SUBJECT_LEN] = {0,};
137
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;
141
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);
146
147     setMmsType(MULTIPART_MIXED);
148     setReadStatus(false);
149     setMessageStatus(MESSAGE_STATUS_CREATED);
150
151         msg_release_struct(&sendOpt);
152     LoggerD("Message created successfully, Id: " << getIdRef());
153 }
154
155 void Mms::readExistingMessage()
156 {
157         LoggerD("entered");
158
159         if (getIdRef().empty() || (EMPTY_ID == getIdRef())) 
160         {
161                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
162         }
163
164         msg_release_struct(&m_messageData);
165         m_messageData = NULL;
166         msg_struct_t sendOpt = NULL;
167
168         Try {
169
170                 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
171                 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
172
173                 // trying to get message from platform
174                 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt)) 
175                 {
176                         LoggerE("get message error");
177                         Throw(WrtDeviceApis::Commons::PlatformException);
178                 }
179                 LoggerD("message found with msgId=" << getIdRef());
180
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);
191
192                 msg_release_struct(&sendOpt);
193         }
194         Catch(WrtDeviceApis::Commons::PlatformException) {
195                 LoggerE("exception");
196                 // nothing to do
197                 msg_release_struct(&sendOpt);
198         }
199 }
200
201 void Mms::readDateTime(msg_struct_t& messageData)
202 {
203 //  tm* time = localtime(msg_get_time(messageData));
204 //    tm dateT = getDateTime();
205     int tempInt = 0;
206     msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
207
208     LoggerE("readDateTime : " <<tempInt);
209
210     tm* time = localtime((time_t*)&tempInt);
211     if (!time) {
212         LoggerE("localtime failed");
213         Throw(WrtDeviceApis::Commons::PlatformException);
214     }
215     setDateTime(*time);
216 }
217
218 void Mms::readReadStatus(msg_struct_t& messageData)
219 {
220     bool tempBool = 0;
221     msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
222     setReadStatus(tempBool);
223 }
224
225 void Mms::readFolder(msg_struct_t& messageData)
226 {
227     int tempValue = 0;
228     msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
229
230     switch (tempValue) {
231     case MSG_INBOX_ID:
232         setFolderType(INBOX);
233         break;
234     case MSG_OUTBOX_ID:
235         setFolderType(OUTBOX);
236         break;
237     case MSG_SENTBOX_ID:
238         setFolderType(SENTBOX);
239         break;
240     case MSG_DRAFT_ID:
241         setFolderType(DRAFTBOX);
242         break;
243     default:
244         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
245     }
246 }
247
248 void Mms::readMessageStatus(msg_struct_t& messageData)
249 {
250         int tempValue = 0;
251         msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
252
253         LoggerD("readMessageStatus folder : " << tempValue);
254
255         switch (tempValue) {
256                 case MSG_INBOX_ID:
257                         setMessageStatus(MESSAGE_STATUS_LOADED);
258                         break;
259                 case MSG_OUTBOX_ID:
260                         setMessageStatus(MESSAGE_STATUS_SENDING);
261                         break;
262                 case MSG_SENTBOX_ID:
263                         setMessageStatus(MESSAGE_STATUS_SENT);
264                         break;
265                 case MSG_DRAFT_ID:
266                         setMessageStatus(MESSAGE_STATUS_DRAFT);
267                         break;
268                 default:
269                         setMessageStatus(MESSAGE_STATUS_LOADED);
270                         break;
271         }
272 }
273
274 void Mms::readPriority(msg_struct_t& messageData)
275 {
276 //    switch (msg_get_priority_info(messageData)) {
277     int tempInt = 0;
278     msg_get_int_value(messageData, MSG_MESSAGE_PRIORITY_INT, &tempInt);
279     switch (tempInt) {
280     case MSG_MESSAGE_PRIORITY_LOW:
281         setPriority(MessagePriority::LOW);
282         break;
283     case MSG_MESSAGE_PRIORITY_NORMAL:
284         setPriority(MessagePriority::NORMAL);
285         break;
286     case MSG_MESSAGE_PRIORITY_HIGH:
287         setPriority(MessagePriority::HIGH);
288         break;
289     default:
290         LoggerE("Wrong priority type");
291         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong priority type");
292     }
293 }
294
295 void Mms::readConversationId(msg_struct_t& messageData)
296 {
297         int tempInt = 0;
298         msg_get_int_value(messageData, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
299         LoggerD("conversationID : " <<tempInt);
300         setConvId(tempInt);
301 }
302
303 void Mms::readRecipientList(msg_struct_t& messageData)
304 {
305         std::string phoneNumber;
306 //      int recipientCount = msg_get_address_count(messageData);
307 //      LoggerD("Recipient count " << recipientCount);
308
309         msg_struct_list_s *addr_list;
310         msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
311
312         int tempInt = 0;
313         char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
314
315         int recipientCount = addr_list->nCount;
316         LoggerD("Recipient count " << recipientCount);
317
318         for (int i = 0; i < recipientCount; ++i) 
319         {
320 //        int type = msg_get_direction_info(messageData);
321                 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
322                 int type = tempInt;
323                 LoggerD("Direction: " << type);
324
325                 if (MSG_DIRECTION_TYPE_MT == type) 
326                 {
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;
331                 
332                         if (validatePhoneNumber(phoneNumber)) 
333                         {
334                                 setSourceAddress(phoneNumber);
335                                 setFrom(phoneNumber);
336                         }
337                         LoggerD("MT number: " << phoneNumber);
338                 } 
339                 else if (MSG_DIRECTION_TYPE_MO == type) 
340                 {
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);
347                         switch (tempInt) 
348                         {
349                                 case MSG_RECIPIENTS_TYPE_TO:
350                                         appendToRecipients(strNumber);
351                                         break;
352                                 case MSG_RECIPIENTS_TYPE_CC:
353                                         appendCcRecipients(strNumber);
354                                         break;
355                                 case MSG_RECIPIENTS_TYPE_BCC:
356                                         appendBccRecipients(strNumber);
357                                         break;
358                                 default:
359                                 LoggerE("Wrong type of recipient");
360                         }
361                 } 
362                 else 
363                 {
364                         LoggerE("Wrong type of recipient");
365                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
366                 }
367         }
368 }
369
370 void Mms::readSubject(msg_struct_t& messageData)
371 {
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);
376     setSubject(strTemp);
377 }
378
379 void Mms::readBodyAndAttachments(msg_struct_t& messageData)
380 {
381
382         int pageLen, mediaLen, attachLen, tempInt, ret;
383
384         msg_struct_t mms_struct = NULL;
385
386         msg_list_handle_t page_list = NULL;
387         msg_list_handle_t media_list = NULL;
388         msg_list_handle_t attach_list = NULL;
389         
390         msg_struct_t page = NULL;
391         msg_struct_t media = NULL;
392         msg_struct_t attach = NULL;
393
394         mms_struct = msg_create_struct(MSG_STRUCT_MMS);
395         ret = msg_get_mms_struct(messageData, mms_struct);
396
397         if (ret != MSG_SUCCESS) 
398         {
399                 LoggerE("cannot get mms struct");
400                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
401         }
402
403         char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
404         char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
405
406         msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
407         pageLen = msg_list_length(page_list);
408
409         if (pageLen > 0) {
410                 setMmsType(MULTIPART_RELATED);
411         } else {
412                 setMmsType(MULTIPART_MIXED);
413         }
414
415         LoggerD("page count: " << pageLen);
416
417         for (int p = 0; p < pageLen; ++p) 
418         {
419                 LoggerD("page " << p);
420                 page = (msg_struct_t)msg_list_nth_data(page_list, p);
421                 
422                 if (NULL  == page) {
423                         LoggerE("returned page is null, continue");
424                         continue;
425                 }
426                 
427                 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
428                 mediaLen = msg_list_length(media_list);
429
430                 for (int m = 0; m < mediaLen; ++m) 
431                 {
432                         LoggerD("media file " << m);
433                         media = (msg_struct_t)msg_list_nth_data(media_list, m);
434                         if (NULL == media) 
435                         {
436                                 LoggerE("returned media is null, continue");
437                                 continue;
438                         }
439
440                         msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
441
442                         memset(szFilePath, 0, sizeof(szFilePath));
443                         msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
444                         
445                         if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt)) 
446                         {
447                                 //text value on first page goes to body attribute
448                                 LoggerD("setting body from " << szFilePath);
449                                 
450                                 FILE* f = NULL;
451                                 f = fopen(szFilePath, "r");
452                                 if (!f) 
453                                 {
454                                         LoggerE("cannot read file with body" << szFilePath);
455                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
456                                 }
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];
461                                 size_t error;
462                                 if (data) {
463                                         memset(data, 0, size + 1);
464                                         error = fread(data, 1, size, f);
465                                         setBody(data);
466                                         delete[] data;
467                                 } else {
468                                         LoggerE("body is not set");
469                                 }
470                                 LoggerD("message body: '" << getBody() << "'");
471                                 fclose(f);
472                         } 
473                         else 
474                         {
475                                 LoggerD("adding attachment " << szFilePath);
476
477                                 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
478                                 //attachment->setMessage(this); //set IMessagePtr
479
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)) 
483                                 {
484                                         LoggerD("renaming to " << szFileName);
485                                         attachment->rename(szFileName);
486                                 }
487                                 else if (MMS_SMIL_MEDIA_TEXT == tempInt) 
488                                 {
489                                         std::stringstream newName;
490                                         newName << "body_page_" << p + 1 << ".txt";
491                                         LoggerD("renaming to " << newName.str());
492                                         attachment->rename(newName.str());
493                                 }
494                         }
495                 }
496         }
497
498         msg_get_list_handle(mms_struct, MSG_MMS_ATTACH_LIST_HND, (void **)&attach_list);
499         
500         attachLen= msg_list_length(attach_list);
501
502         LoggerD("attachment count: " << attachLen);
503         for (int a = 0; a < attachLen; ++a) 
504         {
505                 std::string tempString;
506                 int tempInt;
507                 
508                 attach = (msg_struct_t)msg_list_nth_data(attach_list, a);
509                 if (NULL == attach) 
510                 {
511                         LoggerE("attachment is null, continue");
512                         continue;
513                 }
514
515                 memset(szFilePath, 0, sizeof(szFilePath));
516                 memset(szFileName, 0, sizeof(szFileName));
517
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));
520
521                 msg_get_int_value(attach, MSG_MMS_ATTACH_MIME_TYPE_INT, &tempInt);
522                 tempString = indexIntToMimeTypeString((MimeType)tempInt);
523                 
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);
529                 }
530                 att->setMimeType(tempString);
531                 att->setAttachmentID((int)a);
532                 att->setDownloaded(true);
533         }
534         msg_release_struct(&mms_struct);
535 }
536
537 void Mms::readBody(msg_struct_t& messageData)
538 {
539
540         int pageLen, mediaLen, tempInt, ret;
541
542         msg_struct_t mms_struct = NULL;
543
544         msg_list_handle_t page_list = NULL;
545         msg_list_handle_t media_list = NULL;
546         
547         msg_struct_t page = NULL;
548         msg_struct_t media = NULL;
549
550         mms_struct = msg_create_struct(MSG_STRUCT_MMS);
551         ret = msg_get_mms_struct(messageData, mms_struct);
552
553         if (ret != MSG_SUCCESS) 
554         {
555                 LoggerE("cannot get mms struct");
556                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
557         }
558
559         char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
560         char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
561
562         msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
563         pageLen = msg_list_length(page_list);
564
565         if (pageLen > 0) {
566                 setMmsType(MULTIPART_RELATED);
567         } else {
568                 setMmsType(MULTIPART_MIXED);
569         }
570
571         LoggerD("page count: " << pageLen);
572
573         for (int p = 0; p < pageLen; ++p) 
574         {
575                 LoggerD("page " << p);
576                 page = (msg_struct_t)msg_list_nth_data(page_list, p);
577                 
578                 if (NULL  == page) {
579                         LoggerE("returned page is null, continue");
580                         continue;
581                 }
582                 
583                 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
584                 mediaLen = msg_list_length(media_list);
585
586                 for (int m = 0; m < mediaLen; ++m) 
587                 {
588                         LoggerD("media file " << m);
589                         media = (msg_struct_t)msg_list_nth_data(media_list, m);
590                         if (NULL == media) 
591                         {
592                                 LoggerE("returned media is null, continue");
593                                 continue;
594                         }
595
596                         msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
597
598                         memset(szFilePath, 0, sizeof(szFilePath));
599                         msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
600                         
601                         if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt)) 
602                         {
603                                 //text value on first page goes to body attribute
604                                 LoggerD("setting body from " << szFilePath);
605                                 
606                                 FILE* f = NULL;
607                                 f = fopen(szFilePath, "r");
608                                 if (!f) 
609                                 {
610                                         LoggerE("cannot read file with body" << szFilePath);
611                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
612                                 }
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];
617                                 size_t error;
618                                 if (data) {
619                                         memset(data, 0, size + 1);
620                                         error = fread(data, 1, size, f);
621                                         setBody(data);
622                                         delete[] data;
623                                 } else {
624                                         LoggerE("body is not set");
625                                 }
626                                 LoggerD("message body: '" << getBody() << "'");
627                                 fclose(f);
628                         } 
629                         else 
630                         {
631                                 LoggerD("adding attachment " << szFilePath);
632
633                                 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
634                                 //attachment->setMessage(this); //set IMessagePtr
635
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)) 
639                                 {
640                                         LoggerD("renaming to " << szFileName);
641                                         attachment->rename(szFileName);
642                                 }
643                                 else if (MMS_SMIL_MEDIA_TEXT == tempInt) 
644                                 {
645                                         std::stringstream newName;
646                                         newName << "body_page_" << p + 1 << ".txt";
647                                         LoggerD("renaming to " << newName.str());
648                                         attachment->rename(newName.str());
649                                 }
650                         }
651                 }
652         }
653         msg_release_struct(&mms_struct);
654 }
655
656
657 bool Mms::hasAttachment()
658 {
659         std::size_t attachmentSize = getAttachmentsCount();
660         if ( attachmentSize > 0)
661                 return true;
662         else
663                 return false;
664 }
665
666 void Mms::update(bool draftsOnly)
667 {
668     LoggerD("updating m_id=" << getIdRef());
669
670     if (!m_messageData) {
671         //error if platform message not exists
672         LoggerE("message can not be updated");
673         Throw(WrtDeviceApis::Commons::PlatformException);
674     }
675
676     //update mms data from abstraction
677     if (!draftsOnly || getCurrentFolder() == DRAFTBOX) {
678         updateSubject();
679         updateBodyAndAttachments();
680         updateRecipientList();
681         updatePriority();
682     }
683     updateReadStatus();
684 }
685
686 void Mms::updatePriority()
687 {
688     if (isPriorityValid()) {
689         return;
690     }
691     int priority = -1;
692     LoggerI("MMS updating priority");
693
694     //set priority in platform
695     switch (getPriority()) {
696     case MessagePriority::LOW:
697         priority = MSG_MESSAGE_PRIORITY_LOW;
698         break;
699     case MessagePriority::NORMAL:
700         priority = MSG_MESSAGE_PRIORITY_NORMAL;
701         break;
702     case MessagePriority::HIGH:
703         priority = MSG_MESSAGE_PRIORITY_HIGH;
704         break;
705     default:
706         LoggerE("Wrong priority");
707         Throw(WrtDeviceApis::Commons::PlatformException);
708     }
709     LoggerI("priority : " << priority);
710
711     if (MSG_SUCCESS !=
712         msg_set_int_value(m_messageData, MSG_MESSAGE_PRIORITY_INT, priority)){
713         
714         LoggerE("Error during setting priority");
715         Throw(WrtDeviceApis::Commons::PlatformException);
716     }
717 }
718
719 void Mms::updateRecipientList()
720 {
721     // check if abstraction recipient value has been changed
722     if (getToRecipients().isValid() &&
723         getBccRecipients().isValid() &&
724         getCcRecipients().isValid()) {
725         return;
726     }
727
728     LoggerI("MMS updating platform recipients");
729
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);
734         int nToCnt = 0;
735         nToCnt = addr_list->nCount;
736
737         LoggerI("addr_list->nCount" << addr_list->nCount);
738         
739         if (nToCnt > 0)         
740         {               
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);
747                 }
748                 nToCnt = 0;
749                 addr_list->nCount = nToCnt;
750         }               
751
752         LoggerI("addr_list->nCount" << addr_list->nCount);
753
754         vector<string> to = getToRecipients().getRecipients();
755         vector<string> cc = getCcRecipients().getRecipients();
756         vector<string> bcc = getBccRecipients().getRecipients();
757
758         // update addresses in platform structure
759         if (to.size()) 
760         {
761                 LoggerI("updating to");
762                 for (size_t i = 0; i < to.size(); i++) 
763                 {
764                         if (i >= MAX_TO_ADDRESS_CNT) 
765                         {
766                                 LoggerE("max number of recipient exceeded");
767                                 break;
768                         }
769                         LoggerD("adding to[" << i << "]=" << to[i]);
770
771                         msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
772
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) 
775                         {
776                                 LoggerE("problem with adding to address");
777                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
778                         }
779                         
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) 
782                         {
783                                 LoggerE("problem with adding to address");
784                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
785                         }
786                         nToCnt ++;
787                 }
788                 addr_list->nCount = nToCnt;
789                 LoggerE("nToCnt : " << nToCnt);
790                 LoggerE("addr_list->nCount: " <<addr_list->nCount);
791                 
792         }
793         
794         LoggerI("addr_list->nCount" << addr_list->nCount);
795
796         if (cc.size()) 
797         {
798                 LoggerI("updating cc");
799                 for (size_t i = 0; i < cc.size(); i++) 
800                 {
801                         if (nToCnt >= MAX_TO_ADDRESS_CNT) 
802                         {
803                                 LoggerE("max number of recipient exceeded");
804                                 break;
805                         }
806                         LoggerD("adding cc[" << i << "]=" << cc[i]);
807
808                         msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
809
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) 
812                         {
813                                 LoggerE("problem with adding cc address");
814                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
815                         }
816                         
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) 
819                         {
820                                 LoggerE("problem with adding cc address");
821                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
822                         }
823                         nToCnt ++;
824                 }
825                 addr_list->nCount = nToCnt;
826                 LoggerE("nToCnt : " << nToCnt);
827                 LoggerE("addr_list->nCount: " <<addr_list->nCount);
828         }
829
830         LoggerI("addr_list->nCount" << addr_list->nCount);
831
832         if (bcc.size()) 
833         {
834                 LoggerI("updating bcc");
835                 for (size_t i = 0; i < bcc.size(); i++) 
836                 {
837                         if (nToCnt >= MAX_TO_ADDRESS_CNT) 
838                         {
839                                 LoggerE("max number of recipient exceeded");
840                                 break;
841                         }
842                         LoggerD("adding bcc[" << i << "]=" << bcc[i]);
843
844                         msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
845
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) 
848                         {
849                                 LoggerE("problem with adding bcc address");
850                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
851                         }
852                         
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) 
855                         {
856                                 LoggerE("problem with adding bcc address");
857                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
858                         }
859                         nToCnt ++;
860                 }
861                 addr_list->nCount = nToCnt;
862                 LoggerE("nToCnt : " << nToCnt);
863                 LoggerE("addr_list->nCount: " <<addr_list->nCount);
864         }
865
866         LoggerI("addr_list->nCount" << addr_list->nCount);              
867         setToValidity(true);
868         setCcValidity(true);
869         setBccValidity(true);
870 }
871
872 void Mms::updateSubject()
873 {
874     // check if abstraction subject value has been changed
875     if (isSubjectValid()) {
876         return;
877     }
878     LoggerI("updating platform subject: " << getSubjectRef());
879     if (MSG_SUCCESS !=
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)) {
882
883         LoggerE("problem with setting subject");
884         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
885     }
886     setSubjectValidity(true);
887 }
888
889 void Mms::updateBodyAndAttachments()
890 {
891                 // check if attachment or body source address value has been changed
892                 if (isAttachmentsValid() && isBodyValid()) {
893                         return;
894                 }
895         
896 //              MMS_MESSAGE_DATA_S *mmsData = NULL;
897                 msg_struct_t mms_struct = NULL;
898 //              msg_struct_t old_mms_struct = NULL;// THIS
899 //              int ret;// THIS
900
901                 LoggerI("updating platform body and attachment");
902         
903                 Try
904                 {
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];
909                         
910                         if (getMessageType() != MMS) {
911                                 LoggerE("Wrong msg type");
912                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong msg type");
913                         }
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
917
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
922
923                         if (!mms_struct) {
924                                 LoggerE("create message body failed");
925                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "create message body failed");
926                         }
927         
928                         //body
929                         if (!getBodyRef().empty()) {
930                                 FILE* f = NULL;
931                                 f = fopen(m_bodyFilePath.c_str(), "w");
932                                 if (!f) {
933                                         LoggerE("cannot create file with body" << m_bodyFilePath);
934                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
935                                                          "cannot create file with body");
936                                 }
937                                 LoggerD("body file: " << m_bodyFilePath);
938                                 fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
939                          
940                                 fclose(f);
941
942                                 LoggerD("getBodyRef(): " << getBodyRef());
943
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);
949                                 
950                                 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_REGION, &region[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);
957                                 
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);
962
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);
965                                 
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);
969                                 int error;
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);
977
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);
982                                 
983                         }
984                         
985                         //attachments
986                         struct stat buffer;
987                         int errnum = 0;
988
989                         msg_struct_t attachment[20];                    
990                         
991                         for (size_t idx = 0; idx < getAttachmentsRef().size(); ++idx) {
992                                 IAttachmentPtr att = getAttachment(idx);
993                                 if (!att) {
994                                         continue;
995                                 }
996         
997                                 LoggerD("Add attachment=" << att->getFullPath());
998                                 //checking file
999                                 errnum = stat(att->getFullPath().c_str(), &buffer);
1000                                 LoggerD("errnum=" << errnum);
1001
1002                                 if (errnum != 0) {
1003                                         LoggerE("Opening file: " << att->getFullPath().c_str());
1004                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1005                                                          "cannot open attachment file");
1006                                 }
1007         
1008                                 //this function should return valid pointer
1009                                 att->setMessage(SharedFromThis());      // setMessage to setMessageId
1010                                 att->setAttachmentID((int)idx);
1011                                 att->setDownloaded(true);
1012
1013                                 int ret = mimeTypeStringToIndexInt(att->getMimeType());
1014
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);
1017
1018                                 if(ret != MIME_UNKNOWN)
1019                                 {
1020                                         msg_set_int_value(attachment[idx], MSG_MMS_ATTACH_MIME_TYPE_INT, ret);
1021                                 }
1022                                 
1023                                 LoggerD("Attachment added");
1024         
1025                                 //reset errno
1026                                 errnum = 0;
1027                         }
1028         
1029                 if (MSG_SUCCESS !=msg_set_mms_struct(m_messageData, mms_struct))
1030                 {
1031                         LoggerE("set message body error");
1032                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set message body error");
1033                 }
1034
1035                 msg_release_struct(&mms_struct);
1036
1037                 setAttachmentsValidity(true);
1038                 setBodyValidity(true);
1039                 
1040                 }
1041                 Catch(WrtDeviceApis::Commons::PlatformException) {
1042                         LoggerE("Platform error");
1043                         msg_release_struct(&mms_struct);
1044                         throw;
1045                 }
1046 }
1047
1048
1049 void Mms::updateReadStatus()
1050 {
1051     if (isReadStatusValid()) {
1052         return;
1053     }
1054
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");
1060     }
1061
1062     setReadStatusValidity(true);
1063 }
1064
1065 void Mms::updateIsRead()
1066 {
1067     LoggerD("updating m_id=" << getIdRef());
1068
1069     if (!m_messageData) {
1070         //error if platform message not exists
1071         LoggerE("message can not be updated");
1072         Throw(WrtDeviceApis::Commons::PlatformException);
1073     }
1074         
1075     // check if abstraction from m_isReadChange value has been changed
1076     if (isReadChangeStatusValid()) {
1077         // do not update if not changed
1078         return;
1079     }
1080
1081     Try
1082     {
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");
1087         }
1088
1089         if (MSG_SUCCESS !=
1090             msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
1091         {
1092             LoggerE("Failed to update isRead");
1093             ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
1094         }
1095     }
1096     Catch(WrtDeviceApis::Commons::PlatformException) {
1097         LoggerE("platform error occurs");
1098     }
1099     setisReadChangeStatusValidity(true);
1100
1101 }
1102
1103 void Mms::updateMessage()
1104 {
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;
1109         
1110         if (!m_messageData) {
1111                 //error if platform message not exists
1112                 LoggerE("message can not be updated");
1113                 Throw(WrtDeviceApis::Commons::PlatformException);
1114         }
1115
1116         
1117         Try
1118         {
1119                 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1120                 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);                        
1121                 
1122                 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
1123                 
1124                 if (err != MSG_SUCCESS)
1125                 {
1126                         LoggerE("Get Message Failed!");
1127                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
1128                 }
1129         
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");
1134                 }
1135                 
1136                 update(TRUE);
1137                 
1138                 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
1139                 {
1140                         LoggerE("Failed to update message");
1141                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
1142                 }
1143                 msg_release_struct(&msg);
1144                 msg_release_struct(&sendOpt);
1145         }
1146         Catch(WrtDeviceApis::Commons::PlatformException) {
1147                 msg_release_struct(&msg);
1148                 msg_release_struct(&sendOpt);
1149                 LoggerE("platform error occurs");
1150         }
1151 }
1152
1153
1154 void Mms::createSendMessage()
1155 {
1156     LoggerD("convert m_id= " << convertId(getIdRef())); 
1157
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);
1163     }
1164
1165     //update all sms data
1166     if (getCurrentFolder() == DRAFTBOX) {
1167                 LoggerD("update all mms data");
1168         updateSubject();
1169         updateBodyAndAttachments();
1170         updateRecipientList();
1171         updatePriority();
1172     }
1173
1174     Try
1175     {
1176         int msgId = 0;
1177 //        MSG_SENDINGOPT_S option = { false, false, false };
1178 //        option.option.smsSendOpt.bReplyPath = true;
1179         // trying to get message from platform
1180
1181 //        msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1182 //        msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
1183
1184
1185 //        const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
1186
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);
1190
1191         setId(convertId(msgId));
1192         setFolderType(DRAFTBOX);
1193         setMessageStatus(MESSAGE_STATUS_DRAFT);
1194     }
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);         
1201         }
1202         throw;
1203     }
1204
1205 }       
1206
1207 void Mms::addMessageToDraft()
1208 {
1209         LoggerD("convert m_id= " << convertId(getIdRef()));
1210
1211         msg_struct_t sendOpt = NULL;
1212
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);
1218         }
1219
1220         //update all mms data
1221         if (getCurrentFolder() == DRAFTBOX) {
1222                 updateSubject();
1223                 updateBodyAndAttachments();
1224                 updateRecipientList();
1225                 updatePriority();
1226         }
1227
1228         Try
1229         {
1230                 int msgId = -1;
1231                 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1232
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);
1239                 }
1240                 else
1241                 {
1242                         msgId = ret;
1243                 }
1244
1245                 LoggerD("Message ID : " << msgId);
1246                 if (msgId < 0)
1247                 {
1248                         LoggerD("Message ID is invailded ");
1249                         Throw(WrtDeviceApis::Commons::PlatformException);
1250                 }
1251
1252                 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1253
1254                 setId(convertId(msgId));
1255                 loadDraftMessage();
1256
1257                 msg_release_struct(&sendOpt);
1258
1259         }
1260         Catch(WrtDeviceApis::Commons::PlatformException) {
1261                 LoggerE("add draft message error");
1262                 msg_release_struct(&sendOpt);
1263                 throw;
1264         }
1265
1266 }               
1267
1268 void Mms::loadDraftMessage()
1269 {
1270         LoggerD("entered");
1271
1272         if (getIdRef().empty() || (EMPTY_ID == getIdRef())) 
1273         {
1274                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
1275         }
1276
1277         msg_release_struct(&m_messageData);
1278         m_messageData = NULL;
1279         msg_struct_t sendOpt = NULL;
1280
1281         Try {
1282
1283                 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1284                 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1285
1286                 // trying to get message from platform
1287                 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt)) 
1288                 {
1289                         LoggerE("get message error");
1290                         Throw(WrtDeviceApis::Commons::PlatformException);
1291                 }
1292                 LoggerD("message found with msgId=" << getIdRef());
1293
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);
1303
1304                 msg_release_struct(&sendOpt);
1305         }
1306         Catch(WrtDeviceApis::Commons::PlatformException) {
1307                 LoggerE("exception");
1308                 // nothing to do
1309                 msg_release_struct(&sendOpt);
1310         }
1311
1312 }
1313
1314 void Mms::readAllData()
1315 {
1316         LoggerD("entered");
1317
1318         if (getIdRef().empty() || (EMPTY_ID == getIdRef())) 
1319         {
1320                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
1321         }
1322
1323         msg_release_struct(&m_messageData);
1324         m_messageData = NULL;
1325         msg_struct_t sendOpt = NULL;
1326
1327         Try {
1328
1329                 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1330                 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1331
1332                 // trying to get message from platform
1333                 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt)) 
1334                 {
1335                         LoggerE("get message error");
1336                         Throw(WrtDeviceApis::Commons::PlatformException);
1337                 }
1338                 LoggerD("message found with msgId=" << getIdRef());
1339
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);
1350
1351                 msg_release_struct(&sendOpt);
1352         }
1353         Catch(WrtDeviceApis::Commons::PlatformException) {
1354                 LoggerE("exception");
1355                 // nothing to do
1356                 msg_release_struct(&sendOpt);
1357         }
1358
1359 }
1360
1361 void Mms::moveToFolder(const FolderType newFolder)
1362 {
1363 /*
1364     update();
1365
1366     Try
1367     {
1368         msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1369                 newFolder);
1370
1371         if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1372                                    platfromFolderId) != MSG_SUCCESS) {
1373             ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error during movinf message");
1374         }
1375     }
1376
1377     Catch(WrtDeviceApis::Commons::PlatformException) {
1378         LoggerE("remove message error");
1379         throw;
1380     }
1381 */
1382 }
1383
1384 void Mms::moveToFolder(const string& newFolder)
1385 {
1386 /*
1387     update();
1388
1389     Try
1390     {
1391         msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1392                 newFolder);
1393
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");
1398         }
1399     }
1400
1401     Catch(WrtDeviceApis::Commons::PlatformException) {
1402         LoggerE("remove message error");
1403         throw;
1404     }
1405     */
1406 }
1407
1408 void Mms::copyToFolder(const FolderType newFolder)
1409 {
1410 /*
1411     update();
1412
1413     msg_message_t msg = msg_new_message();
1414
1415     Try
1416     {
1417         MSG_SENDINGOPT_S option = { false, false, false };
1418         option.option.smsSendOpt.bReplyPath = true;
1419         if (MSG_SUCCESS ==
1420             msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1421                             &option)) {
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);
1426
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");
1431             }
1432         }
1433         if (msg) {
1434             msg_release_message(&msg);
1435         }
1436     }
1437
1438     Catch(WrtDeviceApis::Commons::PlatformException) {
1439         LoggerE("remove message error");
1440         if (msg) {
1441             msg_release_message(&msg);
1442         }
1443         throw;
1444     }
1445 */
1446 }
1447
1448 void Mms::copyToFolder(const string& newFolder)
1449 {
1450 /*
1451     update();
1452
1453     msg_message_t msg = msg_new_message();
1454
1455     Try
1456     {
1457         MSG_SENDINGOPT_S option = { false, false, false };
1458         option.option.smsSendOpt.bReplyPath = true;
1459         if (MSG_SUCCESS ==
1460             msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1461                             &option)) {
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);
1466
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");
1471             }
1472         }
1473         if (msg) {
1474             msg_release_message(&msg);
1475         }
1476     }
1477
1478     Catch(WrtDeviceApis::Commons::PlatformException) {
1479         LoggerE("remove message error");
1480         if (msg) {
1481             msg_release_message(&msg);
1482         }
1483         throw;
1484     }
1485 */
1486 }
1487
1488 void Mms::remove()
1489 {
1490     LoggerD("delete m_id=" << getIdRef());
1491
1492     Try
1493     {
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");
1498         }
1499
1500         if (MSG_SUCCESS !=
1501             msg_delete_message(MsgGetCommonHandle(),
1502                                convertId(getIdRef()))) {
1503             LoggerE("Failed to delete Message");
1504             ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
1505         }
1506     }
1507
1508     Catch(WrtDeviceApis::Commons::PlatformException) {
1509         LoggerE("platform error occurs");
1510     }
1511 }
1512
1513 int Mms::send()
1514 {
1515         LoggerD("sending message, id=" << getIdRef());
1516         Try
1517         {
1518                 //prepare for sending sms/mms
1519                 update();
1520
1521                 LoggerD("Start Sending Message...");
1522
1523                 LoggerD("trying to send mms");
1524                 msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
1525
1526                 if (err != MSG_SUCCESS) 
1527                 {
1528                         LoggerE("Sending Message (submit request) failed!!! err=" << err);
1529                         setMessageStatus(MESSAGE_STATUS_FAILED);
1530                         Throw(WrtDeviceApis::Commons::PlatformException);
1531                 }
1532
1533                 setMessageStatus(MESSAGE_STATUS_SENDING);
1534
1535                 LoggerD("Sending Message request is submitted!");
1536         }
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);
1545         }
1546         }
1547
1548         return 0;
1549 }
1550
1551 void Mms::sendingCallback(msg_struct_t sent_status)
1552 {
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);
1560         
1561         LoggerD("status : " << status);
1562         
1563         if (MSG_NETWORK_SEND_SUCCESS == status) {
1564                 LoggerD("sending ok");
1565                 setSendingStatusOk();
1566                 setMessageStatus(MESSAGE_STATUS_SENT);
1567         } else {
1568                 LoggerE("sending failed: " << static_cast<unsigned int>(status));
1569                 setSendingStatusFailed();
1570                 setMessageStatus(MESSAGE_STATUS_FAILED);
1571         }
1572 }
1573
1574 void Mms::sendCancel(int handle)
1575 {
1576     LoggerD("sending message, id=" << getIdRef());
1577     //#warning "TODO"
1578     LoggerD("handle =" << handle);
1579 }
1580
1581 void Mms::setSendingStatusOk()
1582 {
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,};
1587         int nToCnt;
1588         
1589         if (requestReceiver) {
1590                 LoggerI("calling JS success callback");
1591                 EventMessagingServicePtr event = getMessagingServiceEvent();
1592                 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
1593
1594                 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1595
1596                 nToCnt = addr_list->nCount;
1597
1598                 for ( int index=0; index < nToCnt; index++)
1599                 {
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);
1602                 }
1603           
1604                 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1605         }
1606 }
1607
1608 void Mms::setSendingStatusFailed()
1609 {       
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,};
1614         int nToCnt;
1615         
1616         if (emitter) 
1617         {
1618                 EventOnSendingFailedPtr event(new EventOnSendingFailed);
1619                 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
1620                 emitter->emit(event);
1621         } 
1622         else 
1623         {
1624                 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1625                 EventMessagingServicePtr event = getMessagingServiceEvent();
1626                 if (requestReceiver) 
1627                 {
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;
1632
1633                         LoggerD("nToCnt : " << nToCnt);
1634
1635                         for ( int index=0; index < nToCnt; index++)
1636                         {
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);
1639                         }
1640
1641                 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1642                 }
1643         }
1644 }
1645
1646 FolderType Mms::toFolder(const std::string &folder)
1647 {
1648     if (folder == "INBOX") {
1649         return INBOX;
1650     } else if (folder == "OUTBOX") {
1651         return OUTBOX;
1652     } else if (folder == "SENTBOX") {
1653         return SENTBOX;
1654     } else if (folder == "DRAFTBOX") {
1655         return DRAFTBOX;
1656     }
1657     ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
1658 }
1659
1660 MimeType Mms::mimeTypeStringToIndexInt(std::string inputString)
1661 {
1662         const char* szMimeStr = inputString.c_str();
1663         MimeType retInt = MIME_UNKNOWN;
1664
1665         LoggerD("szMimeStr " << szMimeStr);
1666
1667         for(int idx =0; mimeTable[idx].szMIME != NULL ; idx++)
1668         {
1669                 if (!strcmp(mimeTable[idx].szMIME, szMimeStr)) {
1670                         retInt = mimeTable[idx].mime;
1671                         break;
1672                 }
1673         }
1674         return retInt;
1675
1676 }
1677
1678 std::string Mms::indexIntToMimeTypeString(MimeType inputIndex)
1679 {
1680         std::string retString;
1681         
1682         for (int idx=0; mimeTable[idx].szMIME != NULL; idx++) {
1683                 if (inputIndex == mimeTable[idx].mime) {
1684                         retString = (char *)mimeTable[idx].szMIME;
1685                 }
1686         }
1687         return retString;
1688 }
1689
1690 msg_struct_t Mms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
1691 {
1692         int tempInt, nCount, ret;
1693         bool tempBool;
1694         msg_struct_list_s *addr_list;
1695         msg_struct_list_s *new_addr_list;
1696
1697         msg_struct_t mms_struct = NULL;
1698         msg_struct_t mms_struct_dummy = NULL;   
1699
1700         msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1701
1702         msg_set_int_value(msg, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
1703
1704         char strSubject[MAX_SUBJECT_LEN] = {0};
1705         msg_get_str_value(src, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
1706         msg_set_str_value(msg, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
1707
1708         msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1709         msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1710
1711         msg_get_int_value(src, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
1712         msg_set_int_value(msg, MSG_MESSAGE_THREAD_ID_INT, tempInt);
1713
1714         msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1715         msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1716
1717 //      msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1718 //      char tempStr[tempInt+1];
1719 //      memset(tempStr, 0, tempInt+1);
1720
1721 //      msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1722 //      msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1723 //    copy mms body and attachment
1724         mms_struct = msg_create_struct(MSG_STRUCT_MMS);
1725         mms_struct_dummy = msg_create_struct(MSG_STRUCT_MMS);
1726         ret = msg_get_mms_struct(src, mms_struct);
1727         if (ret != MSG_SUCCESS)
1728         {
1729                 LoggerE("cannot get mms struct");
1730                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
1731         }
1732
1733         msg_set_mms_struct(src, mms_struct_dummy);
1734         msg_set_mms_struct(msg, mms_struct);
1735
1736         msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1737         msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1738
1739 //    msg_set_network_status(msg, msg_get_network_status(src));
1740         msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1741         msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT,  tempInt);
1742
1743 //    msg_set_encode_type(msg, msg_get_encode_type(src));
1744         msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1745         msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT,  tempInt);
1746
1747 //    msg_set_read_status(msg, msg_is_read(src));
1748         msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1749         msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1750
1751 //        msg_set_protect_status(msg, msg_is_protected(src));
1752         msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1753         msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1754
1755 //        msg_set_priority_info(msg, msg_get_priority_info(src));
1756         msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1757         msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT,  tempInt);
1758
1759 //        msg_set_direction_info(msg, msg_get_direction_info(src));
1760         msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1761         msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT,  tempInt);
1762
1763 //        msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1764         msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1765         msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT,  tempInt);
1766         msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1767         msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT,  tempInt);
1768
1769 // copy addr list
1770         msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1771         msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
1772
1773         new_addr_list->nCount = addr_list->nCount;
1774
1775         for(int i=0; i<addr_list->nCount; i++)
1776         {
1777                 msg_struct_t addr_info = NULL;
1778                 msg_struct_t new_addr_info = NULL;
1779                 char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
1780                 
1781                 //get original address
1782                 addr_info = addr_list->msg_struct_info[i];
1783                 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1784                 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
1785
1786                 //copy original address
1787                 new_addr_info = new_addr_list->msg_struct_info[i];
1788                 msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1789                 msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);
1790         }
1791
1792         msg_release_struct(&mms_struct_dummy);
1793         msg_release_struct(&mms_struct);
1794
1795     return msg;
1796 }
1797
1798 }
1799 }