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