summaryrefslogtreecommitdiff
path: root/mailbox/src/email-mailbox-noti-mgr.c
blob: 4f5de4dc3d89d7b303db9d9e99ad60b8ef9e5a7f (plain)
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
/*
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
 *
 * 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 "email-mailbox.h"
#include "email-mailbox-item.h"
#include "email-mailbox-list.h"
#include "email-mailbox-search.h"
#include "email-mailbox-noti-mgr.h"


E_DBus_Connection *_g_mailbox_conn = NULL;
E_DBus_Signal_Handler *_g_signal_handler_storage = NULL;
E_DBus_Signal_Handler *_g_signal_handler_network = NULL;

extern int ug_pushed;
extern gboolean list_lock;
extern Eina_List *g_account_list;
extern char *group_title[EMAIL_GROUP_MAX][2];


DBusHandlerResult _on_dbus_receive(DBusConnection *connection, DBusMessage *message, void *user_data);
static void _edbus_event_mailbox_receive(void *local_data, DBusMessage *message);
static Eina_Bool email_check_account_list(int account_id);
static void email_maillist_insert_sorted(list_data *ld);
static void add_seed_mail_cb(void *data, Ecore_Thread *thd, void* msg_data);
static gint _find_insert_position(gconstpointer a, gconstpointer b);
static gint _find_next_group_position(gconstpointer a, gconstpointer b);


static gint _find_next_group_position(gconstpointer a, gconstpointer b)
{
	list_data *pos = (list_data *)a;
	list_data *src = (list_data *)b;

	if(pos->group_index > src->group_index)
		return 0;
	else
		return -1;

}

void _release_noti_Q_event(EmailMailboxUGD *mailbox_ugd)
{
	debug_enter();

	GList *noti_Q = mailbox_ugd->noti_Q;
	int i = 0;
	int count = g_list_length(noti_Q);
	GList *cur = g_list_last(noti_Q);

	for(; i < count; ++i, cur = g_list_previous(cur))
	{
		noti_event *noti = (noti_event *)g_list_nth_data(cur, 0);
		FREE(noti->data3);
	}
	G_LIST_FREE(mailbox_ugd->noti_Q);

	debug_leave();
}

static gint _find_insert_position(gconstpointer a, gconstpointer b)
{
	list_data *pos = (list_data *)a;
	list_data *src = (list_data *)b;

	if(pos->group_index == src->group_index && pos->absolute_time < src->absolute_time)
		return 0;
	else
		return -1;

}

void _response_cb(void *data, Evas_Object *obj, void *event_info)
{
	debug_log("");
	if (data == NULL) {
		debug_log("data is NULL");
		return;
	}

	evas_object_del(data);
}

void _delete_finish_cb(void* data, Ecore_Thread *thd)
{
	debug_enter();
	if( !data ) {
		debug_warning("PARAM NULL: data(%p)", data);
		return;
	}
	delete_req_t *req = (delete_req_t *)data;
	_release_noti_Q_event(req->mailbox_ugd);

	FREE(req->msg_buf);
	FREE(req);
	debug_leave();
}

static void email_maillist_insert_sorted(list_data *ld)
{
	debug_log("");
	EmailMailboxUGD *mailbox_ugd = ld->mailbox_ugd;
	GList *_list = mailbox_ugd->list_data[mailbox_ugd->view_type];
	GList *pos = NULL;

	pos = g_list_find_custom(_list, ld, _find_insert_position);

	if(pos)
		_list = g_list_insert_before(_list, pos, ld);
	else
	{
		// ld is the only entry having corresponding group index
		if(!mailbox_ugd->git[mailbox_ugd->view_type][ld->group_index]) {
			_list = g_list_insert_sorted(_list, ld, _compare_sort_rule_by_viewtype);
		}
		else // ld is the oldest mail in same group
		{
			// find the first entry in next group
			pos = g_list_find_custom(_list, ld, _find_next_group_position);
			if(pos)
				_list = g_list_insert_before(_list, pos, ld);
			else // the list has one group
				_list = g_list_append(_list,ld);
		}
	}

}

static Eina_Bool email_check_account_list(int account_id)
{
	debug_log("");
	Eina_List *it = NULL;
	int *acc_id = NULL;

	int checked_count = eina_list_count(g_account_list);
	debug_log("checked_count = [%d]", checked_count);

	EINA_LIST_FOREACH(g_account_list, it, acc_id) {
		if (*acc_id == account_id) {
			g_account_list = eina_list_remove(g_account_list, acc_id);
		}
	}
	if (eina_list_count(g_account_list))
		return EINA_FALSE;
	else
		return EINA_TRUE;
}

static void add_seed_mail_cb(void *data, Ecore_Thread *thd, void* msg_data)//(EmailMailboxUGD *mailbox_ugd, gint uid)
{
	debug_enter();

	if( !data || !msg_data) {
		debug_warning("PARAM NULL: data(%p), msg_data(%p)", data, msg_data);
		return;
	}

	sync_req_t *req = (sync_req_t *)data;
	EmailMailboxUGD *mailbox_ugd = req->mailbox_ugd;
	list_data *ld = (list_data *) msg_data;

	debug_log("SEED: thdid(%d) mailid(%d) info(%p)", req->thread_id, req->mail_id, ld);

	_remove_get_more_progress_item(mailbox_ugd);

	if (list_lock) {
		debug_log("locked");
		if (!evas_object_visible_get(mailbox_ugd->gl[mailbox_ugd->view_type]))
			evas_object_show(mailbox_ugd->gl[mailbox_ugd->view_type]);

		edje_object_signal_emit(_EDJ(mailbox_ugd->search_layout), "hide_noc", "elm");
		edje_object_signal_emit(_EDJ(mailbox_ugd->search_layout), "show_list", "elm");

		list_lock = false;
	}

	if (mailbox_ugd->mode == EMAIL_MAILBOX_MODE_ALL) {
		mailbox_ugd->account_id = 0;
		mailbox_ugd->mailbox_id = 0;
	}

	debug_log("req->view_type[%d], mailbox_ugd->view_type[%d], req->mode[%d], mailbox_ugd->mode[%d]", req->view_type, mailbox_ugd->view_type, req->mode, mailbox_ugd->mode);

	if(req->view_type == mailbox_ugd->view_type && req->mode == mailbox_ugd->mode)
	{
		/* The group items might be inserted before to receive any normal mail item */
		mailbox_ugd->list_data[mailbox_ugd->view_type] =
			g_list_insert_sorted(mailbox_ugd->list_data[mailbox_ugd->view_type], ld, _compare_sort_rule_by_viewtype);
		if(mailbox_ugd->view_type != EMAIL_VIEW_DATE)
			email_maillist_insert_sorted(ld);

	//	debug_log("ADDED: vt(%d), thdid(%d), mailid(%d)", mailbox_ugd->view_type, ld->thread_id, ld->mail_id);
		if (mailbox_ugd->view_type != EMAIL_VIEW_RECIPIENT) {
			if (!group_title[ld->group_index][0])
				group_title[ld->group_index][0] = g_strdup(ld->group_title);
			if (!group_title[ld->group_index][1])
				group_title[ld->group_index][1] = g_strdup(ld->group_date);
			debug_log("group_title: %s", group_title[ld->group_index][0]);
		}

		_insert_mail_to_mailist(mailbox_ugd, ld);
	}

	debug_log("mode: %d, folder_id: %d, ld->recipient : %s", ld->mailbox_ugd->mode, ld->mailbox_id, ld->recipient);

	if (mailbox_ugd->delete_all_button != NULL) {
		elm_object_item_disabled_set(mailbox_ugd->edit_button, EINA_FALSE);
	}
	debug_leave();
	FREE(req);
}

void _delete_mail_item_cb(void *data, Ecore_Thread *thd, void* msg_data)
{
	debug_enter();

	delete_req_t *req = (delete_req_t *)data;
	delete_ret_t *ret = (delete_ret_t *)msg_data;

	if( !req || !ret) {
		debug_warning("PARAM NULL: data(%p), msg_data(%p)", req, ret);
		goto CLEANUP;
	}

	list_data *ld = ret->ld;
	EmailMailboxUGD *mailbox_ugd = req->mailbox_ugd;
	EmailMailboxViewType vt = mailbox_ugd->view_type;

	if(!_find_mailinfo_by_mailid(ret->mail_id, mailbox_ugd->list_data[vt]))
		goto CLEANUP;

	if(req->current_view != vt) {
		debug_warning("mismatched view_type: current_view(%d), mailbox_ugd_view(%d)", req->current_view, vt);
		goto CLEANUP;
	}
	mailbox_delete_mail_item_from_list(mailbox_ugd, ld);

	if(!g_list_length(mailbox_ugd->list_data[vt]))
	{
		if (!list_lock) {
			if (evas_object_visible_get(mailbox_ugd->gl[mailbox_ugd->view_type]))
				evas_object_hide(mailbox_ugd->gl[mailbox_ugd->view_type]);
		}

		Evas_Object *no_content = elm_object_part_content_get(mailbox_ugd->search_layout, "noc");
		elm_layout_theme_set(no_content, "layout", "nocontents", "text");
		elm_object_part_text_set(no_content, "elm.text", dgettext("sys_string", "IDS_COM_BODY_NO_CONTENTS"));
		edje_object_signal_emit(_EDJ(mailbox_ugd->search_layout), "hide_list", "elm");
		edje_object_signal_emit(_EDJ(mailbox_ugd->search_layout), "show_noc", "elm");
		//elm_object_item_disabled_set(mailbox_ugd->edit_button, EINA_TRUE);
		if (mailbox_ugd->delete_all_button != NULL) {
			elm_object_item_disabled_set(mailbox_ugd->delete_all_button, EINA_TRUE);
		}
		list_lock = true;
	}

CLEANUP:
	FREE(ret);
	debug_leave();
}

void _move_mail_item_cb(void *data, Ecore_Thread *thd, void* msg_data)
{
	debug_enter();

	move_req_t *req = (move_req_t *)data;
	delete_ret_t *ret = (delete_ret_t *)msg_data;

	if( !req || !ret) {
		debug_warning("PARAM NULL: data(%p), msg_data(%p)", req, ret);
		goto CLEANUP;
	}

	list_data *ld = ret->ld;
	EmailMailboxUGD *mailbox_ugd = req->mailbox_ugd;
	EmailMailboxViewType vt = mailbox_ugd->view_type;

	if(req->current_view != vt) {
		debug_warning("mismatched view_type: current_view(%d), mailbox_ugd_view(%d)", req->current_view, vt);
		goto CLEANUP;
	}

	if(!_find_mailinfo_by_mailid(ret->mail_id, mailbox_ugd->list_data[vt]))
		goto CLEANUP;


	if(mailbox_ugd->mode != EMAIL_MAILBOX_MODE_MAILBOX
		&& req->mailbox_type == EMAIL_MAILBOX_TYPE_SENTBOX)
	{
		if(ld->item) elm_genlist_item_update(ld->item);
	}
	else
	{
		mailbox_delete_mail_item_from_list(mailbox_ugd, ld);
	}

	if(!g_list_length(mailbox_ugd->list_data[vt]))
	{
		if (!list_lock) {
			if (evas_object_visible_get(mailbox_ugd->gl[mailbox_ugd->view_type]))
				evas_object_hide(mailbox_ugd->gl[mailbox_ugd->view_type]);
		}

		Evas_Object *no_content = elm_object_part_content_get(mailbox_ugd->search_layout, "noc");
		elm_layout_theme_set(no_content, "layout", "nocontents", "text");
		elm_object_part_text_set(no_content, "elm.text", dgettext("sys_string", "IDS_COM_BODY_NO_CONTENTS"));
		edje_object_signal_emit(_EDJ(mailbox_ugd->search_layout), "hide_list", "elm");
		edje_object_signal_emit(_EDJ(mailbox_ugd->search_layout), "show_noc", "elm");
		//elm_object_item_disabled_set(mailbox_ugd->edit_button, EINA_TRUE);
		if (mailbox_ugd->delete_all_button != NULL) {
			elm_object_item_disabled_set(mailbox_ugd->delete_all_button, EINA_TRUE);
		}
		list_lock = true;
	}

CLEANUP:
	FREE(ret);
	debug_leave();
}

void _move_finish_cb(void* data, Ecore_Thread *thd)
{
	debug_enter();
	if( !data ) {
		debug_warning("PARAM NULL: data(%p)", data);
		return;
	}
	move_req_t *req = (move_req_t *)data;
	_release_noti_Q_event(req->mailbox_ugd);

	FREE(req->msg_buf);
	FREE(req);
	debug_leave();
}

void _dbus_receiver_setup(EmailMailboxUGD *mailbox_ugd)
{
	debug_log("");
	int ret = e_dbus_init();
	debug_log("ret: %d", ret);

	DBusError derror;

	if (_g_mailbox_conn == NULL) {
		debug_log("");
		dbus_error_init(&derror);
		_g_mailbox_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);

		if (e_dbus_request_name(_g_mailbox_conn, "User.Email.StorageChange", 0, NULL, NULL) == NULL) {
			debug_critical("Failed to e_dbus_request_name()");
			return;
		}
		if (_g_signal_handler_storage != NULL) {
			debug_warning("_g_signal_handler_storage must be NULL at this point");
		}
		_g_signal_handler_storage = e_dbus_signal_handler_add(_g_mailbox_conn, NULL, "/User/Email/StorageChange", "User.Email.StorageChange", "email", _edbus_event_mailbox_receive, mailbox_ugd);
		if (_g_signal_handler_storage == NULL) {
			debug_critical("Failed to e_dbus_signal_handler_add()");
			return;
		}

		if (e_dbus_request_name(_g_mailbox_conn, "User.Email.NetworkStatus", 0, NULL, NULL) == NULL) {
			debug_critical("Failed to e_dbus_request_name()");
			return;
		}
		if (_g_signal_handler_network != NULL) {
			debug_warning("_g_signal_handler_storage must be NULL at this point");
		}
		_g_signal_handler_network = e_dbus_signal_handler_add(_g_mailbox_conn, NULL, "/User/Email/NetworkStatus", "User.Email.NetworkStatus", "email", _edbus_event_mailbox_receive, mailbox_ugd);
		if (_g_signal_handler_network == NULL) {
			debug_critical("Failed to e_dbus_signal_handler_add()");
			return;
		}
	}
}

void _remove_dbus_receiver(EmailMailboxUGD *mailbox_ugd)
{
	debug_log("");

	if (_g_signal_handler_storage != NULL) {
		e_dbus_signal_handler_del(_g_mailbox_conn, _g_signal_handler_storage);
		_g_signal_handler_storage = NULL;
	}

	if (_g_signal_handler_network != NULL) {
		e_dbus_signal_handler_del(_g_mailbox_conn, _g_signal_handler_network);
		_g_signal_handler_network = NULL;
	}

	if (e_dbus_release_name(_g_mailbox_conn, "User.Email.StorageChange", NULL, NULL) == NULL) {
		debug_critical("e_dbus_release_name to failed");
	}

	if (_g_mailbox_conn != NULL) {
		_g_mailbox_conn = NULL;
	}
}


static void _edbus_event_mailbox_receive(void *local_data, DBusMessage *message)
{
	debug_enter();
	if (get_app_terminated()) {
		debug_log("App is in terminating");
		return;
	}

	EmailMailboxUGD *mailbox_ugd = (EmailMailboxUGD *)local_data;
	DBusError error;

	if (mailbox_ugd == NULL) {
		debug_log("data is NULL");
		return;
	}

	if (dbus_message_is_signal(message, "User.Email.StorageChange", "email")) {
		debug_log("User.Email.StorageChange");

		int subtype = 0;
		int data1 = 0;
		int data2 = 0;
		char *data3 = NULL;
		int data4 = 0;

		dbus_error_init(&error);

		if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype,
			DBUS_TYPE_INT32, &data1, DBUS_TYPE_INT32, &data2,
			DBUS_TYPE_STRING, &data3, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID)) {
			debug_log("STORE_ENABLE: subtype: %d, data1: %d, data2: %d, data3: %s, data4: %d", subtype, data1, data2, data3, data4);

			int account_id = 0;
			int thread_id = 0;
			int mailid = 0;
			int mailbox_id = 0;
			char* msg_buf = NULL;
			int view_type = mailbox_ugd->view_type;

			switch (subtype) {

			/* This notification could be called in pause state when an account is added or deleted in setting app */
			case NOTI_ACCOUNT_ADD:
			case NOTI_ACCOUNT_DELETE:
				debug_log("account added or deleted during pause status");

				/* destroy all top ug and refresh all emails */
				if (mailbox_ugd->ug_account) {
					destroy_account_cb(mailbox_ugd->ug_account, mailbox_ugd);
					ug_pushed = false;
				}
				if (mailbox_ugd->ug_composer) {
					ug_destroy(mailbox_ugd->ug_composer);
					mailbox_ugd->ug_composer = NULL;
					ug_pushed = false;
				}

				if (!email_engine_get_default_account(&account_id)) {
					debug_log("no account exists");
					ug_destroy_me(mailbox_ugd->ug);
				} else {
					if (list_lock) {
						debug_log("locked");
						if (!evas_object_visible_get(mailbox_ugd->gl[view_type]))
							evas_object_show(mailbox_ugd->gl[view_type]);

						edje_object_signal_emit(_EDJ(mailbox_ugd->search_layout), "hide_noc", "elm");
						edje_object_signal_emit(_EDJ(mailbox_ugd->search_layout), "show_list", "elm");

						list_lock = false;
					}

					mailbox_ugd->account_id = 0;
					mailbox_ugd->mode = EMAIL_MAILBOX_MODE_ALL;
					mailbox_ugd->mailbox_type = EMAIL_MAILBOX_TYPE_NONE;
					mailbox_ugd->mailbox_id = 0;
					FREE(mailbox_ugd->user_email);
					FREE(mailbox_ugd->folder_alias);

					switch(view_type)
					{
						case EMAIL_VIEW_SEARCH:
							elm_object_focus_set(mailbox_ugd->gl[view_type], EINA_TRUE);
							evas_object_smart_callback_call(mailbox_ugd->searchbar_layout, "cancel,clicked", mailbox_ugd);
							break;
						case EMAIL_VIEW_EDIT:
							//elm_toolbar_item_selected_set(mailbox_ugd->edit_cancel_button, EINA_TRUE);
							_edit_back_cb(mailbox_ugd, NULL, NULL);
							break;
						default:
							break;
					}
					elm_segment_control_item_selected_set(mailbox_ugd->date_tab, EINA_TRUE);
					_update_navigationbar_title(mailbox_ugd);
					mailbox_make_date_mail_list(mailbox_ugd);
					_sync_all_folder(mailbox_ugd);

				}
				break;

			case NOTI_MAIL_MOVE:
				account_id = data1;
				msg_buf = data3;

				if(view_type == EMAIL_VIEW_RECIPIENT) {
					_refresh_mailbox(mailbox_ugd);
				}
				else {
					move_req_t *req = MEM_ALLOC(req, 1);
					if(!req) return;
					/* this dynamic var should be freed in NotiCB */
					*req = (move_req_t) {account_id, view_type, 0, g_strdup(msg_buf), mailbox_ugd};
					ecore_thread_feedback_run(_worker_get_move_mail_list_cb, _move_mail_item_cb,
											_move_finish_cb, NULL, req, EINA_TRUE);

					debug_log("Insert noti event to noti_Q to update previous view: data[%s]", data3);
					// insert the notification to noti_Q to update previous view (EMAIL_VIEW_DATE || EMAIL_VIEW_RECIPIENT)
					noti_event *noti = MEM_ALLOC(noti, 1);
					*noti = (noti_event){NOTI_MAIL_MOVE, data1, data2, g_strdup(data3), data4};
					mailbox_ugd->noti_Q = g_list_prepend(mailbox_ugd->noti_Q, (gpointer)noti);
				}
				break;

			case NOTI_MAIL_DELETE:
				account_id = data1;
				msg_buf = data3;

				if(view_type == EMAIL_VIEW_RECIPIENT) {
					_refresh_mailbox(mailbox_ugd);
				} else {
					delete_req_t *req = MEM_ALLOC(req, 1);
					if(!req) return;
					/* this dynamic var should be freed in NotiCB */
					*req = (delete_req_t) {account_id, view_type, 0, g_strdup(msg_buf), mailbox_ugd};
					ecore_thread_feedback_run(_worker_get_delete_mail_list_cb, _delete_mail_item_cb,
											_delete_finish_cb, NULL, req, EINA_TRUE);

					debug_log("Insert noti event to noti_Q to update previous view: data[%s]", data3);
					// insert the notification to noti_Q to update previous view (EMAIL_VIEW_RECIPIENT || EMAIL_VIEW_DATE)
					noti_event *noti = MEM_ALLOC(noti, 1);
					*noti = (noti_event){NOTI_MAIL_DELETE, data1, data2, g_strdup(data3), data4};
					mailbox_ugd->noti_Q = g_list_prepend(mailbox_ugd->noti_Q, (gpointer)noti);

				}
				break;

			case NOTI_MAIL_ADD: /* Seed mail was received */
				account_id = data1;
				thread_id = data4;
				mailid = data2;
				mailbox_id = atoi(data3);

				email_mailbox_type_e mailbox_type = GET_MAILBOX_TYPE(mailbox_id);

				if(mailid == thread_id)
				{
					if (mailbox_ugd->mode == EMAIL_MAILBOX_MODE_ALL && mailbox_ugd->mailbox_type == mailbox_type)
					{
						if ( view_type == EMAIL_VIEW_DATE || view_type == EMAIL_VIEW_UNREAD ||
								view_type == EMAIL_VIEW_IMPORTANT ||view_type == EMAIL_VIEW_PRIORITY ||
								view_type == EMAIL_VIEW_ATTACHMENTS)
						{
							sync_req_t *req = MEM_ALLOC(req, 1);
							if(!req) return;
							/* this dynamic var should be freed in NotiCB */
							*req = (sync_req_t) {account_id, thread_id, mailid, mailbox_id,
												view_type, mailbox_ugd->mode, mailbox_ugd};
							ecore_thread_feedback_run(_worker_get_mail_info_cb, add_seed_mail_cb,
													NULL, NULL, req, EINA_TRUE);

						}
						else if (view_type == EMAIL_VIEW_RECIPIENT)
						{
							_refresh_mailbox(mailbox_ugd);
						}
						else {
							/* Do nothing */
							debug_log("Do nothing in view_type[%d]", view_type);
						}
					}
					else
					{
						if (mailbox_ugd->mailbox_id == mailbox_id) {
							if ((view_type == EMAIL_VIEW_DATE || view_type == EMAIL_VIEW_UNREAD ||
									view_type == EMAIL_VIEW_IMPORTANT || view_type == EMAIL_VIEW_PRIORITY ||
									view_type == EMAIL_VIEW_ATTACHMENTS) &&
									mailbox_ugd->account_id == account_id &&
								mailbox_ugd->mailbox_id == mailbox_id)
							{
								_mailbox_list_add_item(mailbox_ugd, data2);
							}
							else if (view_type == EMAIL_VIEW_RECIPIENT && mailbox_ugd->account_id == account_id
									&& mailbox_ugd->mailbox_id == mailbox_id)
							{
								_refresh_mailbox(mailbox_ugd);
							}
							else {
								/* Do nothing */
								debug_log("Do nothing in view_type[%d]", view_type);
							}
						}
					}
				}
				break;

			case NOTI_MAIL_UPDATE:
				account_id = data1;
				mailid = data2;
				int type = data4;

				if(type == UPDATE_PARTIAL_BODY_DOWNLOAD) {
					list_data *ld = _find_mailinfo_by_mailid(mailid, mailbox_ugd->list_data[view_type]);
					if(ld) {
						email_mail_list_item_t* mail_info = NULL;
						mail_info = get_mail_info(mailid);
						if(!mail_info) break;
						ld->is_attachment = mail_info->has_attachment;
						ld->preview_body = STRNDUP(mail_info->previewBodyText, MAX_PREVIEW_TEXT_LENGTH-1);
						elm_genlist_item_update(ld->item);
						FREE(mail_info);
					}
				} else if(type == UPDATE_EXTRA_FLAG) {
					if (mailbox_ugd->mode == EMAIL_MAILBOX_MODE_MAILBOX && mailbox_ugd->mailbox_type == EMAIL_MAILBOX_TYPE_OUTBOX)
					{
						list_data *ld = _find_mailinfo_by_mailid(mailid, mailbox_ugd->list_data[view_type]);
						if(ld) {
							email_mail_list_item_t* mail_info = NULL;
							mail_info = get_mail_info(mailid);
							if(!mail_info) break;
							ld->is_sending_now = mail_info->save_status;
							elm_genlist_item_update(ld->item);
							FREE(mail_info);
						}
					}
				} else if(type == UPDATE_MAIL){
					list_data *ld = _find_mailinfo_by_mailid(mailid, mailbox_ugd->list_data[view_type]);
					if(ld) {
						email_mail_list_item_t* mail_info = NULL;
						mail_info = get_mail_info(mailid);
						if(!mail_info) break;
						ld->is_seen = mail_info->flags_seen_field;
						ld->followup_flag = mail_info->flags_flagged_field;
						ld->reply_flag = mail_info->flags_answered_field;
						ld->forward_flag = mail_info->flags_forwarded_field;
						elm_genlist_item_update(ld->item);
						FREE(mail_info);
					}
				}
				break;

			default:
				debug_log("Uninterested notification");
				break;
			}
		}
		else {
			debug_critical("receive data error: %s", error.message);
			dbus_error_free(&error);
		}

	}
	else if (dbus_message_is_signal(message, "User.Email.NetworkStatus", "email"))
	{
		debug_log("User.Email.NetworkStatus");

		int subtype = 0;
		int data1 = 0;
		char *data2 = NULL;
		int data3 = 0;
		int data4 = 0;

		dbus_error_init(&error);

		if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype,
			DBUS_TYPE_INT32, &data1, DBUS_TYPE_STRING, &data2,
			DBUS_TYPE_INT32, &data3, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID)) {
			debug_log("subtype: %d, data1: %d, data2: %s, data3: %d, data4: %d", subtype, data1, data2, data3, data4);

			switch (subtype) {
			case NOTI_DOWNLOAD_START:
				break;

			case NOTI_DOWNLOAD_FINISH:
			case NOTI_DOWNLOAD_FAIL:
				if (email_check_account_list(data1)) {
					_remove_get_more_progress_item(mailbox_ugd);

					if (mailbox_ugd->sync_progress == elm_object_part_content_get(mailbox_ugd->navi_title_ly, "right_btn"))
					{
						elm_object_part_content_unset(mailbox_ugd->navi_title_ly, "right_btn");
						evas_object_hide(mailbox_ugd->sync_progress);
						elm_object_part_content_set(mailbox_ugd->navi_title_ly, "right_btn", mailbox_ugd->update_button);
						evas_object_show(mailbox_ugd->update_button);
					}
				}
				break;

			case NOTI_VALIDATE_AND_CREATE_ACCOUNT_FINISH:
				break;

			default:
				debug_log("Uninterested notification");
				break;
			}
		}
		else {
			debug_critical("receive data error: %s", error.message);
			dbus_error_free(&error);
		}
	}
	else {
		debug_warning("We receive dbus message, but we can't do anything");
	}
	debug_leave();
}