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