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