remove Add to Calendar & remove 2nd ctx popup for Add to Contacts
[apps/core/preloaded/email.git] / viewer / src / email-viewer.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef UG_MODULE_API
18 #define UG_MODULE_API __attribute__ ((visibility("default")))
19 #endif
20
21 /* Header Include */
22 #include <app_service.h>
23 #include <status.h>
24 #include <calendar2.h>
25 #include <media-util-register.h>
26 #include <contacts-ug.h>
27
28 #include "email-viewer.h"
29 #include "email-viewer-webview.h"
30 #include "email-viewer-utils.h"
31 #include "email-engine.h"
32 #include "email-utils.h"
33 #include "email-common-types.h"
34 #include "email-debug.h"
35
36 #define EMAIL_VCONF_KEY_BLOCK_RULE_CHANGED      "file/private/org.tizen.email/spam_rule_changed"
37
38 /* Global Val */
39 EmailViewerUGD *_g_ug_data = NULL;
40 E_DBus_Connection *_g_viewer_dbus_conn = NULL;
41 E_DBus_Signal_Handler *_g_viewer_signal_handler_network = NULL;
42 E_DBus_Signal_Handler *_g_viewer_signal_handler_storage = NULL;
43
44 extern ui_gadget_h _g_mailbox_ug;
45 extern char *icu_locale;
46 extern enum appcore_time_format icu_timeformat;
47 extern void _set_mail_flags(EmailViewerProp *prop, EmailViewerPrivate *email_data);
48
49 /* appcore */
50 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv);
51 static void on_start(ui_gadget_h ug, service_h data, void *priv);
52 static void on_pause(ui_gadget_h ug, service_h data, void *priv);
53 static void on_resume(ui_gadget_h ug, service_h data, void *priv);
54 static void on_destroy(ui_gadget_h ug, service_h data, void *pd);
55 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv);
56 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv);
57 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv);
58
59 /* ui-gadget */
60 static void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv);
61 static void result_cb(ui_gadget_h ug, service_h result, void *priv);
62 static void destroy_cb(ui_gadget_h ug, void *priv);
63 static ui_gadget_h create_ug(char *ug_name, service_h bd, void *data);
64
65 /* View related */
66 static void _create_view(EmailViewerUGD *ug_data);
67 static void _reset_view(EmailViewerUGD *ug_data);
68
69 static void _win_profile_changed_cb(void *data, Evas_Object *obj, void *event);
70
71 static Evas_Object *_create_navigation_bar(EmailViewerUGD *ug_data);
72 static Evas_Object *_create_subject(EmailViewerUGD *ug_data);
73 static Evas_Object *_create_to_addrs(EmailViewerUGD *ug_data);
74 static Evas_Object *_create_cc_addrs(EmailViewerUGD *ug_data);
75 static Evas_Object *_create_bcc_addrs(EmailViewerUGD *ug_data);
76 static Evas_Object *_create_attach(EmailViewerUGD *ug_data);
77 static Evas_Object *_create_attach_ex(EmailViewerUGD *ug_data);
78 static Evas_Object *_create_body(EmailViewerUGD *ug_data);
79 static Evas_Object *_create_tab_bar(EmailViewerUGD *ug_data);
80 static Evas_Object *_update_tab_bar(EmailViewerUGD *ug_data);
81 static Evas_Object *_create_partial_body_dn_btn(EmailViewerUGD *ug_data);
82 static Evas_Object *_create_bg(Evas_Object *win);
83
84 static void _create_down_progress(char *message, popup_cb resp_cb);
85 static void _create_down_progress_ex(int index, EMAIL_VIEWER_PROGRESSBAR_TYPE p_type);
86 static void _destroy_down_progress_ex(void *data, Evas_Object *obj, void *event_info);
87 static void _create_more_ctxpopup(EmailViewerUGD *ug_data);
88 static void _delete_evas_objects(EmailViewerUGD *ug_data);
89
90 /* callback functions */
91 static void _back_cb(void *data, Evas_Object *obj, void *event_info);
92 static void _prev_mail_cb(void *data, Evas_Object *obj, void *event_info);
93 static void _next_mail_cb(void *data, Evas_Object *obj, void *event_info);
94 static void _reply_cb(void *data, Evas_Object *obj, void *event_info);
95 static void _reply_all_cb(void *data, Evas_Object *obj, void *event_info);
96 static void _reply_option_cb(void *data, Evas_Object *obj, void *event_info);
97 static void _forward_cb(void *data, Evas_Object *obj, void *event_info);
98 static void _resend_cb(void *data, Evas_Object *obj, void *event_info);
99 static void _delete_cb(void *data, Evas_Object *obj, void *event_info);
100 static void _move_cb(void *data, Evas_Object *obj, void *event_info);
101 static void _more_cb(void *data, Evas_Object *obj, void *event_info);
102 static void _body_down_cb(void *data, Evas_Object *obj, void *event_info);
103 static void _subject_favorite_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
104 static void _subject_detail_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
105 static void _attachment_item_collapse_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
106 static void _attachment_save_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
107 static void _attachment_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
108 static void _attachment_save_all_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
109 static void _attachment_bg_set_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
110 static void _attachment_bg_unset_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
111 static void _mark_as_unread_cb(void *data, Evas_Object *obj, void *event_info);
112 static void _mark_as_read_cb(void *data, Evas_Object *obj, void *event_info);
113 static void _save_email_cb(void *data, Evas_Object *obj, void *event_info);
114 static Eina_Bool _save_email_prog_cb(void *data);
115
116 static void _ctxpopup_detail_contact_cb(void *data, Evas_Object *obj, void *event_info);
117 static void _ctxpopup_send_email_cb(void *data, Evas_Object *obj, void *event_info);
118 static void _ctxpopup_add_contact_cb(void *data, Evas_Object *obj, void *event_info);
119 static void _ctxpopup_add_block_rule_cb(void *data, Evas_Object *obj, void *event_info);
120 static void _popup_waiting_response_cb(void *data, Evas_Object *obj, void *event_info);
121 static void _popup_response_cb(void *data, Evas_Object *obj, void *event_info);
122 static void _popup_response_delete_ok_cb(void *data, Evas_Object *obj, void *event_info);
123 static void _popup_response_to_destroy_cb(void *data, Evas_Object *obj, void *event_info);
124
125 static void _webview_multi_up_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
126 static void _webview_multi_down_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info);
127 static void _webview_policy_navigation_decide_cb(void *data, Evas_Object *obj, void *event_info);
128
129 static void _outter_scroller_bottom_hit_cb(void *data, Evas_Object *obj, void *event_info);
130 static void _outter_scroller_top_hit_cb(void *data, Evas_Object *obj, void *event_info);
131 static void _outter_scroller_scroll_cb(void *data, Evas_Object *obj, void *event_info);
132
133 static void _mbe_focused_cb(void *data, Evas_Object *obj, void *event_info);
134 static void _mbe_unfocused_cb(void *data, Evas_Object *obj, void *event_info);
135 static void _mbe_added_cb(void *data, Evas_Object *obj, void *event_info);
136 static void _mbe_selected_cb(void *data, Evas_Object *obj, void *event_info);
137 static void _destroy_down_progress_cb(void *data, Evas_Object *obj, void *event_info);
138
139 /* Logic Functions */
140 static void _init_viewer_data(int account_id, int mail_id, char *srv_mail_id, EmailViewerUGD *ug_data);
141 static int _init_webview_data(EmailViewerUGD *ug_data);
142 static Eina_Bool _check_body_download(void *data);
143 static int _update_attachment_info(EmailViewerUGD *ug_data, int index);
144 static int _get_attachment_info_index(EmailViewerUGD *ug_data, int index);
145 static void _show_select_info(EmailViewerUGD *ug_data, char *str);
146 static void _save_attachment(EmailViewerUGD *ug_data, int index);
147 static void _show_attachment(EmailViewerUGD *ug_data, int index);
148 static void _save_attachment_all(EmailViewerUGD *ug_data);
149 static void _dbus_receiver_setup(EmailViewerUGD *ug_data);
150 static void _dbus_receiver_remove(EmailViewerUGD *ug_data);
151 static void _on_edbus_event_email_viewer_receive(void *local_data, DBusMessage *message);
152
153 static void _delete_contacts_list(EMAIL_CONTACT_LIST_INFO_S *contacts_list_item);
154 static void *_contact_search_by_email(EmailViewerUGD *ug_data, const char *search_word);
155 static void _set_value_down_progress(double val);
156 static void _set_value_down_progress_by_index(double val, int index);
157 static void _cancel_download_attachment(EmailViewerUGD *ug_data);
158
159 /* Util Functions */
160 static char *_get_service_fail_type(int type);
161 static Evas_Object *_load_edj(Evas_Object *parent, const char *file, const char *group);
162
163 /* genlist cb */
164 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part);
165 static void _gl_del(void *data, Evas_Object *obj);
166 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part);
167 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part);
168 static void _move_here_cb(void *data, Evas_Object *obj, void *event_info);
169 static void _move_back_cb(void *data, Evas_Object *obj, void *event_info);
170
171
172 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
173 {
174         debug_log("");
175
176         EmailViewerUGD *ug_data;
177
178         if (!ops)
179                 return -1;
180
181         ug_data = calloc(1, sizeof(EmailViewerUGD));
182         if (!ug_data)
183                 return -1;
184
185         _g_ug_data = ug_data;
186 //      g_type_init();
187
188         ops->create = on_create;
189         ops->start = on_start;
190         ops->pause = on_pause;
191         ops->resume = on_resume;
192         ops->destroy = on_destroy;
193         ops->message = on_message;
194         ops->event = on_event;
195         ops->key_event = on_key_event;
196         ops->priv = ug_data;
197         ops->opt = UG_OPT_INDICATOR_ENABLE;
198
199         return 0;
200 }
201
202 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
203 {
204         debug_log("");
205         EmailViewerUGD *ug_data;
206
207         if (!ops)
208                 return;
209
210         ug_data = ops->priv;
211         if (ug_data)
212                 free(ug_data);
213
214         debug_log("~");
215 }
216
217 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv)
218 {
219         debug_log("");
220         EmailViewerUGD *ug_data;
221         char *account_id = NULL;
222         char *mail_id = NULL;
223         char *mailbox_id = NULL;
224         char *binternal = NULL;
225         char *landscape = NULL;
226
227         if (!ug || !priv)
228                 return NULL;
229
230         ug_data = priv;
231         ug_data->ug = ug;
232
233         if (!data) {
234                 debug_log("account_id and mail_id are required by arguments");
235                 ug_data->b_direct_destroy = 1;
236                 ug_destroy_me(ug_data->ug);
237                 _g_ug_data = NULL;
238                 return NULL;
239         }
240
241         /* email engine initialize */
242         if (email_engine_initialize() == FALSE) {
243                 debug_log("Failed to initialize email engine");
244                 ug_data->b_direct_destroy = 1;
245                 ug_destroy_me(ug_data->ug);
246                 _g_ug_data = NULL;
247                 return NULL;
248         }
249
250 /*      Elm_Theme *theme = elm_theme_new();
251         elm_theme_ref_set(theme, NULL);
252         ug_data->theme = theme;
253         elm_theme_extension_add(ug_data->theme, EV_THEME_PATH);*/
254
255         int ret;
256         ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_ACCOUNT_ID, (char **)&account_id);
257         debug_log("service_get_extra_data: %d", ret);
258         debug_log("account_id:%s", account_id);
259         ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_MAIL_ID, (char **)&mail_id);
260         debug_log("service_get_extra_data: %d", ret);
261         debug_log("mail_id:%s", mail_id);
262         ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_MAILBOX, (char **)&mailbox_id);
263         debug_log("service_get_extra_data: %d", ret);
264         debug_log("mailbox:%s", mailbox_id);
265         ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_INTERNAL, (char **)&binternal);
266         debug_log("service_get_extra_data: %d", ret);
267         debug_log("binternal:%s", binternal);
268         ret = service_get_extra_data(data, EMAIL_BUNDLE_KEY_FIRST_LANDSCAPE, (char **)&landscape);
269         debug_log("service_get_extra_data: %d", ret);
270         debug_log("landscape:%s", landscape);
271
272         if (landscape) {
273                 ug_data->isRotate = atoi(landscape);
274                 debug_log("@@@@ Landscape = %d @@@@", ug_data->isRotate);
275                 g_free(landscape);
276         }
277
278         if (account_id) {
279                 ug_data->account_id = atoi(account_id);
280                 ug_data->folder_list = email_engine_get_ca_mailbox_list_using_glist(ug_data->account_id);
281                 g_free(account_id);
282         }
283
284         if (mail_id) {
285                 ug_data->mail_id = atoi(mail_id);
286                 g_free(mail_id);
287         }
288
289         if (mailbox_id) {
290                 g_free(ug_data->mailbox_name);
291                 ug_data->mailbox_name = NULL;
292                 ug_data->mailbox_id = atoi(mailbox_id);
293                 g_free(mailbox_id);
294
295                 int err = 0;
296                 email_mail_data_t *mail_data = NULL;
297                 if ((err = email_get_mail_data(ug_data->mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
298                         debug_log("fail to get mail - err (%d)", err);
299                 }
300
301                 if (mail_data == NULL) {
302                         debug_log("mail_data is NULL");
303                 }
304
305                 if (mail_data->server_mailbox_name)
306                         ug_data->mailbox_name = g_strdup(mail_data->server_mailbox_name);
307                 ug_data->mailbox_type = mail_data->mailbox_type;
308                 debug_log("server_mailbox_name:%s", mail_data->server_mailbox_name);
309                 debug_log("mailbox_name:%s", ug_data->mailbox_name);
310                 debug_log("mailbox_type:%d", ug_data->mailbox_type);
311
312                 if (mail_data) {
313                         debug_log("email_free_mail is called");
314                         email_free_mail_data(&(mail_data), 1);
315                         mail_data = NULL;
316                 }
317         }
318
319         if (binternal) {
320                 ug_data->b_internal = atoi(binternal);
321                 if (ug_data->b_internal == 1)
322                         debug_log("############Launched from email-mailbox###############");
323                 g_free(binternal);
324         }
325
326         debug_log("account_id [%d], mail_id [%d], mailbox_id [%d], mailbox name [%s]", ug_data->account_id, ug_data->mail_id, ug_data->mailbox_id, ug_data->mailbox_name);
327
328         if (ug_data->account_id <= 0 || ug_data->mail_id <= 0 || ug_data->mailbox_id <= 0) {
329                 debug_log("Required bundle parameters are missing!");
330                 ug_data->timeout_popup = elm_popup_add(ug_get_window());
331                 evas_object_size_hint_weight_set(ug_data->timeout_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
332                 elm_popup_timeout_set(ug_data->timeout_popup, 2);
333                 elm_object_text_set(ug_data->timeout_popup, _("IDS_EMAIL_POP_UNABLE_TO_OPEN_EMAIL_MESSAGE"));
334                 elm_object_part_text_set(ug_data->timeout_popup, "title,text", _("IDS_EMAIL_POP_ALERT"));
335                 evas_object_smart_callback_add(ug_data->timeout_popup, "block,clicked", _popup_response_to_destroy_cb, ug_data);
336                 evas_object_smart_callback_add(ug_data->timeout_popup, "timeout", _popup_response_to_destroy_cb, ug_data);
337                 evas_object_show(ug_data->timeout_popup);
338
339                 return elm_layout_add(ug_get_window());
340         }
341
342         ug_data->win_main = ug_get_window();
343
344         char *proxy_address = vconf_get_str(VCONFKEY_NETWORK_PROXY);
345         debug_log("network proxy: %s", proxy_address);
346         if (proxy_address && (g_strcmp0(proxy_address, "") != 0)) {
347                 ewk_context_proxy_uri_set(ewk_context_default_get(), proxy_address);
348         }
349
350         if (proxy_address)
351                 free(proxy_address);
352
353         int w, h;
354         ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
355         debug_log("WINDOW W[%d] H[%d]", w, h);
356         ug_data->main_w = w;
357         ug_data->main_h = h;
358
359         ug_data->scale_factor = elm_scale_get();
360         debug_log("ELM Scale[%f]", ug_data->scale_factor);
361
362         if (w == 480) {
363                 ug_data->webview_width = 710.0;
364                 ug_data->webview_height = 949.0;
365                 ug_data->webview_width_landscape = 710.0;
366                 ug_data->webview_height_landscape = 568.0;
367                 ug_data->webview_margin = 633;
368                 ug_data->webview_margin_landscape = 379;
369         } else if (w == 720) {
370                 ug_data->webview_width = 710.0;
371                 ug_data->webview_height = 1021.0;
372                 ug_data->webview_width_landscape = 710.0;
373                 ug_data->webview_height_landscape = 558.0;
374                 ug_data->webview_margin = 1029;
375                 ug_data->webview_margin_landscape = 558;
376         } else {
377                 ug_data->webview_width = 710.0;
378                 ug_data->webview_height = 949.0;
379                 ug_data->webview_width_landscape = 710.0;
380                 ug_data->webview_height_landscape = 568.0;
381                 ug_data->webview_margin = 633;
382                 ug_data->webview_margin_landscape = 379;
383         }
384
385         ug_data->evas = evas_object_evas_get(ug_data->win_main);
386
387         /* Double_Scroller */
388         ug_data->b_noc = 1;
389
390         email_account_t *account = NULL;
391         if (email_engine_get_account_full_data(ug_data->account_id, &account)) {
392                 debug_log("email_engine_get_account");
393                 if (account) {
394                         ug_data->account_type = account->incoming_server_type;
395                         snprintf(ug_data->account_email_address, sizeof(ug_data->account_email_address), "%s", account->user_email_address);
396
397                         account_user_data_t *ud = (account_user_data_t*)account->user_data;
398                         if (ud != NULL) {
399                                 debug_log("show_images is %d", ud->show_images);
400                                 ug_data->b_show_remote_images = ud->show_images;
401                         }
402                         email_free_account(&account, 1);
403                         account = NULL;
404                 }
405         }
406
407         /* DBUS */
408         _dbus_receiver_setup(ug_data);
409
410         _init_viewer_data(ug_data->account_id, ug_data->mail_id, NULL, ug_data);
411         _create_view(ug_data);
412
413         _check_body_download(ug_data);
414
415         ug_data->base = ug_data->layout_main;
416
417         ug_data->display_download_result = TRUE;
418
419         return ug_data->base;
420 }
421
422 static void on_start(ui_gadget_h ug, service_h data, void *priv)
423 {
424         debug_log("");
425 }
426
427 static void on_pause(ui_gadget_h ug, service_h data, void *priv)
428 {
429         debug_log("");
430 }
431
432 static void on_resume(ui_gadget_h ug, service_h data, void *priv)
433 {
434         debug_log("");
435 }
436
437 static void on_destroy(ui_gadget_h ug, service_h data, void *pd)
438 {
439         debug_log("");
440         EmailViewerUGD *ug_data;
441
442         if (!ug || !pd)
443                 return;
444
445         ug_data = pd;
446
447         _g_ug_data = NULL;
448
449         if (ug_data->b_direct_destroy)
450                 return;
451
452         /* stop engine */
453         EmailViewerPrivate *priv = ug_data->email_data;
454         EmailViewerProp *prop = ug_data->property;
455         int i = 0;
456         int att_len = g_list_length(prop->attachments);
457
458         if (priv->email_handle != 0)
459                 email_engine_stop_working(ug_data->account_id, priv->email_handle);
460
461         for (i = 0; i < att_len; i++) {
462                 if (priv->download_all_email_handle[i] != 0)
463                         email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[i]);
464         }
465
466 /*      if (ug_data->theme) {
467                 elm_theme_extension_del(ug_data->theme, EV_THEME_PATH);
468                 elm_theme_free(ug_data->theme);
469                 ug_data->theme = NULL;
470         }*/
471
472         _delete_evas_objects(ug_data);
473
474         debug_log("free webview_data");
475         if (ug_data->webview_data) {
476                 free(ug_data->webview_data);
477                 ug_data->webview_data = NULL;
478         }
479
480         if (ecore_file_exists(DIR_TMP_PREFIX"/mail.txt"))
481                 ecore_file_remove(DIR_TMP_PREFIX"/mail.txt");
482
483         debug_log("free address info list");
484         email_free_address_info_list(&(priv->addrs_info_list));
485         ug_data->from_list = NULL;
486         ug_data->to_list = NULL;
487         ug_data->cc_list = NULL;
488         ug_data->bcc_list = NULL;
489
490         debug_log("free mail_info");
491         if (ug_data->email_data->mail_info) {
492                 email_free_mail_data(&(ug_data->email_data->mail_info), 1);
493                 ug_data->email_data->mail_info = NULL;
494         }
495
496         if (ug_data->email_data->attachment_info && ug_data->email_data->attachment_count > 0) {
497                 email_free_attachment_data(&(ug_data->email_data->attachment_info), ug_data->email_data->attachment_count);
498                 ug_data->email_data->attachment_info = NULL;
499                 ug_data->email_data->attachment_count = 0;
500         }
501
502         debug_log("free email_data");
503         if (ug_data->email_data) {
504                 free(ug_data->email_data);
505                 ug_data->email_data = NULL;
506         }
507
508         debug_log("free attachment");
509         if (ug_data->property->attachments) {
510                 int i = 0;
511                 LIST_ITER_START(i, ug_data->property->attachments) {
512                         EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, ug_data->property->attachments);
513                         if (info->name)
514                                 free(info->name);
515                         if (info->path)
516                                 free(info->path);
517                         free(info);
518                 }
519                 g_list_free(ug_data->property->attachments);
520                 ug_data->property->attachments = NULL;
521         }
522
523         debug_log("free property");
524         if (ug_data->property) {
525                 free(ug_data->property);
526                 ug_data->property = NULL;
527         }
528
529         ug_data->base = NULL;
530
531         _dbus_receiver_remove(NULL);
532         int ret = e_dbus_shutdown();
533         debug_log("ret: %d", ret);
534
535         email_engine_finalize();
536
537
538         debug_log("~");
539 }
540
541 static void on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
542 {
543         debug_log("");
544
545         if (!ug || !priv)
546                 return;
547
548         debug_log("_g_ug_data - %p", _g_ug_data);
549         if (_g_ug_data != NULL) {
550                 debug_log("Hide previous mail data");
551                 _hide_view(_g_ug_data);
552         }
553
554         char *account_id = NULL;
555         char *mail_id = NULL;
556         char *mailbox_id = NULL;
557         char *binternal = NULL;
558         char *landscape = NULL;
559
560         EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
561         _g_ug_data = ug_data;
562
563         /* reset viewer */
564         int ret;
565         ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_ACCOUNT_ID, (char **)&account_id);
566         debug_log("service_get_extra_data: %d", ret);
567         debug_log("account_id:%s", account_id);
568         ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_MAIL_ID, (char **)&mail_id);
569         debug_log("service_get_extra_data: %d", ret);
570         debug_log("mail_id:%s", mail_id);
571         ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_MAILBOX, (char **)&mailbox_id);
572         debug_log("service_get_extra_data: %d", ret);
573         debug_log("mailbox:%s", mailbox_id);
574         ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_INTERNAL, (char **)&binternal);
575         debug_log("service_get_extra_data: %d", ret);
576         debug_log("binternal:%s", binternal);
577         ret = service_get_extra_data(msg, EMAIL_BUNDLE_KEY_FIRST_LANDSCAPE, (char **)&landscape);
578         debug_log("service_get_extra_data: %d", ret);
579         debug_log("landscape:%s", landscape);
580
581         if (landscape) {
582                 ug_data->isRotate = atoi(landscape);
583                 debug_log("@@@@ Landscape = %d @@@@", ug_data->isRotate);
584                 g_free(landscape);
585         }
586
587         if (account_id) {
588                 ug_data->account_id = atoi(account_id);
589                 ug_data->folder_list = email_engine_get_ca_mailbox_list_using_glist(ug_data->account_id);
590                 g_free(account_id);
591         }
592
593         if (mail_id) {
594                 ug_data->mail_id = atoi(mail_id);
595                 g_free(mail_id);
596         }
597
598         if (mailbox_id) {
599                 g_free(ug_data->mailbox_name);
600                 ug_data->mailbox_name = NULL;
601                 ug_data->mailbox_id = atoi(mailbox_id);
602                 g_free(mailbox_id);
603
604                 int err = 0;
605                 email_mail_data_t *mail_data = NULL;
606                 if ((err = email_get_mail_data(ug_data->mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
607                         debug_log("fail to get mail - err (%d)", err);
608                 }
609
610                 if (mail_data == NULL) {
611                         debug_log("mail_data is NULL");
612                 }
613
614                 if (mail_data->server_mailbox_name)
615                         ug_data->mailbox_name = g_strdup(mail_data->server_mailbox_name);
616                 ug_data->mailbox_type = mail_data->mailbox_type;
617                 debug_log("server_mailbox_name:%s", mail_data->server_mailbox_name);
618                 debug_log("mailbox_name:%s", ug_data->mailbox_name);
619                 debug_log("mailbox_type:%d", ug_data->mailbox_type);
620
621                 if (mail_data) {
622                         debug_log("email_free_mail is called");
623                         email_free_mail_data(&(mail_data), 1);
624                         mail_data = NULL;
625                 }
626         }
627
628         if (binternal) {
629                 ug_data->b_internal = atoi(binternal);
630                 if (ug_data->b_internal == 1)
631                         debug_log("############Launched from email-mailbox###############");
632                 g_free(binternal);
633         }
634
635         debug_log("account_id [%d], mail_id [%d], mailbox_id[%d], mailbox name [%s]", ug_data->account_id, ug_data->mail_id, ug_data->mailbox_id, ug_data->mailbox_name);
636
637         if (ug_data->account_id <= 0 || ug_data->mail_id <= 0 || ug_data->mailbox_id <= 0) {
638                 debug_log("Required bundle parameters are missing!");
639                 _g_ug_data = NULL;
640                 return;
641         }
642
643         email_account_t *account = NULL;
644         if (email_engine_get_account_full_data(ug_data->account_id, &account)) {
645                 debug_log("email_engine_get_account");
646                 if (account) {
647                         ug_data->account_type = account->incoming_server_type;
648                         snprintf(ug_data->account_email_address, sizeof(ug_data->account_email_address), "%s", account->user_email_address);
649
650                         account_user_data_t *ud = (account_user_data_t*)account->user_data;
651                         if (ud != NULL) {
652                                 debug_log("show_images is %d", ud->show_images);
653                                 ug_data->b_show_remote_images = ud->show_images;
654                         }
655                         email_free_account(&account, 1);
656                         account = NULL;
657                 }
658
659                 Ewk_Setting *setting = ewk_view_setting_get(ug_data->webview);
660
661                 debug_log("b_show_remote_images is %d", ug_data->b_show_remote_images);
662                 if (ewk_setting_load_remote_images_set(setting, ug_data->b_show_remote_images) == EINA_FALSE) {
663                         debug_log("SET remote images is FAILED!");
664                 }
665         }
666
667         _init_viewer_data(ug_data->account_id, ug_data->mail_id, NULL, ug_data);
668
669         evas_object_show(ug_data->layout_main);
670         evas_object_raise(ug_data->layout_main);
671
672         _reset_view(ug_data);
673
674         ug_data->display_download_result = TRUE;
675 }
676
677 static void on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
678 {
679         debug_log("");
680
681         if (!ug || !priv)
682                 return;
683
684         EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
685         EmailViewerProp *prop = ug_data->property;
686         char date_time[MAX_STR_LEN] = { 0, };
687         char *formatted_date = NULL;
688         int ret = 0;
689
690         debug_log("rotate event = %d", event);
691
692         switch (event) {
693         case UG_EVENT_LOW_MEMORY:
694                 break;
695         case UG_EVENT_LOW_BATTERY:
696                 break;
697         case UG_EVENT_LANG_CHANGE:
698                 break;
699         case UG_EVENT_ROTATE_PORTRAIT:
700         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
701                 if (ug_data->b_internal && ug_data->isRotate == true) {
702                         ewk_view_command_execute(ug_data->webview, "Unselect", NULL);
703                         debug_log("In Full view - Showing navi bar");
704                         elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_TRUE);
705
706                         if (ug_data->con_popup) {
707                                 evas_object_del(ug_data->con_popup);
708                                 ug_data->con_popup = NULL;
709                         }
710
711                         if (ug_data->navi_move_it1) {
712                                 debug_log("move1");
713                                 Evas_Object *move_back_btn = elm_button_add(ug_data->navi_bar);
714                                 elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
715                                 evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb, ug_data);
716                                 elm_object_item_part_content_set(ug_data->navi_move_it1, "prev_btn", move_back_btn);
717                                 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_TRUE);
718                                 if (ug_data->move_cbar) {
719                                         elm_object_item_part_content_unset(ug_data->navi_move_it1, "controlbar");
720                                         evas_object_del(ug_data->move_cbar);
721                                         ug_data->move_cbar = NULL;
722                                 }
723                         }
724
725                         if (ug_data->b_btn) {
726                                 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
727                                 evas_object_del(ug_data->b_btn);
728                                 ug_data->b_btn = NULL;
729                         }
730
731                         ug_data->b_btn = elm_button_add(ug_data->navi_bar);
732                         elm_object_style_set(ug_data->b_btn, "naviframe/back_btn/default");
733                         evas_object_smart_callback_add(ug_data->b_btn, "clicked", _back_cb, ug_data);
734                         elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", ug_data->b_btn);
735
736                         ug_data->isRotate = false;
737                 }
738
739                 break;
740
741         case UG_EVENT_ROTATE_LANDSCAPE:
742         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
743                 if (ug_data->b_internal && ug_data->isRotate == false) {
744                         ewk_view_command_execute(ug_data->webview, "Unselect", NULL);
745                         debug_log("In Split view - Hiding navi bar");
746                         elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_FALSE);
747
748                         if (ug_data->con_popup) {
749                                 evas_object_del(ug_data->con_popup);
750                                 ug_data->con_popup = NULL;
751                         }
752
753                         if (ug_data->navi_move_it1) {
754                                 debug_log("move1");
755                                 ug_data->move_cbar = elm_toolbar_add(ug_data->navi_bar);
756                                 elm_toolbar_shrink_mode_set(ug_data->move_cbar, ELM_TOOLBAR_SHRINK_EXPAND);
757                                 elm_object_style_set(ug_data->move_cbar, "naviframe");
758                                 evas_object_show(ug_data->move_cbar);
759
760                                 elm_object_item_disabled_set(elm_toolbar_item_append(ug_data->move_cbar, NULL, "", NULL, NULL), EINA_TRUE);
761                                 elm_toolbar_item_append(ug_data->move_cbar, NULL, dgettext("sys_string", "IDS_COM_SK_CANCEL"), _move_back_cb, ug_data);
762                                 elm_object_item_part_content_set(ug_data->navi_move_it1, "controlbar", ug_data->move_cbar);
763
764                                 Evas_Object *move_back_btn = elm_object_item_part_content_get(ug_data->navi_move_it1, "prev_btn");
765                                 if (move_back_btn) {
766                                         evas_object_smart_callback_del(move_back_btn, "clicked", _move_back_cb);
767                                         evas_object_del(move_back_btn);
768                                         elm_object_item_part_content_set(ug_data->navi_move_it1, "prev_btn", NULL);
769                                 }
770                                 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_FALSE);
771                         }
772
773                         if (ug_data->b_btn) {
774                                 evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
775                                 evas_object_del(ug_data->b_btn);
776                                 ug_data->b_btn = NULL;
777                                 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
778                         }
779
780                         ug_data->isRotate = true;
781                 }
782
783                 break;
784
785         case UG_EVENT_REGION_CHANGE:
786                 appcore_get_timeformat(&icu_timeformat);
787                 /* ICU API to set default locale */
788                 if (icu_timeformat == APPCORE_TIME_FORMAT_12)
789                         formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
790                 else
791                         formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
792                 ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
793
794                 free(formatted_date);
795                 formatted_date = NULL;
796
797                 edje_object_part_text_set(_EDJ(ug_data->ly_subject), "elm.text.sub", date_time);
798                 evas_object_show(ug_data->ly_subject);
799                 break;
800
801         default:
802                 break;
803         }
804 }
805
806 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv)
807 {
808         debug_log("");
809
810         if (!ug)
811                 return;
812
813         EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
814         EmailViewerPrivate *private = ug_data->email_data;
815         EmailViewerProp *prop = ug_data->property;
816
817         switch (event) {
818         case UG_KEY_EVENT_END:
819                 if (_g_ug_data) {
820                         if (ug_data->notify != NULL || ug_data->pb_notify != NULL || ug_data->timeout_popup != NULL) {
821                                 if (ug_data->timeout_popup) {
822                                         evas_object_del(ug_data->timeout_popup);
823                                         ug_data->timeout_popup = NULL;
824                                 }
825
826                                 if (ug_data->notify) {
827                                         evas_object_del(ug_data->notify);
828                                         ug_data->notify = NULL;
829                                 }
830
831                                 if (ug_data->pb_notify) {
832                                         int i = 0;
833                                         int att_len = g_list_length(prop->attachments);
834
835                                         evas_object_del(ug_data->pb_notify);
836                                         ug_data->pb_notify = NULL;
837
838                                         if (private->email_handle != 0)
839                                                 email_engine_stop_working(ug_data->account_id, private->email_handle);
840
841                                         for (i = 0; i < att_len; i++) {
842                                                 if (private->download_all_email_handle[i] != 0)
843                                                         email_engine_stop_working(ug_data->account_id, private->download_all_email_handle[i]);
844                                         }
845                                 }
846
847                                 if (ug_data->pb_notify_lb) {
848                                         evas_object_del(ug_data->pb_notify_lb);
849                                         ug_data->pb_notify_lb = NULL;
850                                 }
851                         } else {
852                                 if (ug_data->isRotate == false && ug_data->b_internal) {
853                                         /* Viewer to hide, so set left content (mailbox) size to full */
854                                         _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
855                                 }
856
857                                 if (ug_data->b_internal)
858                                         _hide_view(ug_data);
859                                 else
860                                         ug_destroy_me(ug_data->ug);
861                         }
862                 } else {
863                         int ret;
864                         service_h service = NULL;
865
866                         ret = service_create(&service);
867                         debug_log("service_create: %d", ret);
868                         if (!service) {
869                                 debug_log("service create failed");
870                                 return;
871                         }
872
873                         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_END_KEY);
874                         debug_log("service_add_extra_data: %d", ret);
875
876                         ug_send_message(_g_mailbox_ug, service);
877
878                         ret = service_destroy(service);
879                         debug_log("service_destroy: %d", ret);
880                 }
881                 break;
882
883         default:
884                 break;
885         }
886 }
887
888 static void layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
889 {
890         debug_log("");
891         Evas_Object *base, *win;
892
893         if (!ug || !priv)
894                 return;
895
896         base = ug_get_layout(ug);
897         if (!base)
898                 return;
899
900         win = ug_get_window();
901
902         switch (mode) {
903         case UG_MODE_FULLVIEW:
904                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
905                 elm_win_resize_object_add(win, base);
906                 evas_object_show(base);
907                 break;
908         default:
909                 break;
910         }
911 }
912
913 static void result_cb(ui_gadget_h ug, service_h result, void *priv)
914 {
915         debug_log("");
916
917         if (!ug || !priv)
918                 return;
919
920         EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
921         EmailViewerProp *prop = ug_data->property;
922         EmailViewerPrivate *private = ug_data->email_data;
923
924         if (ug == ug_data->ug_composer) {
925                 char *cmd = NULL;
926                 int ret = service_get_extra_data(result, EMAIL_BUNDLE_KEY_SAVE_ALL, (char **)&cmd);
927                 debug_log("service_get_extra_data: %d", ret);
928                 debug_log("return of bundle_get_val for save all(%s)", cmd);
929                 if (cmd) {
930                         debug_log("save all from composer(%s), real_att_len(%d), att_len(%d)", cmd, prop->real_att_len, prop->att_len);
931
932                         if (prop->real_att_len == 1) {
933                                 private->b_all_att_save = TRUE;
934                                 _save_attachment(ug_data, 0);
935                         } else if (prop->real_att_len > 1) {
936                                 _save_attachment_all(ug_data);
937                         }
938                         g_free(cmd);
939                         return;
940                 }
941
942                 ret = service_get_extra_data(result, EMAIL_BUNDLE_KEY_CANCEL_ALL, (char **)&cmd);
943                 debug_log("service_get_extra_data: %d", ret);
944                 debug_log("return of bundle_get_val for cancel all(%s)", cmd);
945                 if (cmd) {
946                         debug_log("cancel all attachment from composer(%s)", cmd);
947
948                         _cancel_download_attachment(ug_data);
949                         g_free(cmd);
950                         return;
951                 }
952         }
953 }
954
955 static void destroy_cb(ui_gadget_h ug, void *priv)
956 {
957         debug_log("");
958         if (!ug || !priv)
959                 return;
960
961         EmailViewerUGD *ug_data = (EmailViewerUGD *)priv;
962         EmailViewerProp *prop = ug_data->property;
963         ug_data->display_download_result = TRUE;
964
965         if (ug == ug_data->ug_composer) {
966                 ug_data->ug_composer = NULL;
967         }
968
969         ug_destroy(ug);
970
971         if (ug_data->b_contact_ug_launched) {
972                 debug_log("change navibar title label");
973                 EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
974                 contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, prop->sender);
975
976                 if (contact_list_item) {
977                         elm_object_item_text_set(ug_data->navi_main_it, contact_list_item->display_name);
978                         _delete_contacts_list(contact_list_item);
979                 } else {
980                         elm_object_item_text_set(ug_data->navi_main_it, prop->sender_display_name);
981                 }
982
983                 ug_data->b_contact_ug_launched = FALSE;
984         }
985 }
986
987 static ui_gadget_h create_ug(char *ug_name, service_h bd, void *data)
988 {
989         debug_log("");
990         ui_gadget_h ug;
991         struct ug_cbs cbs = { 0, };
992
993         cbs.layout_cb = layout_cb;
994         cbs.result_cb = result_cb;
995         cbs.destroy_cb = destroy_cb;
996         cbs.priv = data;
997
998         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
999
1000         ug = ug_create(ug_data->ug, ug_name, UG_MODE_FULLVIEW, bd, &cbs);
1001
1002         return ug;
1003 }
1004
1005 static void _create_view(EmailViewerUGD *ug_data)
1006 {
1007         debug_log("");
1008
1009         Evas_Object *b_btn;
1010         Evas_Object *prev_btn;
1011         Evas_Object *next_btn;
1012         EmailViewerProp *prop = ug_data->property;
1013
1014         ug_data->bg = _create_bg(ug_data->win_main);
1015
1016         /* create layout */
1017         ug_data->layout_main = elm_layout_add(ug_data->win_main);
1018
1019         if (ug_data->b_internal)
1020                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "noindicator");
1021         else
1022                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "default");
1023         evas_object_size_hint_weight_set(ug_data->layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1024         evas_object_show(ug_data->layout_main);
1025
1026         elm_object_part_content_set(ug_data->layout_main, "elm.swallow.bg", ug_data->bg);
1027
1028         /* indicator */
1029         elm_win_indicator_mode_set(ug_data->win_main, ELM_WIN_INDICATOR_SHOW);
1030
1031         evas_object_smart_callback_add(ug_data->win_main, "profile,changed", _win_profile_changed_cb, ug_data);
1032
1033         /* navigation Bar */
1034         _create_navigation_bar(ug_data);
1035
1036         /* push navigation bar */
1037         ug_data->sub_ly = elm_layout_add(ug_data->navi_bar);
1038         elm_layout_theme_set(ug_data->sub_ly, "layout", "application", "noindicator");
1039         evas_object_size_hint_weight_set(ug_data->sub_ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1040         evas_object_show(ug_data->sub_ly);
1041
1042         /* back button */
1043         b_btn = elm_button_add(ug_data->navi_bar);
1044         elm_object_style_set(b_btn, "naviframe/back_btn/default");
1045         evas_object_smart_callback_add(b_btn, "clicked", _back_cb, ug_data);
1046         ug_data->b_btn = b_btn;
1047
1048         ug_data->navi_main_it = elm_naviframe_item_push(ug_data->navi_bar, prop->sender_display_name, b_btn, NULL, ug_data->sub_ly, NULL);
1049
1050         if (ug_data->b_internal) {
1051                 /* Left : previous button */
1052                 prev_btn = elm_button_add(ug_data->navi_bar);
1053                 Evas_Object *prev_ic = elm_icon_add(prev_btn);
1054                 elm_icon_file_set(prev_ic, IMGDIR "/M02_icon_previous.png", NULL);
1055                 elm_object_style_set(prev_btn, "naviframe/title/default");
1056                 evas_object_size_hint_aspect_set(prev_ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1057                 elm_icon_resizable_set(prev_ic, 0.8, 0.8);
1058                 elm_object_part_content_set(prev_btn, "icon", prev_ic);
1059                 elm_object_item_part_content_set(ug_data->navi_main_it, "title_left_btn", prev_btn);
1060                 evas_object_smart_callback_add(prev_btn, "clicked", _prev_mail_cb, ug_data);
1061                 ug_data->prev_btn = prev_btn;
1062
1063                 /* Right : next button */
1064                 next_btn = elm_button_add(ug_data->navi_bar);
1065                 Evas_Object *next_ic = elm_icon_add(next_btn);
1066                 elm_icon_file_set(next_ic, IMGDIR "/M02_icon_next.png", NULL);
1067                 elm_object_style_set(next_btn, "naviframe/title/default");
1068                 evas_object_size_hint_aspect_set(next_ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1069                 elm_icon_resizable_set(next_ic, 0.8, 0.8);
1070                 elm_object_part_content_set(next_btn, "icon", next_ic);
1071                 elm_object_item_part_content_set(ug_data->navi_main_it, "title_right_btn", next_btn);
1072                 evas_object_smart_callback_add(next_btn, "clicked", _next_mail_cb, ug_data);
1073                 ug_data->next_btn = next_btn;
1074         }
1075
1076         /* create scroller */
1077         ug_data->scroller = elm_scroller_add(ug_data->navi_bar);
1078         evas_object_propagate_events_set(ug_data->scroller, EINA_FALSE);
1079         elm_scroller_bounce_set(ug_data->scroller, EINA_FALSE, EINA_TRUE);
1080         elm_scroller_policy_set(ug_data->scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
1081         evas_object_show(ug_data->scroller);
1082         evas_object_smart_callback_add(ug_data->scroller, "edge,bottom", _outter_scroller_bottom_hit_cb, ug_data);
1083         evas_object_smart_callback_add(ug_data->scroller, "edge,top", _outter_scroller_top_hit_cb, ug_data);
1084         evas_object_smart_callback_add(ug_data->scroller, "scroll,drag,start", _outter_scroller_scroll_cb, ug_data);
1085
1086         /* create conformant */
1087         elm_win_conformant_set(ug_data->win_main, EINA_TRUE);
1088         ug_data->conformant = elm_conformant_add(ug_data->sub_ly);
1089         elm_object_style_set(ug_data->conformant, "internal_layout");
1090         evas_object_size_hint_weight_set(ug_data->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1091         evas_object_size_hint_align_set(ug_data->conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
1092         elm_object_content_set(ug_data->conformant, ug_data->scroller);
1093         elm_object_part_content_set(ug_data->sub_ly, "elm.swallow.content", ug_data->conformant);
1094         evas_object_show(ug_data->conformant);
1095
1096         if (ug_data->from_list != NULL) {
1097                 email_address_info_t *addrs_info = NULL;
1098                 int n_from_list = g_list_length(ug_data->from_list);
1099                 debug_log("from list count [%d]", n_from_list);
1100
1101                 if (n_from_list > 0) {
1102                         addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->from_list, 0);
1103                         debug_log("From Address:%s", addrs_info->address);
1104                         debug_log("Display Name:%s", addrs_info->display_name);
1105                         debug_log("Storage Type:%d", addrs_info->storage_type);
1106                         debug_log("Contact ID:%d", addrs_info->contact_id);
1107                         debug_log("");
1108                         g_free(prop->sender_display_name);
1109                         prop->sender_display_name = g_strdup(addrs_info->display_name);
1110                         g_free(prop->sender);
1111                         prop->sender = g_strdup(addrs_info->address);
1112
1113                         if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1114                                 elm_object_item_text_set(ug_data->navi_main_it, addrs_info->display_name);
1115                         else
1116                                 elm_object_item_text_set(ug_data->navi_main_it, addrs_info->address);
1117                 }
1118         }
1119
1120         /* create main box */
1121         ug_data->main_bx = elm_box_add(ug_data->navi_bar);
1122         evas_object_size_hint_weight_set(ug_data->main_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1123         evas_object_size_hint_align_set(ug_data->main_bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
1124         evas_object_show(ug_data->main_bx);
1125         elm_object_content_set(ug_data->scroller, ug_data->main_bx);
1126
1127         if (ug_data->property->has_attachment)
1128                 ug_data->got_att = 1;
1129         else
1130                 ug_data->got_att = 0;
1131
1132         /* packing subject, addrs, attachment */
1133         _create_subject(ug_data);
1134
1135         if (ug_data->got_att) {
1136                 _create_attach(ug_data);
1137         }
1138
1139         if (ug_data->isRotate == true) {
1140                 debug_log("In Split view - Hiding navi bar");
1141                 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_FALSE);
1142
1143                 if (ug_data->b_btn) {
1144                         debug_log("hiding back button");
1145
1146                         evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1147                         evas_object_del(ug_data->b_btn);
1148                         ug_data->b_btn = NULL;
1149
1150                         elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
1151                 }
1152         }
1153 }
1154
1155 static void _reset_view(EmailViewerUGD *ug_data)
1156 {
1157         debug_log("");
1158         EmailViewerProp *prop = ug_data->property;
1159         int ret;
1160         char date_time[MAX_STR_LEN] = { 0, };
1161
1162         debug_log("@@@@@@@@@@ isRotate = %d", ug_data->isRotate);
1163         if (ug_data->isRotate == true) {
1164                 debug_log("In Split view - Hiding navi bar");
1165                 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_FALSE);
1166
1167                 if (ug_data->b_btn) {
1168                         debug_log("hiding back button");
1169
1170                         evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1171                         evas_object_del(ug_data->b_btn);
1172                         ug_data->b_btn = NULL;
1173
1174                         elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", NULL);
1175                 }
1176
1177                 /* Set scroller to start - height made 480 to consider viewer in split view */
1178                 elm_scroller_region_show(ug_data->scroller, 0, 0, (int)((double)ug_data->main_h * 0.6), ug_data->main_w);
1179         } else {
1180                 debug_log("In Full view - Showing navi bar");
1181                 elm_naviframe_item_title_visible_set(ug_data->navi_main_it, EINA_TRUE);
1182
1183                 if (ug_data->b_btn) {
1184
1185                         evas_object_smart_callback_del(ug_data->b_btn, "clicked", _back_cb);
1186                         evas_object_del(ug_data->b_btn);
1187                         ug_data->b_btn = NULL;
1188                 }
1189
1190                 debug_log("showing back button");
1191
1192                 ug_data->b_btn = elm_button_add(ug_data->navi_bar);
1193                 elm_object_style_set(ug_data->b_btn, "naviframe/back_btn/default");
1194                 evas_object_smart_callback_add(ug_data->b_btn, "clicked", _back_cb, ug_data);
1195
1196                 elm_object_item_part_content_set(ug_data->navi_main_it, "prev_btn", ug_data->b_btn);
1197
1198                 /* Set scroller to start */
1199                 elm_scroller_region_show(ug_data->scroller, 0, 0, ug_data->main_w, ug_data->main_h);
1200         }
1201
1202         if (ug_data->from_list != NULL) {
1203                 email_address_info_t *addrs_info = NULL;
1204                 int n_from_list = g_list_length(ug_data->from_list);
1205                 debug_log("from list count [%d]", n_from_list);
1206
1207                 if (n_from_list > 0) {
1208                         addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->from_list, 0);
1209                         if (addrs_info) {
1210                                 debug_log("From Address:%s", addrs_info->address);
1211                                 debug_log("Display Name:%s", addrs_info->display_name);
1212                                 debug_log("Storage Type:%d", addrs_info->storage_type);
1213                                 debug_log("Contact ID:%d", addrs_info->contact_id);
1214                                 g_free(prop->sender_display_name);
1215                                 prop->sender_display_name = g_strdup(addrs_info->display_name);
1216                                 g_free(prop->sender);
1217                                 prop->sender = g_strdup(addrs_info->address);
1218
1219                                 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1220                                         elm_object_item_text_set(ug_data->navi_main_it, addrs_info->display_name);
1221                                 else
1222                                         elm_object_item_text_set(ug_data->navi_main_it, addrs_info->address);
1223                         }
1224                 }
1225         } else {
1226                 elm_object_item_text_set(ug_data->navi_main_it, prop->sender_display_name);
1227         }
1228
1229         /* reset subject */
1230         char *_subject = elm_entry_utf8_to_markup(prop->subject);
1231         if (!g_strcmp0(_subject, "")) {
1232                 g_free(_subject);
1233                 _subject = g_strdup(_("IDS_EMAIL_BODY_NO_SUBJECT"));
1234         }
1235         char *_subject_concated = g_strconcat("<font_size=44><color=#000000FF>", _subject, "</color></font_size>", NULL);
1236         elm_object_text_set(ug_data->lb_subject, _subject_concated);
1237         elm_label_wrap_width_set(ug_data->lb_subject, ug_data->main_w - (int)(110 * ug_data->scale_factor));
1238         elm_label_line_wrap_set(ug_data->lb_subject, ELM_WRAP_WORD);
1239         g_free(_subject);
1240         g_free(_subject_concated);
1241
1242         /* reset date & time */
1243         char *formatted_date = NULL;
1244
1245         if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1246                 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
1247         else
1248                 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
1249         ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
1250
1251         free(formatted_date);
1252         formatted_date = NULL;
1253
1254         elm_object_part_text_set(ug_data->ly_subject, "elm.text.sub", date_time);
1255
1256         Evas_Object *favorite_icon = elm_icon_add(ug_data->ly_subject);
1257         switch(prop->favorite)
1258         {
1259                 case EMAIL_FLAG_NONE:
1260                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_off.png", NULL);
1261                         break;
1262                 case EMAIL_FLAG_FLAGED:
1263                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_on.png", NULL);
1264                         break;
1265                 case EMAIL_FLAG_TASK_STATUS_CLEAR:
1266                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
1267                         break;
1268                 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
1269                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
1270                         break;
1271                 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
1272                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
1273                         break;
1274         }
1275         evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1276         elm_icon_resizable_set(favorite_icon, 1, 1);
1277         evas_object_del(elm_object_part_content_unset(ug_data->ly_subject, "elm.icon.favorite"));
1278         elm_object_part_content_set(ug_data->ly_subject, "elm.icon.favorite", favorite_icon);
1279         evas_object_show(favorite_icon);
1280
1281         evas_object_show(ug_data->ly_subject);
1282         elm_box_pack_end(ug_data->main_bx, ug_data->ly_subject);
1283
1284         Evas_Object *edje = elm_layout_edje_get(ug_data->ly_subject);
1285
1286         if (!ug_data->to_list && !ug_data->cc_list && !ug_data->bcc_list) {
1287                 edje_object_signal_emit(edje, "elm,state,arrow_hidden", "elm");
1288         } else {
1289                 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _subject_detail_clicked_cb, ug_data->ly_subject);
1290         }
1291
1292         if (prop->has_attachment)
1293                 ug_data->got_att = 1;
1294         else
1295                 ug_data->got_att = 0;
1296
1297         /* pack attachment if it exist */
1298         if (ug_data->got_att) {
1299                 _create_attach(ug_data);
1300         }
1301
1302         /* check body downloaded */
1303         _check_body_download(ug_data);
1304 }
1305
1306 void _hide_view(EmailViewerUGD *ug_data)
1307 {
1308         debug_log("");
1309         EmailViewerProp *prop = ug_data->property;
1310         EmailViewerPrivate *priv = ug_data->email_data;
1311
1312         debug_log("Cancelling all attachment downloads");
1313         _cancel_download_attachment(ug_data);
1314
1315         ug_data->display_download_result = FALSE;
1316         _g_ug_data = NULL;
1317
1318         if (elm_naviframe_top_item_get(ug_data->navi_bar) != ug_data->navi_main_it) {
1319                 ug_data->navi_move_it1 = NULL;
1320                 elm_naviframe_item_pop_to(ug_data->navi_main_it);
1321         }
1322
1323         evas_object_hide(ug_data->layout_main);
1324         elm_box_unpack_all(ug_data->main_bx);
1325         elm_object_scroll_freeze_pop(ug_data->scroller);
1326
1327         evas_object_hide(ug_data->ly_subject);
1328         evas_object_hide(ug_data->lb_subject);
1329         evas_object_hide(ug_data->webview_bx);
1330         evas_object_hide(ug_data->webview);
1331
1332         if (ug_data->partial_dn_btn) {
1333                 evas_object_del(ug_data->partial_dn_btn);
1334                 ug_data->partial_dn_btn = NULL;
1335         }
1336
1337         if (ug_data->partial_dn_btn_bx) {
1338                 evas_object_del(ug_data->partial_dn_btn_bx);
1339                 ug_data->partial_dn_btn_bx = NULL;
1340         }
1341
1342         if (ug_data->ctr_bar) {
1343                 elm_object_item_part_content_unset(ug_data->navi_main_it, "controlbar");
1344                 evas_object_del(ug_data->ctr_bar);
1345                 ug_data->ctr_bar = NULL;
1346
1347                 ug_data->reply_ctr_it = NULL;
1348                 ug_data->replyall_ctr_it = NULL;
1349                 ug_data->forward_ctr_it = NULL;
1350                 ug_data->calendar_ctr_it = NULL;
1351                 ug_data->resend_ctr_it = NULL;
1352                 ug_data->move_ctr_it = NULL;
1353                 ug_data->del_ctr_it = NULL;
1354         }
1355
1356         if (ug_data->to_ly) {
1357                 evas_object_del(ug_data->to_ly);
1358                 ug_data->to_ly = NULL;
1359         }
1360
1361         if (ug_data->cc_ly) {
1362                 evas_object_del(ug_data->cc_ly);
1363                 ug_data->cc_ly = NULL;
1364         }
1365
1366         if (ug_data->bcc_ly) {
1367                 evas_object_del(ug_data->bcc_ly);
1368                 ug_data->bcc_ly = NULL;
1369         }
1370
1371         if (ug_data->got_att) {
1372                 int i;
1373
1374                 evas_object_del(ug_data->attach_hd_bk);
1375                 ug_data->attach_hd_ly = NULL;
1376                 ug_data->attach_hd_bk = NULL;
1377
1378                 if (prop->real_att_len > 1) {
1379                         for (i = 0; i < prop->real_att_len; i++) {
1380                                 if (ug_data->attach_ex_ly != NULL) {
1381                                         if (ug_data->attach_ex_ly[i] != NULL) {
1382                                                 debug_log("index %d", i);
1383                                                 evas_object_del(ug_data->attach_ex_bk[i]);
1384                                                 ug_data->attach_ex_ly[i] = NULL;
1385                                                 ug_data->attach_ex_bk[i] = NULL;
1386                                         }
1387                                 }
1388                         }
1389
1390                         if (ug_data->attach_ex_ly != NULL) {
1391                                 free(ug_data->attach_ex_ly);
1392                                 ug_data->attach_ex_ly = NULL;
1393                                 ug_data->attach_ex_bk = NULL;
1394                         }
1395                 }
1396
1397                 for (i = 0; i <= prop->att_len; i++) {
1398                         if (ug_data->progress_bar_ly[i] != NULL) {
1399                                 evas_object_del(ug_data->progress_bar_ly[i]);
1400                                 ug_data->progress_bar_ly[i] = NULL;
1401                                 ug_data->progress_bar[i] = NULL;
1402                         }
1403                 }
1404         }
1405
1406         if (ug_data->con_popup != NULL) {
1407                 evas_object_del(ug_data->con_popup);
1408                 ug_data->con_popup = NULL;
1409         }
1410
1411         if (ug_data->notify != NULL) {
1412                 evas_object_del(ug_data->notify);
1413                 ug_data->notify = NULL;
1414         }
1415
1416         edje_object_signal_emit(_EDJ(ug_data->ly_subject), "elm,state,contracted", "elm");
1417         edje_object_signal_callback_del(_EDJ(ug_data->ly_subject), "elm,action,expand,toggle", "elm", _subject_detail_clicked_cb);
1418
1419         evas_object_hide(ug_data->noc_bx);
1420         evas_object_hide(ug_data->dn_btn);
1421
1422         if (ecore_file_exists(EMAIL_TMP_FILE_PATH ".html"))
1423                 ecore_file_remove(EMAIL_TMP_FILE_PATH ".html");
1424
1425         if (ecore_file_exists(DIR_TMP_PREFIX"/mail.txt"))
1426                 ecore_file_remove(DIR_TMP_PREFIX"/mail.txt");
1427
1428         ewk_view_uri_set(ug_data->webview, EMAIL_DEFAULT_HTML);
1429
1430         debug_log("free address info list");
1431         email_free_address_info_list(&(priv->addrs_info_list));
1432         ug_data->from_list = NULL;
1433         ug_data->to_list = NULL;
1434         ug_data->cc_list = NULL;
1435         ug_data->bcc_list = NULL;
1436
1437         ug_data->got_att = 0;
1438         ug_data->subject_onoff_flag = 0;
1439         ug_data->attach_onoff_flag = 0;
1440         ug_data->b_partial_body = 0;
1441         ug_data->b_internal = 0;
1442         ug_data->scroller_locked = 0;
1443         ug_data->m_is_multi_touch = 0;
1444
1445         ug_data->navi_move_it1 = NULL;
1446
1447         /* Double_Scroller */
1448         ug_data->b_noc = 1;
1449         ug_data->b_load_finished = EINA_FALSE;
1450         ug_data->b_show_remote_images = EINA_FALSE;
1451         ug_data->is_webview_scrolling = EINA_FALSE;
1452         ug_data->is_main_scroller_scrolling = EINA_FALSE;
1453 }
1454
1455 static void _win_profile_changed_cb(void *data, Evas_Object *obj, void *event)
1456 {
1457         debug_log("");
1458         if (!data) {
1459                 debug_log("data is NULL");
1460                 return;
1461         }
1462
1463         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
1464
1465         const char *profile = elm_config_profile_get();
1466         if (!g_strcmp0(profile, "desktop"))
1467                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "noindicator");
1468         else
1469                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "default");
1470
1471         evas_object_size_hint_weight_set(ug_data->layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1472         elm_win_resize_object_add(ug_data->win_main, ug_data->layout_main);
1473         evas_object_show(ug_data->layout_main);
1474 }
1475
1476 static Evas_Object *_create_navigation_bar(EmailViewerUGD *ug_data)
1477 {
1478         debug_log("");
1479         Evas_Object *navi_bar;
1480
1481         navi_bar = elm_naviframe_add(ug_data->layout_main);
1482         if (navi_bar == NULL) {
1483                 debug_log("navi_bar == NULL");
1484                 return NULL;
1485         }
1486
1487         elm_object_part_content_set(ug_data->layout_main, "elm.swallow.content", navi_bar);
1488         evas_object_show(navi_bar);
1489
1490         ug_data->navi_bar = navi_bar;
1491         return navi_bar;
1492 }
1493
1494 static Evas_Object *_create_subject(EmailViewerUGD *ug_data)
1495 {
1496         debug_log("");
1497         EmailViewerProp *prop = ug_data->property;
1498         int ret;
1499         char date_time[MAX_STR_LEN] = { 0, };
1500
1501         /* append subject */
1502         Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1503         elm_layout_file_set(di, EV_THEME_PATH, "layout.email.detail_subject");
1504         evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1505
1506         Evas_Object *subject_label;
1507         subject_label = elm_label_add(di);
1508         elm_object_part_content_set(di, "elm.text", subject_label);
1509         char *subject = elm_entry_utf8_to_markup(prop->subject);
1510         if (!g_strcmp0(subject, "")) {
1511                 g_free(subject);
1512                 subject = g_strdup(_("IDS_EMAIL_BODY_NO_SUBJECT"));
1513         }
1514         char *subject_tagged = g_strconcat("<font_size=44><color=#000000FF>", subject, "</color></font_size>", NULL);
1515         elm_object_text_set(subject_label, subject_tagged);
1516         elm_label_wrap_width_set(subject_label, ug_data->main_w - (int)(110 * ug_data->scale_factor));
1517         elm_label_line_wrap_set(subject_label, ELM_WRAP_WORD);
1518         ug_data->lb_subject = subject_label;
1519         g_free(subject);
1520         g_free(subject_tagged);
1521
1522         char *formatted_date = NULL;
1523
1524         if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1525                 formatted_date = email_get_date_text(icu_locale, "yMdhms", &(prop->mktime));
1526         else
1527                 formatted_date = email_get_date_text(icu_locale, "yMdHms", &(prop->mktime));
1528         ret = snprintf(date_time, MAX_STR_LEN, "%s", formatted_date);
1529         free(formatted_date);
1530         formatted_date = NULL;
1531
1532         elm_object_part_text_set(di, "elm.text.sub", date_time);
1533
1534         Evas_Object *favorite_icon = elm_icon_add(di);
1535         switch(prop->favorite)
1536         {
1537                 case EMAIL_FLAG_NONE:
1538                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_off.png", NULL);
1539                         break;
1540                 case EMAIL_FLAG_FLAGED:
1541                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_on.png", NULL);
1542                         break;
1543                 case EMAIL_FLAG_TASK_STATUS_CLEAR:
1544                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
1545                         break;
1546                 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
1547                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
1548                         break;
1549                 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
1550                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
1551                         break;
1552         }
1553         evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1554         elm_icon_resizable_set(favorite_icon, 1, 1);
1555         elm_object_part_content_set(di, "elm.icon.favorite", favorite_icon);
1556         evas_object_show(favorite_icon);
1557
1558         evas_object_show(di);
1559         elm_box_pack_end(ug_data->main_bx, di);
1560         ug_data->ly_subject = di;
1561
1562         Evas_Object *edje = elm_layout_edje_get(di);
1563
1564         if (ug_data->to_list || ug_data->cc_list || ug_data->bcc_list) {
1565                 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _subject_detail_clicked_cb, di);
1566         } else {
1567                 edje_object_signal_emit(edje, "elm,state,arrow_hidden", "elm");
1568         }
1569         edje_object_signal_callback_add(edje, "elm,action,toggle", "elm", _subject_favorite_clicked_cb, di);
1570
1571         return di;
1572 }
1573
1574 static Evas_Object *_create_to_addrs(EmailViewerUGD *ug_data)
1575 {
1576         debug_log("");
1577         email_address_info_t *addrs_info = NULL;
1578         Elm_Object_Item *mbe_item;
1579
1580         if (ug_data->to_list == NULL) {
1581                 debug_log("to_list is NULL");
1582                 return NULL;
1583         }
1584
1585         int n_to_list = g_list_length(ug_data->to_list);
1586         int i = 0;
1587
1588         if (n_to_list <= 0) {
1589                 debug_log("to_list count is 0");
1590                 return NULL;
1591         }
1592
1593         Evas_Object *di = elm_layout_add(ug_data->main_bx);
1594         elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1595         evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1596         evas_object_show(di);
1597         ug_data->to_ly = di;
1598         elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1599
1600         Evas_Object *to_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1601         char desc[MAX_STR_LEN] = { 0, };
1602         snprintf(desc, MAX_STR_LEN, "%s:", dgettext("sys_string", "IDS_COM_BODY_TO"));
1603         char *to_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1604         elm_object_text_set(to_mbe, to_str);
1605         g_free(to_str);
1606
1607         evas_object_smart_callback_add(to_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1608         evas_object_smart_callback_add(to_mbe, "item,added", _mbe_added_cb, ug_data);
1609         evas_object_smart_callback_add(to_mbe, "focused", _mbe_focused_cb, ug_data);
1610         evas_object_smart_callback_add(to_mbe, "unfocused", _mbe_unfocused_cb, ug_data);
1611         elm_object_part_content_set(di, "elm.icon", to_mbe);
1612         ug_data->to_mbe = to_mbe;
1613
1614         Evas_Object *entry = elm_multibuttonentry_entry_get(to_mbe);
1615         if (entry)
1616                 elm_entry_editable_set(entry, EINA_FALSE);
1617
1618         if (n_to_list > EMAIL_VIEW_MAX_TO_COUNT)
1619                 n_to_list = EMAIL_VIEW_MAX_TO_COUNT;
1620
1621         for (i = 0; i < n_to_list; i++) {
1622                 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->to_list, i);
1623                 debug_log("Address:%s", addrs_info->address);
1624                 debug_log("Display Name:%s", addrs_info->display_name);
1625                 debug_log("Storage Type:%d", addrs_info->storage_type);
1626                 debug_log("Contact ID:%d", addrs_info->contact_id);
1627                 debug_log("");
1628                 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1629                         mbe_item = elm_multibuttonentry_item_append(to_mbe, addrs_info->display_name, NULL, NULL);
1630                 else
1631                         mbe_item = elm_multibuttonentry_item_append(to_mbe, addrs_info->address, NULL, NULL);
1632                 elm_object_item_data_set(mbe_item, addrs_info);
1633         }
1634
1635         return di;
1636 }
1637
1638 static Evas_Object *_create_cc_addrs(EmailViewerUGD *ug_data)
1639 {
1640         debug_log("");
1641         email_address_info_t *addrs_info = NULL;
1642         Elm_Object_Item *mbe_item;
1643
1644         if (ug_data->cc_list == NULL) {
1645                 debug_log("cc_list is NULL");
1646                 return NULL;
1647         }
1648
1649         int n_cc_list = g_list_length(ug_data->cc_list);
1650         int i = 0;
1651
1652         if (n_cc_list <= 0) {
1653                 debug_log("cc_list count is 0");
1654                 return NULL;
1655         }
1656
1657         Evas_Object *di = elm_layout_add(ug_data->main_bx);
1658         elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1659         evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1660         evas_object_show(di);
1661         ug_data->cc_ly = di;
1662
1663         if (ug_data->to_ly) {
1664                 elm_box_pack_after(ug_data->main_bx, di, ug_data->to_ly);
1665         } else {
1666                 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1667         }
1668
1669         Evas_Object *cc_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1670         char desc[MAX_STR_LEN] = { 0, };
1671         snprintf(desc, MAX_STR_LEN, "%s:", _("IDS_EMAIL_BODY_CC"));
1672         char *cc_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1673         elm_object_text_set(cc_mbe, cc_str);
1674         g_free(cc_str);
1675         evas_object_smart_callback_add(cc_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1676         evas_object_smart_callback_add(cc_mbe, "item,added", _mbe_added_cb, ug_data);
1677         evas_object_smart_callback_add(cc_mbe, "focused", _mbe_focused_cb, ug_data);
1678         evas_object_smart_callback_add(cc_mbe, "unfocused", _mbe_unfocused_cb, ug_data);
1679         elm_object_part_content_set(di, "elm.icon", cc_mbe);
1680         ug_data->cc_mbe = cc_mbe;
1681
1682         Evas_Object *entry = elm_multibuttonentry_entry_get(cc_mbe);
1683         if (entry)
1684                 elm_entry_editable_set(entry, EINA_FALSE);
1685
1686         if (n_cc_list > EMAIL_VIEW_MAX_CC_COUNT)
1687                 n_cc_list = EMAIL_VIEW_MAX_CC_COUNT;
1688
1689         for (i = 0; i < n_cc_list; i++) {
1690                 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->cc_list, i);
1691
1692                 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1693                         mbe_item = elm_multibuttonentry_item_append(cc_mbe, addrs_info->display_name, NULL, NULL);
1694                 else
1695                         mbe_item = elm_multibuttonentry_item_append(cc_mbe, addrs_info->address, NULL, NULL);
1696                 elm_object_item_data_set(mbe_item, addrs_info);
1697         }
1698
1699         return di;
1700 }
1701
1702 static Evas_Object *_create_bcc_addrs(EmailViewerUGD *ug_data)
1703 {
1704         debug_log("");
1705         email_address_info_t *addrs_info = NULL;
1706         Elm_Object_Item *mbe_item;
1707
1708         if (ug_data->bcc_list == NULL) {
1709                 debug_log("bcc_list is NULL");
1710                 return NULL;
1711         }
1712
1713         int n_bcc_list = g_list_length(ug_data->bcc_list);
1714         int i = 0;
1715
1716         if (n_bcc_list <= 0) {
1717                 debug_log("bcc_list count is 0");
1718                 return NULL;
1719         }
1720
1721         Evas_Object *di = elm_layout_add(ug_data->main_bx);
1722         elm_layout_file_set(di, EV_THEME_PATH, "layout.email.to_cc");
1723         evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1724         evas_object_show(di);
1725         ug_data->bcc_ly = di;
1726
1727         if (ug_data->cc_ly) {
1728                 elm_box_pack_after(ug_data->main_bx, di, ug_data->cc_ly);
1729         }
1730         if (ug_data->to_ly && ug_data->cc_ly == NULL) {
1731                 elm_box_pack_after(ug_data->main_bx, di, ug_data->to_ly);
1732         }
1733         if (ug_data->to_ly == NULL && ug_data->cc_ly == NULL) {
1734                 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1735         }
1736
1737         Evas_Object *bcc_mbe = elm_multibuttonentry_add(ug_data->main_bx);
1738         char desc[MAX_STR_LEN] = { 0, };
1739         snprintf(desc, MAX_STR_LEN, "%s:", _("IDS_EMAIL_BODY_BCC"));
1740         char *bcc_str = g_strconcat("<font_size=36><color=#000000FF>", desc, "</color></font_size>", NULL);
1741         elm_object_text_set(bcc_mbe, bcc_str);
1742         g_free(bcc_str);
1743         evas_object_smart_callback_add(bcc_mbe, "item,clicked", _mbe_selected_cb, ug_data);
1744         evas_object_smart_callback_add(bcc_mbe, "item,added", _mbe_added_cb, ug_data);
1745         evas_object_smart_callback_add(bcc_mbe, "focused", _mbe_focused_cb, ug_data);
1746         evas_object_smart_callback_add(bcc_mbe, "unfocused", _mbe_unfocused_cb, ug_data);
1747         elm_object_part_content_set(di, "elm.icon", bcc_mbe);
1748         ug_data->bcc_mbe = bcc_mbe;
1749
1750         Evas_Object *entry = elm_multibuttonentry_entry_get(bcc_mbe);
1751         if (entry)
1752                 elm_entry_editable_set(entry, EINA_FALSE);
1753
1754         if (n_bcc_list > EMAIL_VIEW_MAX_BCC_COUNT)
1755                 n_bcc_list = EMAIL_VIEW_MAX_BCC_COUNT;
1756
1757         for (i = 0; i < n_bcc_list; i++) {
1758                 addrs_info = (email_address_info_t *) g_list_nth_data(ug_data->bcc_list, i);
1759
1760                 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
1761                         mbe_item = elm_multibuttonentry_item_append(bcc_mbe, addrs_info->display_name, NULL, NULL);
1762                 else
1763                         mbe_item = elm_multibuttonentry_item_append(bcc_mbe, addrs_info->address, NULL, NULL);
1764                 elm_object_item_data_set(mbe_item, addrs_info);
1765         }
1766
1767         return di;
1768 }
1769
1770 static Evas_Object *_create_attach(EmailViewerUGD *ug_data)
1771 {
1772         debug_log("");
1773
1774         EmailViewerProp *prop = ug_data->property;
1775         char buff[MAX_STR_LEN];
1776         int i = 0;
1777         int att_len = prop->real_att_len;
1778         int att_index = 0;
1779
1780         RETURN_VAL_IF_FAIL(prop->attachments != NULL, NULL);
1781         RETURN_VAL_IF_FAIL(att_len > 0, NULL);
1782
1783         GList *attachment_list = prop->attachments;
1784
1785         if (att_len == 1) {
1786                 LIST_ITER_START(i, attachment_list) {
1787                         EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
1788
1789                         if (info && !info->inline_content) {
1790                                 if (info->size < 1024) {
1791                                         g_sprintf(buff, "%s (%d %s)", info->name, (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
1792                                 } else {
1793                                         gdouble tmpsize = (gdouble) (info->size / 1024.);
1794                                         if (tmpsize < 1024) {
1795                                                 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1796                                         } else {
1797                                                 tmpsize /= 1024.;
1798                                                 if (tmpsize < 1024) {
1799                                                         g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1800                                                 } else {
1801                                                         tmpsize /= 1024.;
1802                                                         g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1803                                                 }
1804                                         }
1805                                 }
1806
1807                                 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1808                                 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_item");
1809                                 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1810                                 evas_object_show(di);
1811                                 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1812
1813                                 Evas_Object *thumbnail = NULL;
1814
1815                                 if (info->download_yn) {
1816                                         thumbnail = viewer_make_thumbnail(info->path, di);
1817                                 } else
1818                                         thumbnail = viewer_make_thumbnail(NULL, di);
1819                                 evas_object_size_hint_aspect_set(thumbnail, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1820                                 elm_icon_resizable_set(thumbnail, 1, 1);
1821                                 elm_object_part_content_set(di, "elm.icon", thumbnail);
1822                                 evas_object_show(thumbnail);
1823
1824                                 elm_object_part_text_set(di, "elm.text", buff);
1825
1826                                 att_index = i;
1827
1828                                 Evas_Object *edje = elm_layout_edje_get(di);
1829                                 edje_object_signal_callback_add(edje, "elm,action,download", "elm", _attachment_save_cb, (void *)att_index);
1830                                 edje_object_signal_callback_add(edje, "clicked", "*", _attachment_clicked_cb, (void *)att_index);
1831
1832                                 Evas_Object *text_bg = NULL;
1833                                 text_bg = (Evas_Object *)edje_object_part_object_get(_EDJ(di), "elm.event.rect");
1834
1835                                 if (text_bg) {
1836                                         evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_DOWN, _attachment_bg_set_cb, (void *)att_index);
1837                                         evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_UP, _attachment_bg_unset_cb, (void *)att_index);
1838                                 }
1839
1840                                 ug_data->attach_hd_ly = di;
1841                                 ug_data->attach_hd_bk = di;
1842                         }
1843                 }
1844         } else if (att_len > 1) {
1845                 gint64 total_size = prop->total_att_size;
1846
1847                 Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1848                 elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_head");
1849                 evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1850                 snprintf(buff, sizeof(buff), "%d %s", att_len, _("IDS_EMAIL_BODY_ATTACHMENTS"));
1851
1852                 Evas_Object *att_head_label;
1853                 att_head_label = elm_label_add(di);
1854                 elm_object_part_content_set(di, "elm.text", att_head_label);
1855
1856                 char *buff_tagged = g_strconcat("<font_size=35><color=#000000FF>", buff, "<color></font_size>", NULL);
1857                 elm_object_text_set(att_head_label, buff_tagged);
1858                 g_free(buff_tagged);
1859
1860                 if (total_size < 1024) {
1861                         g_sprintf(buff, "(%d %s)", (gint) total_size, dgettext("sys_string", "IDS_COM_BODY_B"));
1862                 } else {
1863                         gdouble tmpsize = (gdouble) (total_size / 1024.);
1864
1865                         if (tmpsize < 1024) {
1866                                 g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1867                         } else {
1868                                 tmpsize /= 1024.;
1869
1870                                 if (tmpsize < 1024) {
1871                                         g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1872                                 } else {
1873                                         tmpsize /= 1024.;
1874                                         g_sprintf(buff, "(%.2f %s)", tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1875                                 }
1876                         }
1877                 }
1878
1879                 edje_object_part_text_set(_EDJ(di), "elm.text.sub", buff);
1880
1881                 Evas_Object *edje = elm_layout_edje_get(di);
1882                 edje_object_signal_callback_add(edje, "att,icon,save,all", "", _attachment_save_all_cb, di);
1883                 edje_object_signal_callback_add(edje, "elm,action,expand,toggle", "elm", _attachment_item_collapse_cb, di);
1884                 evas_object_show(di);
1885                 elm_box_pack_after(ug_data->main_bx, di, ug_data->ly_subject);
1886                 ug_data->attach_hd_ly = di;
1887                 ug_data->attach_hd_bk = di;
1888         } else {
1889                 debug_log("Attachment doesn't exist");
1890         }
1891
1892         return NULL;
1893 }
1894
1895 static Evas_Object *_create_attach_ex(EmailViewerUGD *ug_data)
1896 {
1897         debug_log("");
1898
1899         EmailViewerProp *prop = ug_data->property;
1900         char buff[MAX_STR_LEN];
1901         int i = 0;
1902         int j = 0;
1903         int att_len = prop->real_att_len;
1904         int att_index = 0;
1905
1906         RETURN_VAL_IF_FAIL(prop->attachments != NULL, NULL);
1907         RETURN_VAL_IF_FAIL(att_len > 0, NULL);
1908
1909         GList *attachment_list = prop->attachments;
1910
1911         ug_data->attach_ex_ly = (Evas_Object **)calloc(att_len, sizeof(Evas_Object *));
1912         ug_data->attach_ex_bk = (Evas_Object **)calloc(att_len, sizeof(Evas_Object *));
1913
1914         LIST_ITER_START(i, attachment_list) {
1915                 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
1916
1917                 if (info && !info->inline_content) {
1918                         if (info->size < 1024) {
1919                                 g_sprintf(buff, "%s (%d %s)", info->name, (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
1920                         } else {
1921                                 gdouble tmpsize = (gdouble) (info->size / 1024.);
1922                                 if (tmpsize < 1024) {
1923                                         g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
1924                                 } else {
1925                                         tmpsize /= 1024.;
1926                                         if (tmpsize < 1024) {
1927                                                 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
1928                                         } else {
1929                                                 tmpsize /= 1024.;
1930                                                 g_sprintf(buff, "%s (%.2f %s)", info->name, tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
1931                                         }
1932                                 }
1933                         }
1934
1935                         Evas_Object *di = elm_layout_add(ug_data->navi_bar);
1936                         elm_layout_file_set(di, EV_THEME_PATH, "layout.email.attachment_item");
1937                         evas_object_size_hint_align_set(di, EVAS_HINT_FILL, 0.0);
1938                         elm_box_pack_after(ug_data->main_bx, di, ug_data->attach_hd_ly);
1939                         evas_object_show(di);
1940
1941                         Evas_Object *thumbnail = NULL;
1942
1943                         if (info->download_yn) {
1944                                 thumbnail = viewer_make_thumbnail(info->path, di);
1945                         } else
1946                                 thumbnail = viewer_make_thumbnail(NULL, di);
1947                         evas_object_size_hint_aspect_set(thumbnail, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
1948                         elm_icon_resizable_set(thumbnail, 1, 1);
1949                         elm_object_part_content_set(di, "elm.icon", thumbnail);
1950                         evas_object_show(thumbnail);
1951
1952                         elm_object_part_text_set(di, "elm.text", buff);
1953
1954                         att_index = i;
1955
1956                         Evas_Object *edje = elm_layout_edje_get(di);
1957                         edje_object_signal_callback_add(edje, "elm,action,download", "elm", _attachment_save_cb, (void *)att_index);
1958                         edje_object_signal_callback_add(edje, "clicked", "*", _attachment_clicked_cb, (void *)att_index);
1959
1960                         Evas_Object *text_bg = NULL;
1961                         text_bg = (Evas_Object *)edje_object_part_object_get(_EDJ(di), "elm.event.rect");
1962
1963                         if (text_bg) {
1964                                 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_DOWN, _attachment_bg_set_cb, (void *)att_index);
1965                                 evas_object_event_callback_add(text_bg, EVAS_CALLBACK_MOUSE_UP, _attachment_bg_unset_cb, (void *)att_index);
1966                         }
1967
1968                         debug_log("attach ly %d, att_index %d", j, i);
1969
1970                         ug_data->attach_ex_ly[j] = di;
1971                         ug_data->attach_ex_bk[j] = di;
1972
1973                         j++;
1974                 }
1975         }
1976
1977         return NULL;
1978 }
1979
1980 static Evas_Object *_create_body(EmailViewerUGD *ug_data)
1981 {
1982         debug_log("");
1983         EmailViewerProp *prop = ug_data->property;
1984         EmailViewerPrivate *priv = ug_data->email_data;
1985
1986         ug_data->b_noc = 0;
1987
1988         if (ug_data->noc_bx) {
1989                 elm_box_unpack(ug_data->main_bx, ug_data->noc_bx);
1990                 evas_object_hide(ug_data->noc_bx);
1991         }
1992
1993         if (ug_data->dn_btn) {
1994                 evas_object_hide(ug_data->dn_btn);
1995         }
1996
1997         if (ug_data->webview_bx) {
1998                 _init_webview_data(ug_data);
1999
2000                 ewk_view_scale_set(ug_data->webview, 1.0f, 0, 0);
2001
2002                 if (prop->has_html) {
2003                 /* html mail */
2004                         ug_data->webview_data->body_type_prev = BODY_TYPE_HTML;
2005                         ug_data->webview_data->body_type = BODY_TYPE_HTML;
2006                         ug_data->webview_data->uri = prop->body_uri;
2007                 } else {
2008                 /* text mail */
2009                         ug_data->webview_data->body_type_prev = BODY_TYPE_TEXT;
2010                         ug_data->webview_data->body_type = BODY_TYPE_TEXT;
2011                         ug_data->webview_data->text_content = prop->body;
2012                 }
2013
2014                 viewer_set_webview_content(ug_data, 0);
2015
2016                 evas_object_show(ug_data->webview_bx);
2017                 evas_object_show(ug_data->webview);
2018                 elm_box_pack_end(ug_data->main_bx, ug_data->webview_bx);
2019
2020                 _update_tab_bar(ug_data);
2021         } else {
2022                 /* create webview layout */
2023                 ug_data->webview_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.web_view");
2024                 if (ug_data->webview_bx == NULL) {
2025                         debug_log("Cannot load edj");
2026                         return NULL;
2027                 }
2028
2029                 evas_object_size_hint_align_set(ug_data->webview_bx, EVAS_HINT_FILL, 0.0);
2030                 evas_object_show(ug_data->webview_bx);
2031                 elm_box_pack_end(ug_data->main_bx, ug_data->webview_bx);
2032
2033                 /* create webview */
2034                 if (NULL == ug_data->webview) {
2035                         _init_webview_data(ug_data);
2036                         viewer_get_webview(ug_data, prop->has_html);
2037
2038                         if (prop->has_html) {
2039                                 ug_data->webview_data->body_type_prev = BODY_TYPE_HTML;
2040                                 ug_data->webview_data->body_type = BODY_TYPE_HTML;
2041                                 ug_data->webview_data->uri = prop->body_uri;
2042                         } else {
2043                                 ug_data->webview_data->body_type_prev = BODY_TYPE_TEXT;
2044                                 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
2045                                 ug_data->webview_data->text_content = prop->body;
2046                         }
2047                         viewer_set_webview_content(ug_data, 0);
2048                 }
2049
2050                 evas_object_show(ug_data->webview);
2051                 elm_object_part_content_set(ug_data->webview_bx, "web_body", ug_data->webview);
2052
2053                 int resized_w = 0;
2054                 int resized_h = 0;
2055                 if (ug_data->isRotate) {
2056                         resized_w = ug_data->webview_width_landscape * ug_data->scale_factor;
2057                         resized_h = ug_data->webview_height_landscape * ug_data->scale_factor;
2058                 } else {
2059                         resized_w = ug_data->webview_width * ug_data->scale_factor;
2060                         resized_h = ug_data->webview_height * ug_data->scale_factor;
2061                 }
2062                 debug_log("resized_w:%d, resized_h:%d", resized_w, resized_h);
2063
2064                 evas_object_size_hint_min_set(ug_data->webview, resized_w, resized_h);
2065
2066                 /* set touch callbacks */
2067                 evas_object_smart_callback_add(ug_data->webview, "policy,navigation,decide", _webview_policy_navigation_decide_cb, ug_data);
2068                 evas_object_event_callback_add(ug_data->webview, EVAS_CALLBACK_MULTI_DOWN, _webview_multi_down_cb, ug_data);
2069                 evas_object_event_callback_add(ug_data->webview, EVAS_CALLBACK_MULTI_UP, _webview_multi_up_cb, ug_data);
2070
2071                 /* update control Bar */
2072                 _update_tab_bar(ug_data);
2073         }
2074
2075         viewer_set_mail_seen(prop, priv->mail_info);
2076
2077         if (ug_data->timer) {
2078                 ecore_timer_del(ug_data->timer);
2079                 ug_data->timer = NULL;
2080         }
2081
2082         debug_log("send message - list unlock");
2083         ug_data->timer = ecore_timer_add(0.0, viewer_send_message, ug_data);
2084
2085         return ug_data->webview_bx;
2086 }
2087
2088 static Evas_Object *_create_tab_bar(EmailViewerUGD *ug_data)
2089 {
2090         debug_log("");
2091
2092         EmailViewerProp *prop = ug_data->property;
2093         Evas_Object *obj;
2094         obj = elm_toolbar_add(ug_data->navi_bar);
2095         elm_toolbar_shrink_mode_set(obj, ELM_TOOLBAR_SHRINK_EXPAND);
2096         elm_object_style_set(obj, "naviframe");
2097
2098         if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SENTBOX ||
2099                 ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX) {
2100                 int n_to_list = g_list_length(ug_data->to_list);
2101                 int n_cc_list = g_list_length(ug_data->cc_list);
2102                 debug_log("to:%d, cc:%d", n_to_list, n_cc_list);
2103                 if (n_to_list + n_cc_list >= 2)
2104                         ug_data->reply_ctr_it = elm_toolbar_item_append(obj, ICON_REPLY, dgettext("sys_string", "IDS_COM_SK_REPLY"), _reply_option_cb, ug_data);
2105                 else
2106                         ug_data->reply_ctr_it = elm_toolbar_item_append(obj, ICON_REPLY, dgettext("sys_string", "IDS_COM_SK_REPLY"), _reply_cb, ug_data);
2107                 ug_data->forward_ctr_it = elm_toolbar_item_append(obj, ICON_FORWARD, dgettext("sys_string", "IDS_COM_BODY_FORWARD"), _forward_cb, ug_data);
2108                 ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2109                 ug_data->more_ctr_it = elm_toolbar_item_append(obj, ICON_CONTROLBAR_MORE, dgettext("sys_string", "IDS_COM_SK_MORE"), _more_cb, ug_data);
2110
2111                 elm_object_item_disabled_set(ug_data->reply_ctr_it, EINA_TRUE);
2112                 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_TRUE);
2113         } else if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_OUTBOX) {
2114                 debug_log("save_status: %d", prop->status2);
2115                 if (prop->status2 == EMAIL_MAIL_STATUS_SEND_FAILURE) {
2116                         ug_data->resend_ctr_it = elm_toolbar_item_append(obj, ICON_RESEND, _("IDS_EMAIL_SK_RESEND"), _resend_cb, ug_data);
2117                         ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2118                 } else {
2119                         ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2120                 }
2121         } else {
2122                 ug_data->del_ctr_it = elm_toolbar_item_append(obj, ICON_DELETE, dgettext("sys_string", "IDS_COM_SK_DELETE"), _delete_cb, ug_data);
2123                 ug_data->move_ctr_it = elm_toolbar_item_append(obj, ICON_MOVE, _("IDS_EMAIL_SK_MOVE"), _move_cb, ug_data);
2124         }
2125
2126         elm_object_item_part_content_set(ug_data->navi_main_it, "controlbar", obj);
2127         ug_data->ctr_bar = obj;
2128
2129         return NULL;
2130 }
2131
2132 static Evas_Object *_update_tab_bar(EmailViewerUGD *ug_data)
2133 {
2134         debug_log("");
2135
2136         if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SENTBOX ||
2137                   ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH || ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX) {
2138                 elm_object_item_disabled_set(ug_data->reply_ctr_it, EINA_FALSE);
2139                 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_FALSE);
2140         }
2141
2142         return NULL;
2143 }
2144
2145 static Evas_Object *_create_partial_body_dn_btn(EmailViewerUGD *ug_data)
2146 {
2147         debug_log("");
2148
2149         ug_data->partial_dn_btn_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.partial_download_btn");
2150         if (ug_data->partial_dn_btn_bx == NULL) {
2151                 debug_log("Cannot load edj");
2152                 return NULL;
2153         }
2154
2155         evas_object_size_hint_align_set(ug_data->partial_dn_btn_bx, EVAS_HINT_FILL, 0.0);
2156         evas_object_show(ug_data->partial_dn_btn_bx);
2157         elm_box_pack_before(ug_data->main_bx, ug_data->partial_dn_btn_bx, ug_data->webview_bx);
2158
2159         Evas_Object *dn_btn = elm_button_add(ug_data->navi_bar);
2160         elm_object_text_set(dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_FULL_MESSAGE"));
2161         evas_object_smart_callback_add(dn_btn, "clicked", _body_down_cb, (void *)ug_data);
2162         /*elm_object_theme_set(dn_btn, ug_data->theme);*/
2163         elm_object_style_set(dn_btn, "text_only/style2");
2164         evas_object_show(dn_btn);
2165         ug_data->partial_dn_btn = dn_btn;
2166
2167         elm_object_part_content_set(ug_data->partial_dn_btn_bx, "button", ug_data->partial_dn_btn);
2168
2169         return ug_data->partial_dn_btn_bx;
2170 }
2171
2172 static Evas_Object *_create_bg(Evas_Object *win)
2173 {
2174         debug_log("");
2175
2176         Evas_Object *bg = elm_bg_add(win);
2177         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2178         elm_win_resize_object_add(win, bg);
2179         evas_object_show(bg);
2180
2181         return bg;
2182 }
2183
2184 static void _create_down_progress(char *message, popup_cb resp_cb)
2185 {
2186         debug_log("");
2187
2188         if (!_g_ug_data) {
2189                 debug_log("data is NULL");
2190                 return;
2191         }
2192
2193         EmailViewerUGD *ug_data = _g_ug_data;
2194         Evas_Object *notify, *pb;
2195
2196         notify = elm_popup_add(ug_data->win_main);
2197         if (!notify) {
2198                 debug_log("elm_popup_add returns NULL");
2199                 return;
2200         }
2201         evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2202         ug_data->pb_notify = notify;
2203
2204         elm_object_part_text_set(notify, "title,text", message);
2205
2206         pb = elm_progressbar_add(notify);
2207
2208         elm_object_style_set(pb, "list_progress");
2209
2210         elm_progressbar_horizontal_set(pb, EINA_TRUE);
2211         evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, EVAS_HINT_FILL);
2212         evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2213         evas_object_show(pb);
2214         elm_progressbar_value_set(pb, 0.0);
2215         elm_object_content_set(notify, pb);
2216         ug_data->pb_notify_lb = pb;
2217
2218         Evas_Object *btn1 = elm_button_add(notify);
2219         elm_object_style_set(btn1, "popup_button/default");
2220         elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
2221         elm_object_part_content_set(notify, "button1", btn1);
2222         evas_object_smart_callback_add(btn1, "clicked", resp_cb, ug_data);
2223         debug_log("Cancel btn1 for downloading body: %p", btn1);
2224
2225         evas_object_show(notify);
2226 }
2227
2228 static void _create_down_progress_ex(int index, EMAIL_VIEWER_PROGRESSBAR_TYPE p_type)
2229 {
2230         debug_log("");
2231
2232         if (!_g_ug_data) {
2233                 debug_log("data is NULL");
2234                 return;
2235         }
2236
2237         EmailViewerUGD *ug_data = _g_ug_data;
2238         EmailViewerProp *prop = ug_data->property;
2239         EmailViewerPrivate *priv = ug_data->email_data;
2240
2241         if (!prop || !prop->attachments) {
2242                 debug_log("");
2243                 return;
2244         }
2245
2246         if (!priv) {
2247                 debug_log("");
2248                 return;
2249         }
2250
2251         if (ug_data->forward_ctr_it)
2252                 elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_TRUE);
2253
2254         int scr_x = 0;
2255         int scr_y = 0;
2256         int scr_w = 0;
2257         int scr_h = 0;
2258         elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
2259         debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
2260
2261         GList *attachment_list = prop->attachments;
2262         int i = 0, j = 0;
2263         debug_log("index %d of attachment_count %d", index, prop->att_len);
2264
2265         EmailAttachmentType *info = NULL;
2266         info = g_list_nth_data(attachment_list, index);
2267         if (info == NULL) {
2268                 debug_log("info is NULL");
2269         }
2270
2271         Evas_Object *pbar_ly = elm_layout_add(ug_data->navi_bar);
2272         elm_layout_file_set(pbar_ly, EV_THEME_PATH, "layout.email.attachment_downloading");
2273         evas_object_size_hint_align_set(pbar_ly, EVAS_HINT_FILL, 0.0);
2274         evas_object_show(pbar_ly);
2275         ug_data->progress_bar_ly[index + 1] = pbar_ly;
2276
2277         if (info) {
2278                 char buff[MAX_STR_LEN] = { 0, };
2279
2280                 Evas_Object *downloading_label1;
2281                 downloading_label1 = elm_label_add(pbar_ly);
2282                 elm_object_part_content_set(pbar_ly, "elm.text.1", downloading_label1);
2283                 char *text_tagged = g_strconcat("<font_size=32><align=left><color=#000000FF>", info->name, "</color></align></font_size>", NULL);
2284                 elm_object_text_set(downloading_label1, text_tagged);
2285                 elm_label_ellipsis_set(downloading_label1, EINA_TRUE);
2286                 elm_label_wrap_width_set(downloading_label1, ug_data->main_w - 240);
2287                 g_free(text_tagged);
2288
2289                 if (info->size < 1024) {
2290                         g_sprintf(buff, "%d %s", (gint) info->size, dgettext("sys_string", "IDS_COM_BODY_B"));
2291                 } else {
2292                         gdouble tmpsize = (gdouble) (info->size / 1024.);
2293
2294                         if (tmpsize < 1024) {
2295                                 g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB"));
2296                         } else {
2297                                 tmpsize /= 1024.;
2298
2299                                 if (tmpsize < 1024) {
2300                                         g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB"));
2301                                 } else {
2302                                         tmpsize /= 1024.;
2303                                         g_sprintf(buff, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB"));
2304                                 }
2305                         }
2306                 }
2307
2308                 Evas_Object *downloading_label3;
2309                 downloading_label3 = elm_label_add(pbar_ly);
2310                 elm_object_part_content_set(pbar_ly, "elm.text.3", downloading_label3);
2311                 text_tagged = g_strconcat("<font_size=26><align=right><color=#646464FF>", buff, "</color></align></font_size>", NULL);
2312                 elm_object_text_set(downloading_label3, text_tagged);
2313                 g_free(text_tagged);
2314         }
2315
2316         Evas_Object *progressbar = elm_progressbar_add(pbar_ly);
2317         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
2318         elm_object_style_set(progressbar, "list_progress");
2319         elm_object_part_content_set(pbar_ly, "elm.icon.2", progressbar);
2320         ug_data->progress_bar[index + 1] = progressbar;
2321         evas_object_show(progressbar);
2322
2323         Evas_Object *cancel_btn = elm_button_add(pbar_ly);
2324         /*elm_object_theme_set(cancel_btn, ug_data->theme);*/
2325         elm_object_style_set(cancel_btn, "text_only/style2");
2326         elm_object_text_set(cancel_btn, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
2327
2328         elm_object_part_content_set(pbar_ly, "elm.icon.1", cancel_btn);
2329         evas_object_show(cancel_btn);
2330         evas_object_smart_callback_add(cancel_btn, "clicked", _destroy_down_progress_ex, (void *)index);
2331         debug_log("Cancel button for attachment downloading progress popup: %p", cancel_btn);
2332
2333         /* packing progress layout */
2334         if (p_type == EMAIL_VIEWER_PROGRESSBAR_ATT && prop->real_att_len > 1) {
2335                 for (i = 0; i < prop->att_len; i++) {
2336                         info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2337                         if (info && !info->inline_content) {
2338                                 if (index == i) {
2339                                         if (ug_data->attach_ex_ly != NULL && ug_data->attach_ex_ly[j] != NULL) {
2340                                                 debug_log("");
2341                                                 elm_box_pack_after(ug_data->main_bx, pbar_ly, ug_data->attach_ex_ly[j]);
2342                                                 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[j]);
2343                                                 evas_object_hide(ug_data->attach_ex_ly[j]);
2344                                                 ug_data->attach_ex_ly[j] = pbar_ly;
2345                                         }
2346                                 }
2347                                 j++;
2348                         }
2349                 }
2350         }
2351         if ((p_type == EMAIL_VIEWER_PROGRESSBAR_ATT && prop->real_att_len == 1) || (p_type == EMAIL_VIEWER_PROGRESSBAR_ATT_ALL)) {
2352                 debug_log("");
2353                 elm_box_pack_after(ug_data->main_bx, pbar_ly, ug_data->attach_hd_ly);
2354                 elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2355                 evas_object_hide(ug_data->attach_hd_ly);
2356                 ug_data->attach_hd_ly = pbar_ly;
2357         }
2358
2359         elm_object_focus_set(pbar_ly, EINA_TRUE);
2360         elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
2361 }
2362
2363 static void _destroy_down_progress_ex(void *data, Evas_Object *obj, void *event_info)
2364 {
2365         debug_log("");
2366
2367         if (!_g_ug_data) {
2368                 debug_log("data is NULL");
2369                 return;
2370         }
2371
2372         EmailViewerUGD *ug_data = _g_ug_data;
2373         EmailViewerPrivate *priv = ug_data->email_data;
2374         EmailViewerProp *prop = ug_data->property;
2375
2376         if (!prop || !prop->attachments) {
2377                 debug_log("");
2378                 return;
2379         }
2380
2381         if (!priv) {
2382                 debug_log("");
2383                 return;
2384         }
2385
2386         int scr_x = 0;
2387         int scr_y = 0;
2388         int scr_w = 0;
2389         int scr_h = 0;
2390         elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
2391         debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
2392
2393         GList *attachment_list = prop->attachments;
2394         int index = (int)data;
2395         int i = 0, j = 0;
2396
2397         /* Cancel the download in email-service */
2398         if (index >= 0) {
2399                 debug_log("index[%d] download_all_cnt[%d] email_handle[%d]", index, priv->download_all_cnt, priv->download_all_email_handle[index]);
2400                 if (priv->download_all_email_handle[index] != 0) {
2401                         email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[index]);
2402                         priv->download_all_email_handle[index] = 0;
2403                 }
2404
2405                 (priv->download_all_cnt)--;
2406
2407                 if (priv->download_all_cnt == 0)
2408                         priv->b_all_att_save = FALSE;
2409         } else if (index == -1) {
2410                 for (i = 0; i < prop->att_len; i++) {
2411                         EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2412                         if (info && !info->inline_content) {
2413                                 debug_log("index[%d] download_all_cnt[%d] email_handle[%d]", i, priv->download_all_cnt, priv->download_all_email_handle[i]);
2414                                 if (priv->download_all_email_handle[i] != 0) {
2415                                         email_engine_stop_working(ug_data->account_id, priv->download_all_email_handle[i]);
2416                                 }
2417                         }
2418                         priv->download_all_email_handle[i] = 0;
2419                 }
2420                 priv->download_all_cnt = 0;
2421                 priv->b_all_att_save = FALSE;
2422         }
2423
2424         /* upack and delete, pack again */
2425         if (index >= 0) {
2426                 debug_log("real_att_len:%d", prop->real_att_len);
2427                 if (prop->real_att_len == 1) {
2428                         debug_log("index[%d]", index);
2429                         elm_box_pack_after(ug_data->main_bx, ug_data->attach_hd_bk, ug_data->attach_hd_ly);
2430                         elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2431                         evas_object_del(ug_data->attach_hd_ly);
2432                         ug_data->attach_hd_ly = ug_data->attach_hd_bk;
2433                         evas_object_show(ug_data->attach_hd_ly);
2434                         elm_object_focus_set(ug_data->attach_hd_ly, EINA_TRUE);
2435                         ug_data->progress_bar[index + 1] = NULL;
2436                         ug_data->progress_bar_ly[index + 1] = NULL;
2437                 } else if (prop->real_att_len > 1) {
2438                         for (i = 0; i < prop->att_len; i++) {
2439                                 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
2440                                 if (info && !info->inline_content) {
2441                                         if (index == i) {
2442                                                 debug_log("index[%d]", i);
2443                                                 debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
2444                                                 if (ug_data->attach_onoff_flag > 0) {
2445                                                         elm_box_pack_after(ug_data->main_bx, ug_data->attach_ex_bk[j], ug_data->attach_ex_ly[j]);
2446                                                         elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[j]);
2447                                                         evas_object_del(ug_data->attach_ex_ly[j]);
2448                                                         ug_data->attach_ex_ly[j] = ug_data->attach_ex_bk[j];
2449                                                         evas_object_show(ug_data->attach_ex_ly[j]);
2450                                                         elm_object_focus_set(ug_data->attach_ex_ly[j], EINA_TRUE);
2451                                                         ug_data->progress_bar[index + 1] = NULL;
2452                                                         ug_data->progress_bar_ly[index + 1] = NULL;
2453                                                 } else {
2454                                                         evas_object_del(ug_data->attach_ex_ly[j]);
2455                                                         ug_data->attach_ex_ly[j] = ug_data->attach_ex_bk[j];
2456                                                         ug_data->progress_bar[index + 1] = NULL;
2457                                                         ug_data->progress_bar_ly[index + 1] = NULL;
2458                                                 }
2459                                         }
2460                                         j++;
2461                                 }
2462                         }
2463                 }
2464         } else if (index == -1) {
2465                 debug_log("index[%d]", index);
2466                 elm_box_pack_after(ug_data->main_bx, ug_data->attach_hd_bk, ug_data->attach_hd_ly);
2467                 elm_box_unpack(ug_data->main_bx, ug_data->attach_hd_ly);
2468                 evas_object_del(ug_data->attach_hd_ly);
2469                 ug_data->attach_hd_ly = ug_data->attach_hd_bk;
2470                 evas_object_show(ug_data->attach_hd_ly);
2471                 elm_object_focus_set(ug_data->attach_hd_ly, EINA_TRUE);
2472                 ug_data->progress_bar[index + 1] = NULL;
2473                 ug_data->progress_bar_ly[index + 1] = NULL;
2474         }
2475
2476         elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
2477
2478         if (priv && priv->download_all_cnt <= 0) {
2479                 if (ug_data->forward_ctr_it)
2480                         elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_FALSE);
2481         }
2482 }
2483
2484 static void _create_more_ctxpopup(EmailViewerUGD *ug_data)
2485 {
2486         debug_log("");
2487         if (!ug_data) {
2488                 debug_log("ug_data is NULL");
2489                 return;
2490         }
2491
2492         EmailViewerProp *prop = ug_data->property;
2493         EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
2494         contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, prop->sender);
2495
2496         if (ug_data->con_popup) {
2497                 evas_object_del(ug_data->con_popup);
2498                 ug_data->con_popup = NULL;
2499         }
2500
2501         ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
2502         if (ug_data->con_popup == NULL) {
2503                 debug_log("cannot create context popup");
2504                 return;
2505         }
2506
2507         if (contact_list_item) {
2508                 debug_log("Contact Item Exist: index[%d]", contact_list_item->index);
2509                 char index[10] = { 0, };
2510                 snprintf(index, sizeof(index), "%d", contact_list_item->index);
2511
2512                 if (email_engine_check_seen_mail(ug_data->account_id, ug_data->mail_id))
2513                         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_UNREAD"), NULL, _mark_as_unread_cb, ug_data);
2514                 else
2515                         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_READ"), NULL, _mark_as_read_cb, ug_data);
2516
2517                 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, _move_cb, ug_data);
2518                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SAVE_EMAIL_ABB"), NULL, _save_email_cb, ug_data);
2519                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_VIEW_CONTACT"), NULL, _ctxpopup_detail_contact_cb, g_strdup(index));
2520                 ug_data->more_ctx_block_item = elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_BLOCK"), NULL, _ctxpopup_add_block_rule_cb, prop->sender);
2521
2522                 _delete_contacts_list(contact_list_item);
2523         } else {
2524                 if (email_engine_check_seen_mail(ug_data->account_id, ug_data->mail_id))
2525                         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_UNREAD"), NULL, _mark_as_unread_cb, ug_data);
2526                 else
2527                         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_MARK_AS_READ"), NULL, _mark_as_read_cb, ug_data);
2528
2529                 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, _move_cb, ug_data);
2530                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SAVE_EMAIL_ABB"), NULL, _save_email_cb, ug_data);
2531                 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_OPT_ADD_TO_CONTACTS"), NULL, _ctxpopup_add_contact_cb, prop->sender);
2532                 ug_data->more_ctx_block_item = elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_BLOCK"), NULL, _ctxpopup_add_block_rule_cb, prop->sender);
2533         }
2534
2535         int count, i;
2536         email_rule_t *rule_list = NULL;
2537
2538         /* get the rule list from service */
2539         if (email_get_rule_list(&rule_list, &count) < 0) {
2540                 debug_log("email_get_rule_list failed");
2541         } else {
2542                 if (count > 0) {
2543                         for (i = 0; i < count; i++) {
2544                                 if (rule_list[i].type == EMAIL_FILTER_FROM) {
2545                                         debug_log("block address %s", rule_list[i].value);
2546
2547                                         if (g_strcmp0(rule_list[i].value, prop->sender) == 0) {
2548                                                 debug_log("[%s] already blocked", rule_list[i].value);
2549                                                 if (ug_data->more_ctx_block_item)
2550                                                         elm_object_item_disabled_set(ug_data->more_ctx_block_item, EINA_TRUE);
2551                                         }
2552                                 }
2553                         }
2554                 }
2555                 /* free email rule_list */
2556                 email_free_rule(&rule_list, count);
2557         }
2558
2559         Evas_Coord x, y, w, h;
2560         evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
2561 //      evas_object_move(ug_data->con_popup, x, y - 20);
2562         evas_object_geometry_get(ug_data->ctr_bar, &x, &y, &w, &h);
2563         debug_log("x:%d, y:%d, w:%d, h:%d, mx:%d", x, y, w, h, ((w - x) * 6) / 7);
2564         evas_object_move(ug_data->con_popup, ((w - x) * 6) / 7 , y);
2565         evas_object_show(ug_data->con_popup);
2566 }
2567
2568 static void _create_reply_ctxpopup(EmailViewerUGD *ug_data)
2569 {
2570         debug_log("");
2571         if (!ug_data) {
2572                 debug_log("ug_data is NULL");
2573                 return;
2574         }
2575
2576         if (ug_data->con_popup) {
2577                 evas_object_del(ug_data->con_popup);
2578                 ug_data->con_popup = NULL;
2579         }
2580
2581         ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
2582         if (ug_data->con_popup == NULL) {
2583                 debug_log("cannot create context popup");
2584                 return;
2585         }
2586
2587         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_TO_SENDER_ABB"), NULL, _reply_cb, ug_data);
2588         elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_TO_ALL_ABB"), NULL, _reply_all_cb, ug_data);
2589
2590         Evas_Coord x, y;
2591         evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
2592         evas_object_move(ug_data->con_popup, x, y - 20);
2593         evas_object_show(ug_data->con_popup);
2594 }
2595
2596 static void _delete_evas_objects(EmailViewerUGD *ug_data)
2597 {
2598         debug_log("");
2599         EmailViewerProp *prop = ug_data->property;
2600
2601         if (ug_data->webview) {
2602                 evas_object_del(ug_data->webview);
2603                 ug_data->webview = NULL;
2604         }
2605
2606         if (ug_data->webview_bx) {
2607                 evas_object_del(ug_data->webview_bx);
2608                 ug_data->webview_bx = NULL;
2609         }
2610
2611         if (ug_data->scroller) {
2612                 evas_object_del(ug_data->scroller);
2613                 ug_data->scroller = NULL;
2614         }
2615
2616         if (ug_data->main_bx) {
2617                 evas_object_del(ug_data->main_bx);
2618                 ug_data->main_bx = NULL;
2619         }
2620
2621         if (ug_data->b_btn) {
2622                 evas_object_del(ug_data->b_btn);
2623                 ug_data->b_btn = NULL;
2624         }
2625
2626         if (ug_data->sub_ly) {
2627                 evas_object_del(ug_data->sub_ly);
2628                 ug_data->sub_ly = NULL;
2629         }
2630
2631         if (ug_data->navi_bar) {
2632                 evas_object_del(ug_data->navi_bar);
2633                 ug_data->navi_bar = NULL;
2634         }
2635
2636         if (ug_data->ctr_bar) {
2637                 evas_object_del(ug_data->ctr_bar);
2638                 ug_data->ctr_bar = NULL;
2639         }
2640
2641         if (ug_data->layout_main) {
2642                 evas_object_del(ug_data->layout_main);
2643                 ug_data->layout_main = NULL;
2644         }
2645
2646         if (ug_data->con_popup) {
2647                 evas_object_del(ug_data->con_popup);
2648                 ug_data->con_popup = NULL;
2649         }
2650
2651         if (ug_data->select_info) {
2652                 evas_object_del(ug_data->select_info);
2653                 ug_data->select_info = NULL;
2654         }
2655
2656         if (ug_data->selectioninfo_layout != NULL) {
2657                 evas_object_del(ug_data->selectioninfo_layout);
2658                 ug_data->selectioninfo_layout = NULL;
2659         }
2660
2661         if (ug_data->notify) {
2662                 evas_object_del(ug_data->notify);
2663                 ug_data->notify = NULL;
2664         }
2665
2666         if (ug_data->pb_notify) {
2667                 evas_object_del(ug_data->pb_notify);
2668                 ug_data->pb_notify = NULL;
2669         }
2670
2671         if (ug_data->pb_notify_lb) {
2672                 evas_object_del(ug_data->pb_notify_lb);
2673                 ug_data->pb_notify_lb = NULL;
2674         }
2675
2676         if (ug_data->partial_dn_btn) {
2677                 evas_object_del(ug_data->partial_dn_btn);
2678                 ug_data->partial_dn_btn = NULL;
2679         }
2680
2681         if (ug_data->partial_dn_btn_bx) {
2682                 evas_object_del(ug_data->partial_dn_btn_bx);
2683                 ug_data->partial_dn_btn_bx = NULL;
2684         }
2685
2686         if (ug_data->waiting_timer) {
2687                 ecore_timer_del(ug_data->waiting_timer);
2688                 ug_data->waiting_timer = NULL;
2689         }
2690
2691         if (ug_data->timer) {
2692                 ecore_timer_del(ug_data->timer);
2693                 ug_data->timer = NULL;
2694         }
2695
2696         if (ug_data->idler) {
2697                 ecore_idler_del(ug_data->idler);
2698                 ug_data->idler = NULL;
2699         }
2700
2701         if (ug_data->got_att) {
2702                 int i;
2703
2704                 evas_object_del(ug_data->attach_hd_bk);
2705                 ug_data->attach_hd_ly = NULL;
2706                 ug_data->attach_hd_bk = NULL;
2707
2708                 if (prop->real_att_len > 1) {
2709                         for (i = 0; i < prop->real_att_len; i++) {
2710                                 if (ug_data->attach_ex_ly != NULL) {
2711                                         if (ug_data->attach_ex_ly[i] != NULL) {
2712                                                 debug_log("index %d", i);
2713                                                 evas_object_del(ug_data->attach_ex_bk[i]);
2714                                                 ug_data->attach_ex_ly[i] = NULL;
2715                                                 ug_data->attach_ex_bk[i] = NULL;
2716                                         }
2717                                 }
2718                         }
2719
2720                         if (ug_data->attach_ex_ly != NULL) {
2721                                 free(ug_data->attach_ex_ly);
2722                                 ug_data->attach_ex_ly = NULL;
2723                                 ug_data->attach_ex_bk = NULL;
2724                         }
2725                 }
2726
2727                 for (i = 0; i <= prop->att_len; i++) {
2728                         if (ug_data->progress_bar_ly[i] != NULL) {
2729                                 evas_object_del(ug_data->progress_bar_ly[i]);
2730                                 ug_data->progress_bar_ly[i] = NULL;
2731                                 ug_data->progress_bar[i] = NULL;
2732                         }
2733                 }
2734         }
2735 }
2736
2737 void _launch_composer(EmailViewerUGD *ug_data, int type)
2738 {
2739         debug_log("");
2740
2741         if (!ug_data) {
2742                 debug_log("ug_data is NULL");
2743                 return;
2744         }
2745
2746         EmailViewerPrivate *priv = ug_data->email_data;
2747         char tmp[256];
2748
2749         int ret;
2750         service_h service = NULL;
2751
2752         ret = service_create(&service);
2753         debug_log("service_create: %d", ret);
2754         if (!service) {
2755                 debug_log("service create failed");
2756                 return;
2757         }
2758
2759         char rtype[10] = { 0, };
2760         snprintf(rtype, sizeof(rtype), "%d", type);
2761         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
2762         debug_log("service_add_extra_data: %d", ret);
2763
2764         memset(tmp, 0x0, sizeof(tmp));
2765         snprintf(tmp, sizeof(tmp), "%d", priv->account_id);
2766         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_ACCOUNT_ID, tmp);
2767         debug_log("service_add_extra_data: %d", ret);
2768
2769         memset(tmp, 0x0, sizeof(tmp));
2770         snprintf(tmp, sizeof(tmp), "%d", priv->mailbox_id);
2771         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MAILBOX, tmp);
2772         debug_log("service_add_extra_data: %d", ret);
2773
2774         memset(tmp, 0x0, sizeof(tmp));
2775         snprintf(tmp, sizeof(tmp), "%d", priv->mail_id);
2776         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MAIL_ID, tmp);
2777         debug_log("service_add_extra_data: %d", ret);
2778
2779         ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
2780
2781         ret = service_destroy(service);
2782         debug_log("service_destroy: %d", ret);
2783 }
2784
2785 static void _back_cb(void *data, Evas_Object *obj, void *event_info)
2786 {
2787         debug_log("");
2788
2789         if (_g_ug_data == NULL) {
2790                 debug_log("_g_ug_data is NULL");
2791                 return;
2792         }
2793
2794         if (!data) {
2795                 debug_log("data is NULL");
2796                 return;
2797         }
2798         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2799
2800         if (ug_data->con_popup != NULL) {
2801                 evas_object_del(ug_data->con_popup);
2802                 ug_data->con_popup = NULL;
2803         }
2804
2805         debug_log("isRoate = %d", ug_data->isRotate);
2806         if (ug_data->isRotate == false && ug_data->b_internal) {
2807                 /* Viewer to hide, so set left content (mailbox) size to full */
2808                 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
2809         }
2810
2811         if (ug_data->b_internal != 1) {
2812                 debug_log("ug_destory_me");
2813                 ug_destroy_me(ug_data->ug);
2814         } else {
2815                 _hide_view(ug_data);
2816         }
2817 }
2818
2819 static void _prev_mail_cb(void *data, Evas_Object *obj, void *event_info)
2820 {
2821         debug_log("");
2822         if (!data) {
2823                 debug_log("data is NULL");
2824                 return;
2825         }
2826
2827         /* send next or previous mail request to mailbox. */
2828         int ret;
2829         service_h service = NULL;
2830
2831         ret = service_create(&service);
2832         debug_log("service_create: %d", ret);
2833         if (!service) {
2834                 debug_log("service create failed");
2835                 return;
2836         }
2837
2838         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_PREV_MSG);
2839         debug_log("service_add_extra_data: %d", ret);
2840         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "0");
2841         debug_log("service_add_extra_data: %d", ret);
2842
2843         ug_send_message(_g_mailbox_ug, service);
2844
2845         ret = service_destroy(service);
2846         debug_log("service_destroy: %d", ret);
2847 }
2848
2849 static void _next_mail_cb(void *data, Evas_Object *obj, void *event_info)
2850 {
2851         debug_log("");
2852         if (!data) {
2853                 debug_log("data is NULL");
2854                 return;
2855         }
2856
2857         /* send next or previous mail request to mailbox. */
2858         int ret;
2859         service_h service = NULL;
2860
2861         ret = service_create(&service);
2862         debug_log("service_create: %d", ret);
2863         if (!service) {
2864                 debug_log("service create failed");
2865                 return;
2866         }
2867
2868         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
2869         debug_log("service_add_extra_data: %d", ret);
2870         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "0");
2871         debug_log("service_add_extra_data: %d", ret);
2872
2873         ug_send_message(_g_mailbox_ug, service);
2874
2875         ret = service_destroy(service);
2876         debug_log("service_destroy: %d", ret);
2877 }
2878
2879 static void _reply_cb(void *data, Evas_Object *obj, void *event_info)
2880 {
2881         debug_log("");
2882         if (!data) {
2883                 debug_log("data is NULL");
2884                 return;
2885         }
2886
2887         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2888
2889         if (ug_data->con_popup) {
2890                 evas_object_del(ug_data->con_popup);
2891                 ug_data->con_popup = NULL;
2892         }
2893
2894         ug_data->display_download_result = FALSE;
2895
2896         _launch_composer(ug_data, RUN_COMPOSER_REPLY);
2897
2898         if (ug_data->notify) {
2899                 evas_object_del(ug_data->notify);
2900                 ug_data->notify = NULL;
2901         }
2902 }
2903
2904 static void _reply_all_cb(void *data, Evas_Object *obj, void *event_info)
2905 {
2906         debug_log("");
2907         if (!data) {
2908                 debug_log("data is NULL");
2909                 return;
2910         }
2911
2912         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2913
2914         if (ug_data->con_popup) {
2915                 evas_object_del(ug_data->con_popup);
2916                 ug_data->con_popup = NULL;
2917         }
2918
2919         ug_data->display_download_result = FALSE;
2920
2921         _launch_composer(ug_data, RUN_COMPOSER_REPLY_ALL);
2922
2923         if (ug_data->notify) {
2924                 evas_object_del(ug_data->notify);
2925                 ug_data->notify = NULL;
2926         }
2927 }
2928
2929 static void _reply_option_cb(void *data, Evas_Object *obj, void *event_info)
2930 {
2931         debug_log("");
2932         if (!data) {
2933                 debug_log("data is NULL");
2934                 return;
2935         }
2936
2937         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2938
2939         _create_reply_ctxpopup(ug_data);
2940 }
2941
2942 static void _forward_cb(void *data, Evas_Object *obj, void *event_info)
2943 {
2944         debug_log("");
2945         if (!data) {
2946                 debug_log("data is NULL");
2947                 return;
2948         }
2949
2950         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2951
2952         ug_data->display_download_result = FALSE;
2953
2954         _launch_composer(ug_data, RUN_COMPOSER_FORWARD);
2955 }
2956
2957 static void _resend_cb(void *data, Evas_Object *obj, void *event_info)
2958 {
2959         debug_log("");
2960 }
2961
2962 static void _delete_cb(void *data, Evas_Object *obj, void *event_info)
2963 {
2964         debug_log("");
2965         if (!data) {
2966                 debug_log("data is NULL");
2967                 return;
2968         }
2969
2970         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2971
2972         if (ug_data->con_popup) {
2973                 evas_object_del(ug_data->con_popup);
2974                 ug_data->con_popup = NULL;
2975         }
2976
2977         _create_notify(ug_data, NULL, dgettext("sys_string", "IDS_COM_POP_DELETE_Q"),
2978                                         2, dgettext("sys_string", "IDS_COM_SK_DELETE"),
2979                                         _popup_response_delete_ok_cb, dgettext("sys_string", "IDS_COM_SK_CANCEL"),
2980                                         _popup_response_cb, NULL);
2981 }
2982
2983 static void _move_cb(void *data, Evas_Object *obj, void *event_info)
2984 {
2985         debug_log("");
2986         if (!data) {
2987                 debug_log("data is NULL");
2988                 return;
2989         }
2990
2991         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
2992         EmailViewerPrivate *priv = ug_data->email_data;
2993
2994         if (ug_data->con_popup) {
2995                 evas_object_del(ug_data->con_popup);
2996                 ug_data->con_popup = NULL;
2997         }
2998
2999         Evas_Object *gl = elm_genlist_add(ug_data->navi_bar);
3000         evas_object_show(gl);
3001
3002         ug_data->itc1.item_style = "1text.1icon.2";
3003         ug_data->itc1.func.text_get = _gl_text_get;
3004         ug_data->itc1.func.content_get = _gl_content_get;
3005         ug_data->itc1.func.state_get = _gl_state_get;
3006         ug_data->itc1.func.del = _gl_del;
3007
3008         Elm_Object_Item *navi_it = NULL;
3009         navi_it = elm_naviframe_item_push(ug_data->navi_bar, dgettext("sys_string", "IDS_COM_BODY_MOVE"), NULL, NULL, gl, NULL);
3010         ug_data->navi_move_it1 = navi_it;
3011         if (ug_data->isRotate)
3012                 elm_naviframe_item_title_visible_set(ug_data->navi_move_it1, EINA_FALSE);
3013
3014         email_mailbox_t *mailbox_list = NULL;
3015         int mailbox_count = 0;
3016         int i = 0;
3017
3018         email_get_mailbox_list(priv->account_id, -1, &mailbox_list, &mailbox_count);
3019         debug_log("folder count %d", mailbox_count);
3020         ug_data->move_mailbox_list = mailbox_list;
3021         ug_data->move_mailbox_count = mailbox_count;
3022
3023         for (i = 0; i < mailbox_count; i++) {
3024                 if (g_strcmp0(ug_data->mailbox_name, mailbox_list[i].mailbox_name) != 0) {
3025                         if (mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_OUTBOX &&
3026                                 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_SENTBOX &&
3027                                 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_DRAFT &&
3028                                 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_TRASH &&
3029                                 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_ALL_EMAILS &&
3030                                 mailbox_list[i].mailbox_type != EMAIL_MAILBOX_TYPE_SEARCH_RESULT)
3031                                 if (g_strcmp0(mailbox_list[i].alias, "[Gmail]")) {
3032                                         elm_genlist_item_append(gl, &ug_data->itc1, (void *)&(mailbox_list[i]), NULL, ELM_GENLIST_ITEM_NONE, _move_here_cb, (void *)&(mailbox_list[i]));
3033                                 }
3034                 }
3035         }
3036
3037         /*if (ug_data->b_internal)
3038                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "noindicator");
3039         else
3040                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "default");*/
3041
3042         Evas_Object *move_back_btn = NULL;
3043         if (ug_data->isRotate) {
3044                 ug_data->move_cbar = elm_toolbar_add(ug_data->navi_bar);
3045                 elm_toolbar_shrink_mode_set(ug_data->move_cbar, ELM_TOOLBAR_SHRINK_EXPAND);
3046                 elm_object_style_set(ug_data->move_cbar, "naviframe");
3047                 evas_object_show(ug_data->move_cbar);
3048
3049                 elm_object_item_disabled_set(elm_toolbar_item_append(ug_data->move_cbar, NULL, "", NULL, NULL), EINA_TRUE);
3050                 elm_toolbar_item_append(ug_data->move_cbar, NULL, dgettext("sys_string", "IDS_COM_SK_CANCEL"), _move_back_cb, ug_data);
3051                 elm_object_item_part_content_set(navi_it, "controlbar", ug_data->move_cbar);
3052
3053                 move_back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
3054                 if (move_back_btn) {
3055                         evas_object_del(move_back_btn);
3056                         elm_object_item_part_content_set(navi_it, "prev_btn", NULL);
3057                 }
3058         } else {
3059                 move_back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
3060                 if (move_back_btn) {
3061                         evas_object_del(move_back_btn);
3062                         move_back_btn = elm_button_add(ug_data->navi_bar);
3063                         elm_object_style_set(move_back_btn, "naviframe/back_btn/default");
3064                         evas_object_smart_callback_add(move_back_btn, "clicked", _move_back_cb, ug_data);
3065                         elm_object_item_part_content_set(navi_it, "prev_btn", move_back_btn);
3066                 }
3067         }
3068 }
3069
3070 static void _more_cb(void *data, Evas_Object *obj, void *event_info)
3071 {
3072         debug_log("");
3073         if (!data) {
3074                 debug_log("data is NULL");
3075                 return;
3076         }
3077
3078         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3079
3080         _create_more_ctxpopup(ug_data);
3081 }
3082
3083 static void _body_down_cb(void *data, Evas_Object *obj, void *event_info)
3084 {
3085         debug_log("");
3086         if (!data) {
3087                 debug_log("data is NULL");
3088                 return;
3089         }
3090
3091         int handle;
3092         gboolean ret = 0;
3093         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3094         EmailViewerPrivate *priv = ug_data->email_data;
3095
3096         /* check already downloaded */
3097         int body_download_status = ug_data->property->body_download;
3098
3099         if (body_download_status == 0) {        //EMAIL_BODY_DOWNLOAD_STATUS_NONE
3100                 debug_log("only header downloaded -> need body download");
3101         } else if (body_download_status == 1) { //EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED
3102                 debug_log("already downloaded fully, create body directly");
3103
3104                 /* set property */
3105                 if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
3106                         debug_log("");
3107                         viewer_make_internal_mail(ug_data->property, ug_data->email_data);
3108                 }
3109
3110                 if (ug_data->b_partial_body) {
3111                         int scr_x = 0;
3112                         int scr_y = 0;
3113                         int scr_w = 0;
3114                         int scr_h = 0;
3115                         elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
3116                         debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
3117
3118                         elm_box_unpack(ug_data->main_bx, ug_data->partial_dn_btn_bx);
3119                         if (ug_data->partial_dn_btn) {
3120                                 evas_object_del(ug_data->partial_dn_btn);
3121                                 ug_data->partial_dn_btn = NULL;
3122                         }
3123                         if (ug_data->partial_dn_btn_bx) {
3124                                 evas_object_del(ug_data->partial_dn_btn_bx);
3125                                 ug_data->partial_dn_btn_bx = NULL;
3126                         }
3127
3128                         if (ug_data->property->has_html) {
3129                                 ug_data->webview_data->body_type = BODY_TYPE_HTML;
3130                                 ug_data->webview_data->uri = ug_data->property->body_uri;
3131                         } else {
3132                                 ug_data->webview_data->body_type = BODY_TYPE_TEXT;
3133                                 ug_data->webview_data->text_content = ug_data->property->body;
3134                         }
3135
3136                         viewer_set_webview_content(ug_data, 1);
3137                         ug_data->b_partial_body = 0;
3138
3139                         elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
3140                         elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
3141                 } else {
3142                         if (ug_data->property->has_attachment)
3143                                 ug_data->got_att = 1;
3144                         else
3145                                 ug_data->got_att = 0;
3146
3147                         /* pack attachment if it exist */
3148                         if (ug_data->got_att) {
3149                                 _create_attach(ug_data);
3150                         }
3151
3152                         _create_body(ug_data);
3153                 }
3154
3155                 return;
3156         } else if (body_download_status == 2) { //EMAILL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED
3157                 debug_log("body downloaded partially -> need full body download");
3158         }
3159
3160         ret = email_engine_body_download(priv->account_id, priv->mail_id, &handle);
3161
3162         if (ret == TRUE) {
3163                 priv->email_handle = handle;
3164                 debug_log("succeed in email_engine_body_download");
3165                 _create_down_progress(dgettext("sys_string", "IDS_COM_POP_DOWNLOADING"), _destroy_down_progress_cb);
3166
3167                 /* If attachment download is in progress, first cancel to attachment download of the mail and then carry out body download */
3168                 _cancel_download_attachment(ug_data);
3169
3170         } else {
3171                 debug_log("unable to download mail body");
3172                 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
3173                                                 _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), 1,
3174                                                 dgettext("sys_string", "IDS_COM_SK_OK"),
3175                                                 _popup_response_cb, NULL, NULL, NULL);
3176         }
3177 }
3178
3179 static void _subject_favorite_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3180 {
3181         debug_log("");
3182         if (!data) {
3183                 debug_log("data is NULL");
3184                 return;
3185         }
3186
3187         EmailViewerUGD *ug_data = _g_ug_data;
3188         EmailViewerProp *prop = ug_data->property;
3189         int err = EMAIL_ERROR_NONE;
3190
3191         if (ug_data->con_popup) {
3192                 evas_object_del(ug_data->con_popup);
3193                 ug_data->con_popup = NULL;
3194         }
3195
3196         debug_log("Before prop->favorite: %d", prop->favorite);
3197         switch(prop->favorite) {
3198                 case EMAIL_FLAG_NONE:
3199                         prop->favorite = EMAIL_FLAG_FLAGED;
3200                         break;
3201                 case EMAIL_FLAG_FLAGED:
3202                         prop->favorite = EMAIL_FLAG_NONE;
3203                         break;
3204                 case EMAIL_FLAG_TASK_STATUS_CLEAR:
3205                         prop->favorite = EMAIL_FLAG_TASK_STATUS_ACTIVE;
3206                         break;
3207                 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
3208                         prop->favorite = EMAIL_FLAG_TASK_STATUS_COMPLETE;
3209                         break;
3210                 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
3211                         prop->favorite = EMAIL_FLAG_TASK_STATUS_CLEAR;
3212                         break;
3213                 default:
3214                         debug_log("Never here");
3215         }
3216         debug_log("After prop->favorite: %d", prop->favorite);
3217
3218         err = email_set_flags_field(ug_data->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_FLAGGED_FIELD, prop->favorite, 1);
3219         if (err != EMAIL_ERROR_NONE) {
3220                 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3221                                 N_("Failed to set favourite"), 0,
3222                                 NULL, NULL, NULL, NULL, _popup_response_cb);
3223                 return;
3224         }
3225
3226         evas_object_del(elm_object_part_content_unset(ug_data->ly_subject, "elm.icon.favorite"));
3227         Evas_Object *favorite_icon = elm_icon_add(ug_data->ly_subject);
3228         switch(prop->favorite)
3229         {
3230                 case EMAIL_FLAG_NONE:
3231                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_off.png", NULL);
3232                         break;
3233                 case EMAIL_FLAG_FLAGED:
3234                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_icon_favorite_on.png", NULL);
3235                         break;
3236                 case EMAIL_FLAG_TASK_STATUS_CLEAR:
3237                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Clear.png", NULL);
3238                         break;
3239                 case EMAIL_FLAG_TASK_STATUS_ACTIVE:
3240                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Active.png", NULL);
3241                         break;
3242                 case EMAIL_FLAG_TASK_STATUS_COMPLETE:
3243                         elm_icon_file_set(favorite_icon, IMGDIR "/M02_email_Flag_Complete.png", NULL);
3244                         break;
3245                 default:
3246                         debug_log("Never here");
3247         }
3248         evas_object_size_hint_aspect_set(favorite_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
3249         elm_icon_resizable_set(favorite_icon, 1, 1);
3250         elm_object_part_content_set(ug_data->ly_subject, "elm.icon.favorite", favorite_icon);
3251         evas_object_show(favorite_icon);
3252 }
3253
3254 static void _subject_detail_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3255 {
3256         debug_log("");
3257         if (!_g_ug_data) {
3258                 debug_log("data is NULL");
3259                 return;
3260         }
3261
3262         Evas_Object *item = (Evas_Object *)data;
3263         EmailViewerUGD *ug_data = _g_ug_data;
3264
3265         if (!(ug_data->subject_onoff_flag)) {
3266                 edje_object_signal_emit(_EDJ(item), "elm,state,expanded", "elm");
3267                 (ug_data->subject_onoff_flag)++;
3268
3269                 _create_to_addrs(ug_data);
3270                 _create_cc_addrs(ug_data);
3271                 _create_bcc_addrs(ug_data);
3272         } else {
3273                 edje_object_signal_emit(_EDJ(item), "elm,state,contracted", "elm");
3274                 (ug_data->subject_onoff_flag)--;
3275
3276                 if (ug_data->to_ly) {
3277                         elm_box_unpack(ug_data->main_bx, ug_data->to_ly);
3278                         evas_object_del(ug_data->to_ly);
3279                         ug_data->to_ly = NULL;
3280                 }
3281                 if (ug_data->cc_ly) {
3282                         elm_box_unpack(ug_data->main_bx, ug_data->cc_ly);
3283                         evas_object_del(ug_data->cc_ly);
3284                         ug_data->cc_ly = NULL;
3285                 }
3286                 if (ug_data->bcc_ly) {
3287                         elm_box_unpack(ug_data->main_bx, ug_data->bcc_ly);
3288                         evas_object_del(ug_data->bcc_ly);
3289                         ug_data->bcc_ly = NULL;
3290                 }
3291
3292                 elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
3293         }
3294 }
3295
3296 static void _attachment_item_collapse_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3297 {
3298         debug_log("");
3299         if (!data || !_g_ug_data) {
3300                 debug_log("data is NULL");
3301                 return;
3302         }
3303
3304         Evas_Object *item = (Evas_Object *)data;
3305         EmailViewerUGD *ug_data = _g_ug_data;
3306         EmailViewerProp *prop = ug_data->property;
3307         int i = 0;
3308
3309         debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
3310         if (!(ug_data->attach_onoff_flag)) {
3311                 debug_log("attachments expanded");
3312                 edje_object_signal_emit(_EDJ(item), "elm,state,expanded", "elm");
3313                 (ug_data->attach_onoff_flag)++;
3314
3315                 if (ug_data->attach_ex_ly == NULL)
3316                         _create_attach_ex(ug_data);
3317                 else {
3318                         for (i = 0; i < prop->real_att_len; i++) {
3319                                 debug_log("index %d", i);
3320                                 elm_box_pack_after(ug_data->main_bx, ug_data->attach_ex_ly[i], ug_data->attach_hd_ly);
3321                                 evas_object_show(ug_data->attach_ex_ly[i]);
3322                         }
3323                 }
3324         } else {
3325                 debug_log("attachments contracted");
3326                 edje_object_signal_emit(_EDJ(item), "elm,state,contracted", "elm");
3327                 ug_data->attach_onoff_flag = 0;
3328
3329                 for (i = 0; i < prop->real_att_len; i++) {
3330                         if (ug_data->attach_ex_ly[i] != NULL) {
3331                                 debug_log("index %d", i);
3332                                 elm_box_unpack(ug_data->main_bx, ug_data->attach_ex_ly[i]);
3333                                 evas_object_hide(ug_data->attach_ex_ly[i]);
3334                         }
3335                 }
3336         }
3337 }
3338
3339 static void _attachment_save_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3340 {
3341         debug_log("");
3342
3343         if (!_g_ug_data) {
3344                 debug_log("ug_data is NULL");
3345                 return;
3346         }
3347
3348         EmailViewerUGD *ug_data = _g_ug_data;
3349         int att_index = (int)data;
3350
3351         ug_data->display_download_result = FALSE;
3352
3353         debug_log("Selected item index = %d", att_index);
3354         _show_attachment(ug_data, att_index);
3355 }
3356
3357 static void _attachment_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3358 {
3359         debug_log("");
3360
3361         if (!_g_ug_data) {
3362                 debug_log("ug_data is NULL");
3363                 return;
3364         }
3365
3366         EmailViewerUGD *ug_data = _g_ug_data;
3367         int att_index = (int)data;
3368
3369         debug_log("Selected item index = %d", att_index);
3370         ug_data->display_download_result = TRUE;
3371         _show_attachment(ug_data, att_index);
3372 }
3373
3374 static void _attachment_save_all_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
3375 {
3376         debug_log("");
3377         if (!_g_ug_data) {
3378                 debug_log("ug_data is NULL");
3379                 return;
3380         }
3381
3382         EmailViewerUGD *ug_data = _g_ug_data;
3383
3384         _save_attachment_all(ug_data);
3385 }
3386
3387 static void _attachment_bg_set_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
3388 {
3389         debug_log("");
3390         if (!_g_ug_data) {
3391                 debug_log("ug_data is NULL");
3392                 return;
3393         }
3394
3395         EmailViewerUGD *ug_data = _g_ug_data;
3396         EmailViewerProp *prop = ug_data->property;
3397
3398         int att_index = (int)data;
3399         debug_log("att_index = %d, attachments count = %d", att_index, prop->real_att_len);
3400
3401         if (prop->real_att_len > 1) {
3402                 int i = 0;
3403                 int j = 0;
3404                 GList *attachment_list = prop->attachments;
3405                 LIST_ITER_START(i, attachment_list) {
3406                         EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
3407                         if (info && !info->inline_content) {
3408                                 if (att_index == i)
3409                                         break;
3410                                 j++;
3411                         }
3412                 }
3413                 edje_object_signal_emit(_EDJ(ug_data->attach_ex_ly[j]), "pressed", "elm.event.rect");
3414         }
3415         else
3416                 edje_object_signal_emit(_EDJ(ug_data->attach_hd_ly), "pressed", "elm.event.rect");
3417 }
3418
3419 static void _attachment_bg_unset_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
3420 {
3421         debug_log("");
3422         if (!_g_ug_data) {
3423                 debug_log("ug_data is NULL");
3424                 return;
3425         }
3426
3427         EmailViewerUGD *ug_data = _g_ug_data;
3428         EmailViewerProp *prop = ug_data->property;
3429
3430         int att_index = (int)data;
3431         debug_log("att_index = %d, attachments count = %d", att_index, prop->real_att_len);
3432
3433         if (prop->real_att_len > 1) {
3434                 int i = 0;
3435                 int j = 0;
3436                 GList *attachment_list = prop->attachments;
3437                 LIST_ITER_START(i, attachment_list) {
3438                         EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, attachment_list);
3439                         if (info && !info->inline_content) {
3440                                 if (att_index == i)
3441                                         break;
3442                                 j++;
3443                         }
3444                 }
3445                 edje_object_signal_emit(_EDJ(ug_data->attach_ex_ly[j]), "unpressed", "elm.event.rect");
3446         }
3447         else
3448                 edje_object_signal_emit(_EDJ(ug_data->attach_hd_ly), "unpressed", "elm.event.rect");
3449 }
3450
3451 static void _mark_as_unread_cb(void *data, Evas_Object *obj, void *event_info)
3452 {
3453         debug_log("");
3454         if (!data) {
3455                 debug_log("data is NULL");
3456                 return;
3457         }
3458
3459         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3460         EmailViewerPrivate *priv = ug_data->email_data;
3461
3462         if (ug_data->con_popup) {
3463                 evas_object_del(ug_data->con_popup);
3464                 ug_data->con_popup = NULL;
3465         }
3466
3467         int err = 0;
3468         debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d))", ug_data->mail_id, priv->mail_id, priv->mail_info->mail_id);
3469
3470         err = email_set_flags_field(ug_data->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_SEEN_FIELD, 0, 1);
3471         debug_log("email_set_flags_field - err(%d)", err);
3472
3473         if (err != EMAIL_ERROR_NONE) {
3474                 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3475                                                 _("IDS_EMAIL_POP_FAILED_TO_MARK_AS_UNREAD"), 0,
3476                                                 NULL, NULL, NULL, NULL, _popup_response_cb);
3477         } else {
3478                 char str[128] = { 0, };
3479                 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_MARKED_AS_UNREAD"));
3480                 _show_select_info(ug_data, str);
3481         }
3482 }
3483
3484 static void _mark_as_read_cb(void *data, Evas_Object *obj, void *event_info)
3485 {
3486         debug_log("");
3487         if (!data) {
3488                 debug_log("data is NULL");
3489                 return;
3490         }
3491
3492         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3493         EmailViewerPrivate *priv = ug_data->email_data;
3494
3495         if (ug_data->con_popup) {
3496                 evas_object_del(ug_data->con_popup);
3497                 ug_data->con_popup = NULL;
3498         }
3499
3500         int err = 0;
3501         debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d))", ug_data->mail_id, priv->mail_id, priv->mail_info->mail_id);
3502
3503         err = email_set_flags_field(priv->mail_info->account_id, &ug_data->mail_id, 1, EMAIL_FLAGS_SEEN_FIELD, 1, 1);
3504         debug_log("email_set_flags_field - err(%d)", err);
3505
3506         if (err != EMAIL_ERROR_NONE) {
3507                 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3508                                                 _("IDS_EMAIL_POP_FAILED_TO_MARK_AS_READ"), 0,
3509                                                 NULL, NULL, NULL, NULL, _popup_response_cb);
3510         } else {
3511                 char str[128] = { 0, };
3512                 snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_MARKED_AS_READ"));
3513                 _show_select_info(ug_data, str);
3514         }
3515 }
3516
3517 static void _create_waiting_popup(EmailViewerUGD *ug_data, const char *title_text, const char *style)
3518 {
3519         debug_enter();
3520         if (title_text == NULL) {
3521                 debug_log("popup text is null");
3522                 return;
3523         }
3524
3525         Evas_Object *popup = elm_popup_add(ug_data->win_main);
3526         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3527         elm_object_part_text_set(popup, "title,text", title_text);
3528
3529         Evas_Object *progress = elm_progressbar_add(popup);
3530         elm_object_style_set(progress, style);
3531         elm_progressbar_pulse_set(progress, EINA_TRUE);
3532         elm_progressbar_pulse(progress, EINA_TRUE);
3533         evas_object_show(progress);
3534
3535         elm_object_content_set(popup, progress);
3536
3537         Evas_Object *btn1 = elm_button_add(popup);
3538         elm_object_style_set(btn1, "popup_button/default");
3539         elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
3540         elm_object_part_content_set(popup, "button1", btn1);
3541         evas_object_smart_callback_add(btn1, "clicked", _popup_waiting_response_cb, ug_data);
3542
3543         ug_data->timeout_popup = popup;
3544
3545         evas_object_show(popup);
3546 }
3547
3548 static void _save_email_cb(void *data, Evas_Object *obj, void *event_info)
3549 {
3550         debug_log("");
3551         if (!data) {
3552                 debug_log("data is NULL");
3553                 return;
3554         }
3555
3556         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3557
3558         if (ug_data->con_popup) {
3559                 evas_object_del(ug_data->con_popup);
3560                 ug_data->con_popup = NULL;
3561         }
3562
3563         if (ug_data->timeout_popup) {
3564                 evas_object_del(ug_data->timeout_popup);
3565                 ug_data->timeout_popup = NULL;
3566         }
3567         _create_waiting_popup(ug_data, dgettext("sys_string", "IDS_COM_POP_SAVING_ING"), "pending_list");       //"list_process"
3568
3569         if (ug_data->waiting_timer) {
3570                 ecore_timer_del(ug_data->waiting_timer);
3571                 ug_data->waiting_timer = NULL;
3572         }
3573         ug_data->waiting_timer = ecore_timer_add(0.2, _save_email_prog_cb, ug_data);
3574 }
3575
3576 static Eina_Bool _save_email_prog_cb(void *data)
3577 {
3578         debug_log("");
3579
3580         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3581
3582         int err = 0;
3583         debug_log("ug_data->mail_id(%d), priv->mail_id(%d), mail_info->mail_id(%d))", ug_data->mail_id, ug_data->email_data->mail_id, ug_data->email_data->mail_info->mail_id);
3584
3585         email_mail_data_t *mail_t = NULL;
3586         err = email_get_mail_data(ug_data->email_data->mail_id, &mail_t);
3587         debug_log("email_get_mail_data - err (%d)", err);
3588
3589         if (mail_t == NULL) {
3590                 debug_log("mail_t is NULL");
3591                 return EINA_FALSE;
3592         }
3593
3594         email_attachment_data_t *attachment_t = NULL;
3595         int attachment_count = 0;
3596         err = email_get_attachment_data_list(ug_data->email_data->mail_id, &attachment_t, &attachment_count);
3597         debug_log("email_get_attachment_data_list - err (%d)", err);
3598
3599         char file_name[MAX_PATH_LEN] = { 0, };
3600         snprintf(file_name, sizeof(file_name), "%s_%d_%d.%s", DIR_DEFAULT_MEDIA_PHONE"/Downloads/email", ug_data->account_id, ug_data->mail_id, "eml");
3601         char *output_file_path = g_strdup(file_name);
3602         debug_log("output_file_path(%s)", file_name, output_file_path);
3603
3604         err = email_write_mime_file(mail_t, attachment_t, attachment_count, &output_file_path);
3605         debug_log("email_write_mime_file - err(%d)", err);
3606
3607         g_free(output_file_path);
3608
3609         if (mail_t) {
3610                 email_free_mail_data(&(mail_t), 1);
3611                 mail_t = NULL;
3612         }
3613
3614         if (attachment_t && attachment_count > 0) {
3615                 email_free_attachment_data(&(attachment_t), attachment_count);
3616                 attachment_t = NULL;
3617                 attachment_count = 0;
3618         }
3619
3620         if (ug_data->timeout_popup) {
3621                 evas_object_del(ug_data->timeout_popup);
3622                 ug_data->timeout_popup = NULL;
3623         }
3624
3625         if (err != EMAIL_ERROR_NONE) {
3626                 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3627                                                 dgettext("sys_string", "IDS_COM_POP_UNABLE_TO_SAVE"), 0,
3628                                                 NULL, NULL, NULL, NULL, _popup_response_cb);
3629         } else {
3630 #ifdef _SMALL_NOTI
3631                 char str[128] = { 0, };
3632                 snprintf(str, sizeof(str), "%s", N_("Saved in My files"));
3633                 int ret = status_message_post(str);
3634                 if (ret)
3635                         debug_log("status_message_post failed: %d", ret);
3636 #else
3637                 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_OPT_INFORMATION"),
3638                                                 N_("Saved in My files"), 0,
3639                                                 NULL, NULL, NULL, NULL, _popup_response_cb);
3640 #endif
3641         }
3642
3643         if (ug_data->waiting_timer) {
3644                 ecore_timer_del(ug_data->waiting_timer);
3645                 ug_data->waiting_timer = NULL;
3646         }
3647
3648         return EINA_FALSE;
3649 }
3650
3651 static void _ctxpopup_detail_contact_cb(void *data, Evas_Object *obj, void *event_info)
3652 {
3653         debug_log("");
3654         if (data == NULL || _g_ug_data == NULL) {
3655                 debug_log("data is NULL");
3656                 return;
3657         }
3658
3659         EmailViewerUGD *ug_data = _g_ug_data;
3660
3661         if (ug_data->con_popup) {
3662                 evas_object_del(ug_data->con_popup);
3663                 ug_data->con_popup = NULL;
3664         }
3665
3666         char *index = (char *)data;
3667         char type[10] = { 0, };
3668         int ret;
3669         service_h service = NULL;
3670
3671         ret = service_create(&service);
3672         debug_log("service_create: %d", ret);
3673         if (!service) {
3674                 debug_log("service create failed");
3675                 return;
3676         }
3677
3678         snprintf(type, sizeof(type), "%d", CT_UG_REQUEST_DETAIL);
3679
3680         ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, type);
3681         debug_log("service_add_extra_data: %d", ret);
3682         ret = service_add_extra_data(service, CT_UG_BUNDLE_ID, index);
3683         debug_log("service_add_extra_data: %d", ret);
3684
3685         create_ug(UG_CONTACTS_DETAILS, service, ug_data);
3686
3687         ret = service_destroy(service);
3688         debug_log("service_destroy: %d", ret);
3689
3690         debug_log("set flag for contact ug");
3691         ug_data->b_contact_ug_launched = TRUE;
3692 }
3693
3694 static void _ctxpopup_send_email_cb(void *data, Evas_Object *obj, void *event_info)
3695 {
3696         debug_log("");
3697         if (!data || !_g_ug_data) {
3698                 debug_log("data is NULL");
3699                 return;
3700         }
3701
3702         EmailViewerUGD *ug_data = _g_ug_data;
3703
3704         if (ug_data->con_popup == NULL) {
3705                 debug_log("con_popup is NULL");
3706                 return;
3707         }
3708
3709         if (ug_data->con_popup) {
3710                 evas_object_del(ug_data->con_popup);
3711                 ug_data->con_popup = NULL;
3712         }
3713
3714         debug_log("email: %s", (char *)data);
3715
3716         int ret;
3717         service_h service = NULL;
3718
3719         ret = service_create(&service);
3720         debug_log("service_create: %d", ret);
3721         if (!service) {
3722                 debug_log("service create failed");
3723                 return;
3724         }
3725
3726         char rtype[10] = { 0, };
3727         snprintf(rtype, sizeof(rtype), "%d", RUN_COMPOSER_EXTERNAL);
3728
3729         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
3730         debug_log("service_add_extra_data: %d", ret);
3731         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_TO, (char *)data);
3732         debug_log("service_add_extra_data: %d", ret);
3733         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CC, NULL);
3734         debug_log("service_add_extra_data: %d", ret);
3735         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_BCC, NULL);
3736         debug_log("service_add_extra_data: %d", ret);
3737         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_SUBJECT, NULL);
3738         debug_log("service_add_extra_data: %d", ret);
3739         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_BODY, NULL);
3740         debug_log("service_add_extra_data: %d", ret);
3741         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_ATTACHMENT, NULL);
3742         debug_log("service_add_extra_data: %d", ret);
3743
3744         ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
3745
3746         ret = service_destroy(service);
3747         debug_log("service_destroy: %d", ret);
3748 }
3749
3750 static void _ctxpopup_add_contact_cb(void *data, Evas_Object *obj, void *event_info)
3751 {
3752         debug_log("");
3753         if (!data || !_g_ug_data) {
3754                 debug_log("data is NULL");
3755                 return;
3756         }
3757
3758         char tmp[MAX_STR_LEN] = { 0, };
3759         EmailViewerUGD *ug_data = _g_ug_data;
3760
3761         if (ug_data->con_popup == NULL) {
3762                 debug_log("con_popup is NULL");
3763                 return;
3764         }
3765
3766         if (ug_data->con_popup) {
3767                 evas_object_del(ug_data->con_popup);
3768                 ug_data->con_popup = NULL;
3769         }
3770
3771         int ret;
3772         service_h service = NULL;
3773
3774         ret = service_create(&service);
3775         debug_log("service_create: %d", ret);
3776         if (!service) {
3777                 debug_log("service create failed");
3778                 return;
3779         }
3780
3781         if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_PHONE_NUMBER) {
3782                 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_NUM);
3783                 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3784                 debug_log("service_add_extra_data: %d", ret);
3785                 ret = service_add_extra_data(service, CT_UG_BUNDLE_NUM, (char *)data);
3786                 debug_log("service_add_extra_data: %d", ret);
3787         }
3788         if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_EMAIL) {
3789                 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_EMAIL);
3790                 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3791                 debug_log("service_add_extra_data: %d", ret);
3792                 ret = service_add_extra_data(service, CT_UG_BUNDLE_EMAIL, (char *)data);
3793                 debug_log("service_add_extra_data: %d", ret);
3794         }
3795         if (ug_data->create_contact_arg == CONTACTUI_REQ_ADD_URL) {
3796                 snprintf(tmp, sizeof(tmp), "%d", CT_UG_REQUEST_ADD_WITH_WEB);
3797                 ret = service_add_extra_data(service, CT_UG_BUNDLE_TYPE, tmp);
3798                 debug_log("service_add_extra_data: %d", ret);
3799                 ret = service_add_extra_data(service, CT_UG_BUNDLE_WEB, (char *)data);
3800                 debug_log("service_add_extra_data: %d", ret);
3801         }
3802
3803         create_ug(UG_CONTACTS_DETAILS, service, ug_data);
3804
3805         ret = service_destroy(service);
3806         debug_log("service_destroy: %d", ret);
3807 }
3808
3809 static void _ctxpopup_add_block_rule_cb(void *data, Evas_Object *obj, void *event_info)
3810 {
3811         debug_log("");
3812
3813         if (!data || !_g_ug_data) {
3814                 debug_log("data is NULL");
3815                 return;
3816         }
3817
3818         EmailViewerUGD *ug_data = _g_ug_data;
3819         EmailViewerPrivate *priv = ug_data->email_data;
3820         char *addr = (char *)data;
3821
3822         debug_log("Block address: %s", addr);
3823
3824         if (ug_data->con_popup) {
3825                 evas_object_del(ug_data->con_popup);
3826                 ug_data->con_popup = NULL;
3827         }
3828
3829         int ret;
3830         email_rule_t *rule = NULL;
3831
3832         /* add filtering rule */
3833         rule = malloc(sizeof(email_rule_t));
3834         rule->account_id = priv->account_id;
3835         rule->type = EMAIL_FILTER_FROM;
3836         rule->value = g_strdup(addr);
3837         rule->faction = EMAIL_FILTER_BLOCK;
3838
3839         int err = 0;
3840         email_mailbox_t *mail_box = NULL;
3841         if ((err = email_get_mailbox_by_mailbox_type(ug_data->account_id, ug_data->mailbox_type, &mail_box)) != EMAIL_ERROR_NONE) {
3842                 debug_log("email_get_mailbox_by_mailbox_type failed! - err (%d)", err);
3843         }
3844
3845         if (mail_box == NULL) {
3846                 debug_log("mail_box is NULL");
3847         }
3848
3849         rule->target_mailbox_id = mail_box->mailbox_id;
3850
3851         if (mail_box) {
3852                 debug_log("email_free_mailbox is called");
3853                 email_free_mailbox(&mail_box, 1);
3854                 mail_box = NULL;
3855         }
3856
3857         rule->flag1 = 1;
3858         rule->flag2 = RULE_TYPE_INCLUDES;
3859
3860         ret = email_add_rule(rule);
3861         if (ret < 0) {
3862                 debug_log("email_add_rule failed %d", ret);
3863                 _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3864                                                 _("IDS_EMAIL_POP_FAILED_TO_ADD_BLOCK_RULE"), 0,
3865                                                 NULL, NULL, NULL, NULL, _popup_response_cb);
3866         } else {
3867                 int vconf_ret = -1;
3868                 vconf_ret = vconf_set_int(EMAIL_VCONF_KEY_BLOCK_RULE_CHANGED, 1);
3869                 if (vconf_ret == -1) {
3870                         debug_log("fail to set vconf int(spam_rule_changed)");
3871                         _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
3872                                                         _("IDS_EMAIL_POP_FAILED_TO_ADD_BLOCK_RULE"), 0,
3873                                                         NULL, NULL, NULL, NULL, _popup_response_cb);
3874                 } else {
3875                         char str[128] = { 0, };
3876                         snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_BLOCKED"));
3877                         ret = status_message_post(str);
3878                         if (ret)
3879                                 debug_log("status_message_post failed: %d", ret);
3880                 }
3881         }
3882
3883         email_free_rule(&rule, 1);
3884 }
3885
3886 static void _popup_waiting_response_cb(void *data, Evas_Object *obj, void *event_info)
3887 {
3888         debug_log("");
3889         if (!_g_ug_data) {
3890                 debug_log("_g_ug_data is NULL");
3891                 return;
3892         }
3893
3894         if (!data) {
3895                 debug_log("data is NULL");
3896                 return;
3897         }
3898
3899         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3900
3901         if (ug_data->timeout_popup) {
3902                 evas_object_del(ug_data->timeout_popup);
3903                 ug_data->timeout_popup = NULL;
3904         }
3905 }
3906
3907 static void _popup_response_cb(void *data, Evas_Object *obj, void *event_info)
3908 {
3909         debug_log("");
3910         if (!_g_ug_data) {
3911                 debug_log("_g_ug_data is NULL");
3912                 return;
3913         }
3914
3915         if (!data) {
3916                 debug_log("data is NULL");
3917                 return;
3918         }
3919
3920         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3921
3922         if (ug_data->notify) {
3923                 evas_object_del(ug_data->notify);
3924                 ug_data->notify = NULL;
3925         }
3926 }
3927
3928 static void _popup_response_delete_ok_cb(void *data, Evas_Object *obj, void *event_info)
3929 {
3930         debug_log("");
3931         if (!_g_ug_data) {
3932                 debug_log("_g_ug_data is NULL");
3933                 return;
3934         }
3935
3936         if (!data) {
3937                 debug_log("data is NULL");
3938                 return;
3939         }
3940
3941         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3942
3943         if (ug_data->notify) {
3944                 evas_object_del(ug_data->notify);
3945                 ug_data->notify = NULL;
3946         }
3947
3948         if (ug_data->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH)
3949                 _delete_email(ug_data);
3950         else
3951                 _move_email(ug_data, _find_folder_id_using_folder_type(ug_data, EMAIL_MAILBOX_TYPE_TRASH), TRUE);
3952
3953         if (ug_data->isRotate == false && ug_data->b_internal) {
3954                 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
3955         }
3956
3957         /* close viewer */
3958         if (ug_data->b_internal) {
3959                 _hide_view(ug_data);
3960
3961                 /* send next or previous mail request to mailbox. */
3962                 int ret;
3963                 service_h service = NULL;
3964
3965                 ret = service_create(&service);
3966                 debug_log("service_create: %d", ret);
3967                 if (!service) {
3968                         debug_log("service create failed");
3969                         return;
3970                 }
3971
3972                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
3973                 debug_log("service_add_extra_data: %d", ret);
3974                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "1");
3975                 debug_log("service_add_extra_data: %d", ret);
3976
3977                 ug_send_message(_g_mailbox_ug, service);
3978
3979                 ret = service_destroy(service);
3980                 debug_log("service_destroy: %d", ret);
3981         } else
3982                 ug_destroy_me(ug_data->ug);
3983 }
3984
3985 static void _popup_response_to_destroy_cb(void *data, Evas_Object *obj, void *event_info)
3986 {
3987         debug_log("");
3988
3989         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
3990         evas_object_del(obj);
3991
3992         ug_data->b_direct_destroy = 1;
3993         ug_destroy_me(ug_data->ug);
3994         _g_ug_data = NULL;
3995 }
3996
3997 static void _webview_multi_up_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
3998 {
3999         debug_log("");
4000         if (_g_ug_data == NULL)
4001                 return;
4002
4003         if (!data) {
4004                 debug_log("data is NULL");
4005                 return;
4006         }
4007
4008         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4009
4010         ug_data->m_is_multi_touch = FALSE;
4011
4012         if (ug_data->scroller_locked) {
4013                 ug_data->scroller_locked = FALSE;
4014                 debug_log("<<unlock scroller>>");
4015                 debug_log("<<lock webview>>");
4016         }
4017 }
4018
4019 static void _webview_multi_down_cb(void *data, Evas * evas, Evas_Object *obj, void *event_info)
4020 {
4021         debug_log("");
4022         if (_g_ug_data == NULL)
4023                 return;
4024
4025         if (!data) {
4026                 debug_log("data is NULL");
4027                 return;
4028         }
4029
4030         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4031
4032         ug_data->m_is_multi_touch = TRUE;
4033         if (ug_data->scroller_locked == FALSE) {
4034                 ug_data->scroller_locked = TRUE;
4035                 debug_log("<<lock scroller>>");
4036                 debug_log("<<unlock webview>>");
4037         }
4038 }
4039
4040 static void _webview_policy_navigation_decide_cb(void *data, Evas_Object *obj, void *event_info)
4041 {
4042         debug_log("");
4043         if (!_g_ug_data) {
4044                 debug_log("data is NULL");
4045                 return;
4046         }
4047
4048         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4049         Ewk_Policy_Decision *policy_decision = (Ewk_Policy_Decision *)event_info;
4050         Ewk_Policy_Navigation_Type pd_type = ewk_policy_decision_navigation_type_get(policy_decision);
4051         debug_log("Ewk_Policy_Navigation_Type:%d", pd_type);
4052
4053         const char *uri = NULL;
4054         uri = ewk_view_uri_get(ug_data->webview);
4055         debug_log("ewk_view_uri_get(%s)", uri);
4056
4057         if (ug_data->b_load_finished == EINA_TRUE) {
4058                 ewk_policy_decision_ignore(policy_decision);
4059
4060                 debug_log("url:%s", ewk_policy_decision_url_get(policy_decision));
4061                 debug_log("scheme:%s", ewk_policy_decision_scheme_get(policy_decision));
4062                 debug_log("cookie:%s", ewk_policy_decision_cookie_get(policy_decision));
4063                 debug_log("host:%s", ewk_policy_decision_host_get(policy_decision));
4064                 debug_log("response_mime:%s", ewk_policy_decision_response_mime_get(policy_decision));
4065
4066                 char *url = (char *)ewk_policy_decision_url_get(policy_decision);
4067
4068                 if ((strncmp(url, "http://", 7) == 0) ||
4069                         (strncmp(url, "https://", 8) == 0) ||
4070                         (strncmp(url, "ftp://", 6) == 0) ||
4071                         (strncmp(url, "mms://", 6) == 0) ||
4072                         (strncmp(url, "file://", 7) == 0) ||
4073                         (strncmp(url, "rtsp://", 7) == 0) ||
4074                         (strncmp(url, "wap://", 6) == 0)) {
4075                         int ret;
4076                         service_h service = NULL;
4077                         ret = service_create(&service);
4078                         debug_log("service_create: %d", ret);
4079                         if (!service) {
4080                                 debug_log("service create failed");
4081                                 return;
4082                         }
4083                         ret = service_set_operation(service, SERVICE_OPERATION_VIEW);
4084                         debug_log("service_set_operation: %d", ret);
4085                         ret = service_set_uri(service, url);
4086                         debug_log("service_set_uri: %d", ret);
4087                         ret = service_send_launch_request(service, NULL, NULL);
4088                         debug_log("service_send_launch_request: %d", ret);
4089                         ret = service_destroy(service);
4090                         debug_log("service_destroy: %d", ret);
4091                 }
4092
4093                 if (strncmp(url, "tel:", 4) == 0) {
4094                         char refined_num[MAX_STR_LEN] = { 0, };
4095                         int i = 0, j = 0;
4096
4097                         while (url[i] != '\0') {
4098                                 if (url[i] >= '0' && url[i] <= '9')
4099                                         refined_num[j++] = url[i];
4100                                 i++;
4101                         }
4102
4103                         char *number = refined_num;
4104                         debug_log("number: %s", number);
4105
4106                         int ret;
4107                         service_h service = NULL;
4108                         char telnum[255] = { 0, };
4109                         ret = service_create(&service);
4110                         debug_log("service_create: %d", ret);
4111                         if (!service) {
4112                                 debug_log("service create failed");
4113                                 return;
4114                         }
4115                         ret = service_set_operation(service, SERVICE_OPERATION_CALL);
4116                         debug_log("service_set_operation: %d", ret);
4117                         snprintf(telnum, sizeof(telnum), "tel:%s", number); /* Number to make a call */
4118                         ret = service_set_uri(service, telnum);
4119                         debug_log("service_set_uri: %d", ret);
4120                         ret = service_add_extra_data(service, "ctindex", "-1"); /* If you don't know ctindex, you don't have to add it. */
4121                         debug_log("service_add_extra_data: %d", ret);
4122                         ret = service_send_launch_request(service, NULL, NULL);
4123                         debug_log("service_send_launch_request: %d", ret);
4124                         ret = service_destroy(service);
4125                         debug_log("service_destroy: %d", ret);
4126                 }
4127
4128                 if (strncmp(url, "mailto:", 7) == 0) {
4129                         int ret;
4130                         service_h service = NULL;
4131                         ret = service_create(&service);
4132                         debug_log("service_create: %d", ret);
4133                         if (!service) {
4134                                 debug_log("service create failed");
4135                                 return;
4136                         }
4137
4138                         char rtype[10] = { 0, };
4139                         snprintf(rtype, sizeof(rtype), "%d", RUN_COMPOSER_EXTERNAL);
4140
4141                         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_RUN_TYPE, rtype);
4142                         debug_log("service_add_extra_data: %d", ret);
4143                         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_TO, &url[7]);
4144                         debug_log("service_add_extra_data: %d", ret);
4145
4146                         ug_data->ug_composer = create_ug(UG_NAME_EMAIL_COMPOSER, service, ug_data);
4147
4148                         ret = service_destroy(service);
4149                         debug_log("service_destroy: %d", ret);
4150                 }
4151         } else {
4152                 if (ug_data->timeout_popup) {
4153                         evas_object_del(ug_data->timeout_popup);
4154                         ug_data->timeout_popup = NULL;
4155                 }
4156                 _create_waiting_popup(ug_data, _("IDS_EMAIL_POP_LOADING_CONTENTS_ING"), "list_process");
4157
4158                 if (pd_type == EWK_POLICY_NAVIGATION_TYPE_LINK_CLICKED) {
4159                         debug_log("Link click is ignored.");
4160                         ewk_policy_decision_ignore(policy_decision);
4161                         return;
4162                 }
4163         }
4164 }
4165
4166 /* Double_Scroller */
4167 static void _outter_scroller_bottom_hit_cb(void *data, Evas_Object *obj, void *event_info)
4168 {
4169         debug_log("");
4170
4171         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4172         int res = email_engine_check_body_download(ug_data->email_data->mail_id);
4173
4174         if (ug_data->is_main_scroller_scrolling && res != 0) {
4175                 debug_log("Main scroller hold push");
4176                 elm_object_scroll_freeze_push(ug_data->scroller);       //stop
4177                 ewk_view_vertical_panning_hold_set(ug_data->webview, EINA_FALSE);       //restart
4178                 ug_data->is_main_scroller_scrolling = EINA_FALSE;
4179                 ug_data->is_webview_scrolling = EINA_TRUE;
4180         }
4181 }
4182
4183 static void _outter_scroller_top_hit_cb(void *data, Evas_Object *obj, void *event_info)
4184 {
4185         debug_log("");
4186 }
4187
4188 static void _outter_scroller_scroll_cb(void *data, Evas_Object *obj, void *event_info)
4189 {
4190         debug_log("");
4191         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4192
4193         ug_data->is_main_scroller_scrolling = EINA_TRUE;
4194 }
4195
4196 static void _mbe_focused_cb(void *data, Evas_Object *obj, void *event_info)
4197 {
4198         debug_log("");
4199         Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(obj);
4200         elm_multibuttonentry_item_selected_set(item, EINA_FALSE);
4201 }
4202
4203 static void _mbe_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
4204 {
4205         debug_log("");
4206 }
4207
4208 static void _mbe_added_cb(void *data, Evas_Object *obj, void *event_info)
4209 {
4210         debug_log("");
4211 }
4212
4213 static void _mbe_selected_cb(void *data, Evas_Object *obj, void *event_info)
4214 {
4215         debug_log("");
4216         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4217         email_address_info_t *addrs_info = NULL;
4218         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
4219         debug_log("selected item:%s", elm_object_item_text_get(item));
4220
4221         addrs_info = elm_object_item_data_get(item);
4222
4223         Evas_Coord x, y;
4224         EMAIL_CONTACT_LIST_INFO_S *contact_list_item = NULL;
4225         contact_list_item = (EMAIL_CONTACT_LIST_INFO_S *)_contact_search_by_email(ug_data, addrs_info->address);
4226
4227         if (ug_data->con_popup != NULL) {
4228                 evas_object_del(ug_data->con_popup);
4229                 ug_data->con_popup = NULL;
4230         }
4231
4232         ug_data->con_popup = elm_ctxpopup_add(ug_data->navi_bar);
4233         if (ug_data->con_popup == NULL) {
4234                 debug_log("cannot create context popup");
4235                 return;
4236         }
4237
4238         if (contact_list_item) {
4239                 debug_log("Contact Item Exist: index[%d]", contact_list_item->index);
4240                 char index[10] = { 0, };
4241                 snprintf(index, sizeof(index), "%d", contact_list_item->index);
4242
4243                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_VIEW_CONTACT"), NULL, _ctxpopup_detail_contact_cb, g_strdup(index));
4244                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SEND_EMAIL"), NULL, _ctxpopup_send_email_cb, addrs_info->address);
4245                 ug_data->ctx_block_item = elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_BLOCK"), NULL, _ctxpopup_add_block_rule_cb, addrs_info->address);
4246                 _delete_contacts_list(contact_list_item);
4247         } else {
4248                 elm_ctxpopup_item_append(ug_data->con_popup, dgettext("sys_string", "IDS_COM_OPT_ADD_TO_CONTACTS"), NULL, _ctxpopup_add_contact_cb, addrs_info->address);
4249                 elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_SEND_EMAIL"), NULL, _ctxpopup_send_email_cb, addrs_info->address);
4250                 ug_data->ctx_block_item = elm_ctxpopup_item_append(ug_data->con_popup, _("IDS_EMAIL_OPT_BLOCK"), NULL, _ctxpopup_add_block_rule_cb, addrs_info->address);
4251         }
4252
4253         int count, i;
4254         email_rule_t *rule_list = NULL;
4255
4256         /* get the rule list from service */
4257         if (email_get_rule_list(&rule_list, &count) < 0) {
4258                 debug_log("email_get_rule_list failed");
4259         } else {
4260                 if (count > 0) {
4261                         for (i = 0; i < count; i++) {
4262                                 if (rule_list[i].type == EMAIL_FILTER_FROM/*TYPE_BLOCK_ADDRESS*/) {
4263                                         debug_log("block address %s", rule_list[i].value);
4264
4265                                         if (g_strcmp0(rule_list[i].value, addrs_info->address) == 0) {
4266                                                 debug_log("[%s] already blocked", rule_list[i].value);
4267                                                 if (ug_data->ctx_block_item)
4268                                                         elm_object_item_disabled_set(ug_data->ctx_block_item, EINA_TRUE);
4269                                         }
4270                                 }
4271                         }
4272                 }
4273                 /* free email rule_list */
4274                 email_free_rule(&rule_list, count);
4275         }
4276
4277         evas_pointer_canvas_xy_get(ug_data->evas, &x, &y);
4278                 debug_log("canvas x:%d, y:%d", x, y);
4279         evas_object_move(ug_data->con_popup, x, y);
4280         evas_object_show(ug_data->con_popup);
4281 }
4282
4283 static void _destroy_down_progress_cb(void *data, Evas_Object *obj, void *event_info)
4284 {
4285         debug_log("");
4286
4287         if (!_g_ug_data) {
4288                 debug_log("data is NULL");
4289                 return;
4290         }
4291
4292         EmailViewerUGD *ug_data = _g_ug_data;
4293         EmailViewerPrivate *priv = ug_data->email_data;
4294
4295         email_engine_stop_working(ug_data->account_id, priv->email_handle);
4296
4297         if (ug_data->pb_notify) {
4298                 evas_object_del(ug_data->pb_notify);
4299                 ug_data->pb_notify = NULL;
4300         }
4301
4302         if (ug_data->pb_notify_lb) {
4303                 evas_object_del(ug_data->pb_notify_lb);
4304                 ug_data->pb_notify_lb = NULL;
4305         }
4306
4307         if (data == NULL) {
4308                 if (priv->att_file_id) {
4309                         free(priv->att_file_id);
4310                         priv->att_file_id = NULL;
4311                 }
4312
4313                 priv->file_size = 0;
4314                 priv->attachment_id = -1;
4315                 priv->multi_body = FALSE;
4316         }
4317 }
4318
4319 static void _init_viewer_data(int account_id, int mail_id, char *srv_mail_id, EmailViewerUGD *ug_data)
4320 {
4321         debug_log("");
4322         EmailViewerPrivate *priv = NULL;
4323         EmailViewerProp *prop = NULL;
4324         email_address_info_list_t *addrs_info_list = NULL;
4325
4326         /* Create Email Viewer Private Structure */
4327         if (ug_data->email_data) {
4328                 if (ug_data->email_data->mail_info) {
4329                         debug_log("mail_info freed");
4330                         email_free_mail_data(&(ug_data->email_data->mail_info), 1);
4331                         ug_data->email_data->mail_info = NULL;
4332                 }
4333
4334                 if (ug_data->email_data->attachment_info && ug_data->email_data->attachment_count > 0) {
4335                         debug_log("attachment_info freed p[%p] n[%d]", ug_data->email_data->attachment_info, ug_data->email_data->attachment_count);
4336                         email_free_attachment_data(&(ug_data->email_data->attachment_info), ug_data->email_data->attachment_count);
4337                         ug_data->email_data->attachment_info = NULL;
4338                         ug_data->email_data->attachment_count = 0;
4339                 }
4340
4341                 memset(ug_data->email_data, 0x0, sizeof(EmailViewerPrivate));
4342                 priv = ug_data->email_data;
4343         } else {
4344                 priv = (EmailViewerPrivate *)malloc(sizeof(EmailViewerPrivate));
4345                 memset(priv, 0x0, sizeof(EmailViewerPrivate));
4346                 ug_data->email_data = priv;
4347         }
4348
4349         /* Create Email Viewer Property Structure */
4350         if (ug_data->property) {
4351                 if (ug_data->property->attachments) {
4352                         int i = 0;
4353                         LIST_ITER_START(i, ug_data->property->attachments) {
4354                                 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, ug_data->property->attachments);
4355                                 if (info->name)
4356                                         free(info->name);
4357                                 if (info->path)
4358                                         free(info->path);
4359                                 free(info);
4360                         }
4361                         g_list_free(ug_data->property->attachments);
4362                 }
4363                 memset(ug_data->property, 0x0, sizeof(EmailViewerProp));
4364                 prop = ug_data->property;
4365         } else {
4366                 prop = (EmailViewerProp *)malloc(sizeof(EmailViewerProp));
4367                 memset(prop, 0x0, sizeof(EmailViewerProp));
4368                 ug_data->property = prop;
4369         }
4370
4371         /* Set account ID */
4372         priv->account_id = account_id;
4373         prop->account_id = account_id;
4374
4375         /* Set mail ID */
4376         priv->mail_id = mail_id;
4377         prop->mail_id = mail_id;
4378
4379         priv->mailbox_id = ug_data->mailbox_id;
4380         prop->src_box = ug_data->mailbox_name;
4381         debug_log("mailbox_name [%s]", ug_data->mailbox_name);
4382
4383         /* Get mail_info from service, and fill property */
4384         if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
4385                 viewer_make_internal_mail(ug_data->property, ug_data->email_data);
4386         }
4387
4388         email_get_address_info_list(priv->mail_id, &addrs_info_list);
4389
4390         if (addrs_info_list) {
4391                 ug_data->from_list = addrs_info_list->from;
4392                 ug_data->to_list = addrs_info_list->to;
4393                 ug_data->cc_list = addrs_info_list->cc;
4394                 ug_data->bcc_list = addrs_info_list->bcc;
4395                 priv->addrs_info_list = addrs_info_list;
4396         }
4397
4398         ug_data->option_header_opened = 0;
4399 }
4400
4401 static int _init_webview_data(EmailViewerUGD *ug_data)
4402 {
4403         debug_log("");
4404
4405         EmailViewerWebview *wvd;
4406
4407         if (ug_data->webview_data == NULL) {
4408                 wvd = (EmailViewerWebview *)malloc(sizeof(EmailViewerWebview));
4409                 memset(wvd, 0x0, sizeof(EmailViewerWebview));
4410                 ug_data->webview_data = wvd;
4411         }
4412
4413         if (STR_VALID(ug_data->property->charset)) {
4414                 ug_data->webview_data->charset = g_strdup(ug_data->property->charset);
4415                 debug_log("charset:%s", ug_data->webview_data->charset);
4416         } else {
4417                 ug_data->webview_data->charset = DEFAULT_CHARSET;
4418                 debug_log("charset:%s", ug_data->webview_data->charset);
4419         }
4420
4421         return 0;
4422 }
4423
4424 static Eina_Bool _check_body_download(void *data)
4425 {
4426         debug_log("");
4427         if (!data) {
4428                 debug_log("data is NULL");
4429                 return ECORE_CALLBACK_CANCEL;
4430         }
4431
4432         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
4433
4434         _create_tab_bar(ug_data);
4435
4436         /* check mail body downloaded */
4437         int body_download_status = ug_data->property->body_download;
4438
4439         if (body_download_status == 0) {        //EMAIL_BODY_DOWNLOAD_STATUS_NONE
4440                 debug_log("need body download");
4441                 ug_data->b_noc = 1;     /* Double_Scroller */
4442
4443                 if (ug_data->noc_bx) {
4444                         debug_log("no content layout exist");
4445                         evas_object_show(ug_data->noc_bx);
4446                         elm_object_text_set(ug_data->dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_MESSAGE"));
4447                         evas_object_show(ug_data->dn_btn);
4448                         elm_box_pack_end(ug_data->main_bx, ug_data->noc_bx);
4449                 } else {
4450                         /* add body download button */
4451                         ug_data->noc_bx = _load_edj(ug_data->navi_bar, EV_THEME_PATH, "layout.email.no_content");
4452                         if (ug_data->noc_bx == NULL) {
4453                                 debug_log("Cannot load edj");
4454                                 return ECORE_CALLBACK_CANCEL;
4455                         }
4456
4457                         evas_object_size_hint_align_set(ug_data->noc_bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
4458                         evas_object_size_hint_weight_set(ug_data->noc_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
4459                         evas_object_show(ug_data->noc_bx);
4460                         elm_box_pack_end(ug_data->main_bx, ug_data->noc_bx);
4461
4462                         Evas_Object *dn_btn = elm_button_add(ug_data->navi_bar);
4463                         /*elm_object_theme_set(dn_btn, ug_data->theme);*/
4464                         elm_object_style_set(dn_btn, "text_only/style2");
4465                         elm_object_text_set(dn_btn, _("IDS_EMAIL_BODY_DOWNLOAD_MESSAGE"));
4466                         evas_object_smart_callback_add(dn_btn, "clicked", _body_down_cb, (void *)ug_data);
4467                         evas_object_show(dn_btn);
4468                         ug_data->dn_btn = dn_btn;
4469
4470                         elm_object_part_content_set(ug_data->noc_bx, "btn", ug_data->dn_btn);
4471                         debug_log("no content layout created");
4472                 }
4473
4474                 elm_object_focus_set(ug_data->noc_bx, EINA_TRUE);
4475                 if (ug_data->timer) {
4476                         ecore_timer_del(ug_data->timer);
4477                         ug_data->timer = NULL;
4478                 }
4479
4480                 ug_data->timer = ecore_timer_add(0.0, viewer_send_message, ug_data);
4481         } else if (body_download_status == 1) { //EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED
4482                 debug_log("check mail downloaded - ok");
4483                 /* create body */
4484                 _create_body(ug_data);
4485         } else if (body_download_status == 2) { //EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED
4486                 /* partial body */
4487                 debug_log("Partial Body");
4488                 ug_data->b_partial_body = 1;
4489                 _create_body(ug_data);
4490                 _create_partial_body_dn_btn(ug_data);
4491         }
4492
4493         return ECORE_CALLBACK_CANCEL;
4494 }
4495
4496 static int _update_attachment_info(EmailViewerUGD *ug_data, int index)
4497 {
4498         debug_log("");
4499         EmailViewerProp *prop = ug_data->property;
4500         int i = 0;
4501         int j = 0;
4502         int attach_index = 0;
4503
4504         /* update attachment information */
4505         LIST_ITER_START(i, prop->attachments) {
4506                 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, prop->attachments);
4507
4508                 if (info && !info->inline_content) {
4509                         debug_log("info->index[%d] index[%d]", info->index, index);
4510
4511                         if (info->index == index) {
4512                                 info->download_yn = TRUE;
4513                                 info->path = email_engine_get_attachment_path(info->attach_id);
4514
4515                                 attach_index = i;
4516
4517                                 if (prop->real_att_len > 1) {
4518                                         Evas_Object *thumbnail = viewer_make_thumbnail(info->path, ug_data->attach_ex_bk[j]);
4519                                         Evas_Object *content = elm_object_part_content_unset(ug_data->attach_ex_bk[j], "elm.icon");
4520                                         evas_object_del(content);
4521                                         elm_object_part_content_set(ug_data->attach_ex_bk[j], "elm.icon", thumbnail);
4522                                         evas_object_show(thumbnail);
4523                                 } else {
4524                                         Evas_Object *thumbnail = viewer_make_thumbnail(info->path, ug_data->attach_hd_bk);
4525                                         Evas_Object *content = elm_object_part_content_unset(ug_data->attach_hd_bk, "elm.icon");
4526                                         evas_object_del(content);
4527                                         elm_object_part_content_set(ug_data->attach_hd_bk, "elm.icon", thumbnail);
4528                                         evas_object_show(thumbnail);
4529                                 }
4530
4531                                 break;
4532                         }
4533
4534                         j++;
4535                 }
4536         }
4537
4538         debug_log("return id[%d]", attach_index);
4539
4540         return attach_index;
4541 }
4542
4543 static int _get_attachment_info_index(EmailViewerUGD *ug_data, int index)
4544 {
4545         debug_log("");
4546
4547         EmailViewerProp *prop = ug_data->property;
4548         int i = 0;
4549         int attach_index = 0;
4550
4551         /* update attachment information */
4552         LIST_ITER_START(i, prop->attachments) {
4553                 EmailAttachmentType *info = (EmailAttachmentType *)LIST_ITER_GET_DATA(i, prop->attachments);
4554                 if (info) {
4555                         debug_log("info->index[%d] index[%d]", info->index, index);
4556                         if (info->index == index) {
4557                                 attach_index = i;
4558                                 break;
4559                         }
4560                 }
4561         }
4562
4563         debug_log("return id[%d]", attach_index);
4564
4565         return attach_index;
4566 }
4567
4568 static void _show_select_info(EmailViewerUGD *ug_data, char *str)
4569 {
4570         debug_log("");
4571
4572         if (ug_data->select_info != NULL) {
4573                 evas_object_del(ug_data->select_info);
4574                 ug_data->select_info = NULL;
4575         }
4576
4577         if (ug_data->selectioninfo_layout != NULL) {
4578                 evas_object_del(ug_data->selectioninfo_layout);
4579                 ug_data->selectioninfo_layout = NULL;
4580         }
4581
4582         ug_data->select_info = elm_notify_add(ug_data->win_main);
4583         elm_notify_orient_set(ug_data->select_info, ELM_NOTIFY_ORIENT_BOTTOM);
4584
4585         ug_data->selectioninfo_layout = elm_layout_add(ug_data->layout_main);
4586         elm_object_content_set(ug_data->select_info, ug_data->selectioninfo_layout);
4587
4588         elm_layout_theme_set(ug_data->selectioninfo_layout, "standard", "selectioninfo", "vertical/bottom_64");
4589
4590         edje_object_part_text_set(_EDJ(ug_data->selectioninfo_layout), "elm.text", str);
4591         elm_notify_timeout_set(ug_data->select_info, 3);
4592         evas_object_show(ug_data->select_info);
4593 }
4594
4595 static void _save_attachment(EmailViewerUGD *ug_data, int index)
4596 {
4597         debug_log("");
4598         EmailViewerPrivate *priv = ug_data->email_data;
4599         EmailViewerProp *prop = ug_data->property;
4600         char newpath[MAX_PATH_LEN] = { 0, };
4601
4602         RETURN_IF_FAIL(prop->attachments != NULL);
4603         EmailAttachmentType *info = g_list_nth_data(prop->attachments, index);
4604
4605         if (info == NULL) {
4606                 debug_log("EmailAttachmentType *info is NULL");
4607                 return;
4608         }
4609
4610         if (!info->download_yn) {
4611                 int handle = 0;
4612                 gboolean res = FALSE;
4613
4614                 if (ug_data->progress_bar[index + 1] != NULL) {
4615                         debug_log("Already getting downloaded...!");
4616                         _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4617                                                         _("IDS_EMAIL_POP_ALREADY_DOWNLOADING_T_HEADER"), 1,
4618                                                         dgettext("sys_string", "IDS_COM_SK_OK"),
4619                                                         _popup_response_cb, NULL, NULL, NULL);
4620                         return;
4621                 }
4622
4623                 debug_log("Need attachment download");
4624                 /* download attachment */
4625                 priv->b_att_save = TRUE;
4626
4627                 res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4628
4629                 if (res == TRUE) {
4630                         priv->download_all_cnt++;
4631                         debug_log("Assigning Handle[%d] Index[%d] download_all_cnt[%d]", handle, index, priv->download_all_cnt);
4632                         priv->download_all_email_handle[index] = handle;
4633                         _create_down_progress_ex(index, EMAIL_VIEWER_PROGRESSBAR_ATT);
4634                         ug_data->display_download_result = TRUE;
4635                 } else {
4636                         priv->b_att_save = FALSE;
4637                         _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4638                                                         _("IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"), 1,
4639                                                         dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
4640                                                         NULL, NULL, NULL);
4641                 }
4642
4643                 return;
4644         }
4645
4646         if (info && STR_VALID(info->path)) {
4647                 int ret;
4648                 debug_log("path[%s]", info->path);
4649                 ret = email_attachments_save_file(info->path, newpath, NULL);
4650                 if (ret == EMAIL_EXT_SAVE_ERR_NONE) {
4651                         char str[128] = { 0, };
4652                         snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_POP_SAVED"));
4653                         ret = status_message_post(str);
4654                         if (ret)
4655                                 debug_log("status_message_post failed: %d", ret);
4656                 }
4657         }
4658 }
4659
4660 static void _show_attachment(EmailViewerUGD *ug_data, int index)
4661 {
4662         debug_log("");
4663         EmailViewerPrivate *priv = ug_data->email_data;
4664         EmailViewerProp *prop = ug_data->property;
4665         EmailAttachmentType *info = g_list_nth_data(prop->attachments, index);
4666         char newpath[MAX_PATH_LEN] = { 0, };
4667
4668         if (info == NULL) {
4669                 debug_log("EmailAttachmentType *info is NULL");
4670                 return;
4671         }
4672
4673         debug_log("attach_id:%d, index:%d, name(%s), path(%s), size:%d, download_yn:%d, drm:%d, inline_content:%d",
4674                 info->attach_id, info->index, info->name, info->path, (gint) info->size, info->download_yn, info->drm, info->inline_content);
4675
4676         if (!info->download_yn) {
4677                 int handle = 0;
4678                 gboolean res = FALSE;
4679                 debug_log("Need attachment download");
4680
4681                 priv->b_att_open = TRUE;
4682
4683                 res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4684
4685                 if (res == TRUE) {
4686                         priv->download_all_email_handle[index] = handle;
4687                         priv->download_all_cnt++;
4688                         _create_down_progress_ex(index, EMAIL_VIEWER_PROGRESSBAR_ATT);
4689                 } else {
4690                         priv->b_att_open = FALSE;
4691                         _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4692                                                         _("IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"), 1,
4693                                                         dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
4694                                                         NULL, NULL, NULL);
4695                 }
4696                 return;
4697         }
4698
4699                 gboolean res = FALSE;
4700                 res = email_attachments_save_file(info->path, newpath, NULL);
4701                 debug_log("Result:%d, Saved Path:%s", res, newpath);
4702
4703                 if (res == EMAIL_EXT_SAVE_ERR_NONE) {
4704                         char str[128] = { 0, };
4705                         snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_POP_SAVED"));
4706                         int ret = status_message_post(str);
4707                         if (ret)
4708                                 debug_log("status_message_post failed: %d", ret);
4709
4710                         if (g_str_has_suffix(info->path, ".vcs")) {
4711                                 calendar_connect();
4712
4713                                 FILE * fp = NULL;
4714                                 fp = fopen(newpath, "r");
4715                                 if (!fp) {
4716                                         debug_error("fopen(%s) is failed.", newpath);
4717                                         calendar_disconnect();
4718                                         return;
4719                                 }
4720
4721                                 struct stat st;
4722                                 if (stat(newpath, &st) == -1) {
4723                                         debug_error("file(%s), stat Error(%d): %s", newpath, errno, strerror(errno));
4724                                         fclose(fp);
4725                                         calendar_disconnect();
4726                                         return;
4727                                 }
4728
4729                                 int size = st.st_size;
4730                                 char *raw_data = calloc(size + 1, sizeof(char));
4731                                 if (!raw_data) {
4732                                         debug_error("calloc is failed.");
4733                                         fclose(fp);
4734                                         calendar_disconnect();
4735                                         return;
4736                                 }
4737
4738                                 size_t n = 0;
4739                                 if ((n = fread(raw_data, 1, size, fp)) != size) {
4740                                         debug_error("error in fread");
4741                                         g_free(raw_data);
4742                                         fclose(fp);
4743                                         calendar_disconnect();
4744                                         return;
4745                                 }
4746
4747                                 fclose(fp);
4748
4749                                 calendar_list_h list = NULL;
4750
4751                                 ret = calendar_vcalendar_parse_to_calendar(raw_data, &list);
4752
4753                                 if( list && ret == CALENDAR_ERROR_NONE) {
4754                                         calendar_db_insert_records(list, NULL, NULL);
4755                                         debug_log("vcalendar is registered to calendar");
4756                                 }
4757
4758                                 g_free(raw_data);
4759                                 calendar_disconnect();
4760                         } else
4761                                 media_file_register(newpath);
4762                 } else if (res == EMAIL_EXT_SAVE_ERR_ALREADY_EXIST && !ug_data->display_download_result) {
4763                         _create_notify(ug_data, _("IDS_EMAIL_POP_ALERT"),
4764                                                         dgettext("sys_string", "IDS_COM_POP_ALREDY_EXISTS"), 0,
4765                                                         NULL, NULL, NULL, NULL, _popup_response_cb);
4766                 }
4767
4768         debug_log("display_download_result:%d", ug_data->display_download_result);
4769         if (ug_data->display_download_result) {
4770                 if (res == EMAIL_EXT_SAVE_ERR_NONE || res == EMAIL_EXT_SAVE_ERR_ALREADY_EXIST) {
4771                         int ret;
4772                         service_h service = NULL;
4773                         ret = service_create(&service);
4774                         debug_log("service_create: %d", ret);
4775                         if (!service) {
4776                                 debug_log("service create failed");
4777                                 return;
4778                         }
4779                         ret = service_set_operation(service, SERVICE_OPERATION_VIEW);
4780                         debug_log("service_set_operation: %d", ret);
4781                         ret = service_set_uri(service, newpath);
4782                         debug_log("service_set_uri: %d", ret);
4783                         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_VIDEO_PLAYER_LAUNCH_APP, "email");
4784                         debug_log("service_add_extra_data: %d", ret);
4785                         ret = service_send_launch_request(service, NULL, NULL);
4786                         debug_log("service_send_launch_request: %d", ret);
4787                         if (ret != SERVICE_ERROR_NONE) {
4788                                 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
4789                                                                 _("IDS_EMAIL_POP_THIS_ATTACHMENT_CANNOT_BE_DISPLAYED"), 0,
4790                                                                 NULL, NULL, NULL, NULL, _popup_response_cb);
4791                         }
4792                         ret = service_destroy(service);
4793                         debug_log("service_destroy: %d", ret);
4794                 } else {
4795                         debug_log("EMAIL_EXT_SAVE_ERR_UNKNOWN");
4796                 }
4797         }
4798 }
4799
4800 static void _save_attachment_all(EmailViewerUGD *ug_data)
4801 {
4802         debug_log("");
4803         EmailViewerPrivate *priv = ug_data->email_data;
4804         EmailViewerProp *prop = ug_data->property;
4805         EmailAttachmentType *info = NULL;
4806
4807         int i = 0;
4808         int att_len = g_list_length(prop->attachments);
4809
4810         if (priv->b_all_att_save)
4811                 return;
4812
4813         if (att_len > 0) {
4814                 if (ug_data->forward_ctr_it)
4815                         elm_object_item_disabled_set(ug_data->forward_ctr_it, EINA_TRUE);
4816         }
4817
4818         for (i = 0; i < att_len; i++) {
4819                 info = g_list_nth_data(prop->attachments, i);
4820
4821                 if (info && !info->inline_content) {
4822                         if (!info->download_yn) {
4823                                 if (ug_data->progress_bar_ly[i + 1] == NULL) {
4824                                         int handle = 0;
4825                                         gboolean res = FALSE;
4826                                         debug_log("Need attachment [%d] download", i);
4827
4828                                         res = email_engine_attachment_download(priv->account_id, priv->mail_id, info->index, &handle);
4829
4830                                         if (res == TRUE) {
4831                                                 priv->download_all_cnt++;
4832                                                 priv->download_all_email_handle[i] = handle;
4833                                                 priv->b_all_att_save = TRUE;
4834
4835                                                 debug_log("attach_onoff_flag:%d", ug_data->attach_onoff_flag);
4836                                                 if (priv->b_all_att_save) {
4837                                                         if (ug_data->attach_onoff_flag == 0) {
4838                                                                 _attachment_item_collapse_cb(ug_data->attach_hd_bk, NULL, NULL, NULL);
4839                                                         }
4840                                                 }
4841
4842                                                 _create_down_progress_ex(i, EMAIL_VIEWER_PROGRESSBAR_ATT);
4843                                                 ug_data->display_download_result = TRUE;
4844                                         } else {
4845                                                 priv->download_all_fail_cnt++;
4846                                         }
4847                                 }
4848                         }
4849                 }
4850         }
4851
4852         debug_log("download [%d], failed [%d]", priv->download_all_cnt, priv->download_all_fail_cnt);
4853 }
4854
4855 static void _dbus_receiver_setup(EmailViewerUGD *ug_data)
4856 {
4857         debug_log("");
4858
4859         int ret = e_dbus_init();
4860         debug_log("ret: %d", ret);
4861
4862         DBusError derror;
4863
4864         if (_g_viewer_dbus_conn == NULL) {
4865                 debug_log("");
4866                 dbus_error_init(&derror);
4867                 _g_viewer_dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
4868
4869                 if (_g_viewer_dbus_conn == NULL) {
4870                         debug_log("e_dbus_bus_get return NULL");
4871                 }
4872
4873                 /* storage */
4874                 if (e_dbus_request_name(_g_viewer_dbus_conn, "User.Email.StorageChange", 0, NULL, NULL) == NULL) {
4875                         debug_critical("Failed to e_dbus_request_name()");
4876                         return;
4877                 }
4878
4879                 if (_g_viewer_signal_handler_storage != NULL) {
4880                         debug_log("_g_viewer_signal_handler_storage != NULL");
4881                 }
4882
4883                 _g_viewer_signal_handler_storage = e_dbus_signal_handler_add(_g_viewer_dbus_conn, NULL,
4884                                                                                                                                         "/User/Email/StorageChange",
4885                                                                                                                                         "User.Email.StorageChange",
4886                                                                                                                                         "email", _on_edbus_event_email_viewer_receive, ug_data);
4887
4888                 if (_g_viewer_signal_handler_storage == NULL) {
4889                         debug_log("Failed to e_dbus_signal_handler_add()");
4890                         return;
4891                 }
4892
4893                 /* network */
4894                 if (e_dbus_request_name(_g_viewer_dbus_conn, "User.Email.NetworkStatus", 0, NULL, NULL) == NULL) {
4895                         debug_log("Failed to e_dbus_request_name()");
4896                         return;
4897                 }
4898
4899                 if (_g_viewer_signal_handler_network != NULL) {
4900                         debug_log("_g_viewer_signal_handler_network != NULL");
4901                 }
4902
4903                 _g_viewer_signal_handler_network = e_dbus_signal_handler_add(_g_viewer_dbus_conn, NULL,
4904                                                                                                                         "/User/Email/NetworkStatus",
4905                                                                                                                         "User.Email.NetworkStatus",
4906                                                                                                                         "email", _on_edbus_event_email_viewer_receive, ug_data);
4907
4908                 if (_g_viewer_signal_handler_network == NULL) {
4909                         debug_log("Failed to e_dbus_signal_handler_add()");
4910                         return;
4911                 }
4912         }
4913 }
4914
4915 static void _dbus_receiver_remove(EmailViewerUGD *ug_data)
4916 {
4917         debug_log("");
4918
4919         if (_g_viewer_signal_handler_storage != NULL) {
4920                 e_dbus_signal_handler_del(_g_viewer_dbus_conn, _g_viewer_signal_handler_storage);
4921                 _g_viewer_signal_handler_storage = NULL;
4922         }
4923
4924         if (_g_viewer_signal_handler_network != NULL) {
4925                 e_dbus_signal_handler_del(_g_viewer_dbus_conn, _g_viewer_signal_handler_network);
4926                 _g_viewer_signal_handler_network = NULL;
4927         }
4928
4929         if (e_dbus_release_name(_g_viewer_dbus_conn, "User.Email.StorageChange", NULL, NULL) == NULL) {
4930                 debug_critical("e_dbus_release_name to failed");
4931         }
4932
4933         if (e_dbus_release_name(_g_viewer_dbus_conn, "User.Email.NetworkStatus", NULL, NULL) == NULL) {
4934                 debug_critical("e_dbus_release_name to failed");
4935         }
4936
4937         if (_g_viewer_dbus_conn != NULL) {
4938                 /*e_dbus_connection_close(_g_viewer_dbus_conn);*/
4939                 _g_viewer_dbus_conn = NULL;
4940         }
4941 }
4942
4943 static void _on_edbus_event_email_viewer_receive(void *data, DBusMessage *message)
4944 {
4945         debug_log("");
4946
4947         if (!_g_ug_data) {
4948                 debug_log("data is NULL");
4949                 return;
4950         }
4951
4952         EmailViewerUGD *ug_data = _g_ug_data;
4953         EmailViewerPrivate *priv = ug_data->email_data;
4954         char fail_msg[MAX_STR_LEN] = { 0, };
4955         DBusError error;
4956
4957         if (dbus_message_is_signal(message, "User.Email.StorageChange", "email")) {
4958                 debug_log("User.Email.StorageChange");
4959
4960                 int subtype = 0;
4961                 int data1 = 0;
4962                 int data2 = 0;
4963                 char *data3 = NULL;
4964
4965                 dbus_error_init(&error);
4966                 if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype,
4967                         DBUS_TYPE_INT32, &data1, DBUS_TYPE_INT32, &data2,
4968                         DBUS_TYPE_STRING, &data3, DBUS_TYPE_INVALID)) {
4969                         debug_log("STORE_ENABLE: subtype: %d, data1: %d, data2: %d, data3: %s", subtype, data1, data2, data3);
4970
4971                         switch (subtype) {
4972                         case NOTI_ACCOUNT_ADD:
4973                                 if (get_app_paused()) {
4974                                         debug_log("account added during pause status");
4975
4976                                         if (ug_data->isRotate == false && ug_data->b_internal) {
4977                                                 /* Viewer to hide, so set left content (mailbox) size to full */
4978                                                 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
4979                                         }
4980
4981                                         if (ug_data->b_internal != 1) {
4982                                                 debug_log("ug_destory_me");
4983                                                 ug_destroy_me(ug_data->ug);
4984                                         } else {
4985                                                 _hide_view(ug_data);
4986                                         }
4987                                 }
4988                                 break;
4989
4990                         case NOTI_ACCOUNT_DELETE:
4991                                 if (get_app_paused()) {
4992                                         debug_log("account deleted during pause status");
4993                                         int account_id = 0;
4994
4995                                         if (ug_data->isRotate == false && ug_data->b_internal) {
4996                                                 /* Viewer to hide, so set left content (mailbox) size to full */
4997                                                 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
4998                                         }
4999
5000                                         if (email_engine_get_default_account(&account_id)) {
5001                                                 if (ug_data->b_internal != 1) {
5002                                                         debug_log("ug_destory_me");
5003                                                         ug_destroy_me(ug_data->ug);
5004                                                 } else {
5005                                                         _hide_view(ug_data);
5006                                                 }
5007                                         }
5008                                 }
5009                                 break;
5010
5011                         case NOTI_ACCOUNT_UPDATE:
5012                                 if (get_app_paused()) {
5013                                         debug_log("account updated during pause status");
5014                                 }
5015                                 break;
5016
5017                         default:
5018                                 debug_warning("unknown type");
5019                                 break;
5020                         }
5021                 } else {
5022                         debug_critical("receive data error: %s", error.message);
5023                         dbus_error_free(&error);
5024                 }
5025         } else if (dbus_message_is_signal(message, "User.Email.NetworkStatus", "email")) {
5026                 debug_log("");
5027
5028                 int subtype = 0;
5029                 int data1 = 0;
5030                 char *data2 = NULL;
5031                 int data3 = 0;
5032                 int data4 = 0;
5033
5034                 dbus_error_init(&error);
5035
5036                 if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &subtype,
5037                         DBUS_TYPE_INT32, &data1, DBUS_TYPE_STRING, &data2,
5038                         DBUS_TYPE_INT32, &data3, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID)) {
5039                         debug_log("subtype: %d, data1: %d, data2: %s, data3: %d, data4: %d", subtype, data1, data2, data3, data4);
5040                         switch (subtype) {
5041
5042                         case NOTI_DOWNLOAD_BODY_START:
5043                                 /* DATA1[mail_id] DATA2[file_id] DATA3[body_size] DATA4[received size] */
5044                                 debug_log("receive noti, DOWNLOAD_BODY");
5045                                 if (priv->mail_id == data1) {
5046                                         priv->file_id = g_strdup(data2);
5047                                         priv->file_size = data3;
5048
5049                                         if (data4 == 0) {
5050                                                 _set_value_down_progress(0.0);
5051                                         } else {
5052                                                 double per = (double)data4 / (double)data3;
5053                                                 _set_value_down_progress(per);
5054                                         }
5055                                 } else {
5056                                         debug_log("mail_id is different");
5057                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5058                                 }
5059                                 break;
5060
5061                         case NOTI_DOWNLOAD_MULTIPART_BODY:
5062                                 /* DATA1[mail_id] DATA2[file_id] DATA3[body_size] DATA4[received size] */
5063                                 debug_log("receive noti, DOWNLOAD_MULTIPART_BODY");
5064                                 if (priv->mail_id == data1) {
5065                                         priv->file_id = g_strdup(data2);
5066                                         priv->file_size = data3;
5067                                         priv->multi_body = TRUE;
5068
5069                                         if (data4 == 0) {
5070                                                 _set_value_down_progress(0.0);
5071                                         } else {
5072                                                 double per = (double)data4 / (double)data3;
5073                                                 _set_value_down_progress(per);
5074                                         }
5075                                 } else {
5076                                         debug_log("mail_id is different");
5077                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5078                                 }
5079                                 break;
5080
5081                         case NOTI_DOWNLOAD_BODY_FINISH:
5082                                 /* DATA1[mail_id] DATA2[NULL] DATA3[handle_id] */
5083                                 debug_log("receive noti, DOWNLOAD_BODY_FINISH");
5084                                 if (priv->email_handle == data3 && priv->mail_id == data1) {
5085                                         priv->email_handle = 0;
5086
5087                                         ug_data->b_load_finished = EINA_FALSE;
5088
5089                                         /* delete progress */
5090                                         if (ug_data->pb_notify) {
5091                                                 _set_value_down_progress(1.0);
5092                                                 _destroy_down_progress_cb(NULL, NULL, NULL);
5093                                         }
5094
5095                                         char str[128] = { 0, };
5096                                         snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_BODY_DOWNLOADED"));
5097                                         int ret = status_message_post(str);
5098                                         if (ret)
5099                                                 debug_log("status_message_post failed: %d", ret);
5100
5101                                         /* set property */
5102                                         if (viewer_get_internal_mail_info(ug_data->property, ug_data->email_data)) {
5103                                                 viewer_make_internal_mail(ug_data->property, ug_data->email_data);
5104                                         }
5105                                         /* create att and body */
5106                                         if (ug_data->b_partial_body) {
5107                                                 int scr_x = 0;
5108                                                 int scr_y = 0;
5109                                                 int scr_w = 0;
5110                                                 int scr_h = 0;
5111                                                 elm_scroller_region_get(ug_data->scroller, &scr_x, &scr_y, &scr_w, &scr_h);
5112                                                 debug_log("scroller region> x[%d] y[%d] w[%d] h[%d]", scr_x, scr_y, scr_w, scr_h);
5113
5114                                                 elm_box_unpack(ug_data->main_bx, ug_data->partial_dn_btn_bx);
5115                                                 if (ug_data->partial_dn_btn) {
5116                                                         evas_object_del(ug_data->partial_dn_btn);
5117                                                         ug_data->partial_dn_btn = NULL;
5118                                                 }
5119                                                 if (ug_data->partial_dn_btn_bx) {
5120                                                         evas_object_del(ug_data->partial_dn_btn_bx);
5121                                                         ug_data->partial_dn_btn_bx = NULL;
5122                                                 }
5123
5124                                                 if (ug_data->property->has_html) {
5125                                                         ug_data->webview_data->body_type = BODY_TYPE_HTML;
5126                                                         ug_data->webview_data->uri = ug_data->property->body_uri;
5127                                                 } else {
5128                                                         ug_data->webview_data->body_type = BODY_TYPE_TEXT;
5129                                                         ug_data->webview_data->text_content = ug_data->property->body;
5130                                                 }
5131
5132                                                 viewer_set_webview_content(ug_data, 1);
5133
5134                                                 elm_object_focus_set(ug_data->ly_subject, EINA_TRUE);
5135                                                 elm_scroller_region_show(ug_data->scroller, scr_x, scr_y, scr_w, scr_h);
5136                                         } else {
5137
5138                                                 if (ug_data->property->has_attachment)
5139                                                         ug_data->got_att = 1;
5140                                                 else
5141                                                         ug_data->got_att = 0;
5142
5143                                                 /* pack attachment if it exist */
5144                                                 if (ug_data->got_att) {
5145                                                         _create_attach(ug_data);
5146                                                 }
5147
5148                                                 _create_body(ug_data);
5149                                         }
5150                                 } else {
5151                                         debug_log("email_handle or mail_id is different");
5152                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5153                                         debug_log("expected email_handle [%d], received email_handle [%d]", priv->email_handle, data3);
5154                                 }
5155                                 break;
5156
5157                         case NOTI_DOWNLOAD_BODY_FAIL:
5158                                 /* DATA1[mail_id] DATA2[NULL] DATA3[handle_id] */
5159                                 debug_log("receive noti, DOWNLOAD_BODY_FAIL");
5160                                 if (priv->email_handle == data3 && priv->mail_id == data1) {
5161                                         priv->email_handle = 0;
5162
5163                                         /* delete progress */
5164                                         if (ug_data->pb_notify) {
5165                                                 _destroy_down_progress_cb(NULL, NULL, NULL);
5166                                         }
5167
5168                                         char *err_msg = _get_service_fail_type(data4);
5169                                         snprintf(fail_msg, sizeof(fail_msg), "%s<br>%s", _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), err_msg);
5170                                         _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"),
5171                                                                         fail_msg, 1, dgettext("sys_string", "IDS_COM_SK_OK"),
5172                                                                         _popup_response_cb, NULL, NULL, NULL);
5173                                         g_free(err_msg);
5174                                 } else {
5175                                         debug_log("email_handle or mail_id is different");
5176                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5177                                         debug_log("expected email_handle [%d], received email_handle [%d]", priv->email_handle, data3);
5178                                 }
5179                                 break;
5180
5181                         case NOTI_DOWNLOAD_ATTACH_START:
5182                                 /* DATA1[mail_id] DATA2[file_id] DATA3[attachment_id] DATA4[percentage] */
5183                                 debug_log("receive noti, DOWNLOAD_ATTACHMENT");
5184                                 if (priv->mail_id == data1) {
5185                                         priv->att_file_id = g_strdup(data2);
5186                                         priv->attachment_id = data3;
5187
5188                                         if (data4 == 0) {
5189                                                 /* Set the progressbar of particular attachment_id */
5190                                                 _set_value_down_progress_by_index(0.0, priv->attachment_id);
5191                                         }
5192                                         if (data4 > 0) {
5193                                                 double per = (double)data4 / 100.0;
5194                                                 /* Set the progressbar of particular attachment_id */
5195                                                 _set_value_down_progress_by_index(per, priv->attachment_id);
5196                                         }
5197                                 } else {
5198                                         debug_log("mail_id is different");
5199                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5200                                 }
5201                                 break;
5202
5203                         case NOTI_DOWNLOAD_ATTACH_FINISH:
5204                                 /* DATA1[mail_id] DATA2[NULL] DATA3[attachment_id] */
5205                                 debug_log("receive noti, DOWNLOAD_ATTACH_FINISH");
5206
5207                                 if (priv->mail_id == data1) {
5208                                         int attach_index = 0;
5209                                         int attachment_id = (int)data3;
5210                                         debug_log("download_all_cnt [%d]", priv->download_all_cnt);
5211
5212                                         if (priv->download_all_cnt > 0) {
5213                                                 _set_value_down_progress_by_index(1.0, attachment_id);
5214                                                 attach_index = _update_attachment_info(ug_data, attachment_id);
5215                                                 if (priv->b_all_att_save) {
5216                                                         _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5217                                                         _save_attachment(ug_data, attach_index);
5218                                                         if (priv->download_all_cnt == 0) {
5219                                                                 priv->b_all_att_save = FALSE;
5220                                                         }
5221                                                 } else {
5222                                                         _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5223                                                         _show_attachment(ug_data, attach_index);
5224                                                 }
5225                                         }
5226                                 } else {
5227                                         debug_log("mail_id or attachment_id is different");
5228                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5229                                 }
5230                                 break;
5231
5232                         case NOTI_DOWNLOAD_ATTACH_FAIL:
5233                                 /* DATA1[mail_id] DATA2[NULL] DATA3[attachment_id] */
5234                                 debug_log("receive noti, DOWNLOAD_ATTACH_FAIL");
5235                                 if (priv->mail_id == data1) {
5236                                         int attach_index = _get_attachment_info_index(ug_data, data3);
5237                                         debug_log("download_all_cnt[%d]", priv->download_all_cnt);
5238
5239                                         if (priv->download_all_cnt > 0) {
5240                                                 if (ug_data->progress_bar[data3] != NULL && data4 != EMAIL_ERROR_CANCELLED)
5241                                                         _destroy_down_progress_ex((void *)attach_index, NULL, NULL);
5242                                                 else
5243                                                         debug_log("Download already cancelled, No need to destroy again..!");
5244
5245                                                 if (data4 != EMAIL_ERROR_CANCELLED && ug_data->ug_composer == NULL) {
5246                                                         char *err_msg = _get_service_fail_type(data4);
5247                                                         snprintf(fail_msg, sizeof(fail_msg), "%s<br>%s", _("IDS_EMAIL_POP_UNABLE_TO_DOWNLOAD"), err_msg);
5248                                                         _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"), fail_msg, 1,
5249                                                                                         dgettext("sys_string", "IDS_COM_SK_OK"),
5250                                                                                         _popup_response_cb, NULL, NULL, NULL);
5251                                                         g_free(err_msg);
5252                                                 }
5253
5254                                                 if (priv->b_all_att_save && priv->download_all_cnt == 0) {
5255                                                         priv->b_all_att_save = FALSE;
5256                                                 }
5257                                         }
5258                                 } else {
5259                                         debug_log("mail_id is different");
5260                                         debug_log("expected mail_id [%d], received mail_id [%d]", priv->mail_id, data1);
5261                                 }
5262                                 break;
5263
5264                         default:
5265                                 debug_log("unknown type");
5266                                 break;
5267                         }
5268                 } else {
5269                         debug_log("receive data error: %s", error.message);
5270                         dbus_error_free(&error);
5271                 }
5272                 /*return DBUS_HANDLER_RESULT_HANDLED;*/
5273                 return;
5274         }
5275         /*return DBUS_HANDLER_RESULT_HANDLED;*/
5276         return;
5277 }
5278
5279 static void _delete_contacts_list(EMAIL_CONTACT_LIST_INFO_S *contacts_list_item)
5280 {
5281         debug_log("");
5282
5283         if (contacts_list_item) {
5284                 g_free(contacts_list_item->display);
5285                 contacts_list_item->display = NULL;
5286                 g_free(contacts_list_item->email_address);
5287                 contacts_list_item->email_address = NULL;
5288                 g_free(contacts_list_item);
5289                 contacts_list_item = NULL;
5290         }
5291 }
5292
5293 static void *_contact_search_by_email(EmailViewerUGD *ug_data, const char *search_word)
5294 {
5295         debug_log("");
5296         if (!ug_data || !_g_ug_data) {
5297                 debug_log("data is NULL");
5298                 return NULL;
5299         }
5300
5301         int ret = CTS_SUCCESS;
5302         CTSiter *iter = NULL;
5303
5304         EMAIL_CONTACT_LIST_INFO_S *contacts_list_item = NULL;
5305         contacts_svc_connect();
5306
5307         debug_log("search_word = %s", search_word);
5308
5309         if (contacts_svc_get_list_with_str(CTS_LIST_EMAILINFOS_WITH_EMAIL, search_word, &iter) != CTS_SUCCESS) {
5310                 return NULL;
5311         }
5312
5313         ret = contacts_svc_iter_next(iter);
5314
5315         if (CTS_SUCCESS == ret) {
5316                 CTSvalue *row_info = NULL;
5317
5318                 row_info = contacts_svc_iter_get_info(iter);
5319                 if (row_info) {
5320                         contacts_list_item = (EMAIL_CONTACT_LIST_INFO_S *)calloc(1, sizeof(EMAIL_CONTACT_LIST_INFO_S));
5321
5322                         int index = contacts_svc_value_get_int(row_info, CTS_LIST_EMAIL_CONTACT_ID_INT);
5323
5324                         contacts_list_item->index = index;
5325                         contacts_list_item->display = g_strdup(contacts_svc_value_get_str(row_info, CTS_LIST_EMAIL_CONTACT_DISPLAY_STR));
5326                         contacts_list_item->email_address = g_strdup(contacts_svc_value_get_str(row_info, CTS_LIST_EMAIL_ADDR_STR));
5327
5328                         snprintf(contacts_list_item->display_name, sizeof(contacts_list_item->display_name), "%s", contacts_list_item->display);
5329                 }
5330
5331                 contacts_svc_value_free(row_info);
5332                 row_info = NULL;
5333
5334                 contacts_svc_iter_remove(iter);
5335         }
5336
5337         contacts_svc_disconnect();
5338
5339         return contacts_list_item;
5340 }
5341
5342 static void _set_value_down_progress(double val)
5343 {
5344         debug_log("");
5345
5346         if (!_g_ug_data) {
5347                 debug_log("data is NULL");
5348                 return;
5349         }
5350         char buf[30] = { 0, };
5351         EmailViewerUGD *ug_data = _g_ug_data;
5352
5353         sprintf(buf, "%s: %d", dgettext("sys_string", "IDS_COM_POP_DOWNLOADING"), (int)val);
5354
5355         if (ug_data->pb_notify_lb) {
5356                 elm_progressbar_value_set(ug_data->pb_notify_lb, val);
5357                 elm_object_text_set(ug_data->pb_notify_lb, buf);
5358         }
5359 }
5360
5361 static void _set_value_down_progress_by_index(double val, int index)
5362 {
5363         debug_log("");
5364
5365         if (!_g_ug_data) {
5366                 debug_log("data is NULL");
5367                 return;
5368         }
5369
5370         EmailViewerUGD *ug_data = _g_ug_data;
5371         EmailViewerProp *prop = ug_data->property;
5372
5373         if (val < 0.0) {
5374                 debug_log("val(%f) is MINUS", val);
5375                 return;
5376         }
5377
5378         if (index < 0 || index >= ATTACH_MAX) {
5379                 debug_log("index(%d) is overflowed", index);
5380                 return;
5381         }
5382
5383         if (prop == NULL) {
5384                 debug_log("prop is NULL");
5385                 return;
5386         }
5387
5388         if (prop->attachments == NULL) {
5389                 debug_log("attachments is NULL");
5390                 return;
5391         }
5392
5393         int per = val * 100;
5394         int attach_index = _get_attachment_info_index(ug_data, index);
5395         EmailAttachmentType *info = g_list_nth_data(prop->attachments, attach_index);
5396
5397         if (info == NULL) {
5398                 debug_log("info is NULL");
5399         }
5400
5401         if (ug_data->progress_bar[index] == NULL) {
5402                 debug_log("obj is NULL");
5403                 return;
5404         }
5405
5406         char *pszTemp = NULL;
5407         pszTemp = (char *)elm_object_style_get(ug_data->progress_bar[index]);
5408
5409         if (STR_INVALID(pszTemp))
5410                 return;
5411
5412         if (g_strcmp0(pszTemp, "pending_list") == 0) {
5413                 debug_log("pending_list so return");
5414                 return;
5415         }
5416
5417         elm_progressbar_value_set(ug_data->progress_bar[index], val);
5418
5419         if (ug_data->progress_bar_ly[index] != NULL) {
5420                 char buf[30] = { 0, };
5421                 snprintf(buf, sizeof(buf), "%d%%", per);
5422
5423                 Evas_Object *downloading_label2;
5424                 downloading_label2 = elm_label_add(ug_data->progress_bar_ly[index]);
5425                 elm_object_part_content_set(ug_data->progress_bar_ly[index], "elm.text.2", downloading_label2);
5426                 char *buf_tagged = g_strconcat("<font_size=26><align=left><color=#646464FF>", buf, "</align></font_size>", NULL);
5427                 elm_object_text_set(downloading_label2, buf_tagged);
5428                 g_free(buf_tagged);
5429         }
5430 }
5431
5432 static void _cancel_download_attachment(EmailViewerUGD *ug_data)
5433 {
5434         debug_log("");
5435         int i = 0;
5436         gboolean is_cancel = FALSE;
5437
5438         if (!_g_ug_data) {
5439                 debug_log("data is NULL");
5440                 return;
5441         }
5442
5443         EmailViewerPrivate *priv = ug_data->email_data;
5444         EmailViewerProp *prop = ug_data->property;
5445
5446         if (priv && priv->download_all_cnt <= 0) {
5447                 debug_log("No attachment download to be cancelled!");
5448                 return;
5449         }
5450
5451         for (i = 0; i <= prop->att_len; i++) {
5452                 if (ug_data->progress_bar_ly[i]) {
5453                         Evas_Object *btn = elm_object_part_content_get(ug_data->progress_bar_ly[i], "elm.icon.1");
5454                         debug_log("Cancel btn for downloading attachment: %p", btn);
5455                         if (btn) {
5456                                 evas_object_smart_callback_call(btn, "clicked", NULL);
5457                                 is_cancel = TRUE;
5458                         }
5459                 }
5460         }
5461
5462         if (is_cancel == TRUE && ug_data->ug_composer == NULL) {
5463                 _create_notify(ug_data, dgettext("sys_string", "IDS_COM_POP_WARNING"), _("IDS_EMAIL_POP_CANCELLING_ATTACHMENT_DOWNLOAD_ING"),
5464                                                 1, dgettext("sys_string", "IDS_COM_SK_OK"), _popup_response_cb,
5465                                                 NULL, NULL, NULL);
5466         }
5467 }
5468
5469 static char *_get_service_fail_type(int type)
5470 {
5471         debug_log("");
5472
5473         char *ret = NULL;
5474         char str[MAX_STR_LEN] = { 0, };
5475
5476         if (type == -174) {
5477                 snprintf(str, sizeof(str), "%s: %s", _("IDS_EMAIL_POP_FAILED_TO_ACTIVATE_PDP"), N_("IP full"));
5478                 return g_strdup(str);
5479         } else if (type == -176) {
5480                 ret = _("IDS_EMAIL_POP_NO_SERVICE");
5481                 return g_strdup(ret);
5482         } else if (type == -181) {
5483                 snprintf(str, sizeof(str), "%s: %s", _("IDS_EMAIL_POP_FAILED_TO_ACTIVATE_PDP"), N_("Transport Error"));
5484                 return g_strdup(str);
5485         } else if (type == EMAIL_ERROR_NETWORK_TOO_BUSY) {
5486                 ret = _("IDS_EMAIL_POP_NETWORK_BUSY");
5487                 return g_strdup(ret);
5488         } else if (type == EMAIL_ERROR_LOGIN_ALLOWED_EVERY_15_MINS) {
5489                 snprintf(str, sizeof(str), _("IDS_EMAIL_POP_YOU_CAN_ONLY_LOG_IN_ONCE_EVERY_PD_MINUTES"), 15);
5490                 return g_strdup(str);
5491         } else if (type == EMAIL_ERROR_CONNECTION_FAILURE) {
5492                 ret = dgettext("sys_string", "IDS_COM_POP_CONNECTION_FAILED");
5493                 return g_strdup(ret);
5494         } else if (type == EMAIL_ERROR_LOGIN_FAILURE) {
5495                 ret = _("IDS_EMAIL_POP_LOG_IN_FAILED");
5496                 return g_strdup(ret);
5497         } else if (type == EMAIL_ERROR_AUTHENTICATE) {
5498                 ret = _("IDS_EMAIL_POP_AUTHENTICATION_FAILED");
5499                 return g_strdup(ret);
5500         } else if (type == EMAIL_ERROR_CANCELLED) {
5501                 ret = _("IDS_EMAIL_POP_DOWNLOAD_CANCELLED");
5502                 return g_strdup(ret);
5503         } else if (type == EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER) {
5504                 ret = _("IDS_EMAIL_POP_EMAIL_DELETED_FROM_SERVER");
5505                 return g_strdup(ret);
5506         } else if (type == EMAIL_ERROR_NO_SUCH_HOST) {
5507                 ret = _("IDS_EMAIL_POP_HOST_NOT_FOUND");
5508                 return g_strdup(ret);
5509         } else if (type == EMAIL_ERROR_INVALID_SERVER) {
5510                 ret = _("IDS_EMAIL_POP_SERVER_NOT_AVAILABLE");
5511                 return g_strdup(ret);
5512         } else if (type == EMAIL_ERROR_MAIL_MEMORY_FULL) {
5513                 ret = _("IDS_EMAIL_POP_DEVICE_STORAGE_FULL");
5514                 return g_strdup(ret);
5515         } else if (type == EMAIL_ERROR_FAILED_BY_SECURITY_POLICY) {
5516                 ret = _("IDS_EMAIL_POP_DOWNLOADING_ATTACHMENTS_ON_THE_MOBILE_DEVICE_IS_NOT_ALLOWED_BY_EXCHANGE_SERVER_POLICY");
5517                 return g_strdup(ret);
5518         } else {
5519                 snprintf(str, sizeof(str), "%s (%d)", dgettext("sys_string", "IDS_COM_POP_INTERNAL_ERROR"), type);
5520                 return g_strdup(str);
5521         }
5522 }
5523
5524 static Evas_Object *_load_edj(Evas_Object *parent, const char *file, const char *group)
5525 {
5526         debug_log("");
5527         Evas_Object *eo;
5528         int r;
5529
5530         eo = elm_layout_add(parent);
5531         if (eo) {
5532                 r = elm_layout_file_set(eo, file, group);
5533                 if (!r) {
5534                         evas_object_del(eo);
5535                         return NULL;
5536                 }
5537
5538                 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
5539         }
5540
5541         return eo;
5542 }
5543
5544 /* genlist cb */
5545 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part)
5546 {
5547         debug_log("");
5548         return EINA_FALSE;
5549 }
5550
5551 static void _gl_del(void *data, Evas_Object *obj)
5552 {
5553         debug_log("");
5554
5555         if (_g_ug_data == NULL) {
5556                 debug_log("ug_data is NULL");
5557                 return;
5558         }
5559
5560         EmailViewerUGD *ug_data = _g_ug_data;
5561
5562         if (ug_data->move_mailbox_list) {
5563                 email_free_mailbox(&ug_data->move_mailbox_list, ug_data->move_mailbox_count);
5564                 ug_data->move_mailbox_list = NULL;
5565                 ug_data->move_mailbox_count = 0;
5566         }
5567
5568         return;
5569 }
5570
5571 static char *_gl_text_get(void *data, Evas_Object *obj, const char *part)
5572 {
5573         debug_log("");
5574         email_mailbox_t *mailbox_list = NULL;
5575         mailbox_list = (email_mailbox_t *) data;
5576
5577         if (g_strcmp0(part, "elm.text") == 0) {
5578                 char buf[MAX_STR_LEN] = { 0, };
5579                 if (mailbox_list && mailbox_list->alias) {
5580                         snprintf(buf, sizeof(buf), "%s", mailbox_list->alias);
5581                         return g_strdup(buf);
5582                 }
5583         }
5584
5585         return NULL;
5586 }
5587
5588 static Evas_Object *_gl_content_get(void *data, Evas_Object *obj, const char *part)
5589 {
5590         debug_log("");
5591
5592         if (g_strcmp0(part, "elm.icon") == 0) {
5593                 Evas_Object *icon = elm_icon_add(obj);
5594                 elm_icon_file_set(icon, IMGDIR "/U01_icon_folder.png", NULL);
5595                 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
5596
5597                 return icon;
5598         }
5599
5600         return NULL;
5601 }
5602
5603 static void _move_here_cb(void *data, Evas_Object *obj, void *event_info)
5604 {
5605         debug_log("");
5606
5607         if (data == NULL || _g_ug_data == NULL) {
5608                 debug_log("data is NULL");
5609                 return;
5610         }
5611
5612         email_mailbox_t *mailbox_list = NULL;
5613         mailbox_list = (email_mailbox_t *) data;
5614
5615         EmailViewerUGD *ug_data = _g_ug_data;
5616         int folder_id = mailbox_list->mailbox_id;
5617
5618         _move_email(ug_data, folder_id, FALSE);
5619
5620         ug_data->navi_move_it1 = NULL;
5621         elm_naviframe_item_pop_to(ug_data->navi_main_it);
5622
5623         if (ug_data->isRotate == false && ug_data->b_internal) {
5624                 /* Viewer to hide, so set left content (mailbox) size to full */
5625                 _notify_mailbox_size(ug_data, "MAILBOX_RESIZE_FULL");
5626         }
5627
5628         if (ug_data->b_internal) {
5629                 _hide_view(ug_data);
5630
5631                 /* send next or previous mail request to mailbox. */
5632                 int ret;
5633                 service_h service = NULL;
5634
5635                 ret = service_create(&service);
5636                 debug_log("service_create: %d", ret);
5637                 if (!service) {
5638                         debug_log("service create failed");
5639                         return;
5640                 }
5641
5642                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_MSG, EMAIL_BUNDLE_VAL_NEXT_MSG);
5643                 debug_log("service_add_extra_data: %d", ret);
5644                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_DO_DELETE, "1");
5645                 debug_log("service_add_extra_data: %d", ret);
5646
5647                 ug_send_message(_g_mailbox_ug, service);
5648
5649                 ret = service_destroy(service);
5650                 debug_log("service_destroy: %d", ret);
5651         } else {
5652                 ug_destroy_me(ug_data->ug);
5653         }
5654 }
5655
5656 static void _move_back_cb(void *data, Evas_Object *obj, void *event_info)
5657 {
5658         debug_log("");
5659
5660         if (data == NULL || _g_ug_data == NULL) {
5661                 debug_log("data is NULL");
5662                 return;
5663         }
5664
5665         EmailViewerUGD *ug_data = (EmailViewerUGD *)data;
5666
5667         elm_naviframe_item_pop(ug_data->navi_bar);
5668         ug_data->navi_move_it1 = NULL;
5669
5670         /*if (ug_data->b_internal)
5671                 elm_layout_theme_set(ug_data->layout_main, "layout", "controlbar", "default");
5672         else
5673                 elm_layout_theme_set(ug_data->layout_main, "layout", "application", "controlbar");*/
5674 }
5675
5676 /* EOF */