wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Messaging / Conversation.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
19 #include "Conversation.h"
20 #include <CommonsJavaScript/JSUtils.h>
21 #include <Commons/Exception.h>
22 #include "MsgServiceHandleMgr.h"
23 #include "IMessaging.h"
24 #include <email-api-mail.h>
25 #include <time.h>
26
27 // this is msgInternalTypes
28 #define MAX_THREAD_DATA_LEN     128
29
30 using namespace DPL;
31
32 namespace DeviceAPI {
33 namespace Messaging {
34
35 Conversation::Conversation()
36 {
37
38 }
39
40 Conversation::Conversation(unsigned int threadId, MessageType msgType)
41 {
42         LoggerD("Enter");
43         
44         if (msgType == EMAIL)
45         {
46                 makeConversationFromEmailThreadId(threadId);
47         }
48         else if(msgType == EMPTY_MESSAGE)
49         {
50                 // do nothing
51         }
52         else
53         {
54                 makeConversationFromMsgId(threadId, msgType);
55         }
56 }
57         
58 Conversation::Conversation(std::string threadId, MessageType msgType)
59 {
60         LoggerD("Enter");
61         bool result = FALSE;
62         std::istringstream stream(threadId);
63         
64         LoggerD("threadId : " << threadId);
65         
66         unsigned int number = 0;
67         stream >> number;
68         result = makeConversationFromMsgId(number, msgType);
69         if(result == FALSE)
70         {
71                 ThrowMsg(WrtDeviceApis::Commons::PlatformException,     "fail to make conversation");
72         }
73 }
74
75 Conversation::Conversation(unsigned int threadIndex)
76 {
77         makeConversationFromThreadIndex(threadIndex);
78 }
79
80 //Conversation::Conversation(msg_thread_view_t msg_thread)
81 Conversation::Conversation(msg_struct_t msg_thread)
82 {
83         makeConversationFromThread(msg_thread);
84 }
85
86 //void Conversation::makeConversationFromThread(msg_thread_view_t msg_thread)
87 void Conversation::makeConversationFromThread(msg_struct_t msg_thread)  
88 {
89         LoggerD("Enter");
90         msg_handle_t handle = MsgGetCommonHandle();
91
92         msg_struct_list_s convViewList;
93         msg_list_handle_t addr_list = NULL;
94         msg_struct_t addr_info = NULL;
95
96         msg_struct_t msgInfo = NULL;
97         msg_struct_t sendOpt = NULL;
98         
99         msgInfo = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
100         sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
101         
102         msg_error_t err = MSG_SUCCESS;
103         unsigned int lastMsgIndex = 0;
104         char *tempString = NULL;
105         int addressCount = 0;
106         int index = 0;
107         int tempInt;
108         bool tempBool;
109         char msgData[128] = {0,};
110         m_result = true;
111         int nToCnt;
112
113         try 
114         {
115                 //      get thread Id
116                 msg_get_int_value(msg_thread, MSG_THREAD_ID_INT, &tempInt);
117                 m_Id = tempInt;
118                 
119                 //      get thread type
120                 msg_get_int_value(msg_thread, MSG_THREAD_MSG_TYPE_INT, &tempInt);
121                 switch(tempInt)
122                 {
123                         case MSG_TYPE_SMS:
124                         case MSG_TYPE_SMS_CB:
125                         case MSG_TYPE_SMS_JAVACB:
126                         case MSG_TYPE_SMS_WAPPUSH:
127                         case MSG_TYPE_SMS_MWI:
128                         case MSG_TYPE_SMS_SYNCML:
129                         case MSG_TYPE_SMS_REJECT:
130                                 m_type = SMS;
131                                 LoggerD("Type:SMS");
132                                 break;
133                         case MSG_TYPE_MMS:
134                         case MSG_TYPE_MMS_JAVA:
135                         case MSG_TYPE_MMS_NOTI:
136                                 m_type = MMS;;
137                                 LoggerD("Type:MMS");
138                                 break;
139                 } 
140                 
141                 //      get thread time
142                 msg_get_int_value(msg_thread, MSG_THREAD_MSG_TIME_INT, &tempInt);
143                 m_time = tempInt;
144
145                 //      get thread unread count
146                 msg_get_int_value(msg_thread, MSG_THREAD_UNREAD_COUNT_INT, &tempInt);
147                 m_unreadMessages = tempInt;
148
149                 //      get thread preview
150                 msg_get_str_value(msg_thread, MSG_THREAD_MSG_DATA_STR, msgData, 128);
151                 tempString = msgData; // convert char to string
152
153                 if (tempString != NULL)
154                 {
155                         m_preview = tempString; 
156                         LoggerD("preview" << m_preview);
157                 }
158
159                 err = msg_get_conversation_view_list(handle, m_Id, &convViewList);
160                 
161                 if (err != MSG_SUCCESS)
162                 {
163                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get conversation(msg) view list fail");
164                 }
165
166                 //      get thread message count
167                 lastMsgIndex = convViewList.nCount - 1;
168                 m_messageCount = convViewList.nCount;
169
170                 //      get thread read status
171                 msg_get_bool_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_READ_BOOL, &tempBool);
172                 m_read = tempBool;
173
174                 //      get thread last message Id
175                 msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_ID_INT, &tempInt);
176                 m_lastMessageId = tempInt;
177
178                 //      get thread from
179                 if (msg_get_message(handle, m_lastMessageId, msgInfo, sendOpt) != MSG_SUCCESS)
180                 {
181                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get message fail");
182                 }
183
184                 msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_DIRECTION_INT, &tempInt);
185                 int type = tempInt;
186
187                 msg_get_list_handle(msgInfo, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
188
189                 nToCnt = msg_list_length(addr_list);
190
191                 if (type == MSG_DIRECTION_TYPE_MT)
192                 {
193
194                         if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
195                         {
196                                 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
197                                 addr_info = (msg_struct_t)msg_list_nth_data(addr_list, m_lastMessageId);
198                                 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
199                                 
200                                 if (strNumber[0] != '\0')
201                                 {
202                                         m_from = strNumber;     // convert char to string
203                                 }
204                                 else
205                                 {
206                                         LoggerD("address is null ");
207                                 }
208                         }
209                         else 
210                         {
211                                 LoggerD("address count index fail");
212                         }
213                         
214                 }
215                 else
216                 {
217                         LoggerD("Msg direction: MO, from will be omitted");
218                 }
219
220                 //      get thread subject
221                 char strTemp[MAX_SUBJECT_LEN] = {0};
222                 msg_get_str_value(msgInfo, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
223                 tempString = strTemp;
224                 if (tempString != NULL)
225                 {
226                         m_subject = tempString; // convert char to string
227                 }
228
229                 //      get thread to           
230                 if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
231                 {
232                         for (index = 0; index < nToCnt; index++)
233                         {
234                                 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
235                                 addr_info = (msg_struct_t)msg_list_nth_data(addr_list, index);
236                                 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
237                                 tempString = strNumber;
238                                 if (tempString != NULL)
239                                 {
240                                         m_to.push_back(tempString);
241                                 }
242                         }
243                 }
244                 else
245                 {
246                         LoggerD("address fetch fail" << addressCount);
247                 }
248         }
249         catch (const WrtDeviceApis::Commons::Exception& ex) 
250         {
251                 m_result = false;
252                 LoggerE("Exception: " << ex.GetMessage());
253         }
254         
255         msg_release_list_struct(&convViewList);
256         msg_release_struct(&msgInfo);
257         msg_release_struct(&sendOpt);
258
259 }
260
261
262
263 // It is worth for below function to do test for fetching all conversations
264 void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
265 {
266 /*
267         LoggerD("Enter");
268         MSG_HANDLE_T handle = MsgGetCommonHandle();
269         MSG_LIST_S convViewList = {0, NULL};
270         MSG_THREAD_VIEW_LIST_S threadViewList = {0, NULL};
271         msg_error_t err = MSG_SUCCESS;
272         unsigned int lastMsgIndex = 0;
273         char *tempString = NULL;
274         int addressCount = 0;
275         int index = 0;
276         
277         m_result = true;
278
279         try 
280         {
281                 if (msg_get_thread_view_list(handle, NULL, &threadViewList) != MSG_SUCCESS)
282                 {
283                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get thread view fail" );
284                 }
285
286                 if (threadViewList.nCount < 0 || threadIndex >= (unsigned int)threadViewList.nCount)
287                 {
288                         LoggerD(threadIndex << ":" << threadViewList.nCount);
289                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "invalid index reference" );
290                 }
291
292                 
293                 if (msg_thread_view_get_thread_id(threadViewList.msgThreadInfo[threadIndex]) >= 0)
294                 {
295                         m_Id = msg_thread_view_get_thread_id(threadViewList.msgThreadInfo[threadIndex]);
296                 }
297                 
298                 switch(msg_thread_view_get_message_type(threadViewList.msgThreadInfo[threadIndex]))
299                 {
300                         case MSG_TYPE_SMS:
301                         case MSG_TYPE_SMS_CB:
302                         case MSG_TYPE_SMS_JAVACB:
303                         case MSG_TYPE_SMS_WAPPUSH:
304                         case MSG_TYPE_SMS_MWI:
305                         case MSG_TYPE_SMS_SYNCML:
306                         case MSG_TYPE_SMS_REJECT:
307                                 m_type = SMS;
308                                 LoggerD("Type:SMS");
309                                 break;
310                         case MSG_TYPE_MMS:
311                         case MSG_TYPE_MMS_JAVA:
312                         case MSG_TYPE_MMS_NOTI:
313                                 m_type = MMS;;
314                                 LoggerD("Type:MMS");
315                                 break;
316 //                      default:
317                                 // Todo email / chat
318                 } 
319                 
320                 m_time = *(msg_thread_view_get_time(threadViewList.msgThreadInfo[threadIndex]));
321                 m_unreadMessages = msg_thread_view_get_unread_cnt(threadViewList.msgThreadInfo[threadIndex]);
322                 tempString = (char*)msg_thread_view_get_data(threadViewList.msgThreadInfo[threadIndex]);
323
324                 if (tempString != NULL)
325                 {
326                         m_preview = tempString; 
327                         LoggerD("preview" << m_preview);
328                 }
329
330                 
331                 err = msg_get_conversation_view_list(handle, m_Id, &convViewList);
332                 
333                 if (err != MSG_SUCCESS)
334                 {
335                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get conversation(msg) view list fail");
336                 }
337
338                 lastMsgIndex = convViewList.nCount - 1;
339                 m_messageCount = convViewList.nCount;
340                 m_read = msg_is_read(convViewList.msgInfo[lastMsgIndex]);
341                 
342                 LoggerD("lastMsgIndex:" << lastMsgIndex << ",message count:" << m_messageCount << ",read" << m_read);
343
344                 if (msg_get_direction_info(convViewList.msgInfo[lastMsgIndex]) == MSG_DIRECTION_TYPE_MT)
345                 {
346                         addressCount = msg_get_address_count(convViewList.msgInfo[lastMsgIndex]);
347
348                         if (addressCount > 0 && addressCount < MAX_TO_ADDRESS_CNT )
349                         {
350                     tempString = (char*)msg_get_ith_address(convViewList.msgInfo[lastMsgIndex], 0);
351                                 
352                                 if (tempString != NULL)
353                                 {
354                                         m_from = tempString;
355                                 }
356                                 else
357                                 {
358                                         LoggerD("address is null ");
359                                 }
360                         }
361                         else 
362                         {
363                                 LoggerD("address count index fail");
364                         }
365                         LoggerD("from" << m_from);
366                 }
367                 else
368                 {
369                         LoggerD("Msg direction: MO, from will be omitted");
370                 }
371
372
373                 tempString = (char*)msg_get_subject(convViewList.msgInfo[lastMsgIndex]);
374
375                 if (tempString != NULL)
376                 {
377                         m_subject = tempString;
378                 }
379
380                 LoggerD("subject" << m_subject);
381                 
382
383                 addressCount = msg_get_address_count(convViewList.msgInfo[lastMsgIndex]);
384
385
386                 if (addressCount > 0 && addressCount < MAX_TO_ADDRESS_CNT )
387                 {
388                         for (index = 0; index < addressCount; index++)
389                         {
390                                 tempString = (char*)msg_get_ith_address(convViewList.msgInfo[lastMsgIndex], index);
391
392                                 if (tempString != NULL)
393                                 {
394                                         m_to.push_back(tempString);
395                                 }
396                         }
397                         LoggerD("address count" << addressCount);
398                 }
399                 else
400                 {
401                         LoggerD("address fetch fail" << addressCount);
402                 }
403
404                 if (msg_get_message_id(convViewList.msgInfo[lastMsgIndex]) >= 0 )
405                 {
406                         m_lastMessageId = msg_get_message_id(convViewList.msgInfo[lastMsgIndex]);
407                 }
408
409                 LoggerD("message id" << m_lastMessageId);
410
411         }
412         catch (const WrtDeviceApis::Commons::Exception& ex) 
413         {
414                 m_result = false;
415                 LoggerE("Exception: " << ex.GetMessage());
416         }
417         if (convViewList.msgInfo != NULL) 
418         {
419                 msg_release_list_struct(&convViewList);
420         }
421
422         if (threadViewList.msgThreadInfo != NULL)
423         {
424                 msg_release_thread_view_list(&threadViewList);
425         }
426 */
427
428 }
429
430 bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msgType)
431 {
432         LoggerD("Enter");
433
434         msg_handle_t handle = MsgGetCommonHandle();
435
436         msg_struct_t msgInfo = NULL;
437         msg_struct_t sendOpt = NULL;    
438
439         msg_struct_t msg_thread = NULL;
440
441         msg_struct_list_s convViewList;
442         msg_list_handle_t addr_list = NULL;
443         msg_struct_t addr_info = NULL;
444         
445         msg_error_t err = MSG_SUCCESS;
446
447         int tempInt;
448         bool tempBool;
449
450         int nToCnt;
451         
452         unsigned int lastMsgIndex = 0;
453
454         char *tempString = NULL;
455         char msgData[MAX_THREAD_DATA_LEN] = {0,};
456         m_result = true;
457
458         try 
459         {
460                 //      get msg from msgId
461                 msgInfo = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
462                 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
463                 
464                 if (msg_get_message(handle, (msg_message_id_t)msgId, msgInfo, sendOpt) != MSG_SUCCESS)
465                 {
466                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get message fail");
467                 }
468
469                 // get threadId from message
470                 msg_get_int_value(msgInfo, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
471                 m_Id = (unsigned int)tempInt;
472                 LoggerD("m_Id : " << m_Id);
473
474                 // get Thread
475                 msg_thread = msg_create_struct(MSG_STRUCT_THREAD_INFO);
476                 err = msg_get_thread(handle, m_Id, msg_thread);
477
478                 //      get thread type
479                 msg_get_int_value(msg_thread, MSG_THREAD_MSG_TYPE_INT, &tempInt);
480                 switch(tempInt)
481                 {
482                         case MSG_TYPE_SMS:
483                         case MSG_TYPE_SMS_CB:
484                         case MSG_TYPE_SMS_JAVACB:
485                         case MSG_TYPE_SMS_WAPPUSH:
486                         case MSG_TYPE_SMS_MWI:
487                         case MSG_TYPE_SMS_SYNCML:
488                         case MSG_TYPE_SMS_REJECT:
489                                 m_type = SMS;
490                                 LoggerD("Type:SMS");
491                                 break;
492                         case MSG_TYPE_MMS:
493                         case MSG_TYPE_MMS_JAVA:
494                         case MSG_TYPE_MMS_NOTI:
495                                 m_type = MMS;;
496                                 LoggerD("Type:MMS");
497                                 break;
498                 } 
499
500                 //      get thread time
501                 msg_get_int_value(msg_thread, MSG_THREAD_MSG_TIME_INT, &tempInt);
502                 m_time = tempInt;
503                 LoggerD("m_time : " << m_time);
504
505                 //      get thread unread count
506                 msg_get_int_value(msg_thread, MSG_THREAD_UNREAD_COUNT_INT, &tempInt);
507                 m_unreadMessages = tempInt;
508                 LoggerD("m_unreadMessages : " << m_unreadMessages);
509
510                 //      get thread preview
511                 msg_get_str_value(msg_thread, MSG_THREAD_MSG_DATA_STR, msgData, MAX_THREAD_DATA_LEN);
512                 tempString = msgData; // convert char to string
513
514                 if (tempString != NULL)
515                 {
516                         m_preview = tempString; 
517                 }
518                 LoggerD("m_preview : " << m_preview);
519
520                 err = msg_get_conversation_view_list(handle, m_Id, &convViewList);
521                         
522                 if (err != MSG_SUCCESS)
523                 {
524                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get conversation(msg) view list fail");
525                 }
526
527                 //      get thread message count
528                 lastMsgIndex = convViewList.nCount - 1;
529                 m_messageCount = convViewList.nCount;
530                 LoggerD("m_messageCount : " << m_messageCount);
531
532                 //      get thread read status
533                 msg_get_bool_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_READ_BOOL, &tempBool);
534                 m_read = tempBool;
535                 LoggerD("m_read : " << m_read);
536
537                 //      get thread last message Id
538                 msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_ID_INT, &tempInt);
539                 m_lastMessageId = tempInt;
540                 LoggerD("m_lastMessageId : " << m_lastMessageId);
541
542                 //      get thread from
543                 if (msg_get_message(handle, m_lastMessageId, msgInfo, sendOpt) != MSG_SUCCESS)
544                 {
545                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get message fail");
546                 }
547
548                 msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_DIRECTION_INT, &tempInt);
549                 int type = tempInt;
550                 LoggerD("direction : " << type);
551
552                 msg_get_list_handle(msgInfo, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
553                 nToCnt = msg_list_length(addr_list);
554
555                 if (type == MSG_DIRECTION_TYPE_MT)
556                 {
557                         
558                         if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
559                         {
560                                 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
561                                 addr_info = (msg_struct_t)msg_list_nth_data(addr_list, nToCnt-1);
562                                 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
563
564                                 if (strNumber[0] != '\0')
565                                 {
566                                         m_from = strNumber; // convert char to string
567                                 }
568                                 else
569                                 {
570                                         LoggerD("address is null ");
571                                 }
572                         }               
573                         else 
574                         {
575                                 LoggerD("address count index fail");
576                         }
577
578                 }
579                 else
580                 {
581                         LoggerD("Msg direction: MO, from will be omitted");
582                         //      get thread to           
583                         if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
584                         {
585                                 for (int index = 0; index < nToCnt; index++)
586                                 {
587                                         addr_info = (msg_struct_t)msg_list_nth_data(addr_list, index);
588                                         char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
589                                         msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
590                                         tempString = strNumber;
591                                         if (tempString != NULL)
592                                         {
593                                                 LoggerD("m_to : " << tempString);
594                                                 m_to.push_back(tempString);
595                                         }
596                                 }
597                         }
598                         else
599                         {
600                                 LoggerD("address fetch fail");
601                         }
602                 }
603
604                 //      get thread subject
605                 char strTemp[MAX_SUBJECT_LEN] = {0};
606                 msg_get_str_value(msgInfo, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
607                 tempString = strTemp;
608                 if (tempString != NULL)
609                 {
610                         m_subject = tempString; // convert char to string
611                 }               
612                 LoggerD("m_subject : " << m_subject);
613                 
614         }
615         catch (const WrtDeviceApis::Commons::UnknownException& ex)
616         {
617                 m_result = false;
618                 LoggerE("Exception: " << ex.GetMessage());
619         }
620         catch (const WrtDeviceApis::Commons::Exception& ex)
621         {
622                 m_result = false;
623                 LoggerE("Exception: " << ex.GetMessage());
624         }
625
626         msg_release_list_struct(&convViewList);
627         msg_release_struct(&msgInfo);
628         msg_release_struct(&sendOpt);
629         msg_release_struct(&msg_thread);
630         
631         return m_result;
632 }
633
634 bool Conversation::makeConversationFromEmailThreadId(unsigned int emailTreadId)
635 {
636         LoggerD("Enter");
637         
638         email_mail_list_item_t *resultMail = NULL;
639         email_mail_list_item_t *mailList = NULL;
640         int index = 0;
641         int count = 0;
642
643         email_mail_data_t* mailData = NULL;
644         m_result = true;
645
646         try 
647         {
648                 // Todo : will be re-implemented as using email_get_thread_information_ex 
649                 if(email_get_thread_information_ex(emailTreadId, &resultMail) != EMAIL_ERROR_NONE) 
650                 {
651                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get email thread fail" );
652                 }
653
654                 if (!resultMail)
655                 {
656                         return NULL;
657                 }
658
659                 //get mail data
660                 if (email_get_mail_data(resultMail->mail_id,&mailData) != EMAIL_ERROR_NONE)
661                 {
662                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get email data fail" );
663                 }
664         
665                 // account Id
666                 m_unreadMessages = 0;
667
668                 LoggerD("start email_get_mail_list");
669                 if (email_get_mail_list(mailData->account_id, 0, emailTreadId, 0, resultMail->thread_item_count, 
670                         EMAIL_SORT_DATETIME_HIGH, &mailList, &count) != EMAIL_ERROR_NONE)
671                 {
672                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get email data fail" );
673                 }
674                 LoggerD("end email_get_mail_list");
675                 
676                 // unread msg count
677                 for (index = 0; index < count; index++)
678                 {
679                         if (mailList[index].flags_seen_field)
680                         {
681                                 m_unreadMessages++;
682                         }
683                         LoggerD(mailList[index].flags_seen_field);
684                 }
685                 
686                 // message count
687                 m_messageCount = resultMail->thread_item_count;
688                 // id
689                 m_Id = emailTreadId;
690                 // type
691                 m_type = EMAIL;
692
693                 // time horrible split 
694                 // 2011 11 08 00 35 45
695
696                 m_time = resultMail->date_time;
697
698                 // read
699                 m_read = (bool)resultMail->flags_seen_field;
700
701                 // from
702                 if (resultMail->full_address_from[0] != '\0')
703                 {
704                         m_from = resultMail->full_address_from;
705                         LoggerD(m_from);
706                 }
707
708                 // subject
709                 if (resultMail->subject[0] != '\0')
710                 {
711                         m_subject = resultMail->subject;
712                         LoggerD(m_subject);             
713                 }
714
715                 if (mailData->full_address_to != NULL)
716                 {
717                         LoggerD("Header To " << mailData->full_address_to);
718                         m_to.push_back(mailData->full_address_to);
719                 }
720
721                 if (mailData->full_address_bcc != NULL)
722                 {
723                         LoggerD("Header Bcc " << mailData->full_address_bcc);
724                         m_bcc.push_back(mailData->full_address_bcc);
725                 }
726
727                 if (mailData->full_address_cc != NULL)
728                 {
729                         LoggerD("Header CC " << mailData->full_address_cc);
730                         m_cc.push_back(mailData->full_address_cc);
731                 }
732                 
733                 m_lastMessageId = resultMail->mail_id;
734                 LoggerD(m_lastMessageId);               
735                 m_result = true;
736         }
737         catch (const WrtDeviceApis::Commons::Exception& ex) 
738         {
739                 m_result = false;
740                 LoggerE("Exception: " << ex.GetMessage());
741         }
742
743         if (mailData != NULL)
744         {
745                 email_free_mail_data(&mailData , 1);
746         }
747         
748         if (resultMail != NULL)
749         {
750                 free(resultMail);
751         }
752
753         return m_result;
754
755 }
756 Conversation::~Conversation()
757 {
758 }
759
760 #if 0
761 // setter
762 void Conversation::setId(unsigned int id)
763 {
764         m_id = id;
765 }
766 void Conversation::setType(unsigned short type)
767 {
768         m_type = type;
769 }
770 void Conversation::setTime(time_t time)
771 {
772         m_time = time;
773 }
774 void Conversation::setMessageCount(unsigned long messageCount)
775 {
776         m_messageCount = messageCount;
777 }
778 void Conversation::setUnreadMessages(unsigned long unreadMessages)
779 {
780         m_unreadMessages = unreadMessages;
781 }
782 void Conversation::setPreview(unsigned long preview)
783 {
784         m_preview = preview;
785 }
786 void Conversation::setRead(bool read)
787 {
788         m_read = read;
789 }
790 void Conversation::setFrom(std::string from)
791 {
792         m_from = from;
793 }
794 void Conversation::setTo(std::vector<std::string> to)
795 {
796         m_to = to;
797 }
798 void Conversation::setCC(std::vector<std::string> cc)
799 {
800         m_cc = cc;
801 }
802 void Conversation::setBCC(std::vector<std::string> bcc)
803 {
804         m_bcc = bcc;
805 }
806 void Conversation::setLastMessageId(unsigned int id)
807 {
808         m_lastMessageId = id;
809 }
810 #endif
811
812 void Conversation::setConvId(const int id)
813 {
814         m_Id = id;
815 }
816
817 // getter
818 int Conversation::getConvId()
819 {
820         return m_Id;
821 }
822 unsigned short Conversation::getType()
823 {
824         return m_type;
825 }
826 time_t Conversation::getTime()
827 {
828         return m_time;
829 }
830 unsigned long Conversation::getMessageCount()
831 {
832         return m_messageCount;
833 }
834 unsigned long Conversation::getUnreadMessages()
835 {
836         return m_unreadMessages;
837 }
838 std::string Conversation::getPreview()
839 {
840         return m_preview;
841 }
842
843 std::string Conversation::getSubject()
844 {
845         return m_subject;
846 }
847
848
849 bool Conversation::getRead()
850 {
851         return m_read;
852 }
853 std::string Conversation::getFrom()
854 {
855         return m_from;
856 }
857 std::vector<std::string> Conversation::getTo()
858 {
859         return m_to;
860 }
861 std::vector<std::string> Conversation::getCC()
862 {
863         return m_cc;
864 }
865 std::vector<std::string> Conversation::getBCC()
866 {
867         return m_bcc;
868 }
869 int Conversation::getLastMessageId()
870 {
871         return m_lastMessageId;
872 }
873
874 bool Conversation::getResult()
875 {
876         return m_result;
877 }
878
879 }
880 }
881