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