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