Remove SMACK rule file(.rule) according three domain model
[apps/core/preloaded/email.git] / composer / src / email-composer-util.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.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 #include <string.h>
18 #include <glib/gprintf.h>
19 #include <Ecore_X.h>
20 #include <Ethumb.h>
21 #include <ctype.h>
22 #include <appcore-common.h>
23 #undef _
24 #include <iconv.h>
25 #include <fcntl.h>
26 #include <status.h>
27
28 #include "email-composer.h"
29 #include "email-composer-recipient.h"
30 #include "email-composer-util.h"
31 #include "email-composer-predictive-search.h"
32 #include "email-composer-attachment.h"
33 #include "email-composer-callback.h"
34 #include "email-composer-js.h"
35 #include "email-composer-contents.h"
36
37 #include "email-engine.h"
38 #include "email-utils.h"
39
40 #define DIV_TAG_START_ORIGIN_INFO "<div id=\"origin_info\"><p>"
41 #define DIV_TAG_START_ORIGIN_CONTENT "<div id=\"origin_content\"><p>"
42 #define DIV_TAG_END "</div>"
43
44 #define DIVIDE_LEFT_LINE_FOR_HTML "<br><br><b>--------------- "
45 #define DIVIDE_RIGHT_LINE_FOR_HTML " ---------------</b><br>\n"
46 #define ADDED_TEXT "<b>%s:</b> %s<br>\n"
47 #define BODY_TAG_START "<body>\n"
48 #define BODY_TAG_END "</body>\n"
49 #define HTML_TAG_START "<html>\n"
50 #define HTML_TAG_END "</html>\n"
51
52 #define DIVIDE_LINE "\n\n-----------------------------------\n"
53
54 #define DEFAULT_SIGNATURE _("IDS_EMAIL_BODY_SENT_USING_TIZEN_MOBILE")
55
56 #define HTML_META_INFORMATION \
57         "<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=medium-dpi\" /></head>\n"
58
59
60 static void _composer_save_draft_response_cb(void *data, Evas_Object *obj, void *event_info);
61 static void _composer_save_draft_fail_response_cb(void *data, Evas_Object *obj, void *event_info);
62 static void _composer_attachment_popup_response_cb(void *data, Evas_Object *obj, void *event_info);
63 static void _composer_dn_prog_popup_response_cb(void *data, Evas_Object *obj, void *event_info);
64
65 extern void _composer_free_initial_email_content(EmailComposerUGD *ugd);
66
67 void _composer_make_html_body(EmailComposerUGD *ugd);
68
69 extern char *icu_locale;
70 extern enum appcore_time_format icu_timeformat;
71
72 const gchar *email_composer_get_html_tag(const gchar char_val)
73 {
74         const gchar *tag = NULL;
75         switch (char_val) {
76         case '\n':
77                 tag = "<br>";
78                 break;
79         case '\r':
80                 tag = "";
81                 break;
82         case '<':
83                 tag = "&lt;";
84                 break;
85         case '>':
86                 tag = "&gt;";
87                 break;
88         default:
89                 break;
90         }
91         return tag;
92 }
93
94 gchar *email_composer_get_parse_string(const gchar *text, gint size)
95 {
96         debug_log("");
97         RETURN_VAL_IF_FAIL(STR_VALID(text), NULL);
98
99         gchar *html = NULL;
100         gchar *buff = NULL;
101         gchar *temp = NULL;
102         guint i = 0;
103         guint old_offset = 0, offset = 0;
104
105         for (i = 0; i < size; ++i) {
106                 /* Get html tag. */
107                 const gchar *tag = email_composer_get_html_tag(text[i]);
108
109                 /* If need, convert text to html format. */
110                 if (tag) {
111                         temp = html;
112
113                         if (i > old_offset) {
114                                 offset = i - old_offset;
115                                 buff = g_strndup(&text[old_offset], offset);
116                                 if (temp) {
117                                         html = g_strconcat(temp, buff, tag, NULL);
118                                 } else {
119                                         html = g_strconcat(buff, tag, NULL);
120                                 }
121
122                                 if (buff) {
123                                         g_free(buff);
124                                         buff = NULL;
125                                 }
126                         } else {
127                                 if (temp) {
128                                         html = g_strconcat(temp, tag, NULL);
129                                 } else {
130                                         html = g_strconcat(tag, NULL);
131                                 }
132                         }
133
134                         if (temp) {
135                                 g_free(temp);
136                                 temp = NULL;
137                         }
138
139                         old_offset = i + 1;
140                 }
141         }
142
143         /* If not terminated. */
144         if (old_offset < size) {
145                 if (html) {
146                         temp = html;
147                         buff = g_strndup(&text[old_offset], size - old_offset);
148                         html = g_strconcat(temp, buff, NULL);
149                         if (buff) {
150                                 g_free(buff);
151                         }
152                         g_free(temp);
153                 }
154         }
155
156         return html ? html : g_strndup(text, size);
157 }
158
159 /*
160         The following API splits a given filepath string into 'directory path' or 'filename'
161 */
162 char *email_composer_parse_filepath(const char *path, Eina_Bool directorypathORfilename)
163 {
164         debug_log("");
165         RETURN_VAL_IF_FAIL(STR_VALID(path), NULL);
166
167         char *file_path = NULL;
168         int i = 0;
169         int size = STR_LEN((char *)path);
170
171         for (i = (size - 1); i >= 0; --i) {
172                 if (path[i] == '/') {
173                         if (directorypathORfilename) {
174                                 file_path = g_strndup(path, i + 1);     /* directory path is copied. */
175                         } else {
176                                 file_path = g_strndup(path + i + 1, size - i + 1);      /* filename is copied. */
177                         }
178                         break;
179                 }
180         }
181         return file_path;
182 }
183
184 char *email_composer_parse_get_filepath_from_path(const char *path)
185 {
186         RETURN_VAL_IF_FAIL(STR_VALID(path), NULL);
187
188         char *file_path = NULL;
189         int i = 0;
190         int size = STR_LEN((char *)path);
191
192         for (i = (size - 1); i >= 0; --i) {
193                 if (path[i] == '/') {
194                         file_path = g_strndup(path, i + 1);
195                         break;
196                 }
197         }
198         return file_path;
199 }
200
201 char *_composer_get_file_ext(const char *a_pszfile_name)
202 {
203         if (a_pszfile_name != NULL) {
204                 int nlen = strlen(a_pszfile_name);
205                 char *psztemp = (char *)a_pszfile_name + nlen;
206
207                 while (nlen--) {
208                         psztemp--;
209                         if (*psztemp == '.') {
210                                 psztemp++;
211                                 break;
212                         }
213                 }
214                 return psztemp;
215         }
216
217         return NULL;
218 }
219
220 int _composer_copy_temp_file(const char *src_file_path, char *dst_file_path, int size_dst_file_path)
221 {
222         debug_enter();
223         const char *filename = NULL;
224         char temp_file_path[MAX_PATH_LEN] = { 0, };
225         int ret = EINA_TRUE;
226
227         if (ecore_file_exists(src_file_path) == EINA_FALSE) {
228                 ret = EINA_FALSE;
229         }
230
231         filename = ecore_file_file_get(src_file_path);
232         debug_log("filename:%s", filename);
233         if (filename) {
234                 int i = 0;
235                 snprintf(temp_file_path, sizeof(temp_file_path) - 1, "%s/%s", EMAIL_TMP_FOLDER, filename);
236
237                 while (ecore_file_exists(temp_file_path)) {
238                         bzero(temp_file_path, sizeof(temp_file_path));
239                         snprintf(temp_file_path, sizeof(temp_file_path) - 1, "%s/%d_%s", EMAIL_TMP_FOLDER, i, filename);
240                         i++;
241
242                         if (i < 0)
243                                 ret = EINA_FALSE;
244                 }
245
246                 if (ecore_file_cp(src_file_path, temp_file_path) == EINA_FALSE) {
247                         debug_log("temp_file_path = %s", temp_file_path);
248                         ret = EINA_FALSE;
249                 }
250
251                 strncpy(dst_file_path, temp_file_path, size_dst_file_path);
252                 debug_log("copy file from %s to %s", src_file_path, dst_file_path);
253         } else {
254                 ret = EINA_FALSE;
255         }
256
257         debug_leave();
258         return ret;
259 }
260
261 /**
262  * Changes inline images path from absolute to relative, in a given html content.
263  *
264  * @param [in] src_html_content         string buffer contains html file content
265  * @param [out] dest_buffer             string buffer to hold the processed html content
266  *
267  * @return true or false
268  */
269
270 Eina_Bool email_composer_change_image_paths_to_relative(char *src_html_content, char **dest_buffer)
271 {
272         debug_log("");
273
274         if (src_html_content == NULL || dest_buffer == NULL) {
275                 debug_log("NULL arguments passed");
276                 return EINA_FALSE;
277         }
278
279         *dest_buffer = NULL;
280
281         char *src_str = src_html_content;
282         char *buffer = (char *)calloc(1, strlen(src_str) + 1);
283         if (buffer == NULL) {
284                 debug_log("Memory allocation(calloc) failed.");
285                 return EINA_FALSE;
286         }
287
288         char *point1 = NULL;
289         char *point2 = NULL;
290         char *temp = NULL;
291         Eina_Bool success_flag = EINA_TRUE;
292
293         /* Ex. <img src="/opt/media/Images/image5.jpg" width=342 height="192" id="/opt/media/Images/image5.jpg"> */
294         while ((point1 = strstr(src_str, "<img")) || (point1 = strstr(src_str, "<IMG"))) {
295
296                 if (!(temp = strstr(point1, "src=")) && !(temp = strstr(point1, "SRC="))) {
297                         debug_log("1. No src=");
298                         success_flag = EINA_FALSE;
299                         break;
300                 }
301
302                 point1 = temp + 5;
303                 if (point1 == NULL) {
304                         debug_log("2. No file path");
305                         success_flag = EINA_FALSE;
306                         break;
307                 }
308
309                 strncat(buffer, src_str, point1 - src_str);
310
311                 debug_log("point1[0] = %c", point1[0]);
312
313                 if (point1[0] == '/') {
314
315                         point2 = strstr(point1, "\"");
316                         if (point2 == NULL) {
317                                 debug_log("3. No end quotation");
318                                 success_flag = EINA_FALSE;
319                                 break;
320                         }
321                         char *image_path = g_strndup(point1, point2 - point1);
322                         debug_log("image_path : %s", image_path);
323                         char *file_path = email_composer_parse_filepath(image_path, EINA_FALSE);
324                         free(image_path);
325
326                         debug_log("file_path : %s", file_path);
327                         if (file_path == NULL) {
328                                 debug_log("4. Could not parse inline image path");
329                                 success_flag = EINA_FALSE;
330                                 break;
331                         }
332                         strncat(buffer, file_path, strlen(file_path));
333                         free(file_path);
334                         point1 = point2;
335                 }
336                 src_str = point1;
337         }
338
339         if (success_flag == EINA_FALSE) {
340                 free(buffer);
341                 buffer = NULL;
342                 return EINA_FALSE;
343         }
344
345         strncat(buffer, src_str, strlen(src_str));
346         *dest_buffer = buffer;
347
348         return EINA_TRUE;
349 }
350
351 Eina_Bool email_composer_save_file(const gchar *path, const gchar *buf, gsize len)
352 {
353         debug_log("path (%s)", path);
354
355         Eina_Bool success_flag = EINA_TRUE;
356
357         if (STR_LEN((gchar *)buf) > 0 && len > 0) {
358                 int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
359                 if (fd != -1) {
360                         ssize_t nwrite = write(fd, (const void *)buf, (size_t) len);
361                         debug_log("nwrite(%d)", nwrite);
362                         if (nwrite == -1) {
363                                 debug_log("fail to write");
364                                 success_flag = EINA_FALSE;
365                                 close(fd);
366                         }
367                         close(fd);
368                 } else {
369                         debug_log("fail to open");
370                         success_flag = EINA_FALSE;
371                 }
372         } else {
373                 debug_log("check the buf!!");
374                 success_flag = EINA_FALSE;
375         }
376
377         return success_flag;
378 }
379
380 static void _composer_ug_script_executed(Evas_Object *o, const char *result, void *data)
381 {
382         debug_log("");
383 }
384
385 Eina_List *email_composer_change_str_to_EinaList(EmailComposerUGD *ugd, const char *str, char *token)
386 {
387         debug_log("");
388
389         Eina_List *list = NULL;
390         char *p = NULL;
391         char tmp_file_path[MAX_PATH_LEN + 1] = { 0, };
392         char *file_ext = NULL;
393
394         debug_log("str = %s", str);
395         debug_log("token = %s", token);
396         if (token) {
397                 p = strtok((char *)str, token);
398
399                 if (p) {
400                         debug_log("p = %s", p);
401                 }
402
403                 while (p != NULL) {
404                         if (ecore_file_exists(p)) {
405                                 if (email_drm_file_forward_lock_check(p)) {
406                                         if (ugd->composer_noti) {
407                                                 evas_object_del(ugd->composer_noti);
408                                                 ugd->composer_noti = NULL;
409                                         }
410                                         ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
411                                                 _("IDS_EMAIL_POP_UNABLE_TO_FORWARD_DRM_CONTENTS"), 0, NULL, NULL, 2.0, _composer_noti_response_cb);
412                                 } else {
413                                         file_ext = _composer_get_file_ext(p);
414                                         debug_log("file_ext:%s", file_ext);
415
416                                         if (strcasecmp(file_ext, "vcf") == 0 || strcasecmp(file_ext, "vcs") == 0) {
417                                                 if (_composer_copy_temp_file(p, tmp_file_path, MAX_PATH_LEN))
418                                                         list = eina_list_append(list, tmp_file_path);
419                                                 else
420                                                         list = eina_list_append(list, p);
421                                         } else
422                                                 list = eina_list_append(list, p);
423                                 }
424                         } else {
425                                 debug_log("ecore_file_exists failed");
426                                 if (g_str_has_prefix(p, "http://")) {
427                                         if (EINA_TRUE == ugd->has_body_html) {
428                                                 if (ugd->selected_entry != ugd->body_ewkview) {
429                                                         if (ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_SET_FOCUS, _composer_ug_script_executed, 0) == EINA_FALSE) {
430                                                                 debug_log("COMPOSER_JS_SET_FOCUS is failed!");
431                                                         }
432                                                         debug_log("body_ewkview focussed");
433                                                 }
434                                                 if (ugd->body_ewkview) {
435                                                         ewk_view_command_execute(ugd->body_ewkview, "InsertText", p);
436                                                         ewk_view_command_execute(ugd->body_ewkview, "InsertText", "\n");
437                                                 }
438                                         }
439                                 }
440                         }
441
442                         p = strtok(NULL, token);
443                         if (p) {
444                                 debug_log("p = %s", p);
445                         }
446                 }
447         } else {
448                 list = eina_list_append(list, str);
449         }
450
451         return list;
452 }
453
454 Eina_List *email_composer_change_GList_to_EinaList(GList * l)
455 {
456         debug_log("");
457
458         Eina_List *list = NULL;
459
460         int i;
461         int count = g_list_length(l);
462
463         if (count > 0) {
464                 for (i = 0; i < count; i++) {
465                         char *string = g_list_nth_data(l, i);
466                         debug_log("%d = %s", i, string);
467
468                         if (string)
469                                 list = eina_list_append(list, string);
470                 }
471
472                 g_list_free(l);
473         } else
474                 debug_log("count is 0!!");
475
476         return list;
477 }
478
479 int _composer_add_mailbox_folder(EmailComposerUGD *ugd, email_mailbox_type_e mailbox_type, Eina_Bool b_save_to_draft)
480 {
481         debug_log("");
482
483         int nResult = EMAIL_ERROR_NONE;
484
485         nResult = email_get_mailbox_by_mailbox_type(ugd->account_info->account_id, mailbox_type, &ugd->mailbox_info->mail_box);
486         if (nResult != EMAIL_ERROR_NONE) {
487                 debug_log("email_get_mailbox_by_mailbox_type failed! %d", nResult);
488                 return nResult;
489         }
490
491         debug_log("mailbox = %s", ugd->mailbox_info->mail_box->mailbox_name);
492         debug_log("mailbox_id = %d", ugd->mailbox_info->mail_box->mailbox_id);
493
494         nResult = _composer_make_mail(ugd, b_save_to_draft);
495         if (nResult < COMPOSER_ERROR_NONE) {
496                 debug_log("error in _composer_make_mail(%d)", nResult);
497                 return nResult;
498         }
499
500         debug_log("ugd->new_mail_info->mail_data->account_id = %d, ugd->new_mail_info->mail_data->server_mailbox_name = %s",
501                 ugd->new_mail_info->mail_data->account_id, ugd->new_mail_info->mail_data->server_mailbox_name);
502
503         debug_log("attachment_list = %x, attachment_count = %d",
504                 ugd->new_mail_info->attachment_list, ugd->new_mail_info->mail_data->attachment_count);
505
506
507
508         nResult = email_add_mail(ugd->new_mail_info->mail_data, ugd->new_mail_info->attachment_list, ugd->new_mail_info->mail_data->attachment_count, NULL, 0);
509
510         debug_log("result of email_add_mail: %d", nResult);
511         if (nResult != EMAIL_ERROR_NONE) {
512                 debug_warning("email_add_mail failed! %d", nResult);
513                 return nResult;
514         }
515
516         if (email_check_file_exist(ugd->saved_html_path)) {
517                 if (-1 == remove(ugd->saved_html_path)) {
518                         debug_warning("Failed to remove file");
519                         return COMPOSER_ERROR_FAIL;
520                 }
521         }
522
523         return COMPOSER_ERROR_NONE;
524 }
525
526 int _composer_move_mailbox_folder(EmailComposerUGD *ugd, email_mailbox_type_e mailbox_type, Eina_Bool b_save_to_draft)
527 {
528         debug_log("");
529
530         int nResult = EMAIL_ERROR_NONE;
531
532         int mail_ids[1] = { 0, };
533         mail_ids[0] = ugd->nExistingMailID;
534
535         debug_log("id = %d", mail_ids[0]);
536
537         nResult = email_get_mailbox_by_mailbox_type(ugd->account_info->account_id, mailbox_type, &ugd->mailbox_info->mail_box);
538         if (nResult != EMAIL_ERROR_NONE) {
539                 debug_log("email_get_mailbox_by_mailbox_type failed! %d", nResult);
540                 return nResult;
541         }
542
543         nResult = _composer_make_mail(ugd, b_save_to_draft);
544         if (nResult < COMPOSER_ERROR_NONE) {
545                 debug_log("error in _composer_make_mail(%d)", nResult);
546                 return nResult;
547         }
548
549         nResult = email_move_mail_to_mailbox(mail_ids, 1, ugd->mailbox_info->mail_box->mailbox_id);
550         if (nResult != EMAIL_ERROR_NONE) {
551                 debug_log("email_move_mail_to_mailbox failed! %d", nResult);
552                 return nResult;
553         }
554
555         if (email_check_file_exist(ugd->saved_html_path)) {
556                 if (-1 == remove(ugd->saved_html_path)) {
557                         debug_log("Failed to remove file");
558                         return COMPOSER_ERROR_FAIL;
559                 }
560         }
561
562         return COMPOSER_ERROR_NONE;
563 }
564
565 static void _composer_make_draft_html_content(EmailComposerUGD *ugd, char **html_content, Eina_Bool b_save_to_draft)
566 {
567         debug_log("");
568
569         *html_content = g_strdup(ugd->latest_body_html_content);
570 }
571
572 int _composer_make_mail(EmailComposerUGD *ugd, Eina_Bool b_save_to_draft)
573 {
574         debug_log("");
575
576         email_account_t *account = NULL;
577         if (!email_engine_get_account_full_data(ugd->account_info->account_id, &account)) {
578                 debug_log("Failed to Get account full data");
579                 email_free_account(&account, 1);
580                 return COMPOSER_ERROR_GET_DATA_FAIL;
581         }
582
583         if (account == NULL) {
584                 debug_log("account is NULL!");
585                 return COMPOSER_ERROR_GET_DATA_FAIL;
586         }
587
588         debug_log("acc id = %d", ugd->account_info->account_id);
589         debug_log("priority = %d", (*ugd->account_info->account).options.priority);
590         debug_log("mailbox = %s", ugd->mailbox_info->mail_box->mailbox_name);
591         ugd->new_mail_info->mail_data->account_id = ugd->account_info->account_id;
592
593         ugd->new_mail_info->mail_data->report_status = EMAIL_MAIL_REPORT_NONE;
594
595         if (ugd->tracking_option[0] == 1) {
596                 ugd->new_mail_info->mail_data->report_status |= EMAIL_MAIL_REQUEST_MDN;
597         }
598         if (ugd->tracking_option[1] == 1) {
599                 ugd->new_mail_info->mail_data->report_status |= EMAIL_MAIL_REQUEST_DSN;
600         }
601         debug_log("ugd->new_mail_info->mail_data->report_status = %d", ugd->new_mail_info->mail_data->report_status);
602
603         ugd->new_mail_info->mail_data->priority = ugd->priority_option;
604
605         ugd->new_mail_info->mail_data->server_mailbox_name = strdup(ugd->mailbox_info->mail_box->mailbox_name);
606         ugd->new_mail_info->mail_data->mailbox_id = ugd->mailbox_info->mail_box->mailbox_id;
607
608         debug_log("user_name = %s, %s", ugd->account_info->account->user_display_name, account->user_display_name);
609         debug_log("email_addr = %s, %s", ugd->account_info->account->user_email_address, account->user_email_address);
610
611         if (ugd->composer_type == RUN_COMPOSER_EDIT) {
612                 ugd->new_mail_info->mail_data->body_download_status = 1;
613                 ugd->new_mail_info->mail_data->mail_id = ugd->existing_mail_info->mail_data->mail_id;
614         }
615
616         char uc[MAX_STR_LEN];
617         snprintf(uc, sizeof(uc), "\"%s\"<%s>", account->user_display_name, account->user_email_address);
618         ugd->new_mail_info->mail_data->full_address_from = g_strdup(uc);
619         debug_log("from = %s", uc);
620
621         if (account) {
622                 debug_log("email_free_account is called");
623                 email_free_account(&account, 1);
624                 account = NULL;
625         }
626
627         if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->to_mbe)) != NULL) {
628                 debug_log("to mbe");
629                 if (_composer_make_recipient_char_to_list(ugd, ugd->to_mbe, &(ugd->new_mail_info->mail_data->full_address_to)) < COMPOSER_ERROR_NONE)
630                         return COMPOSER_ERROR_GET_DATA_FAIL;
631         }
632
633         if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->cc_mbe)) != NULL) {
634                 debug_log("cc mbe");
635                 if (_composer_make_recipient_char_to_list(ugd, ugd->cc_mbe, &(ugd->new_mail_info->mail_data->full_address_cc)) < COMPOSER_ERROR_NONE)
636                         return COMPOSER_ERROR_GET_DATA_FAIL;
637         }
638
639         if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->bcc_mbe)) != NULL) {
640                 debug_log("bcc mbe");
641                 if (_composer_make_recipient_char_to_list(ugd, ugd->bcc_mbe, &(ugd->new_mail_info->mail_data->full_address_bcc)) < COMPOSER_ERROR_NONE)
642                         return COMPOSER_ERROR_GET_DATA_FAIL;
643         }
644
645         ugd->new_mail_info->mail_data->subject = elm_entry_markup_to_utf8(elm_entry_entry_get(ugd->subject_entry));
646
647         if (EINA_TRUE == ugd->has_body_html) {
648
649                 if (TRUE == email_check_file_exist(ugd->saved_html_path)) {
650                         if (-1 == remove(ugd->saved_html_path)) {
651                                 debug_log("Failed to remove temp html file");
652                                 return COMPOSER_ERROR_MAKE_MAIL_FAIL;
653                         }
654                 }
655
656                 if (TRUE == email_check_file_exist(SAVE_URI)) {
657                         if (-1 == remove(SAVE_URI)) {
658                                 debug_log("Failed to remove temp text file");
659                                 return COMPOSER_ERROR_MAKE_MAIL_FAIL;
660                         }
661                 }
662
663                 char *html_content = NULL;
664                 char *html_content_processed = NULL;
665                 char *plain_text_content = NULL;
666
667                 _composer_make_draft_html_content(ugd, &html_content, b_save_to_draft);
668
669                 if (html_content == NULL) {
670                         debug_log("html_content is NULL.");
671                         return COMPOSER_ERROR_MAKE_MAIL_FAIL;
672                 }
673
674                 debug_log("\nhtml_content:\n%s", html_content);
675
676                 if (ugd->attachment_inline_item_list == NULL) {
677                         debug_log("No images found or ERROR");
678                         html_content_processed = html_content;
679                 } else {
680                         if (!email_composer_change_image_paths_to_relative(html_content, &html_content_processed)) {
681                                 debug_log("email_composer_change_image_paths_to_relative Failed");
682                                 g_free(html_content);
683                                 html_content = NULL;
684                                 return COMPOSER_ERROR_MAKE_MAIL_FAIL;
685                         }
686                         debug_log("\nhtml_source_processed:\n%s", html_content_processed);
687
688                         g_free(html_content);
689                         html_content = NULL;
690                 }
691
692                 if (EINA_FALSE == email_composer_save_file(ugd->saved_html_path, html_content_processed, strlen(html_content_processed))) {
693                         debug_log("Write to html file failed");
694                         g_free(html_content_processed);
695                         html_content_processed = NULL;
696                         return COMPOSER_ERROR_MAKE_MAIL_FAIL;
697                 }
698
699                 g_free(html_content_processed);
700                 html_content_processed = NULL;
701
702                 if (ugd->plain_content != NULL && strlen(ugd->plain_content) == 0) {
703                         plain_text_content = g_strdup("\n");
704                 } else {
705                         plain_text_content = g_strdup(ugd->plain_content);
706                 }
707
708                 if (NULL == plain_text_content) {
709                         debug_log("ugd->plain_content is NULL");
710                         return COMPOSER_ERROR_MAKE_MAIL_FAIL;
711                 }
712                 
713                 if (EINA_FALSE == email_composer_save_file(SAVE_URI, plain_text_content, strlen(plain_text_content))) {
714                         debug_log("Write to %s file failed", SAVE_URI);
715                         g_free(plain_text_content);
716                         plain_text_content = NULL;
717                         return COMPOSER_ERROR_MAKE_MAIL_FAIL;
718                 }
719                 g_free(plain_text_content);
720                 plain_text_content = NULL;
721
722                 ugd->new_mail_info->mail_data->file_path_html = COMPOSER_STRDUP(ugd->saved_html_path);
723                 ugd->new_mail_info->mail_data->file_path_plain = COMPOSER_STRDUP(SAVE_URI);
724         }
725
726         int nAttachmentObjListCount = eina_list_count(ugd->attachment_item_obj_list) + ugd->inline_cnt;
727         debug_log("nAttachmentObjListCount : %d", nAttachmentObjListCount);
728
729         if ((nAttachmentObjListCount > 0) || (ugd->inline_cnt > 0)) {
730
731                 if (ugd->new_mail_info->attachment_list) {
732                         email_free_attachment_data(&ugd->new_mail_info->attachment_list, ugd->new_mail_info->mail_data->attachment_count);
733                         ugd->new_mail_info->attachment_list = NULL;
734                         ugd->new_mail_info->mail_data->attachment_count = 0;
735                 }
736
737                 ugd->new_mail_info->mail_data->attachment_count = nAttachmentObjListCount;
738
739                 debug_log("ugd->save_drafts : %d, ugd->new_mail_info->attachment_count : %d", ugd->save_drafts, ugd->new_mail_info->mail_data->attachment_count);
740
741                 ugd->new_mail_info->attachment_list = (email_attachment_data_t *)calloc(nAttachmentObjListCount, sizeof(email_attachment_data_t));
742
743                 int nCount = 0;
744                 Eina_Iterator *it = NULL;
745                 Evas_Object *attachment_obj = NULL;
746                 email_attachment_data_t *attachment_data;
747
748                 it = eina_list_iterator_new(ugd->attachment_item_obj_list);
749
750                 while (eina_iterator_next(it, (void **)&attachment_obj)) {
751
752                         attachment_data = evas_object_data_get(attachment_obj, "attachment_data");
753
754                         if (attachment_data) {
755                                 if (attachment_data->save_status == 1) {
756                                         ugd->new_mail_info->attachment_list[nCount].inline_content_status = attachment_data->inline_content_status;
757                                         ugd->new_mail_info->attachment_list[nCount].attachment_id = attachment_data->attachment_id;
758                                         ugd->new_mail_info->attachment_list[nCount].attachment_size = attachment_data->attachment_size;
759                                         ugd->new_mail_info->attachment_list[nCount].save_status = attachment_data->save_status;
760                                         ugd->new_mail_info->attachment_list[nCount].attachment_name = COMPOSER_STRDUP(attachment_data->attachment_name);
761                                         ugd->new_mail_info->attachment_list[nCount].attachment_path = COMPOSER_STRDUP(attachment_data->attachment_path);
762
763                                         debug_log("attachment_name : %s", ugd->new_mail_info->attachment_list[nCount].attachment_name);
764                                         debug_log("attachment_path : %s", ugd->new_mail_info->attachment_list[nCount].attachment_path);
765                                         debug_log("attachment_id : %d", ugd->new_mail_info->attachment_list[nCount].attachment_id);
766                                         debug_log("attachment_size : %d", ugd->new_mail_info->attachment_list[nCount].attachment_size);
767                                         debug_log("save_status : %d", ugd->new_mail_info->attachment_list[nCount].save_status);
768                                         debug_log("inline_content_status : %d", ugd->new_mail_info->attachment_list[nCount].inline_content_status);
769
770                                         nCount++;
771                                 }
772                         }
773                 }
774
775                 it = eina_list_iterator_new(ugd->attachment_inline_item_list);
776
777                 while (eina_iterator_next(it, (void **)&attachment_data)) {
778                         if (attachment_data) {
779                                 if (attachment_data->save_status == 1) {
780                                         ugd->new_mail_info->attachment_list[nCount].inline_content_status = attachment_data->inline_content_status;
781                                         ugd->new_mail_info->attachment_list[nCount].attachment_id = attachment_data->attachment_id;
782                                         ugd->new_mail_info->attachment_list[nCount].attachment_size = attachment_data->attachment_size;
783                                         ugd->new_mail_info->attachment_list[nCount].save_status = attachment_data->save_status;
784                                         ugd->new_mail_info->attachment_list[nCount].attachment_name = COMPOSER_STRDUP(attachment_data->attachment_name);
785                                         ugd->new_mail_info->attachment_list[nCount].attachment_path = COMPOSER_STRDUP(attachment_data->attachment_path);
786
787                                         debug_log("attachment_name : %s", ugd->new_mail_info->attachment_list[nCount].attachment_name);
788                                         debug_log("attachment_path : %s", ugd->new_mail_info->attachment_list[nCount].attachment_path);
789                                         debug_log("attachment_id : %d", ugd->new_mail_info->attachment_list[nCount].attachment_id);
790                                         debug_log("attachment_size : %d", ugd->new_mail_info->attachment_list[nCount].attachment_size);
791                                         debug_log("save_status : %d", ugd->new_mail_info->attachment_list[nCount].save_status);
792                                         debug_log("inline_content_status : %d", ugd->new_mail_info->attachment_list[nCount].inline_content_status);
793
794                                         nCount++;
795                                 }
796                         }
797                 }
798         }
799
800         ugd->new_mail_info->mail_data->flags_draft_field = 1;
801
802         return COMPOSER_ERROR_NONE;
803 }
804
805 EmailRecpInfo *_composer_separate_save_recipient_char(EmailComposerUGD *ugd, char *recipient)
806 {
807         debug_log("");
808         if (!ugd || !recipient) {
809                 debug_log("Function arguments NULL");
810                 return NULL;
811         }
812         debug_log("separate recipient char = %s", recipient);
813
814         char *temp = NULL;
815
816         if (recipient[0] == ' ') {
817                 temp = g_strdup(recipient++);
818                 debug_log("temp = %s", temp);
819         } else {
820                 temp = g_strdup(recipient);
821                 debug_log("temp = %s", temp);
822         }
823
824         if (temp == NULL) {
825                 return NULL;
826         }
827
828         gchar **vector = NULL;
829
830         vector = g_strsplit_set(temp, "\"<>", -1);
831
832         if (vector == NULL) {
833                 debug_log("vector == NULL");
834                 free(temp);
835                 return NULL;
836         }
837
838         EmailRecpInfo *ri = (EmailRecpInfo *) calloc(1, sizeof(EmailRecpInfo));
839
840         if (!ri) {
841                 debug_log("Memory allocation failed.");
842                 g_strfreev(vector);
843                 free(temp);
844                 return NULL;
845         }
846
847         gint tok_cnt = g_strv_length(vector);
848
849         debug_log("tok_cnt = %d", tok_cnt);
850         debug_log("temp = %s", temp);
851
852         if (tok_cnt == 1) {
853                 if (vector[0]) {
854                         ri->display_name = g_strdup(vector[0]);
855                         snprintf(ri->email_list[0].email_addr, sizeof(ri->email_list[0].email_addr), "%s", vector[0]);
856                 } else {
857                         g_strfreev(vector);
858                         free(temp);
859                         free(ri);
860                         return NULL;
861                 }
862         } else if (tok_cnt == 3) {
863                 if (vector[1]) {
864                         ri->display_name = g_strdup(vector[1]);
865                         snprintf(ri->email_list[0].email_addr, sizeof(ri->email_list[0].email_addr), "%s", vector[1]);
866                 } else {
867                         g_strfreev(vector);
868                         free(temp);
869                         free(ri);
870                         return NULL;
871                 }
872         } else if (tok_cnt == 5) {
873                 if (vector[1] && vector[3]) {
874                         ri->display_name = g_strdup(vector[1]);
875                         snprintf(ri->email_list[0].email_addr, sizeof(ri->email_list[0].email_addr), "%s", vector[3]);
876                 } else {
877                         g_strfreev(vector);
878                         free(temp);
879                         free(ri);
880                         return NULL;
881                 }
882         } else {
883                 g_strfreev(vector);
884                 free(temp);
885                 free(ri);
886                 return NULL;
887         }
888
889         ri->selected_email_idx = 0;
890         ri->email_cnt = 1;
891         ri->is_contact_info = false;
892         ri->is_always_bcc = false;
893         ri->is_from_addr = false;
894
895         g_strfreev(vector);
896         free(temp);
897
898         return ri;
899 }
900
901 void _composer_convert_ps_to_br(char *input)
902 {
903         const char *char_ps = "<ps>";
904         char *ptr = NULL;
905
906         if (!input)
907                 return;
908         while ((ptr = strstr(input, char_ps))) {
909                 ptr[1] = 'b';
910                 ptr[2] = 'r';
911         }
912
913         return;
914 }
915
916 int _composer_send_mail(EmailComposerUGD *ugd)
917 {
918         debug_log("");
919
920         if (!ugd->account_info->account) {
921                 debug_log("account is NULL");
922                 return COMPOSER_ERROR_SEND_FAIL;
923         }
924
925         debug_log("priority = %d", (*ugd->account_info->account).options.priority);
926         debug_log("request read report = %d", (*ugd->account_info->account).options.req_read_receipt);
927
928         if (ugd->composer_type == RUN_COMPOSER_EDIT) {
929                 /* Currently when a saved email is opened in drafts and edited before sending it then edited mail is not added to Outbox and edited email is not sent.
930                 This is because only mailbox name is updated to Outbox using move mail.
931
932                 Correct process will be as below -
933
934                 1) Add new edited email to Outbox.
935                 2) Delete the old email from Drafts / Outbox */
936
937                 if (0 < ugd->mailbox_info->mailbox_id) {
938                         int ret = _composer_add_mailbox_folder(ugd, EMAIL_MAILBOX_TYPE_OUTBOX, EINA_FALSE);
939
940                         if (ret < COMPOSER_ERROR_NONE) {
941                                 debug_log("error in _composer_add_mailbox_folder(%d)", ret);
942                                 return ret;
943                         }
944
945                         int sync = EMAIL_DELETE_LOCAL_AND_SERVER;
946
947                         /* Retrieve mailbox type from email-service and store it to identify Outbox */
948
949                         debug_log("mailbox type [%d]", ugd->existing_mail_info->mail_data->mailbox_type);
950                         if (EMAIL_MAILBOX_TYPE_OUTBOX == ugd->existing_mail_info->mail_data->mailbox_type)
951                                 sync = EMAIL_DELETE_LOCALLY;
952
953                         debug_log("Account id [%d] mailbox id [%d] mail id [%d]", ugd->account_info->account->account_id, ugd->mailbox_info->mailbox_id, ugd->nExistingMailID);
954
955                         if (!email_engine_delete_mail(ugd->account_info->account->account_id, ugd->mailbox_info->mailbox_id, ugd->nExistingMailID, sync)) {
956                                 debug_log("Deleting email is failed.");
957                                 return COMPOSER_ERROR_SEND_FAIL;
958                         }
959
960                 } else {
961                         debug_critical("mailbox name is null");
962                         return COMPOSER_ERROR_SEND_FAIL;
963                 }
964
965         } else {
966                 int ret = _composer_add_mailbox_folder(ugd, EMAIL_MAILBOX_TYPE_OUTBOX, EINA_FALSE);
967
968                 if (ret < COMPOSER_ERROR_NONE) {
969                         debug_log("error in _composer_add_mailbox_folder(%d)", ret);
970                         return ret;
971                 }
972         }
973
974         int handle = 0;
975         int err = 0;
976
977         if ((err = email_send_mail(ugd->new_mail_info->mail_data->mail_id, &handle)) != EMAIL_ERROR_NONE) {
978                 debug_log("   fail sending [%d]", err);
979                 return COMPOSER_ERROR_SEND_FAIL;
980         } else {
981                 debug_log("   finish sending");
982                 /* Support sync engine */
983                 if (ugd->composer_type == RUN_COMPOSER_REPLY || ugd->composer_type == RUN_COMPOSER_REPLY_ALL) {
984                         debug_log("existing mail id = %d, %d", ugd->nExistingMailID, ugd->existing_mail_info->mail_data->mail_id);
985                         email_set_flags_field(ugd->account_info->account->account_id, &ugd->nExistingMailID, 1, EMAIL_FLAGS_ANSWERED_FIELD, 1, 1);
986                 } else if (ugd->composer_type == RUN_COMPOSER_FORWARD) {
987                         debug_log("existing mail id = %d, %d", ugd->nExistingMailID, ugd->existing_mail_info->mail_data->mail_id);
988                         email_set_flags_field(ugd->account_info->account->account_id, &ugd->nExistingMailID, 1, EMAIL_FLAGS_FORWARDED_FIELD, 1, 1);
989                 }
990         }
991
992         return COMPOSER_ERROR_NONE;
993 }
994
995 int _composer_make_recipient_char_to_list(EmailComposerUGD *ugd, Evas_Object *obj, char **dest)
996 {
997         debug_log("");
998
999         char result[MAX_RECIPIENT_ADDRESSES_LEN] = { 0, };
1000
1001         debug_log("obj = %p", obj);
1002
1003         Elm_Object_Item *mbe_item;
1004         mbe_item = elm_multibuttonentry_first_item_get(obj);
1005         debug_log("mbe_item = %p", mbe_item);
1006
1007         while (mbe_item) {
1008                 EmailRecpInfo *ri;
1009                 int index = 0;
1010
1011                 ri = (EmailRecpInfo *) elm_object_item_data_get(mbe_item);
1012                 if (ri== NULL)
1013                         return COMPOSER_ERROR_GET_DATA_FAIL;
1014
1015                 index = ri->selected_email_idx;
1016
1017                 debug_log("display name = %s", ri->display_name);
1018                 debug_log("email_addr = %s", ri->email_list[index].email_addr);
1019
1020                 if (g_strcmp0(result, "") == 0) {
1021                         if (ri->display_name)
1022                                 snprintf(result, sizeof(result), "\"%s\" <%s>", ri->display_name, ri->email_list[index].email_addr);
1023                         else
1024                                 snprintf(result, sizeof(result), "<%s>", ri->email_list[index].email_addr);
1025                 } else {
1026                         if (ri->display_name)
1027                                 snprintf(result + strlen(result), sizeof(result) - strlen(result), ";\"%s\" <%s>", ri->display_name, ri->email_list[index].email_addr);
1028                         else
1029                                 snprintf(result + strlen(result), sizeof(result) - strlen(result), ";<%s>", ri->email_list[index].email_addr);
1030                 }
1031
1032                 mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
1033         }
1034
1035         debug_log("result = %s", result);
1036
1037         *dest = g_strdup(result);
1038
1039         return COMPOSER_ERROR_NONE;
1040 }
1041
1042 Eina_Bool _composer_save_draft_mail(void *data)
1043 {
1044         EmailComposerUGD *ugd = data;
1045         debug_log("");
1046
1047         if (!ugd) {
1048                 debug_log("ugd is NULL");
1049                 return ECORE_CALLBACK_CANCEL;
1050         }
1051
1052         if (ugd->send_timer) {
1053                 debug_log("delete send_timer");
1054                 ecore_timer_del(ugd->send_timer);
1055                 ugd->send_timer = NULL;
1056         }
1057
1058         int ret = _composer_add_mailbox_folder(ugd, EMAIL_MAILBOX_TYPE_DRAFT, EINA_TRUE);
1059
1060         if (ret < COMPOSER_ERROR_NONE) {
1061                 debug_log("Failed save in Drafts(%d)", ret);
1062
1063                 if (ugd->popup_list) {
1064                         debug_log("popup count = %d", eina_list_count(ugd->popup_list));
1065                         debug_log("composer_noti: %p", ugd->composer_noti);
1066
1067                         ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti/*obj*/);
1068                 }
1069
1070                 evas_object_del(ugd->composer_noti);
1071                 ugd->composer_noti = NULL;
1072
1073                 ugd->idler_save_draft = ecore_idler_add(_composer_show_fail_to_save, ugd);
1074         } else {
1075                 debug_log("Succeed in saving in Drafts");
1076                 debug_log("Account id [%d] mailbox id [%d] mail id [%d]", ugd->account_info->account->account_id, ugd->mailbox_info->mailbox_id, ugd->nExistingMailID);
1077
1078                 if (ugd->popup_list) {
1079                         debug_log("popup count = %d", eina_list_count(ugd->popup_list));
1080                         debug_log("composer_noti: %p", ugd->composer_noti);
1081                 
1082                         ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti/*obj*/);
1083                 }
1084
1085                 evas_object_del(ugd->composer_noti);
1086                 ugd->composer_noti = NULL;
1087
1088                 if (ugd->save_drafts == 0) {
1089                         ugd->idler_save_draft = ecore_idler_add(_composer_show_success_to_save, ugd);
1090                 } else {
1091                         char str[128] = { 0, };
1092                         snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_SAVED_IN_DRAFTS"));
1093                         ret = status_message_post(str);
1094                         if (ret)
1095                                 debug_log("status_message_post failed: %d", ret);
1096
1097                         ug_destroy_me(ugd->ug_main);
1098                 }
1099         }
1100
1101         return ECORE_CALLBACK_CANCEL;
1102 }
1103
1104 void _composer_save_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
1105 {
1106         debug_log("");
1107         if (!data) {
1108                 debug_log("data is NULL");
1109                 return;
1110         }
1111
1112         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1113
1114         char *pszBtnText = (char *)elm_object_text_get(obj);
1115         debug_log("selected button text = %s", pszBtnText);
1116
1117         if (pszBtnText && strcmp(pszBtnText, dgettext("sys_string", "IDS_COM_SK_YES")) == 0) {
1118                 if (ugd->need_download == EINA_TRUE) {
1119                         if (ugd->popup_list) {
1120                                 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
1121                                 debug_log("composer_noti: %p", ugd->composer_noti);
1122
1123                                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti/*obj*/);
1124                         }
1125
1126                         evas_object_del(ugd->composer_noti);
1127                         ugd->composer_noti = NULL;
1128
1129                         _composer_download_attachment(ugd);
1130                 } else {
1131                         _composer_save_draft_mail(ugd);
1132                 }
1133         } else if (pszBtnText && strcmp(pszBtnText, dgettext("sys_string", "IDS_COM_SK_NO")) == 0) {
1134                 ugd->idler_save_draft = ecore_idler_add(_composer_idler_destroy, ugd);
1135         } else if (pszBtnText && strcmp(pszBtnText, dgettext("sys_string", "IDS_COM_SK_CANCEL")) == 0) {
1136                 if (ewk_view_script_execute(ugd->body_ewkview, COMPOSER_JS_BODY_ENABLE_EDITABLE, _composer_focus_script_executed_cb, NULL) == EINA_FALSE)
1137                         debug_log("COMPOSER_JS_BODY_ENABLE_EDITABLE failed.");
1138                 _composer_noti_response_cb(data, obj, event_info);
1139         }
1140 }
1141
1142 Eina_Bool _composer_show_fail_to_save(void *data)
1143 {
1144         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1145
1146         if (ugd->idler_save_draft) {
1147                 debug_log("delete idler_save_draft");
1148                 ecore_idler_del(ugd->idler_save_draft);
1149                 ugd->idler_save_draft = NULL;
1150         }
1151
1152         if (ugd->b_sending)
1153                 ugd->b_sending = false;
1154
1155         if (ugd->composer_noti) {
1156                 evas_object_del(ugd->composer_noti);
1157                 ugd->composer_noti = NULL;
1158         }
1159         ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
1160                 _("IDS_EMAIL_POP_UNABLE_TO_SAVE_IN_DRAFTS"), 0, NULL, NULL, 1.5, _composer_save_draft_fail_response_cb);
1161
1162         return EINA_FALSE;
1163 }
1164
1165 Eina_Bool _composer_show_success_to_save(void *data)
1166 {
1167         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1168
1169         if (ugd->idler_save_draft) {
1170                 debug_log("delete idler_save_draft");
1171                 ecore_idler_del(ugd->idler_save_draft);
1172                 ugd->idler_save_draft = NULL;
1173         }
1174
1175         if (ugd->b_sending)
1176                 ugd->b_sending = false;
1177
1178         if (ugd->composer_noti) {
1179                 evas_object_del(ugd->composer_noti);
1180                 ugd->composer_noti = NULL;
1181         }
1182         ugd->composer_noti = _composer_create_noti(ugd, false, NULL,
1183                 _("IDS_EMAIL_POP_SAVED_IN_DRAFTS"), 0, NULL, NULL, 1.5, _composer_save_draft_response_cb);
1184
1185         return EINA_FALSE;
1186 }
1187
1188 static void _composer_save_draft_response_cb(void *data, Evas_Object *obj, void *event_info)
1189 {
1190         debug_log("");
1191
1192         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1193
1194         ugd->idler_save_draft = ecore_idler_add(_composer_idler_destroy, ugd);
1195 }
1196
1197 static void _composer_save_draft_fail_response_cb(void *data, Evas_Object *obj, void *event_info)
1198 {
1199         debug_log("");
1200
1201         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1202
1203         ugd->idler_save_draft = ecore_idler_add(_composer_idler_return, ugd);
1204 }
1205
1206 Eina_Bool _composer_popup_end_cb(void *data)
1207 {
1208         debug_log("");
1209
1210         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1211         _composer_popup_end(ugd, COMPOSER_ERROR_NONE);
1212
1213         return EINA_TRUE;
1214 }
1215
1216 void _composer_popup_end(EmailComposerUGD *ugd, int close_sg)
1217 {
1218         debug_log("");
1219
1220         if (ugd->send_timer) {
1221                 debug_log("delete send_timer");
1222                 ecore_timer_del(ugd->send_timer);
1223                 ugd->send_timer = NULL;
1224         }
1225
1226         if (ugd->composer_noti) {
1227                 evas_object_del(ugd->composer_noti);
1228                 ugd->composer_noti = NULL;
1229         }
1230
1231         if (close_sg == COMPOSER_ERROR_NONE) {
1232                 if (elm_multibuttonentry_first_item_get(ugd->to_mbe))
1233                         elm_multibuttonentry_clear(ugd->to_mbe);
1234                 if (elm_multibuttonentry_first_item_get(ugd->cc_mbe))
1235                         elm_multibuttonentry_clear(ugd->cc_mbe);
1236                 if (elm_multibuttonentry_first_item_get(ugd->bcc_mbe))
1237                         elm_multibuttonentry_clear(ugd->bcc_mbe);
1238
1239                 ug_destroy_me(ugd->ug_main);
1240         } else {
1241                 elm_object_disabled_set(ugd->send_btn, EINA_FALSE);
1242                 elm_object_disabled_set(ugd->cancel_btn, EINA_FALSE);
1243
1244                 ugd->bSendBtnDisabled = false;
1245         }
1246 }
1247
1248 void _composer_make_default_thumbnail(Evas_Object *eo, char *pszImgPath, int nItemType)
1249 {
1250         debug_log("");
1251
1252         char thumb_path[MAX_ATTACHMENT_FILE_LEN + 1] = { 0, };
1253
1254         if (eo == NULL || pszImgPath == NULL)
1255                 return;
1256
1257         debug_log("Image path = %s", pszImgPath);
1258
1259         Evas_Object *icon = eo;
1260
1261         if (nItemType == COMPOSER_ATTACHMENT_ITEM_IMAGE) {
1262                 debug_log("Thumbnail type - image");
1263
1264                 int err = _composer_attachment_make_ethumb(pszImgPath, thumb_path);
1265
1266                 if (err != COMPOSER_ERROR_NONE)
1267                         elm_image_file_set(icon, ATTACHMENT_IMAGE_FILE_PATH, NULL);
1268                 else {
1269                         debug_log("Thumbnail path = %s", thumb_path);
1270
1271                         elm_image_file_set(icon, thumb_path, NULL);
1272                 }
1273         }
1274
1275         else if (nItemType == COMPOSER_ATTACHMENT_ITEM_SOUND)
1276                 elm_image_file_set(icon, ATTACHMENT_AUDIO_FILE_PATH, NULL);
1277         else if (nItemType == COMPOSER_ATTACHMENT_ITEM_VIDEO)
1278                 elm_image_file_set(icon, ATTACHMENT_VIDEO_FILE_PATH, NULL);
1279         else {
1280                 gchar **vector = NULL;
1281                 gint tok_cnt = g_strv_length(vector);
1282
1283                 vector = g_strsplit_set(pszImgPath, ".", -1);
1284                 tok_cnt = g_strv_length(vector);
1285                 debug_log("tok_cnt: [%d], file(%s, %s)", tok_cnt, vector[tok_cnt - 2], vector[tok_cnt - 1]);
1286                 if (vector[tok_cnt - 1]) {
1287                         if (g_strcmp0(vector[tok_cnt - 1], ATTACHMENT_MEDIA_VCARD) == 0) {
1288                                 elm_image_file_set(icon, ATTACHMENT_VCARD_FILE_PATH, NULL);
1289                         } else if (g_strcmp0(vector[tok_cnt - 1], ATTACHMENT_MEDIA_VCALENDAR) == 0) {
1290                                 elm_image_file_set(icon, ATTACHMENT_VCALENDAR_FILE_PATH, NULL);
1291                         } else {
1292                                 elm_image_file_set(icon, ATTACHMENT_ETC_FILE_PATH, NULL);
1293                         }
1294                 } else
1295                         elm_image_file_set(icon, ATTACHMENT_ETC_FILE_PATH, NULL);
1296
1297                 g_strfreev(vector);
1298         }
1299 }
1300
1301 Evas_Object *_composer_load_edj(Evas_Object *parent, const char *file, const char *group)
1302 {
1303         debug_log("");
1304         Evas_Object *eo;
1305         int r;
1306
1307         eo = elm_layout_add(parent);
1308         if (eo) {
1309                 r = elm_layout_file_set(eo, file, group);
1310                 if (!r) {
1311                         evas_object_del(eo);
1312                         return NULL;
1313                 }
1314
1315                 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1316         }
1317
1318         return eo;
1319 }
1320
1321 Evas_Object *_composer_create_navigation_layout(EmailComposerUGD *ugd)
1322 {
1323         debug_log("");
1324         Evas_Object *parent = ugd->main_layout;
1325         Evas_Object *navi_bar;
1326
1327         navi_bar = elm_naviframe_add(parent);
1328         elm_object_part_content_set(parent, "elm.swallow.content", navi_bar);
1329
1330         evas_object_show(navi_bar);
1331
1332         return navi_bar;
1333 }
1334
1335 Evas_Object *_composer_create_composer_layout(Evas_Object *parent)
1336 {
1337         debug_log("");
1338         Evas_Object *layout;
1339
1340         layout = elm_layout_add(parent);
1341
1342         elm_layout_file_set(layout, COMPOSER_EDJ_NAME, "layout.composer");
1343         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1344         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
1345         evas_object_show(layout);
1346
1347         return layout;
1348 }
1349
1350 Evas_Object *_composer_create_outer_layout(Evas_Object *parent)
1351 {
1352         debug_log("");
1353         Evas_Object *layout;
1354
1355         layout = elm_layout_add(parent);
1356
1357         elm_layout_theme_set(layout, "layout", "application", "noindicator");
1358         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
1359         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1360         evas_object_show(layout);
1361
1362         return layout;
1363 }
1364
1365 Evas_Object *_composer_create_main_scroller(Evas_Object *parent)
1366 {
1367         debug_log("");
1368         Evas_Object *scroller;
1369
1370         scroller = elm_scroller_add(parent);
1371
1372         elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_FALSE);
1373         elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
1374         evas_object_show(scroller);
1375
1376         return scroller;
1377 }
1378
1379 Evas_Object *_composer_create_box(Evas_Object *parent)
1380 {
1381         debug_log("");
1382
1383         Evas_Object *box = elm_box_add(parent);
1384         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1385         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
1386         evas_object_show(box);
1387
1388         elm_object_focus_allow_set(box, EINA_FALSE);
1389
1390         return box;
1391 }
1392
1393 void _composer_set_mail_info(EmailComposerUGD *ugd)
1394 {
1395         debug_log("");
1396
1397         _composer_add_to_address(ugd);
1398         _composer_add_cc_address(ugd);
1399         _composer_add_bcc_address(ugd);
1400
1401         _composer_add_subject(ugd);
1402         _composer_add_body(ugd);
1403
1404         if (ugd->composer_type != RUN_COMPOSER_EDIT) {
1405                 _composer_add_origin_msg(ugd);
1406         }
1407
1408         if (ugd->composer_type == RUN_COMPOSER_FORWARD && ugd->account_info->account->options.forward_with_files) {
1409
1410                 email_mail_data_t *mail_data = ugd->existing_mail_info->mail_data;
1411                 debug_log("attachment_count:%d, inline_content_count:%d", mail_data->attachment_count, mail_data->inline_content_count);
1412
1413                 if (mail_data->attachment_count > 0) {
1414                         int i = 0;
1415                         for (i = 0; i < mail_data->attachment_count; i++) {
1416                                 email_attachment_data_t *attachment_list = ugd->existing_mail_info->attachment_list;
1417                                 debug_log("save_status:%d, inline_content_status:%d", attachment_list[i].save_status, attachment_list[i].inline_content_status);
1418                                 if (attachment_list[i].save_status == FALSE && attachment_list[i].inline_content_status == FALSE) {
1419                                         ugd->need_download = EINA_TRUE;
1420                                         ugd->fw_dn_cnt++;
1421                                 }
1422                                 ugd->fw_attach_cnt++;
1423                         }
1424                         debug_log("ugd->need_download:%d, fw_dn_cnt:%d, fw_attach_cnt:%d", ugd->need_download, ugd->fw_dn_cnt, ugd->fw_attach_cnt);
1425                 }
1426         }
1427
1428         _composer_add_attachment(ugd);
1429
1430         char *plain_charset = NULL;
1431         char *charset = NULL;
1432         if ((EINA_TRUE == ugd->has_body_html) &&
1433                 (ugd->composer_type == RUN_COMPOSER_EDIT || ugd->composer_type == RUN_COMPOSER_REPLY || ugd->composer_type == RUN_COMPOSER_REPLY_ALL || ugd->composer_type == RUN_COMPOSER_FORWARD)) {
1434                 email_mail_data_t *mail_data = ugd->existing_mail_info->mail_data;
1435                 _composer_add_softlink_to_inline_images(ugd);
1436
1437                 if (mail_data && mail_data->file_path_plain) {
1438                         plain_charset = email_parse_get_filename_from_path(mail_data->file_path_plain);
1439                         debug_log("plain_charset : %s", plain_charset);
1440                         if (plain_charset) {
1441                                 Ewk_Settings *ewkSetting = ewk_view_settings_get(ugd->body_ewkview);
1442
1443                                 if (ewkSetting == NULL)
1444                                         debug_log("ewkSetting is NULL.");
1445
1446                                 ewk_settings_default_encoding_set(ewkSetting, plain_charset);
1447                         }
1448                 } else {
1449                         if (mail_data && mail_data->file_path_html) {
1450                                 charset = email_parse_get_filename_from_path(mail_data->file_path_html);
1451                                 debug_log("body html filename charset:%s", charset);
1452                                 if (charset) {
1453                                         Ewk_Settings *ewkSetting = ewk_view_settings_get(ugd->body_ewkview);
1454
1455                                         if (ewkSetting == NULL)
1456                                                 debug_log("ewkSetting is NULL.");
1457
1458                                         ewk_settings_default_encoding_set(ewkSetting, charset);
1459                                 }
1460                         }
1461                 }
1462         }
1463
1464         if (EINA_TRUE == ugd->has_body_html) {
1465                 debug_log("");
1466
1467                 char file_path[MAX_PATH_LEN] = { 0, };
1468                 snprintf(file_path, sizeof(file_path), "file://%s", ugd->saved_html_path);
1469                 debug_log("file_path: (%s)", file_path);
1470
1471                 ewk_view_url_set(ugd->body_ewkview, file_path);
1472                 if (plain_charset)
1473                         g_free(plain_charset);
1474                 if (charset)
1475                         g_free(charset);
1476         }
1477 }
1478
1479 void _composer_show_download_attachment_popup(EmailComposerUGD *ugd)
1480 {
1481         debug_log("");
1482
1483         char msg[MAX_STR_LEN] = { 0, };
1484         if (ugd->fw_dn_cnt > 1)
1485                 snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_DOWNLOAD_ATTACHMENTS_Q"));
1486         else
1487                 snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_DOWNLOAD_ATTACHMENT_Q"));
1488
1489         if (ugd->dn_noti_popup) {
1490                 evas_object_del(ugd->dn_noti_popup);
1491                 ugd->dn_noti_popup = NULL;
1492         }
1493         ugd->dn_noti_popup = _composer_create_noti(ugd, false, NULL, msg, 2,
1494                 dgettext("sys_string", "IDS_COM_SK_OK"), dgettext("sys_string", "IDS_COM_SK_CANCEL"), 0.0, _composer_attachment_popup_response_cb);
1495 }
1496
1497 static void _composer_attachment_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
1498 {
1499         debug_log("");
1500
1501         if (!data) {
1502                 debug_log("data is NULL");
1503                 return;
1504         }
1505
1506         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1507
1508         char *pszBtnText = (char *)elm_object_text_get(obj);
1509         debug_log("selected button text = %s", pszBtnText);
1510
1511         if (ugd->popup_list) {
1512                 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
1513                 debug_log("obj: %p", obj);
1514                 debug_log("dn_noti_popup: %p", ugd->dn_noti_popup);
1515
1516                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->dn_noti_popup/*obj*/);
1517         }
1518
1519         evas_object_del(ugd->dn_noti_popup);
1520         ugd->dn_noti_popup = NULL;
1521
1522         if (pszBtnText && strcmp(pszBtnText, dgettext("sys_string", "IDS_COM_SK_OK")) == 0) {
1523                 _composer_download_attachment(ugd);
1524
1525         } else if (pszBtnText && strcmp(pszBtnText, dgettext("sys_string", "IDS_COM_SK_CANCEL")) == 0) {
1526                 ugd->selected_entry = ugd->to_mbe_entry;
1527                 ugd->idler_set_focus = ecore_idler_add(_composer_mbe_set_focus, ugd);
1528         }
1529
1530 }
1531
1532 Eina_Bool _composer_show_progress_popup(void *data)
1533 {
1534         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1535
1536         Evas_Object *progressbar;
1537         Evas_Object *popup;
1538
1539         if (ugd->idler_show_progress) {
1540                 debug_log("delete idler_show_progress");
1541                 ecore_idler_del(ugd->idler_show_progress);
1542                 ugd->idler_show_progress = NULL;
1543         }
1544
1545         ugd->fw_dn_idx = 0;
1546         ugd->fw_dn_total_cnt = ugd->fw_dn_cnt;
1547
1548         char buf[128] = { 0, };
1549
1550         snprintf(buf, sizeof(buf), "%s [0/%d]", _("IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"), ugd->fw_dn_cnt);
1551
1552         debug_log("popup count = %d", eina_list_count(ugd->popup_list));
1553         debug_log("dn_noti_popup: %p", ugd->dn_noti_popup);
1554
1555         evas_object_del(ugd->dn_noti_popup);
1556         ugd->dn_noti_popup = NULL;
1557
1558         if (ugd->dn_prog_popup) {
1559                 evas_object_del(ugd->dn_prog_popup);
1560                 ugd->dn_prog_popup = NULL;
1561         }
1562         popup = _composer_create_noti(ugd, false, NULL, buf, 1,
1563                 dgettext("sys_string", "IDS_COM_SK_CANCEL"), NULL, 0.0, _composer_dn_prog_popup_response_cb);
1564
1565         ugd->dn_prog_popup = popup;
1566         elm_object_focus_set(popup, EINA_TRUE);
1567
1568         Evas_Object *label = elm_label_add(popup);
1569         elm_object_text_set(label, buf);
1570         evas_object_show(label);
1571         ugd->fw_dn_label = label;
1572
1573         Evas_Object *box = elm_box_add(popup);
1574
1575         progressbar = elm_progressbar_add(popup);
1576
1577         elm_object_style_set(progressbar, "list_progress");
1578
1579         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
1580         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1581         elm_progressbar_value_set(progressbar, 0.0);
1582         evas_object_show(progressbar);
1583         ugd->fw_dn_progress = progressbar;
1584         evas_object_show(box);
1585
1586         elm_box_pack_end(box, label);
1587         elm_box_pack_end(box, progressbar);
1588
1589         elm_object_content_set(popup, box);
1590
1591         return EINA_FALSE;
1592 }
1593
1594 static void _composer_dn_prog_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
1595 {
1596         debug_log("");
1597
1598         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1599
1600         char *pszBtnText = (char *)elm_object_text_get(obj);
1601         debug_log("selected button text = %s", pszBtnText);
1602
1603         if (pszBtnText && strcmp(pszBtnText, dgettext("sys_string", "IDS_COM_SK_CANCEL")) == 0) {
1604                 if (ugd->popup_list) {
1605                         debug_log("popup count = %d", eina_list_count(ugd->popup_list));
1606                         debug_log("obj: %p", obj);
1607                         debug_log("dn_prog_popup: %p", ugd->dn_prog_popup);
1608
1609                         ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->dn_prog_popup/*obj*/);
1610                 }
1611
1612                 if (ugd->dn_prog_popup) {
1613                         evas_object_del(ugd->dn_prog_popup);
1614                         ugd->dn_prog_popup = NULL;
1615                 }
1616
1617                 _composer_webkit_set_body_script(data);
1618                 elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE); // block the focus not to open IME.
1619                 elm_object_disabled_set(ugd->send_btn, EINA_FALSE);
1620                 elm_object_disabled_set(ugd->cancel_btn, EINA_FALSE);
1621
1622                 _composer_cancel_download_attachment(ugd);
1623
1624                 ugd->selected_entry = ugd->to_mbe_entry;
1625                 ugd->idler_set_focus = ecore_idler_add(_composer_mbe_set_focus, ugd);
1626         }
1627 }
1628
1629 static Eina_Bool _composer_save_attachment(EmailComposerUGD *ugd, int index)
1630 {
1631         debug_log("");
1632
1633         if (ugd->fw_attachment_list == NULL) {
1634                 return EINA_FALSE;
1635         }
1636
1637         EMAIL_ATTACHMENT_INFO_S *info = (EMAIL_ATTACHMENT_INFO_S *) g_list_nth_data(ugd->fw_attachment_list, index);
1638
1639         if (info == NULL) {
1640                 debug_log("EMAIL_ATTACHMENT_INFO_S *info is NULL");
1641                 return EINA_FALSE;
1642         }
1643
1644         if (!info->downloaded) {
1645                 int handle = 0;
1646                 gboolean res = FALSE;
1647
1648                 debug_log("Need attachment download");
1649
1650                 res = email_engine_attachment_download(ugd->existing_mail_info->mail_data->account_id, info->mail_id, info->index, &handle);
1651
1652                 if (res == TRUE) {
1653                         ugd->fw_dn_handle[index] = handle;
1654                         ugd->idler_show_progress = ecore_idler_add(_composer_show_progress_popup, ugd);
1655                 } else {
1656                         info->downloaded = false;
1657                         _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
1658                                                         _("IDS_EMAIL_POP_UNABLE_TO_OPEN_ATTACHMENT"), 1,
1659                                                         dgettext("sys_string", "IDS_COM_SK_OK"), NULL,
1660                                                         0, _composer_popup_response_cb);
1661                 }
1662
1663                 return (res ? EINA_TRUE : EINA_FALSE);
1664         }
1665
1666         return EINA_FALSE;
1667 }
1668
1669 void _composer_download_attachment(EmailComposerUGD *ugd)
1670 {
1671         debug_log("");
1672         int i = 0;
1673
1674         debug_log("ugd->fw_attach_cnt = %d", ugd->fw_attach_cnt);
1675
1676         if (ugd->fw_attach_cnt > 0) {
1677                 for ( i = 0 ; i < ugd->fw_attach_cnt ; i++ ) {
1678                         if (_composer_save_attachment(ugd, i) == EINA_TRUE) {
1679                                 int ret;
1680                                 service_h service = NULL;
1681
1682                                 ret = service_create(&service);
1683                                 debug_log("service_create: %d", ret);
1684                                 if (!service) {
1685                                         debug_log("service create failed");
1686                                         return;
1687                                 }
1688
1689                                 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_UPDATE, EMAIL_BUNDLE_KEY_UPDATE);
1690                                 debug_log("service_add_extra_data: %d", ret);
1691
1692                                 ret = ug_send_result(ugd->ug_main, service);
1693                                 debug_log("ug_send_result: %d", ret);
1694
1695                                 ret = service_destroy(service);
1696                                 debug_log("service_destroy: %d", ret);
1697                         }
1698                 }
1699         } else {
1700                 ugd->need_download = EINA_FALSE;
1701                 ugd->bSendBtnDisabled = true;
1702                 ugd->send_timer = ecore_timer_add(0.5, _composer_send_mail_cb, ugd);
1703         }
1704  }
1705
1706 void _composer_attachment_cancel_download(EmailComposerUGD *ugd)
1707 {
1708         debug_log("");
1709
1710         int att_cnt = g_list_length(ugd->fw_attachment_list);
1711         int i;
1712
1713         debug_log("att_cnt = %d", att_cnt);
1714         for (i = 0; i < att_cnt; i++) {
1715                 debug_log("handle index = %d", i);
1716                 debug_log("handle = %d", ugd->fw_dn_handle[i]);
1717                 email_engine_stop_working(ugd->account_info->account_id, ugd->fw_dn_handle[i]);
1718         }
1719 }
1720
1721 void _composer_cancel_download_attachment(EmailComposerUGD *ugd)
1722 {
1723         debug_log("");
1724
1725         int ret;
1726         service_h service = NULL;
1727
1728         _composer_attachment_cancel_download(ugd);
1729
1730         ret = service_create(&service);
1731         debug_log("service_create: %d", ret);
1732         if (!service) {
1733                 debug_log("service create failed");
1734                 return;
1735         }
1736
1737         ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CANCEL_ALL, "CANCEL_ALL");
1738         debug_log("service_add_extra_data: %d", ret);
1739
1740         ug_send_result(ugd->ug_main, service);
1741
1742         ret = service_destroy(service);
1743         debug_log("service_destroy: %d", ret);
1744 }
1745
1746 void _composer_update_attachment_info(EmailComposerUGD *ugd, int index)
1747 {
1748         debug_log("");
1749
1750         int nAttachmentObjListCount = eina_list_count(ugd->attachment_item_obj_list);
1751         debug_log("nAttachmentObjListCount : %d", nAttachmentObjListCount);
1752
1753         if (nAttachmentObjListCount > 0) {
1754                 int nCount = 0;
1755                 Eina_Iterator *it = NULL;
1756                 Evas_Object *attachment_obj = NULL;
1757                 email_attachment_data_t *attachment_data;
1758
1759                 it = eina_list_iterator_new(ugd->attachment_item_obj_list);
1760
1761                 while (eina_iterator_next(it, (void **)&attachment_obj)) {
1762                         char *path = NULL;
1763                         EMAIL_ATTACHMENT_INFO_S *info = (EMAIL_ATTACHMENT_INFO_S *) g_list_nth_data(ugd->fw_attachment_list, nCount);
1764                         debug_log("info : %x", info);
1765                         if (info) {
1766                                 debug_log("info->path : %s", info->path);
1767                                 debug_log("info->downloaded : %d", info->downloaded);
1768                                 debug_log("info->attach_id : %d", info->attach_id);
1769                                 if (info->index == index) {
1770                                         info->downloaded = true;
1771                                         path = email_engine_get_attachment_path(info->attach_id);
1772
1773                                         debug_log("info->downloaded : %d", info->downloaded);
1774                                         debug_log("path : %s", path);
1775
1776                                         attachment_data = evas_object_data_get(attachment_obj, "attachment_data");
1777
1778                                         if (attachment_data && path && STR_VALID(path)) {
1779                                                 int ret;
1780                                                 char newpath[MAX_PATH_LEN] = { 0, };
1781                                                 debug_log("path[%s]", path);
1782                                                 ret = email_attachments_save_file(path, newpath, NULL);
1783                                                 if (ret == EMAIL_EXT_SAVE_ERR_NONE) {
1784                                                         char str[128] = { 0, };
1785                                                         snprintf(str, sizeof(str), "%s", dgettext("sys_string", "IDS_COM_POP_SAVED"));
1786                                                         ret = status_message_post(str);
1787                                                         if (ret)
1788                                                                 debug_log("status_message_post failed: %d", ret);
1789                                                 }
1790
1791                                                 attachment_data->attachment_path = g_strdup(path);
1792                                                 attachment_data->save_status = info->downloaded;
1793                                                 debug_log("attachment_name : %s", attachment_data->attachment_name);
1794                                                 debug_log("attachment_path : %s", attachment_data->attachment_path);
1795                                                 debug_log("attachment_id : %d", attachment_data->attachment_id);
1796                                                 debug_log("attachment_size : %d", attachment_data->attachment_size);
1797                                                 debug_log("save_status : %d", attachment_data->save_status);
1798                                                 debug_log("inline_content_status : %d", attachment_data->inline_content_status);
1799                                         }
1800
1801                                         if (path != NULL) {
1802                                                 g_free(path);
1803                                                 path = NULL;
1804                                         }
1805                                 }
1806                         }
1807                         nCount++;
1808                 }
1809         }
1810 }
1811
1812 const char *_composer_get_sent_time(EmailComposerMail *mail_info)
1813 {
1814         debug_log("");
1815
1816         time_t time;
1817         time = mail_info->mail_data->date_time;
1818
1819         char *formatted_date = NULL;
1820
1821         if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1822                 formatted_date = email_get_date_text(icu_locale, "yMMMEEEdhms", &time);
1823         else
1824                 formatted_date = email_get_date_text(icu_locale, "yMMMEEEdHms", &time);
1825
1826         debug_log("date&time: %d [%s]", time, formatted_date);
1827
1828         return formatted_date;
1829 }
1830
1831 char *_composer_get_wday(int tm_wday)
1832 {
1833         debug_log("");
1834
1835         char *wday;
1836         wday = (char *)g_malloc0(10 * sizeof(char));
1837
1838         switch (tm_wday) {
1839         case 0:
1840                 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_SUN"));
1841                 break;
1842         case 1:
1843                 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_MON"));
1844                 break;
1845         case 2:
1846                 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_TUE"));
1847                 break;
1848         case 3:
1849                 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_WED"));
1850                 break;
1851         case 4:
1852                 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_THU"));
1853                 break;
1854         case 5:
1855                 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_FRI"));
1856                 break;
1857         case 6:
1858                 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_SAT"));
1859                 break;
1860         default:
1861                 break;
1862         }
1863
1864         return wday;
1865 }
1866
1867 char *_composer_get_month(int tm_mon)
1868 {
1869         debug_log("");
1870
1871         char *mon;
1872         mon = (char *)g_malloc0(10 * sizeof(char));
1873
1874         switch (tm_mon) {
1875         case 0:
1876                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_JAN"));
1877                 break;
1878         case 1:
1879                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_FEB"));
1880                 break;
1881         case 2:
1882                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_MAR"));
1883                 break;
1884         case 3:
1885                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_APR"));
1886                 break;
1887         case 4:
1888                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_MAY"));
1889                 break;
1890         case 5:
1891                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_JUN"));
1892                 break;
1893         case 6:
1894                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_JUL"));
1895                 break;
1896         case 7:
1897                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_AUG"));
1898                 break;
1899         case 8:
1900                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_SEP"));
1901                 break;
1902         case 9:
1903                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_OCT"));
1904                 break;
1905         case 10:
1906                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_NOV"));
1907                 break;
1908         case 11:
1909                 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_DEC"));
1910                 break;
1911         default:
1912                 break;
1913         }
1914
1915         return mon;
1916 }
1917
1918 bool _composer_is_valid_email(const char *addr)
1919 {
1920         char *token1 = NULL;
1921         char *token2 = NULL;
1922
1923         debug_log("addr = %s", addr);
1924
1925         if (addr[0] == '\0') {
1926                 return true;
1927         }
1928
1929         token1 = strchr(addr, '@');
1930         if (!token1) {
1931                 debug_log("there is no @");
1932                 return false;
1933         }
1934
1935         if (strchr(&token1[1], '@')) {
1936                 debug_log("there is too many @");
1937                 return false;
1938         }
1939
1940         token2 = strchr(token1, '.');
1941         if (!token2) {
1942                 debug_log("there is no .");
1943                 return false;
1944         }
1945
1946         if ((token2 == token1 + 1) || (*(token2 + 1) == '\0')) {
1947                 debug_log("Should be xxx.xxx");
1948                 return false;
1949         }
1950
1951         return true;
1952 }
1953
1954 bool _composer_check_recipient_is_duplicated(EmailComposerUGD *ugd, Evas_Object *obj, EmailRecpInfo * ri)
1955 {
1956         debug_log("");
1957
1958         bool isDuplicated = false;
1959
1960         Elm_Object_Item *mbe_item;
1961         EmailRecpInfo *iter_ri = NULL;
1962
1963         mbe_item = elm_multibuttonentry_first_item_get(obj);
1964
1965         while (mbe_item) {
1966                 iter_ri = elm_object_item_data_get(mbe_item);
1967
1968                 if (iter_ri != ri) {
1969                         if (!g_strcmp0(iter_ri->email_list[iter_ri->selected_email_idx].email_addr, ri->email_list[0].email_addr)) {
1970                                 isDuplicated = true;
1971                                 break;
1972                         }
1973                 }
1974
1975                 mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
1976         }
1977
1978         return isDuplicated;
1979 }
1980
1981 Eina_Bool _composer_idler_destroy(void *data)
1982 {
1983         debug_log("");
1984         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1985
1986         char str[128] = { 0, };
1987         snprintf(str, sizeof(str), "%s", _("IDS_EMAIL_POP_MESSAGE_DELETED"));
1988         int ret = status_message_post(str);
1989         if (ret)
1990                 debug_log("status_message_post failed: %d", ret);
1991
1992         elm_object_tree_focus_allow_set(ugd->c_layout, EINA_FALSE); // block the focus not to open IME.
1993
1994         if (ugd->idler_save_draft) {
1995                 debug_log("delete idler_save_draft");
1996                 ecore_idler_del(ugd->idler_save_draft);
1997                 ugd->idler_save_draft = NULL;
1998         }
1999
2000         if (ugd->popup_list) {
2001                 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
2002                 debug_log("composer_noti: %p", ugd->composer_noti);
2003
2004                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
2005         }
2006
2007         evas_object_del(ugd->composer_noti);
2008         ugd->composer_noti = NULL;
2009
2010         ug_destroy_me(ugd->ug_main);
2011
2012         return EINA_FALSE;
2013 }
2014
2015 Eina_Bool _composer_idler_return(void *data)
2016 {
2017         debug_log("");
2018         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2019
2020         if (ugd->idler_save_draft) {
2021                 debug_log("delete idler_save_draft");
2022                 ecore_idler_del(ugd->idler_save_draft);
2023                 ugd->idler_save_draft = NULL;
2024         }
2025
2026         if (ugd->popup_list) {
2027                 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
2028                 debug_log("composer_noti: %p", ugd->composer_noti);
2029
2030                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
2031         }
2032
2033         evas_object_del(ugd->composer_noti);
2034         ugd->composer_noti = NULL;
2035
2036         return EINA_FALSE;
2037 }
2038
2039 void _composer_entry_filter_remove_markup(void *data, Evas_Object *entry, char **text)
2040 {
2041         debug_log("");
2042         if (text == NULL || *text == NULL) {
2043                 debug_log("New Text is NULL");
2044                 return;
2045         }
2046
2047         char *preedit_str = NULL;
2048         char *utf8_text = NULL;
2049         char *convert_text = NULL;
2050
2051         /* Check preeditting text and return if it exist */
2052         preedit_str = strstr(*text, "<preedit_sel>");
2053         if (preedit_str)
2054                 return;
2055
2056         /* Convert from markup text to utf8 text from entry */
2057         utf8_text = elm_entry_markup_to_utf8(*text);
2058         if (utf8_text) {
2059
2060                 /* If the string contains "Carrage return ('\n'), it should be changed "<br>" to show properly */
2061                 convert_text = elm_entry_utf8_to_markup(utf8_text);
2062                 if (convert_text) {
2063                         free(*text);
2064                         *text = strdup(convert_text);
2065                         free(convert_text);
2066                 }
2067                 free(utf8_text);
2068         }
2069 }
2070
2071 void _composer_add_to_address(EmailComposerUGD *ugd)
2072 {
2073         debug_log("");
2074
2075         Eina_Bool overflow_flag = TRUE;
2076         Eina_Bool invalid_address_flag = FALSE;
2077
2078         char *from_addr = NULL;
2079
2080         if (ugd->existing_mail_info->mail_data != NULL && ugd->existing_mail_info->mail_data->full_address_from != NULL &&
2081                 (ugd->composer_type == RUN_COMPOSER_REPLY || ugd->composer_type == RUN_COMPOSER_REPLY_ALL)) {
2082
2083                 int ri_used = 0;
2084                 char *from_temp = g_strdup(ugd->existing_mail_info->mail_data->full_address_from);
2085
2086                 EmailRecpInfo *ri = _composer_separate_save_recipient_char(ugd, from_temp);
2087
2088                 if (ri) {
2089                         debug_log("display_name = %s, email_address = %s", ri->display_name, ri->email_list[0].email_addr);
2090
2091                         if (!_composer_check_recipient_is_duplicated(ugd, ugd->to_mbe, ri)) {
2092                                 elm_multibuttonentry_item_append(ugd->to_mbe, ri->display_name, NULL, ri);
2093                                 ri_used = 1;
2094                         } else {
2095                                 if (ugd->composer_noti) {
2096                                         evas_object_del(ugd->composer_noti);
2097                                         ugd->composer_noti = NULL;
2098                                 }
2099                                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
2100                                         dgettext("sys_string", "IDS_COM_POP_ALREDY_EXISTS"), 0, NULL, NULL, 1.0, _composer_noti_response_cb);
2101                         }
2102                 }
2103
2104                 if (ri && !ri_used) {
2105                         if (ri->display_name) {
2106                                 free(ri->display_name);
2107                                 ri->display_name = NULL;
2108                         }
2109                         free(ri);
2110                         ri = NULL;
2111                 }
2112         }
2113
2114         debug_log("");
2115
2116         if ((ugd->existing_mail_info->mail_data != NULL && ugd->existing_mail_info->mail_data->full_address_to != NULL &&
2117                 (ugd->composer_type == RUN_COMPOSER_REPLY_ALL || ugd->composer_type == RUN_COMPOSER_EDIT)) ||
2118                 (ugd->new_mail_info->mail_data != NULL && ugd->new_mail_info->mail_data->full_address_to != NULL && ugd->composer_type == RUN_COMPOSER_EXTERNAL)) {
2119                 char *temp = NULL;
2120                 char *token = NULL;
2121                 char *temp_name[MAX_RECIPIENT_ADDRESS_LEN];
2122
2123                 email_address_info_t *addrs_info = NULL;
2124
2125                 int duplicate_cnt = 0;
2126
2127                 if (ugd->existing_mail_info->mail_data && ugd->existing_mail_info->mail_data->full_address_to) {
2128                         temp = g_strdup(ugd->existing_mail_info->mail_data->full_address_to);
2129                         debug_log("to = %s", ugd->existing_mail_info->mail_data->full_address_to);
2130                 } else if (ugd->new_mail_info->mail_data && ugd->new_mail_info->mail_data->full_address_to) {
2131                         temp = g_strdup(ugd->new_mail_info->mail_data->full_address_to);
2132                         debug_log("to = %s", ugd->new_mail_info->mail_data->full_address_to);
2133                 }
2134
2135                 token = strtok(temp, ";");
2136                 debug_log("to = %s\ntoken = %s", temp, token);
2137
2138                 int i = 0;
2139
2140                 while (token != NULL && (overflow_flag = (i < (MAX_RECIPIENT_COUNT)))) {
2141                         temp_name[i] = g_strdup(token);
2142                         i++;
2143                         token = strtok(NULL, ";");
2144                 }
2145
2146                 if (!overflow_flag) {
2147                         char msg[MAX_STR_LEN] = { 0, };
2148                         snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_RECIPIENTS_HPD_REACHED"), MAX_RECIPIENT_COUNT);
2149
2150                         if (ugd->composer_noti) {
2151                                 evas_object_del(ugd->composer_noti);
2152                                 ugd->composer_noti = NULL;
2153                         }
2154                         ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
2155                                 msg, 0, NULL, NULL, 2.0, _composer_noti_response_cb);
2156                 }
2157
2158                 int max = i;
2159
2160                 if (max >= MAX_RECIPIENT_COUNT)
2161                         max = MAX_RECIPIENT_COUNT - 1;
2162
2163                 debug_log("To recipients count(%d)", max);
2164                 for (i = 0; i < max; i++) {
2165                         temp_name[i] = g_strstrip(temp_name[i]);
2166                         EmailRecpInfo *ri = _composer_separate_save_recipient_char(ugd, temp_name[i]);
2167                         free(temp_name[i]);
2168
2169                         if (ri == NULL) {
2170                                 debug_critical("_composer_separate_save_recipient_char returned NULL");
2171                                 continue;
2172                         }
2173
2174                         int ri_used = 0;
2175                         debug_log("display_name = %s, email_address = %s", ri->display_name, ri->email_list[0].email_addr);
2176
2177                         debug_log("email_addr = %s", ri->email_list[0].email_addr);
2178                         debug_log("account.email_addr = %s", ugd->account_info->account->user_email_address);
2179                         debug_log("from_addr = %s", from_addr);
2180
2181                         if (g_strcmp0(ri->email_list[0].email_addr, ugd->account_info->account->user_email_address) != 0 || ugd->composer_type != RUN_COMPOSER_REPLY_ALL) {
2182                                 if (!_composer_check_recipient_is_duplicated(ugd, ugd->to_mbe, ri)) {
2183
2184                                         if (!_composer_is_valid_email(ri->email_list[0].email_addr)) {
2185                                                 invalid_address_flag = TRUE;
2186                                                 debug_log("invalid_address_flag is SET");
2187                                         } else {
2188                                                 if (ugd->to_list) {
2189                                                         addrs_info = (email_address_info_t *) g_list_nth_data(ugd->to_list, i);
2190
2191                                                         if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
2192                                                                 elm_multibuttonentry_item_append(ugd->to_mbe, addrs_info->display_name, NULL, ri);
2193                                                         else
2194                                                                 elm_multibuttonentry_item_append(ugd->to_mbe, ri->display_name, NULL, ri);
2195                                                 } else
2196                                                         elm_multibuttonentry_item_append(ugd->to_mbe, ri->display_name, NULL, ri);
2197                                         }
2198                                         ri_used = 1;
2199                                 } else
2200                                         duplicate_cnt++;
2201                         }
2202
2203                         if (ri && !ri_used) {
2204                                 if (ri->display_name) {
2205                                         free(ri->display_name);
2206                                         ri->display_name = NULL;
2207                                 }
2208                         }
2209
2210                         if (ri) {
2211                                 free(ri);
2212                                 ri = NULL;
2213                         }
2214                 }
2215
2216                 if (duplicate_cnt) {
2217                         if (ugd->composer_noti) {
2218                                 evas_object_del(ugd->composer_noti);
2219                                 ugd->composer_noti = NULL;
2220                         }
2221                         ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
2222                                 dgettext("sys_string", "IDS_COM_POP_ALREDY_EXISTS"), 0, NULL, NULL, 1.0, _composer_noti_response_cb);
2223                 }
2224
2225                 if (invalid_address_flag) {
2226                         if (ugd->composer_noti) {
2227                                 evas_object_del(ugd->composer_noti);
2228                                 ugd->composer_noti = NULL;
2229                         }
2230                         ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
2231                                 _("IDS_EMAIL_POP_INVALID_EMAIL_ADDRESS"), 0, NULL, NULL, 2.0, _composer_noti_response_cb);
2232                 }
2233
2234                 free(temp);
2235         }
2236
2237         debug_log("");
2238
2239         elm_multibuttonentry_expanded_set(ugd->to_mbe, FALSE);
2240 }
2241
2242 void _composer_add_cc_address(EmailComposerUGD *ugd)
2243 {
2244         debug_log("");
2245
2246         Eina_Bool overflow_flag = TRUE;
2247
2248         if (ugd->composer_type == RUN_COMPOSER_EDIT || ugd->composer_type == RUN_COMPOSER_REPLY_ALL
2249                 || ugd->composer_type == RUN_COMPOSER_NEW || ugd->composer_type == RUN_COMPOSER_EXTERNAL) {
2250
2251                 if ((ugd->existing_mail_info->mail_data && ugd->existing_mail_info->mail_data->full_address_cc && strlen(ugd->existing_mail_info->mail_data->full_address_cc) > 0)
2252                         || (ugd->new_mail_info->mail_data && ugd->new_mail_info->mail_data->full_address_cc && strlen(ugd->new_mail_info->mail_data->full_address_cc) > 0)) {
2253
2254                         if (ugd->cc_mbe == NULL) {
2255                                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.cc", "*");
2256                                 email_composer_create_cc_field(ugd);
2257                                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.bcc", "*");
2258                                 email_composer_create_bcc_field(ugd);
2259                                 ugd->b_cc_bcc = false;
2260                         }
2261
2262                         char *temp = NULL;
2263                         char *token = NULL;
2264                         char *temp_name[MAX_RECIPIENT_ADDRESS_LEN];
2265
2266                         email_address_info_t *addrs_info = NULL;
2267
2268                         int duplicate_cnt = 0;
2269
2270                         if (ugd->existing_mail_info->mail_data && ugd->existing_mail_info->mail_data->full_address_cc) {
2271                                 temp = COMPOSER_STRDUP(ugd->existing_mail_info->mail_data->full_address_cc);
2272                                 debug_log("cc = %s", ugd->existing_mail_info->mail_data->full_address_cc);
2273                         } else if (ugd->new_mail_info->mail_data && ugd->new_mail_info->mail_data->full_address_cc) {
2274                                 temp = COMPOSER_STRDUP(ugd->new_mail_info->mail_data->full_address_cc);
2275                                 debug_log("cc = %s", ugd->new_mail_info->mail_data->full_address_cc);
2276                         }
2277
2278                         token = strtok(temp, ";");
2279                         debug_log("cc = %s\ntoken = %s", temp, token);
2280
2281                         int i = 0;
2282
2283                         while (token != NULL && (overflow_flag = (i < (MAX_RECIPIENT_COUNT)))) {
2284                                 temp_name[i] = g_strdup(token);
2285                                 i++;
2286                                 token = strtok(NULL, ";");
2287                         }
2288
2289                         if (!overflow_flag) {
2290                                 char msg[MAX_STR_LEN] = { 0, };
2291                                 snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_RECIPIENTS_HPD_REACHED"), MAX_RECIPIENT_COUNT);
2292
2293                                 if (ugd->composer_noti) {
2294                                         evas_object_del(ugd->composer_noti);
2295                                         ugd->composer_noti = NULL;
2296                                 }
2297                                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
2298                                         msg, 0, NULL, NULL, 1.0, _composer_noti_response_cb);
2299                         }
2300
2301                         int max = i;
2302
2303                         debug_log("Cc recipients count(%d)", max);
2304                         for (i = 0; i < max; i++) {
2305                                 temp_name[i] = g_strstrip(temp_name[i]);
2306                                 EmailRecpInfo *ri = _composer_separate_save_recipient_char(ugd, temp_name[i]);
2307                                 free(temp_name[i]);
2308
2309                                 if (ri == NULL) {
2310                                         debug_critical("_composer_separate_save_recipient_char returned NULL");
2311                                         continue;
2312                                 }
2313                                 debug_log("display_name = %s, email_address = %s", ri->display_name, ri->email_list[0].email_addr);
2314
2315                                 if (ugd->account_info->account->options.add_my_address_to_bcc == EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_CC && g_strcmp0(ri->email_list[0].email_addr, ugd->account_info->account->user_email_address) == 0) {
2316                                         ri->is_always_bcc = true;
2317                                 }
2318
2319                                 if (!_composer_check_recipient_is_duplicated(ugd, ugd->cc_mbe, ri)) {
2320                                         if (ugd->cc_list) {
2321                                                 addrs_info = (email_address_info_t *) g_list_nth_data(ugd->cc_list, i);
2322
2323                                                 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
2324                                                         elm_multibuttonentry_item_append(ugd->cc_mbe, addrs_info->display_name, NULL, (void *)ri);
2325                                                 else
2326                                                         elm_multibuttonentry_item_append(ugd->cc_mbe, ri->display_name, NULL, (void *)ri);
2327                                         } else
2328                                                 elm_multibuttonentry_item_append(ugd->cc_mbe, ri->display_name, NULL, (void *)ri);
2329                                 } else {
2330                                         duplicate_cnt++;
2331                                         if (ri) {
2332                                                 if (ri->display_name) {
2333                                                         free(ri->display_name);
2334                                                         ri->display_name = NULL;
2335                                                 }
2336                                                 free(ri);
2337                                                 ri = NULL;
2338                                         }
2339                                 }
2340
2341                         }
2342
2343                         if (duplicate_cnt) {
2344                                 if (ugd->composer_noti) {
2345                                         evas_object_del(ugd->composer_noti);
2346                                         ugd->composer_noti = NULL;
2347                                 }
2348                                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
2349                                         dgettext("sys_string", "IDS_COM_POP_ALREDY_EXISTS"), 0, NULL, NULL, 1.0, _composer_noti_response_cb);
2350                         }
2351
2352                         free(temp);
2353                 }
2354         }
2355
2356         if (ugd->account_info->account->options.add_my_address_to_bcc == EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_CC && ugd->composer_type != RUN_COMPOSER_EDIT) {
2357                 debug_log("");
2358                 if (ugd->cc_mbe == NULL) {
2359                         debug_log("");
2360                         edje_object_signal_emit(_EDJ(ugd->c_layout), "show.cc", "*");
2361                         email_composer_create_cc_field(ugd);
2362                         edje_object_signal_emit(_EDJ(ugd->c_layout), "show.bcc", "*");
2363                         email_composer_create_bcc_field(ugd);
2364                         ugd->b_cc_bcc = false;
2365                 }
2366         }
2367
2368         elm_multibuttonentry_expanded_set(ugd->cc_mbe, FALSE);
2369 }
2370
2371 void _composer_add_bcc_address(EmailComposerUGD *ugd)
2372 {
2373         debug_log("");
2374
2375         Eina_Bool overflow_flag = TRUE;
2376
2377         if (ugd->composer_type == RUN_COMPOSER_EDIT || ugd->composer_type == RUN_COMPOSER_REPLY_ALL
2378                 || ugd->composer_type == RUN_COMPOSER_NEW || ugd->composer_type == RUN_COMPOSER_EXTERNAL) {
2379
2380                 if ((ugd->existing_mail_info->mail_data && ugd->existing_mail_info->mail_data->full_address_bcc && strlen(ugd->existing_mail_info->mail_data->full_address_bcc) > 0)
2381                         || (ugd->new_mail_info->mail_data && ugd->new_mail_info->mail_data->full_address_bcc && strlen(ugd->new_mail_info->mail_data->full_address_bcc) > 0)) {
2382
2383                         if (ugd->bcc_mbe == NULL) {
2384                                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.bcc", "*");
2385                                 email_composer_create_bcc_field(ugd);
2386                                 edje_object_signal_emit(_EDJ(ugd->c_layout), "show.cc", "*");
2387                                 email_composer_create_cc_field(ugd);
2388                                 ugd->b_cc_bcc = false;
2389                         }
2390
2391                         char *temp = NULL;
2392                         char *token = NULL;
2393                         char *temp_name[MAX_RECIPIENT_ADDRESS_LEN];
2394
2395                         email_address_info_t *addrs_info = NULL;
2396
2397                         int duplicate_cnt = 0;
2398
2399                         if (ugd->existing_mail_info->mail_data && ugd->existing_mail_info->mail_data->full_address_bcc) {
2400                                 temp = COMPOSER_STRDUP(ugd->existing_mail_info->mail_data->full_address_bcc);
2401                                 debug_log("bcc = %s", ugd->existing_mail_info->mail_data->full_address_bcc);
2402                         } else if (ugd->new_mail_info->mail_data && ugd->new_mail_info->mail_data->full_address_bcc) {
2403                                 temp = COMPOSER_STRDUP(ugd->new_mail_info->mail_data->full_address_bcc);
2404                                 debug_log("bcc = %s", ugd->new_mail_info->mail_data->full_address_bcc);
2405                         }
2406
2407                         token = strtok(temp, ";");
2408                         debug_log("bcc = %s\ntoken = %s", temp, token);
2409
2410                         int i = 0;
2411
2412                         while (token != NULL && (overflow_flag = (i < (MAX_RECIPIENT_COUNT)))) {
2413                                 temp_name[i] = g_strdup(token);
2414                                 i++;
2415                                 token = strtok(NULL, ";");
2416                         }
2417
2418                         if (!overflow_flag) {
2419                                 char msg[MAX_STR_LEN] = { 0, };
2420                                 snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_MAXIMUM_NUMBER_OF_RECIPIENTS_HPD_REACHED"), MAX_RECIPIENT_COUNT);
2421
2422                                 if (ugd->composer_noti) {
2423                                         evas_object_del(ugd->composer_noti);
2424                                         ugd->composer_noti = NULL;
2425                                 }
2426                                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
2427                                         msg, 0, NULL, NULL, 1.0, _composer_noti_response_cb);
2428                         }
2429
2430                         int max = i;
2431
2432                         debug_log("Bcc recipients count(%d)", max);
2433                         for (i = 0; i < max; i++) {
2434                                 temp_name[i] = g_strstrip(temp_name[i]);
2435                                 EmailRecpInfo *ri = _composer_separate_save_recipient_char(ugd, temp_name[i]);
2436                                 free(temp_name[i]);
2437
2438                                 if (ri == NULL) {
2439                                         debug_critical("_composer_separate_save_recipient_char returned NULL");
2440                                         continue;
2441                                 }
2442                                 debug_log("display_name = %s, email_address = %s", ri->display_name, ri->email_list[0].email_addr);
2443
2444                                 if (ugd->account_info->account->options.add_my_address_to_bcc == EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_BCC && g_strcmp0(ri->email_list[0].email_addr, ugd->account_info->account->user_email_address) == 0) {
2445                                         ri->is_always_bcc = true;
2446                                 }
2447
2448                                 if (!_composer_check_recipient_is_duplicated(ugd, ugd->bcc_mbe, ri)) {
2449                                         if (ugd->bcc_list) {
2450                                                 addrs_info = (email_address_info_t *) g_list_nth_data(ugd->bcc_list, i);
2451
2452                                                 if (addrs_info->display_name && strlen(addrs_info->display_name) > 0)
2453                                                         elm_multibuttonentry_item_append(ugd->bcc_mbe, addrs_info->display_name, NULL, (void *)ri);
2454                                                 else
2455                                                         elm_multibuttonentry_item_append(ugd->bcc_mbe, ri->display_name, NULL, (void *)ri);
2456                                         } else
2457                                                 elm_multibuttonentry_item_append(ugd->bcc_mbe, ri->display_name, NULL, (void *)ri);
2458                                 } else {
2459                                         duplicate_cnt++;
2460                                         if (ri) {
2461                                                 if (ri->display_name) {
2462                                                         free(ri->display_name);
2463                                                         ri->display_name = NULL;
2464                                                 }
2465                                                 free(ri);
2466                                                 ri = NULL;
2467                                         }
2468                                 }
2469
2470                         }
2471
2472                         if (duplicate_cnt) {
2473                                 if (ugd->composer_noti) {
2474                                         evas_object_del(ugd->composer_noti);
2475                                         ugd->composer_noti = NULL;
2476                                 }
2477                                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
2478                                         dgettext("sys_string", "IDS_COM_POP_ALREDY_EXISTS"), 0, NULL, NULL, 1.0, _composer_noti_response_cb);
2479                         }
2480
2481                         free(temp);
2482                 }
2483         }
2484
2485         if (ugd->account_info->account->options.add_my_address_to_bcc == EMAIL_ADD_MY_ADDRESS_OPTION_ALWAYS_ADD_TO_BCC && ugd->composer_type != RUN_COMPOSER_EDIT) {
2486                 debug_log("");
2487                 if (ugd->bcc_mbe == NULL) {
2488                         debug_log("");
2489                         edje_object_signal_emit(_EDJ(ugd->c_layout), "show.bcc", "*");
2490                         email_composer_create_bcc_field(ugd);
2491                         edje_object_signal_emit(_EDJ(ugd->c_layout), "show.cc", "*");
2492                         email_composer_create_cc_field(ugd);
2493                         ugd->b_cc_bcc = false;
2494                 }
2495         }
2496
2497         elm_multibuttonentry_expanded_set(ugd->bcc_mbe, FALSE);
2498 }
2499
2500 void _composer_add_from_address(EmailComposerUGD *ugd)
2501 {
2502         debug_log("");
2503
2504         EmailRecpInfo *ri = (EmailRecpInfo *) calloc(1, sizeof(EmailRecpInfo));
2505
2506         ri->selected_email_idx = 0;
2507         ri->display_name = ugd->account_info->account->user_display_name;
2508         snprintf(ri->email_list[0].email_addr, sizeof(ri->email_list[0].email_addr), "%s", ugd->account_info->account->user_email_address);
2509         ri->email_cnt = 1;
2510         ri->is_contact_info = false;
2511         ri->is_always_bcc = false;
2512         ri->is_from_addr = true;
2513
2514         debug_log("display_name : %s", ri->display_name);
2515         debug_log("email_addr : %s", ri->email_list[0].email_addr);
2516
2517         elm_multibuttonentry_item_append(ugd->from_mbe, ri->display_name, NULL, ri);
2518 }
2519
2520 void _composer_add_subject(EmailComposerUGD *ugd)
2521 {
2522         debug_log("");
2523         char *temp = NULL;
2524
2525         if (ugd->existing_mail_info->mail_data) {
2526
2527                 if (ugd->composer_type == RUN_COMPOSER_EDIT) {
2528                         if (ugd->existing_mail_info->mail_data->subject)
2529                                 temp = elm_entry_utf8_to_markup(ugd->existing_mail_info->mail_data->subject);
2530                         else
2531                                 temp = elm_entry_utf8_to_markup("");
2532
2533                         elm_entry_entry_set(ugd->subject_entry, temp);
2534                 } else if (ugd->composer_type == RUN_COMPOSER_REPLY || ugd->composer_type == RUN_COMPOSER_REPLY_ALL || ugd->composer_type == RUN_COMPOSER_FORWARD) {
2535                         char subject_temp[MAX_SUBJECT_LEN];
2536                         char *p;
2537
2538                         if (ugd->composer_type == RUN_COMPOSER_FORWARD) {
2539                                 if (ugd->existing_mail_info->mail_data->subject)
2540                                         snprintf(subject_temp, MAX_SUBJECT_LEN, "%s: %s", _("IDS_EMAIL_BODY_FWD_T_EMAIL_PREFIX_ABB"), ugd->existing_mail_info->mail_data->subject);
2541                                 else
2542                                         snprintf(subject_temp, MAX_SUBJECT_LEN, "%s: ", _("IDS_EMAIL_BODY_FWD_T_EMAIL_PREFIX_ABB"));
2543                         } else {
2544                                 if (ugd->existing_mail_info->mail_data->subject) {
2545                                         p = strchr(ugd->existing_mail_info->mail_data->subject, ':');
2546
2547                                         if (strncasecmp(ugd->existing_mail_info->mail_data->subject, "re:", 3) == 0 || strncasecmp(ugd->existing_mail_info->mail_data->subject, "fw:", 3) == 0 || strncasecmp(ugd->existing_mail_info->mail_data->subject, "fwd:", 4) == 0) {
2548                                                 snprintf(subject_temp, MAX_SUBJECT_LEN, "%s%s", _("IDS_EMAIL_BODY_RE"), p);
2549                                         } else
2550                                                 snprintf(subject_temp, MAX_SUBJECT_LEN, "%s: %s", _("IDS_EMAIL_BODY_RE"), ugd->existing_mail_info->mail_data->subject);
2551                                 } else {
2552                                         snprintf(subject_temp, MAX_SUBJECT_LEN, "%s: ", _("IDS_EMAIL_BODY_RE"));
2553                                 }
2554                         }
2555
2556                         temp = elm_entry_utf8_to_markup(subject_temp);
2557                         elm_entry_entry_set(ugd->subject_entry, temp);
2558                 }
2559         } else if (ugd->new_mail_info->mail_data) {
2560                 debug_log("");
2561                 if (ugd->composer_type == RUN_COMPOSER_EXTERNAL) {
2562                         debug_log("");
2563                         if (ugd->new_mail_info->mail_data->subject)
2564                                 temp = elm_entry_utf8_to_markup(ugd->new_mail_info->mail_data->subject);
2565                         else
2566                                 temp = elm_entry_utf8_to_markup("");
2567
2568                         elm_entry_entry_set(ugd->subject_entry, temp);
2569                 }
2570         }
2571
2572         if (elm_entry_is_empty(ugd->subject_entry))
2573                 elm_object_signal_emit(ugd->subject_editfield, "elm,state,guidetext,show", "elm");
2574         else
2575                 elm_object_signal_emit(ugd->subject_editfield, "elm,state,guidetext,hide", "elm");
2576
2577         debug_log("Freed subject :%s", temp);
2578         if (temp) {
2579                 free(temp);
2580                 temp = NULL;
2581         }
2582 }
2583
2584 void _composer_add_body(EmailComposerUGD *ugd)
2585 {
2586         debug_log("");
2587         char *full_text = NULL;
2588
2589         if (ugd->existing_mail_info->mail_data && ugd->existing_mail_info->mail_data->body_download_status) {
2590                 if (ugd->composer_type == RUN_COMPOSER_EDIT) {
2591                         if (ugd->has_body_html) {
2592                                 debug_log("html composer_type: EDIT");
2593
2594                                 char *html_text_for_body = NULL;
2595                                 if (ugd->existing_mail_info->mail_data->file_path_html) {
2596                                         html_text_for_body = (char *)email_get_buff_from_file(ugd->existing_mail_info->mail_data->file_path_html, 0);
2597                                 } else if (ugd->existing_mail_info->mail_data->file_path_plain) {
2598                                         /*A plain-text draft mail converted to html mail*/
2599                                         char *temp_body_plain = (char *)email_get_buff_from_file(ugd->existing_mail_info->mail_data->file_path_plain, 0);
2600                                         html_text_for_body = (char *)email_composer_get_parse_string(temp_body_plain, STR_LEN(temp_body_plain));
2601                                         debug_log("\nHTML-TEXT:\n%s", html_text_for_body);
2602                                         free(temp_body_plain);
2603                                 }
2604
2605                                 char szMetaViewportInfo[TEMP_BUFFER_SIZE + 1] = { 0x00, };
2606                                 strncpy(szMetaViewportInfo, HTML_META_INFORMATION, TEMP_BUFFER_SIZE);
2607
2608                                 if (html_text_for_body) {
2609                                         debug_log("html_text_for_body: %s", html_text_for_body);
2610                                         full_text = g_strconcat(szMetaViewportInfo, html_text_for_body, NULL);
2611                                         email_composer_save_file(ugd->saved_html_path, full_text, STR_LEN(full_text));
2612                                         g_free(html_text_for_body);
2613                                 } else {
2614                                         html_text_for_body = (char *)email_get_buff_from_file(DATADIR"/_email_default.html", 0);
2615                                         debug_log("html_text_for_body: %s", html_text_for_body);
2616                                         full_text = g_strconcat(szMetaViewportInfo, html_text_for_body, NULL);
2617                                         email_composer_save_file(ugd->saved_html_path, full_text, STR_LEN(full_text));
2618                                         g_free(html_text_for_body);
2619                                 }
2620
2621                                 debug_log("full text:\n%s", full_text);
2622                         }
2623                 }
2624         }
2625
2626         debug_log("full_text :%s", full_text);
2627         if (full_text) {
2628                 free(full_text);
2629                 full_text = NULL;
2630         }
2631 }
2632
2633 static char* _composer_get_recipients_list_for_original_body_info(EmailComposerUGD *ugd)
2634 {
2635         debug_log("");
2636
2637         char *temp = NULL;
2638         char *token = NULL;
2639         char *temp_name[MAX_RECIPIENT_ADDRESS_LEN];
2640         char *recipients_list = NULL;
2641
2642         if (ugd->existing_mail_info->mail_data->full_address_to) {
2643                 temp = COMPOSER_STRDUP(ugd->existing_mail_info->mail_data->full_address_to);
2644                 token = strtok(temp, ";");
2645                 debug_log("to = %s\ntoken = %s", temp, token);
2646
2647                 int i = 0;
2648
2649                 while (token != NULL) {
2650                         temp_name[i] = g_strdup(token);
2651                         debug_log("temp_name[%d] = %s, token = %s", i, temp_name[i], token);
2652
2653                         token = strtok(NULL, ";");
2654                         debug_log(">> temp_name[%d] = %s, token = %s", i, temp_name[i], token);
2655
2656                         if (i == MAX_RECIPIENT_COUNT)
2657                                 break;
2658
2659                         i++;
2660                 }
2661
2662                 int max = i;
2663                 debug_log("To recipients count(%d)", max);
2664                 for (i = 0; i < max; i++) {
2665                         EmailRecpInfo *ri = _composer_separate_save_recipient_char(ugd, temp_name[i]);
2666
2667                         if (ri != NULL) {
2668                                 debug_log("display_name = %s, email_address = %s", ri->display_name, ri->email_list[0].email_addr);
2669                                 if (ri->display_name == NULL) {
2670                                         debug_log("ri->display_name is NULL!");
2671                                         g_free(ri);
2672                                         ri = NULL;
2673                                         continue;
2674                                 }
2675                                 recipients_list = g_strconcat((recipients_list ? "; " : ""), ri->display_name, NULL);
2676                                 debug_log("recipients_list = %s", recipients_list);
2677                                 debug_log("ugd->existing_mail_info->mail_data->full_address_to = %s", ugd->existing_mail_info->mail_data->full_address_to);
2678
2679                                 if (ri->display_name) {
2680                                         free(ri->display_name);
2681                                         ri->display_name = NULL;
2682                                 }
2683                                 g_free(ri);
2684                                 ri = NULL;
2685                         }
2686                 }
2687                 free(temp);
2688         }
2689
2690         return recipients_list ? g_strdup(recipients_list) : NULL;
2691 }
2692
2693 static char* __composer_make_original_email_info(EmailComposerUGD *ugd)
2694 {
2695         debug_log("");
2696
2697         char *recipients_list = NULL;
2698         char *text_for_original_info = NULL;
2699         const char *sent_time = NULL;
2700
2701         char text_for_from[MAX_STR_LEN] = { 0, };
2702         char text_for_sent[MAX_STR_LEN] = { 0, };
2703         char text_for_to[MAX_STR_LEN] = { 0, };
2704         char text_for_subject[MAX_STR_LEN] = { 0, };
2705
2706         if (ugd->existing_mail_info && ugd->existing_mail_info->mail_data) {
2707                 if (ugd->existing_mail_info->mail_data->full_address_from) {
2708                         char *from = NULL;
2709                         from = email_composer_get_parse_string(ugd->existing_mail_info->mail_data->full_address_from, STR_LEN(ugd->existing_mail_info->mail_data->full_address_from));
2710                         snprintf(text_for_from, sizeof(text_for_from), "<b>%s</b> %s<br>\n", _("IDS_EMAIL_BODY_FROM_M_SENDER"), from);
2711                         free(from);
2712                 }
2713
2714                 sent_time = _composer_get_sent_time(ugd->existing_mail_info);
2715                 if (sent_time) {
2716                         snprintf(text_for_sent, sizeof(text_for_sent), "<b>%s</b> %s<br>\n", _("IDS_EMAIL_BODY_SENT_C"), sent_time);
2717                 }
2718
2719                 recipients_list = _composer_get_recipients_list_for_original_body_info(ugd);
2720
2721                 if (recipients_list != NULL) {
2722                         snprintf(text_for_to, sizeof(text_for_to), ADDED_TEXT, dgettext("sys_string", "IDS_COM_BODY_TO"), recipients_list);
2723                 } else {
2724                         debug_log("recipients_list is NULL");
2725                 }
2726
2727                 if (ugd->existing_mail_info->mail_data->subject) {
2728                         snprintf(text_for_subject, sizeof(text_for_subject), ADDED_TEXT"<br>", dgettext("sys_string", "IDS_COM_BODY_SUBJECT"), ugd->existing_mail_info->mail_data->subject);
2729                 }
2730
2731                 text_for_original_info = g_strconcat(DIVIDE_LEFT_LINE_FOR_HTML, _("IDS_EMAIL_BODY_ORIGINAL_MESSAGE"), DIVIDE_RIGHT_LINE_FOR_HTML, text_for_from, text_for_sent, text_for_to, text_for_subject, NULL);
2732
2733                 //debug_log("text_for_original_info: %s", text_for_original_info);
2734
2735                 if (sent_time) {
2736                         free((char *)sent_time);
2737                 }
2738
2739                 if (recipients_list) {
2740                         free(recipients_list);
2741                         recipients_list = NULL;
2742                 }
2743         }
2744
2745         return text_for_original_info ? g_strdup(text_for_original_info) : NULL;
2746 }
2747
2748 static void _composer_get_original_body_info(EmailComposerUGD *ugd, char **text_for_original_info, char *signature_text)
2749 {
2750         debug_log("");
2751
2752         char *encoded_text = NULL;
2753         char *tmp_info_text = __composer_make_original_email_info(ugd);
2754
2755         if (((ugd->composer_type == RUN_COMPOSER_REPLY || ugd->composer_type == RUN_COMPOSER_REPLY_ALL) && ugd->account_info->account->options.reply_with_body) || ugd->composer_type == RUN_COMPOSER_FORWARD) {
2756                 if (tmp_info_text != NULL){
2757                         char *html_charset = email_parse_get_filename_from_path(ugd->existing_mail_info->mail_data->file_path_html);
2758                         debug_log("html_charset : %s", html_charset);
2759
2760                         if (html_charset) {
2761                                 if ((g_strcmp0(html_charset, "ks_c_5601-1987") == 0) ||
2762                                         (g_strcmp0(html_charset, "KS_C_5601-1987") == 0) ||
2763                                         (g_strcmp0(html_charset, "EUCKR") == 0) ||
2764                                         (g_strcmp0(html_charset, "EUC-KR") == 0) ||
2765                                         (g_strcmp0(html_charset, "euckr") == 0) ||
2766                                         (g_strcmp0(html_charset, "euc-kr") == 0)) {
2767
2768                                         encoded_text = eina_str_convert("UTF-8", "EUC-KR", tmp_info_text);
2769
2770                                         if (NULL != encoded_text) {
2771                                                 free(tmp_info_text);
2772                                                 tmp_info_text = g_strdup(encoded_text);
2773
2774                                                 free(encoded_text);
2775                                                 encoded_text = NULL;
2776                                         }
2777                                 }
2778                                 g_free(html_charset);
2779                         }
2780                 } else {
2781                         debug_log("text_for_original_info is NULL");
2782                         tmp_info_text = g_strdup("\n");
2783                 }
2784         } else {
2785                 free(tmp_info_text);
2786                 tmp_info_text = g_strdup("\n");
2787         }
2788
2789         if (signature_text == NULL) {
2790                 *text_for_original_info = g_strconcat(DIV_TAG_START_ORIGIN_INFO, tmp_info_text, DIV_TAG_END, NULL);
2791         } else {
2792                 *text_for_original_info = g_strconcat(DIV_TAG_START_ORIGIN_INFO, signature_text, tmp_info_text, DIV_TAG_END, NULL);
2793         }
2794         debug_log("text_for_original_info: \n%s", *text_for_original_info);
2795
2796         if (tmp_info_text) {
2797                 g_free(tmp_info_text);
2798                 tmp_info_text = NULL;
2799         }
2800 }
2801
2802 static void _composer_get_html_text_for_body(EmailComposerUGD *ugd, char **html_text_for_body)
2803 {
2804         debug_log("");
2805
2806         char *tmp_html_text = NULL;
2807
2808         if (((ugd->composer_type == RUN_COMPOSER_REPLY || ugd->composer_type == RUN_COMPOSER_REPLY_ALL) && ugd->account_info->account->options.reply_with_body) || ugd->composer_type == RUN_COMPOSER_FORWARD) {
2809                 if (ugd->existing_mail_info->mail_data->file_path_html) {
2810                         tmp_html_text = (char *)email_get_buff_from_file(ugd->existing_mail_info->mail_data->file_path_html, 0);
2811                 } else if (ugd->existing_mail_info->mail_data->file_path_plain) {
2812                         char *temp_body_plain = (char *)email_get_buff_from_file(ugd->existing_mail_info->mail_data->file_path_plain, 0);
2813
2814                         /*Convert plain-text to html content*/
2815                         tmp_html_text = (char *)email_composer_get_parse_string(temp_body_plain, STR_LEN(temp_body_plain));
2816                         debug_log("\nHTML-TEXT:\n%s", tmp_html_text);
2817                         free(temp_body_plain);
2818                 } else {
2819                         tmp_html_text = g_strdup("\n");
2820                 }
2821         } else if (ugd->composer_type == RUN_COMPOSER_EXTERNAL) {
2822                 if (ugd->new_mail_info->mail_data && ugd->new_mail_info->mail_data->file_path_plain) {          /*For Text memo*/
2823                         debug_log("file_path_plain(%s)", ugd->new_mail_info->mail_data->file_path_plain);
2824                         tmp_html_text = (char *)email_composer_get_parse_string(ugd->new_mail_info->mail_data->file_path_plain, STR_LEN(ugd->new_mail_info->mail_data->file_path_plain));
2825                 } else {
2826                         debug_log("Empty html body");
2827                         tmp_html_text = g_strdup("\n");
2828                 }
2829         } else {
2830                 debug_log("Empty html body");           /*For RUN_COMPOSER_NEW*/
2831                 tmp_html_text = g_strdup("\n");
2832         }
2833
2834         *html_text_for_body = g_strconcat(DIV_TAG_START_ORIGIN_CONTENT, tmp_html_text, DIV_TAG_END, NULL);
2835         debug_log("html_text_for_body: \n%s", *html_text_for_body);
2836
2837         if (tmp_html_text) {
2838                 g_free(tmp_html_text);
2839                 tmp_html_text = NULL;
2840         }
2841 }
2842
2843 char *_composer_make_text_with_div_tag(char *origin_text, int div_tag)
2844 {
2845         debug_log("");
2846
2847         if (origin_text == NULL) {
2848                 return NULL;
2849         }
2850
2851         if (div_tag == 0) {
2852                 return g_strconcat(DIV_TAG_START_ORIGIN_INFO, origin_text, DIV_TAG_END, NULL);
2853         } else {
2854                 return g_strconcat(DIV_TAG_START_ORIGIN_CONTENT, origin_text, DIV_TAG_END, NULL);
2855         }
2856 }
2857
2858 void _composer_make_html_body(EmailComposerUGD *ugd)
2859 {
2860         debug_log("");
2861
2862         char *full_text = NULL;
2863         char *text_for_original_info = NULL;
2864         char *html_text_for_body = NULL;
2865         char szMetaViewportInfo[TEMP_BUFFER_SIZE + 1] = { 0x00, };
2866
2867         _composer_get_html_text_for_body(ugd, &html_text_for_body);
2868
2869         strncpy(szMetaViewportInfo, HTML_META_INFORMATION, TEMP_BUFFER_SIZE);
2870
2871         if ((ugd->account_info->account->options).add_signature) {
2872                 char signature_text[128] = { 0, };
2873
2874                 if ((ugd->account_info->account->options).signature) {
2875                         snprintf(signature_text, sizeof(signature_text), "<br><br><br>%s<br><br>", (ugd->account_info->account->options).signature);
2876                 }
2877
2878                 _composer_get_original_body_info(ugd, &text_for_original_info, signature_text);
2879
2880                 debug_log("composer_type:%d", ugd->composer_type);
2881                 if (ugd->composer_type == RUN_COMPOSER_NEW || ugd->composer_type == RUN_COMPOSER_REPLY
2882                         || ugd->composer_type == RUN_COMPOSER_REPLY_ALL || ugd->composer_type == RUN_COMPOSER_FORWARD) {
2883
2884                         full_text = g_strconcat(szMetaViewportInfo, BODY_TAG_START, text_for_original_info, html_text_for_body, BODY_TAG_END, HTML_TAG_END, NULL);
2885                 } else if (ugd->composer_type == RUN_COMPOSER_EXTERNAL) {
2886
2887                         full_text = g_strconcat(szMetaViewportInfo, BODY_TAG_START, html_text_for_body, text_for_original_info, BODY_TAG_END, HTML_TAG_END, NULL);
2888                 }
2889         } else {
2890                 //ugd->original_info_content = g_strconcat(DIV_TAG_START_ORIGIN_INFO, text_for_original_info, DIV_TAG_END, NULL);
2891                 _composer_get_original_body_info(ugd, &text_for_original_info, NULL);
2892                 full_text = g_strconcat(szMetaViewportInfo, BODY_TAG_START, text_for_original_info, html_text_for_body, BODY_TAG_END, HTML_TAG_END, NULL);
2893         }
2894
2895         debug_log("full text:\n%s", full_text);
2896         email_composer_save_file(ugd->saved_html_path, full_text, STR_LEN(full_text));
2897
2898         free(text_for_original_info);
2899         free(html_text_for_body);
2900         free(full_text);
2901 }
2902
2903 void _composer_add_origin_msg(EmailComposerUGD *ugd)
2904 {
2905         debug_log("");
2906
2907         _composer_make_html_body(ugd);
2908 }
2909
2910 /* Creates symbolic links to all the inline images */
2911 void _composer_add_softlink_to_inline_images(EmailComposerUGD *ugd)
2912 {
2913         debug_enter();
2914
2915         int i = 0;
2916         char *inline_image_name = NULL;
2917         char *softlink_path = NULL;
2918         char *temp_save_name = NULL;
2919
2920         if (ugd->existing_mail_info->mail_data == NULL)
2921                 return;
2922
2923         if (ugd->existing_mail_info->mail_data->body_download_status && ugd->existing_mail_info->mail_data->attachment_count > 0) {
2924
2925                 for (i = 0; i < ugd->existing_mail_info->mail_data->attachment_count; i++) {
2926                         if (ugd->existing_mail_info->attachment_list[i].inline_content_status && ugd->existing_mail_info->attachment_list[i].attachment_path)
2927                                 /* To do: Must check attachment_temp_list->downloaded condition also.
2928                                 Though inline content is downloaded, in db 'downloaded' flag set to 0. */
2929                         {
2930                                 debug_log("attachment_data_list[%d].attachment_path :%s", i, ugd->existing_mail_info->attachment_list[i].attachment_path);
2931                                 temp_save_name = g_strdup(ugd->existing_mail_info->attachment_list[i].attachment_path);
2932                                 inline_image_name = email_composer_parse_filepath(temp_save_name, EINA_FALSE);
2933                                 softlink_path = g_strconcat(EMAIL_TMP_FOLDER, "/", inline_image_name, NULL);
2934                                 g_free(inline_image_name);
2935
2936                                 if (softlink_path)
2937                                         debug_log("softlink_path :%s", softlink_path);
2938
2939                                 int result = symlink(ugd->existing_mail_info->attachment_list[i].attachment_path, softlink_path);
2940                                 debug_log("result:%d", result);
2941                                 free(softlink_path);
2942                                 free(temp_save_name);
2943                         }
2944                 }
2945         }
2946 }
2947
2948 void _composer_add_attachment(EmailComposerUGD *ugd)
2949 {
2950         debug_log("");
2951
2952         if ((ugd->composer_type == RUN_COMPOSER_FORWARD && (ugd->account_info->account->options).forward_with_files != 0) || ugd->composer_type == RUN_COMPOSER_EDIT) {
2953                 if (ugd->existing_mail_info->mail_data->body_download_status && ugd->existing_mail_info->mail_data->attachment_count > 0) {
2954
2955                         email_attachment_data_t *fwd_attachment_data_list = ugd->existing_mail_info->attachment_list;
2956
2957                         int i = 0;
2958                         int nTotalAttachmentSize = 0;
2959                         int index = 0;
2960
2961                         if (ugd->attachment_item_box == NULL) {
2962                                 Evas_Object *attachment_item_box;
2963                                 attachment_item_box = _composer_create_box(ugd->main_layout);
2964                                 elm_object_part_content_set(ugd->c_layout, "_attachment_field", attachment_item_box);
2965                                 ugd->attachment_item_box = attachment_item_box;
2966                         } else {
2967                                 _composer_attachment_expand_items(ugd);
2968                         }
2969
2970                         for (i = 0; i < ugd->existing_mail_info->mail_data->attachment_count; i++) {
2971                                 index++;
2972
2973                                 if (i >= MAX_ATTACHMENT_ITEM)
2974                                         break;
2975
2976                                 EMAIL_ATTACHMENT_INFO_S *attachment_info = (EMAIL_ATTACHMENT_INFO_S *)calloc(1, sizeof(EMAIL_ATTACHMENT_INFO_S));
2977
2978                                 if (attachment_info) {
2979                                         attachment_info->mail_id = ugd->nExistingMailID;
2980                                         attachment_info->attach_id = fwd_attachment_data_list[i].attachment_id;
2981                                         attachment_info->index = index;
2982                                         attachment_info->size = fwd_attachment_data_list[i].attachment_size;
2983                                         attachment_info->downloaded = fwd_attachment_data_list[i].save_status;
2984                                         attachment_info->drm = fwd_attachment_data_list[i].drm_status;
2985                                         attachment_info->inline_content = fwd_attachment_data_list[i].inline_content_status;
2986                                         attachment_info->name = g_strdup(fwd_attachment_data_list[i].attachment_name);
2987                                         attachment_info->path = g_strdup(fwd_attachment_data_list[i].attachment_path);
2988
2989                                         debug_log("mail id (%d)", attachment_info->mail_id);
2990                                         debug_log("attachments index (%d)", attachment_info->index);
2991                                         debug_log("attachments attach_id (%d)", attachment_info->attach_id);
2992                                         debug_log("attachments name (%s)", attachment_info->name ? attachment_info->name : "@niL");
2993                                         debug_log("attachments path (%s)", attachment_info->path ? attachment_info->path : "@niL");
2994                                         debug_log("attachments size (%d)", attachment_info->size);
2995                                         debug_log("attachments download (%d)", attachment_info->downloaded);
2996                                         debug_log("attachments drm (%d)", attachment_info->drm);
2997                                         debug_log("attachments inline? (%d)", attachment_info->inline_content);
2998
2999                                         nTotalAttachmentSize = nTotalAttachmentSize + attachment_info->size;
3000
3001                                         debug_log("fwd_attachment_data_list[%d] = %x", i, &fwd_attachment_data_list[i]);
3002                                         debug_log("downloaded attachment = %s", fwd_attachment_data_list[i].attachment_path);
3003
3004                                         if (ugd->existing_mail_info->mail_data->file_path_html) {
3005                                                 nTotalAttachmentSize += (int)email_get_file_size(ugd->existing_mail_info->mail_data->file_path_html);
3006                                                 debug_log("Total attachments size (including original html body): %d byte", nTotalAttachmentSize);
3007                                         }
3008
3009                                         if (nTotalAttachmentSize / 1024 > MAX_ATTACHMENT_SIZE) {
3010                                                 char msg[MAX_STR_LEN] = { 0, };
3011                                                 snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_UNABLE_TO_ATTACH_MAXIMUM_SIZE_OF_FILES_IS_PD_KB"), MAX_ATTACHMENT_SIZE);
3012
3013                                                 if (ugd->composer_noti) {
3014                                                         evas_object_del(ugd->composer_noti);
3015                                                         ugd->composer_noti = NULL;
3016                                                 }
3017                                                 ugd->composer_noti = _composer_create_noti(ugd, false, dgettext("sys_string", "IDS_COM_POP_WARNING"),
3018                                                         msg, 0, NULL, NULL, 2.0, _composer_noti_response_cb);
3019
3020                                                 if (attachment_info->name) {
3021                                                         free(attachment_info->name);
3022                                                         attachment_info->name = NULL;
3023                                                 }
3024
3025                                                 if (attachment_info->path) {
3026                                                         free(attachment_info->path);
3027                                                         attachment_info->path = NULL;
3028                                                 }
3029
3030                                                 if (attachment_info) {
3031                                                         free(attachment_info);
3032                                                         attachment_info = NULL;
3033                                                 }
3034                                                 break;
3035                                         }
3036
3037                                         ugd->fw_attachment_list = g_list_append(ugd->fw_attachment_list, attachment_info);
3038
3039                                         if (attachment_info->inline_content == EINA_FALSE) {
3040                                                 email_attachment_data_t *attachment_data = (email_attachment_data_t *)calloc(1, sizeof(email_attachment_data_t));
3041
3042                                                 attachment_data->attachment_id = attachment_info->attach_id;
3043                                                 attachment_data->attachment_name = COMPOSER_STRDUP(attachment_info->name);
3044                                                 attachment_data->attachment_path = COMPOSER_STRDUP(attachment_info->path);
3045                                                 attachment_data->save_status = attachment_info->downloaded;
3046                                                 attachment_data->attachment_size = attachment_info->size;
3047                                                 attachment_data->mail_id = attachment_info->mail_id;
3048                                                 attachment_data->inline_content_status = attachment_info->inline_content;
3049
3050                                                 _composer_attachment_create_list_box(ugd, attachment_data);
3051                                         }
3052                                 }
3053                         }
3054                 }
3055         }
3056 }
3057
3058 Evas_Object *_composer_popup_create(Evas_Object *parent, EmailComposerUGD *ugd)
3059 {
3060         debug_log("");
3061
3062         Evas_Object *popup, *window;
3063
3064         window = _composer_create_sub_window(parent);
3065         ugd->popup_win = window;
3066
3067         if (!window)
3068                 return NULL;
3069
3070         Evas_Object * bg = evas_object_rectangle_add(evas_object_evas_get(window));
3071         elm_win_resize_object_add(window, bg);
3072         evas_object_color_set(bg, 0, 0, 0, 0);
3073         evas_object_render_op_set(bg, EVAS_RENDER_COPY);
3074         evas_object_show(bg);
3075
3076         popup = elm_popup_add(window);
3077         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3078         evas_object_data_set(popup, "window", window);
3079
3080         evas_object_show(popup);
3081         evas_object_show(window);
3082
3083         return popup;
3084 }
3085
3086 void _composer_popup_delete(Evas_Object *popup)
3087 {
3088         debug_log("");
3089         if (!popup)
3090                 return;
3091
3092         Evas_Object *window = evas_object_data_del(popup, "window");
3093
3094         if (window) {
3095                 debug_log("Window Delete");
3096                 evas_object_del(window);
3097         } else {
3098                 debug_log("PopUp Delete");
3099                 evas_object_del(popup);
3100         }
3101 }
3102
3103 /**
3104  * This API gets the latest recipients list from mbe and checks for change from the initial list
3105  *
3106  * @param [in] mbe      multibuttonentry(to,cc or bcc)
3107  * @param [in] initial_recipients_list  contains the list of recipients when composer launched
3108  *
3109  * @return true if recipients modified or false
3110 */
3111 bool _composer_check_recipients_modified(Evas_Object *mbe, Eina_List **initial_recipients_list)
3112 {
3113         debug_log("");
3114
3115         if (!mbe || !initial_recipients_list)
3116                 return false;
3117
3118         const Eina_List *current_list = NULL;
3119         Eina_List *mbe_initial_list = *initial_recipients_list;
3120         bool is_modified = false;
3121
3122         current_list = elm_multibuttonentry_items_get(mbe);
3123
3124         if ((!mbe_initial_list && current_list) || (mbe_initial_list && !current_list)) {
3125                 is_modified = true;
3126         } else if (mbe_initial_list && current_list) {
3127                 if (current_list->accounting->count != mbe_initial_list->accounting->count) {
3128                         is_modified = true;
3129                 } else {
3130                         Eina_List *l1 = mbe_initial_list;
3131                         const Eina_List *l2 = current_list;
3132                         int index;
3133
3134                         for (index = 0; index < current_list->accounting->count; index++) {
3135                                 if (eina_list_data_get(l1) != eina_list_data_get(l2)) {
3136                                         is_modified = true;
3137                                         break;
3138                                 }
3139                                 l1 = eina_list_next(l1);
3140                                 l2 = eina_list_next(l2);
3141                         }
3142                 }
3143         }
3144
3145         return is_modified;
3146 }
3147
3148 /**
3149  * This API checks whether email content has been modified from the original content
3150  *
3151  * @param [in] data     EmailComposerUGD data
3152  *
3153  * @return true if mail is modified or false
3154 */
3155 bool _composer_check_mail_is_modified(void *data)
3156 {
3157         debug_log("");
3158         if (data == NULL)
3159                 return false;
3160
3161         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3162
3163         bool is_modified = false;
3164
3165         if ((ugd->composer_type == RUN_COMPOSER_EXTERNAL)
3166                 || (ugd->to_mbe && _composer_check_recipients_modified(ugd->to_mbe, &ugd->to_mbe_initial_list))
3167                 || (ugd->cc_mbe && _composer_check_recipients_modified(ugd->cc_mbe, &ugd->cc_mbe_initial_list))
3168                 || (ugd->bcc_mbe && _composer_check_recipients_modified(ugd->bcc_mbe, &ugd->bcc_mbe_initial_list))
3169                 || (g_strcmp0(elm_entry_entry_get(ugd->subject_entry), ugd->saved_subject) != 0)) {
3170
3171                 is_modified = true;
3172                 goto FINISH_OFF;
3173         }
3174
3175         bool is_attach_modified = false;
3176
3177         if ((ugd->attach_initial_list && !ugd->attachment_item_obj_list) || (!ugd->attach_initial_list && ugd->attachment_item_obj_list)) {
3178                 is_attach_modified = true;
3179         } else if (ugd->attach_initial_list && ugd->attachment_item_obj_list) {
3180                 int nInitialListCount = eina_list_count(ugd->attach_initial_list);
3181                 int nAttachmentCount = eina_list_count(ugd->attachment_item_obj_list);
3182
3183                 if (nInitialListCount != nAttachmentCount) {
3184                         is_attach_modified = true;
3185                 } else {
3186                         int i = 0;
3187                         int nInitialListCount = eina_list_count(ugd->attach_initial_list);
3188
3189                         for (i = 0; i < nInitialListCount; i++) {
3190                                 if (eina_list_nth(ugd->attach_initial_list, i) != eina_list_nth(ugd->attachment_item_obj_list, i)) {
3191                                         is_attach_modified = true;
3192                                         break;
3193                                 }
3194                         }
3195                 }
3196         }
3197
3198         if (is_attach_modified) {
3199                 is_modified = true;
3200                 goto FINISH_OFF;
3201         }
3202
3203         if (EINA_TRUE == ugd->has_body_html) {
3204                 if (ugd->latest_body_html_content == NULL) {
3205                         debug_log("ugd->latest_body_html_content is NULL");
3206                         is_modified = false;
3207                         goto FINISH_OFF;
3208                 }
3209
3210                 if (ugd->latest_body_html_content && ugd->original_body_html_content) {
3211                         debug_log("original_body_html_content:\n%s", ugd->original_body_html_content);
3212                         debug_log("latest_body_html_content:\n%s", ugd->latest_body_html_content);
3213                         if (g_strcmp0(ugd->original_body_html_content, ugd->latest_body_html_content) != 0) {
3214                                 debug_log("diff => %d", g_strcmp0(ugd->original_body_html_content, ugd->latest_body_html_content));
3215                                 is_modified = true;
3216                                 goto FINISH_OFF;
3217                         }
3218                 } else {
3219                         is_modified = false;    /*if latest_html_content and/or saved_html_content is NULL,
3220                                                                 is_modified set to false; on return false, destroy composer is called*/
3221                 }
3222         }
3223
3224 FINISH_OFF:
3225
3226         if (is_modified) {
3227                 _composer_free_initial_email_content(ugd);
3228         }
3229
3230         return is_modified;
3231 }
3232
3233 bool _composer_check_recipient_is_empty(void *data)
3234 {
3235         debug_log("");
3236         if (data == NULL)
3237                 return true;
3238
3239         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3240
3241         if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->to_mbe)) != NULL) {
3242                 return false;
3243         }
3244         if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->cc_mbe)) != NULL) {
3245                 return false;
3246         }
3247         if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->bcc_mbe)) != NULL) {
3248                 return false;
3249         }
3250
3251         return true;
3252 }
3253
3254 Evas_Object *_composer_create_sub_window(Evas_Object *parent)
3255 {
3256         debug_log("");
3257
3258         Evas_Object *eo;
3259         int x, y, w, h;
3260         unsigned char *prop_data = NULL;
3261         int ret;
3262         int count;
3263
3264         Eina_Bool accepts_focus;
3265         Ecore_X_Window_State_Hint initial_state;
3266         Ecore_X_Pixmap icon_pixmap;
3267         Ecore_X_Pixmap icon_mask;
3268         Ecore_X_Window icon_window;
3269         Ecore_X_Window window_group;
3270         Eina_Bool is_urgent;
3271         int rotation = 0;
3272
3273         eo = elm_win_add(parent, "composer_sub_win", ELM_WIN_DIALOG_BASIC);
3274         if (eo) {
3275                 elm_win_alpha_set(eo, EINA_TRUE);
3276                 elm_win_title_set(eo, "composer_sub_win");
3277                 elm_win_raise(eo);
3278                 ecore_x_window_geometry_get(ecore_x_window_root_get(ecore_x_window_focus_get()), &x, &y, &w, &h);
3279
3280                 ret = ecore_x_window_prop_property_get(ecore_x_window_root_get(ecore_x_window_focus_get()), ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
3281
3282                 if (ret && prop_data)
3283                         memcpy(&rotation, prop_data, sizeof(int));
3284                 if (prop_data)
3285                         free(prop_data);
3286                 evas_object_resize(eo, w, h);
3287                 evas_object_move(eo, x, y);
3288
3289                 if (rotation != -1)
3290                         elm_win_rotation_with_resize_set(eo, rotation);
3291
3292                 ecore_x_icccm_hints_get(elm_win_xwindow_get(eo), &accepts_focus, &initial_state, &icon_pixmap, &icon_mask, &icon_window, &window_group, &is_urgent);
3293                 ecore_x_icccm_hints_set(elm_win_xwindow_get(eo), EINA_FALSE, initial_state, icon_pixmap, icon_mask, icon_window, window_group, is_urgent);
3294
3295                 evas_object_show(eo);
3296         } else {
3297                 debug_log("Fail to make SubWindow");
3298         }
3299         return eo;
3300 }
3301
3302 void _composer_unfocus_and_save(void *data)
3303 {
3304         debug_log("");
3305
3306         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3307
3308         if (ugd->to_mbe_entry && elm_object_focus_get(ugd->to_mbe_entry)) {
3309                 debug_log("to mbe unfocused");
3310                 elm_multibuttonentry_expanded_set(ugd->to_mbe, FALSE);
3311         } else if (ugd->cc_mbe_entry && elm_object_focus_get(ugd->cc_mbe_entry)) {
3312                 debug_log("cc mbe unfocused");
3313                 elm_object_focus_set(ugd->cc_mbe, EINA_FALSE);
3314                 elm_multibuttonentry_expanded_set(ugd->cc_mbe, FALSE);
3315         } else if (ugd->bcc_mbe_entry && elm_object_focus_get(ugd->bcc_mbe_entry)) {
3316                 debug_log("bcc mbe unfocused");
3317                 elm_object_focus_set(ugd->bcc_mbe, EINA_FALSE);
3318                 elm_multibuttonentry_expanded_set(ugd->bcc_mbe, FALSE);
3319         } else if (ugd->subject_entry && elm_object_focus_get(ugd->subject_entry)) {
3320                 debug_log("subject unfocused");
3321                 elm_object_focus_set(ugd->subject_entry, EINA_FALSE);
3322         }
3323
3324 }
3325
3326 void _composer_change_text_to_textblock(char *input, char **output, char *matched_word, char *prefix, char *postfix)
3327 {
3328         char *temp = NULL;
3329
3330         char *found = (char *)strcasestr(input, matched_word);
3331
3332         if (!found) {
3333                 goto FINISH_OFF;
3334         }
3335
3336         int idx = found - input;
3337         int buf_len = strlen(input) + strlen(prefix) + strlen(postfix) + 1;
3338
3339         temp = (char *)malloc(buf_len * sizeof(char));
3340
3341         if (temp == NULL) {
3342                 goto FINISH_OFF;
3343         }
3344
3345         memset(temp, 0x00, buf_len);
3346
3347         strncpy(temp, input, buf_len - 1);
3348         strncpy(temp + idx, prefix, buf_len - strlen(temp) - 1);
3349         strncpy(temp + idx + strlen(prefix), matched_word, buf_len - strlen(temp) - 1);
3350         strncpy(temp + idx + strlen(prefix) + strlen(matched_word), postfix, buf_len - strlen(temp) - 1);
3351         strncpy(temp + idx + strlen(prefix) + strlen(matched_word) + strlen(postfix), input + idx + strlen(matched_word), buf_len - strlen(temp) - 1);
3352         temp[buf_len - 1] = '\0';
3353
3354  FINISH_OFF:
3355
3356         *output = temp;
3357 }
3358
3359 static void _composer_popup_waiting_response_cb(void *data, Evas_Object *obj, void *event_info)
3360 {
3361         debug_log("");
3362         if (!data) {
3363                 debug_log("data is NULL");
3364                 return;
3365         }
3366
3367         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3368
3369         if (ugd->timeout_noti) {
3370                 evas_object_del(ugd->timeout_noti);
3371                 ugd->timeout_noti = NULL;
3372         }
3373 }
3374
3375 void _composer_create_waiting_popup(EmailComposerUGD *ugd, const char *title_text, const char *style)
3376 {
3377         debug_enter();
3378         if (title_text == NULL) {
3379                 debug_log("popup text is null");
3380                 return;
3381         }
3382
3383         Evas_Object *popup = elm_popup_add(ugd->win_main);
3384         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3385         elm_object_part_text_set(popup, "title,text", title_text);
3386
3387         Evas_Object *progress = elm_progressbar_add(popup);
3388         elm_object_style_set(progress, style);
3389         elm_progressbar_pulse_set(progress, EINA_TRUE);
3390         elm_progressbar_pulse(progress, EINA_TRUE);
3391         evas_object_show(progress);
3392
3393         elm_object_content_set(popup, progress);
3394
3395         Evas_Object *btn1 = elm_button_add(popup);
3396         elm_object_style_set(btn1, "popup_button/default");
3397         elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
3398         elm_object_part_content_set(popup, "button1", btn1);
3399         evas_object_smart_callback_add(btn1, "clicked", _composer_popup_waiting_response_cb, ugd);
3400
3401         ugd->timeout_noti = popup;
3402
3403         evas_object_show(popup);
3404 }
3405
3406 Evas_Object *_composer_create_noti_with_list(EmailComposerUGD *ugd, bool use_win, char *title, char *content,
3407                                                                                 int btn_num, char *btn1_lb, char *btn2_lb,
3408                                                                                 double timeout, void (*response_cb) (void *data, Evas_Object *obj, void *event_info))
3409 {
3410         debug_log("");
3411         Evas_Object *notify;
3412
3413         if (use_win)
3414                 notify = _composer_popup_create(ugd->win_main, ugd);
3415         else
3416                 notify = elm_popup_add(ugd->win_main);
3417
3418         debug_log("notify: %p", notify);
3419         if (!notify) {
3420                 debug_log("elm_popup_add returns NULL");
3421                 return NULL;
3422         }
3423         evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3424
3425         if (title) {
3426                 elm_object_part_text_set(notify, "title,text", title);
3427         }
3428
3429         if (content) {
3430                 elm_object_text_set(notify, content);
3431         }
3432
3433 #ifdef _POPUP_WITH_LIST
3434         elm_object_style_set(notify, "min_menustyle");
3435 #else
3436         elm_object_style_set(notify, "menustyle");
3437 #endif
3438
3439         if (btn_num == 1) {
3440                 Evas_Object *peoBtn1 = NULL;
3441                 peoBtn1 = elm_button_add(notify);
3442                 debug_log("peoBtn1: %p", peoBtn1);
3443                 elm_object_style_set(peoBtn1, "popup_button/default");
3444                 elm_object_text_set(peoBtn1, btn1_lb);
3445                 elm_object_part_content_set(notify, "button1", peoBtn1);
3446                 evas_object_smart_callback_add(peoBtn1, "clicked", response_cb, ugd);
3447         } else if (btn_num == 2) {
3448                 Evas_Object *peoBtn1 = NULL;
3449                 peoBtn1 = elm_button_add(notify);
3450                 debug_log("peoBtn1: %p", peoBtn1);
3451                 elm_object_style_set(peoBtn1, "popup_button/default");
3452                 elm_object_text_set(peoBtn1, btn1_lb);
3453                 elm_object_part_content_set(notify, "button1", peoBtn1);
3454                 evas_object_smart_callback_add(peoBtn1, "clicked", response_cb, ugd);
3455
3456                 Evas_Object *peoBtn2 = NULL;
3457                 peoBtn2 = elm_button_add(notify);
3458                 debug_log("peoBtn2: %p", peoBtn2);
3459                 elm_object_style_set(peoBtn2, "popup_button/default");
3460                 elm_object_text_set(peoBtn2, btn2_lb);
3461                 elm_object_part_content_set(notify, "button2", peoBtn2);
3462                 evas_object_smart_callback_add(peoBtn2, "clicked", response_cb, ugd);
3463         }
3464
3465         if (timeout > 0.0) {
3466                 elm_popup_timeout_set(notify, timeout);
3467                 evas_object_smart_callback_add(notify, "timeout", response_cb, ugd);
3468                 evas_object_smart_callback_add(notify, "block,clicked", response_cb, ugd);
3469         }
3470
3471         evas_object_show(notify);
3472
3473         ugd->popup_list = eina_list_append(ugd->popup_list, notify);
3474
3475         debug_log("notify = %x, %p", notify, notify);
3476         return notify;
3477 }
3478
3479 Evas_Object *_composer_create_noti(EmailComposerUGD *ugd, bool use_win, char *title, char *content,
3480                                                                                 int btn_num, char *btn1_lb, char *btn2_lb,
3481                                                                                 double timeout, void (*response_cb) (void *data, Evas_Object *obj, void *event_info))
3482 {
3483         debug_log("");
3484         Evas_Object *notify;
3485
3486         if (use_win)
3487                 notify = _composer_popup_create(ugd->win_main, ugd);
3488         else
3489                 notify = elm_popup_add(ugd->win_main);
3490
3491         debug_log("notify: %p", notify);
3492         if (!notify) {
3493                 debug_log("elm_popup_add returns NULL");
3494                 return NULL;
3495         }
3496         evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3497
3498         if (title) {
3499                 elm_object_part_text_set(notify, "title,text", title);
3500         }
3501
3502         if (content) {
3503                 elm_object_text_set(notify, content);
3504         }
3505
3506         if (btn_num == 1) {
3507                 Evas_Object *peoBtn1 = NULL;
3508                 peoBtn1 = elm_button_add(notify);
3509                 debug_log("peoBtn1: %p", peoBtn1);
3510                 elm_object_style_set(peoBtn1, "popup_button/default");
3511                 elm_object_text_set(peoBtn1, btn1_lb);
3512                 elm_object_part_content_set(notify, "button1", peoBtn1);
3513                 evas_object_smart_callback_add(peoBtn1, "clicked", response_cb, ugd);
3514         } else if (btn_num == 2) {
3515                 Evas_Object *peoBtn1 = NULL;
3516                 peoBtn1 = elm_button_add(notify);
3517                 debug_log("peoBtn1: %p", peoBtn1);
3518                 elm_object_style_set(peoBtn1, "popup_button/default");
3519                 elm_object_text_set(peoBtn1, btn1_lb);
3520                 elm_object_part_content_set(notify, "button1", peoBtn1);
3521                 evas_object_smart_callback_add(peoBtn1, "clicked", response_cb, ugd);
3522
3523                 Evas_Object *peoBtn2 = NULL;
3524                 peoBtn2 = elm_button_add(notify);
3525                 debug_log("peoBtn2: %p", peoBtn2);
3526                 elm_object_style_set(peoBtn2, "popup_button/default");
3527                 elm_object_text_set(peoBtn2, btn2_lb);
3528                 elm_object_part_content_set(notify, "button2", peoBtn2);
3529                 evas_object_smart_callback_add(peoBtn2, "clicked", response_cb, ugd);
3530         }
3531
3532         if (timeout > 0.0) {
3533                 elm_popup_timeout_set(notify, timeout);
3534                 evas_object_smart_callback_add(notify, "timeout", response_cb, ugd);
3535                 evas_object_smart_callback_add(notify, "block,clicked", response_cb, ugd);
3536         }
3537
3538         evas_object_show(notify);
3539
3540         ugd->popup_list = eina_list_append(ugd->popup_list, notify);
3541
3542         debug_log("notify = %x, %p", notify, notify);
3543         return notify;
3544 }
3545
3546 Evas_Object *_composer_create_popup(EmailComposerUGD *ugd, bool use_win, char *title, char *content,
3547                                                                                 int btn_num, char *btn1_lb, char *btn2_lb, char *btn3_lb,
3548                                                                                 double timeout, void (*response_cb) (void *data, Evas_Object *obj, void *event_info))
3549 {
3550         debug_log("");
3551         Evas_Object *notify;
3552
3553         if (use_win)
3554                 notify = _composer_popup_create(ugd->win_main, ugd);
3555         else
3556                 notify = elm_popup_add(ugd->win_main);
3557
3558         debug_log("notify: %p", notify);
3559         if (!notify) {
3560                 debug_log("elm_popup_add returns NULL");
3561                 return NULL;
3562         }
3563         evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3564
3565         if (title) {
3566                 elm_object_part_text_set(notify, "title,text", title);
3567         }
3568
3569         if (content) {
3570                 elm_object_text_set(notify, content);
3571         }
3572
3573         if (btn_num == 1) {
3574                 Evas_Object *peoBtn1 = NULL;
3575                 peoBtn1 = elm_button_add(notify);
3576                 debug_log("peoBtn1: %p", peoBtn1);
3577                 elm_object_style_set(peoBtn1, "popup_button/default");
3578                 elm_object_text_set(peoBtn1, btn1_lb);
3579                 elm_object_part_content_set(notify, "button1", peoBtn1);
3580                 evas_object_smart_callback_add(peoBtn1, "clicked", response_cb, ugd);
3581         } else if (btn_num == 2) {
3582                 Evas_Object *peoBtn1 = NULL;
3583                 peoBtn1 = elm_button_add(notify);
3584                 debug_log("peoBtn1: %p", peoBtn1);
3585                 elm_object_style_set(peoBtn1, "popup_button/default");
3586                 elm_object_text_set(peoBtn1, btn1_lb);
3587                 elm_object_part_content_set(notify, "button1", peoBtn1);
3588                 evas_object_smart_callback_add(peoBtn1, "clicked", response_cb, ugd);
3589
3590                 Evas_Object *peoBtn2 = NULL;
3591                 peoBtn2 = elm_button_add(notify);
3592                 debug_log("peoBtn2: %p", peoBtn2);
3593                 elm_object_style_set(peoBtn2, "popup_button/default");
3594                 elm_object_text_set(peoBtn2, btn2_lb);
3595                 elm_object_part_content_set(notify, "button2", peoBtn2);
3596                 evas_object_smart_callback_add(peoBtn2, "clicked", response_cb, ugd);
3597         } else if (btn_num == 3) {
3598                 Evas_Object *peoBtn1 = NULL;
3599                 peoBtn1 = elm_button_add(notify);
3600                 debug_log("peoBtn1: %p", peoBtn1);
3601                 elm_object_style_set(peoBtn1, "popup_button/default");
3602                 elm_object_text_set(peoBtn1, btn1_lb);
3603                 elm_object_part_content_set(notify, "button1", peoBtn1);
3604                 evas_object_smart_callback_add(peoBtn1, "clicked", response_cb, ugd);
3605
3606                 Evas_Object *peoBtn2 = NULL;
3607                 peoBtn2 = elm_button_add(notify);
3608                 debug_log("peoBtn2: %p", peoBtn2);
3609                 elm_object_style_set(peoBtn2, "popup_button/default");
3610                 elm_object_text_set(peoBtn2, btn2_lb);
3611                 elm_object_part_content_set(notify, "button2", peoBtn2);
3612                 evas_object_smart_callback_add(peoBtn2, "clicked", response_cb, ugd);
3613
3614                 Evas_Object *peoBtn3 = NULL;
3615                 peoBtn3 = elm_button_add(notify);
3616                 debug_log("peoBtn3: %p", peoBtn3);
3617                 elm_object_style_set(peoBtn3, "popup_button/default");
3618                 elm_object_text_set(peoBtn3, btn3_lb);
3619                 elm_object_part_content_set(notify, "button3", peoBtn3);
3620                 evas_object_smart_callback_add(peoBtn3, "clicked", response_cb, ugd);
3621         }
3622
3623         if (timeout > 0.0) {
3624                 elm_popup_timeout_set(notify, timeout);
3625                 evas_object_smart_callback_add(notify, "timeout", response_cb, ugd);
3626                 evas_object_smart_callback_add(notify, "block,clicked", response_cb, ugd);
3627         }
3628
3629         evas_object_show(notify);
3630
3631         ugd->popup_list = eina_list_append(ugd->popup_list, notify);
3632
3633         debug_log("notify = %x, %p", notify, notify);
3634         return notify;
3635 }
3636
3637 void _composer_noti_response_cb(void *data, Evas_Object *obj, void *event_info)
3638 {
3639         debug_log("");
3640
3641         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3642
3643         elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE); // block the focus not to open IME.
3644         ugd->focus_status = COMPOSER_FOCUS_STATUS_NONE;
3645
3646         Evas_Object *mbe = NULL;
3647
3648         if (ugd->selected_entry == ugd->to_mbe_entry) {
3649                 mbe = ugd->to_mbe;
3650         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
3651                 mbe = ugd->cc_mbe;
3652         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
3653                 mbe = ugd->bcc_mbe;
3654         }
3655
3656         if (ugd->popup_list) {
3657                 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
3658                 debug_log("obj: %p", obj);
3659                 debug_log("composer_noti: %p", ugd->composer_noti);
3660
3661                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti/*obj*/);
3662
3663                 debug_log("@@@ b_sending = %d", ugd->b_sending);
3664
3665                 if (!_composer_check_popup_exist(ugd))
3666                         ugd->idler_set_focus = ecore_idler_add(_composer_mbe_set_focus, ugd);
3667         }
3668
3669         if (ugd->b_sending)
3670                 ugd->b_sending = false;
3671
3672         evas_object_del(ugd->composer_noti);
3673         ugd->composer_noti = NULL;
3674 }
3675
3676 void _composer_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
3677 {
3678         debug_log("");
3679
3680         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3681
3682         Evas_Object *mbe = NULL;
3683
3684         if (ugd->selected_entry == ugd->to_mbe_entry) {
3685                 mbe = ugd->to_mbe;
3686         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
3687                 mbe = ugd->cc_mbe;
3688         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
3689                 mbe = ugd->bcc_mbe;
3690         }
3691
3692         if (mbe) {
3693                 Elm_Object_Item *item = elm_multibuttonentry_selected_item_get(mbe);
3694                 elm_multibuttonentry_item_selected_set(item, EINA_FALSE);
3695         }
3696
3697         elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE);
3698
3699         if (ugd->popup_list) {
3700                 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
3701                 debug_log("obj: %p", obj);
3702                 debug_log("composer_noti: %p", ugd->composer_popup);
3703
3704                 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_popup/*obj*/);
3705
3706                 debug_log("@@@ b_sending = %d", ugd->b_sending);
3707
3708                 if (!_composer_check_popup_exist(ugd))
3709                         ugd->idler_set_focus = ecore_idler_add(_composer_mbe_set_focus, ugd);
3710         }
3711
3712         if (ugd->b_sending)
3713                 ugd->b_sending = false;
3714
3715         evas_object_del(ugd->composer_popup);
3716         ugd->composer_popup = NULL;
3717         ugd->is_mbe_selected = false;
3718         ugd->selected_mbe_item = NULL;
3719 }
3720
3721 Eina_Bool _composer_check_popup_exist(EmailComposerUGD *ugd)
3722 {
3723         debug_log("");
3724
3725         if (!ugd) return EINA_FALSE;
3726
3727         debug_log("popup list count = %d", eina_list_count(ugd->popup_list));
3728         if (eina_list_count(ugd->popup_list) > 0)
3729                 return EINA_TRUE;
3730         else
3731                 return EINA_FALSE;
3732 }
3733
3734 int _composer_get_account_list(EmailComposerUGD *ugd)
3735 {
3736         debug_log("");
3737
3738         int err = email_get_account_list(&ugd->account_info->account_list, &ugd->account_info->account_count);
3739
3740         if (err != EMAIL_ERROR_NONE) {
3741                 debug_log("[email-composer] email_account_get_list error");
3742                 return COMPOSER_ERROR_NO_ACCOUNT_LIST;
3743         }
3744
3745         int i;
3746         for (i = 0; i < ugd->account_info->account_count; i++) {
3747                 debug_log("cnt = %d, account_id = %d, email_addr = %s", i, ugd->account_info->account_list[i].account_id, ugd->account_info->account_list[i].user_email_address);
3748         }
3749
3750         debug_log("[email-composer] account count = %d", ugd->account_info->account_count);
3751
3752         return COMPOSER_ERROR_NONE;
3753 }
3754
3755 char *_composer_get_email_addr_from_account_id(EmailComposerUGD *ugd, int account_id)
3756 {
3757         debug_log("");
3758         int i;
3759
3760         for (i = 0; i < ugd->account_info->account_count; i++) {
3761                 if (ugd->account_info->account_list[i].account_id == account_id)
3762                         return g_strdup(ugd->account_info->account_list[i].user_email_address);
3763         }
3764
3765         return NULL;
3766 }
3767
3768 char *_composer_get_service_fail_type(int type)
3769 {
3770         debug_log("");
3771
3772         char *ret = NULL;
3773         char str[MAX_STR_LEN] = { 0, };
3774
3775         if (type == -174) {
3776                 snprintf(str, sizeof(str), "%s: %s", _("IDS_EMAIL_POP_FAILED_TO_ACTIVATE_PDP"), N_("IP full"));
3777                 return g_strdup(str);
3778         } else if (type == -176) {
3779                 ret = _("IDS_EMAIL_POP_NO_SERVICE");
3780                 return g_strdup(ret);
3781         } else if (type == -181) {
3782                 snprintf(str, sizeof(str), "%s: %s", _("IDS_EMAIL_POP_FAILED_TO_ACTIVATE_PDP"), N_("Transport Error"));
3783                 return g_strdup(str);
3784         } else if (type == EMAIL_ERROR_NETWORK_TOO_BUSY) {
3785                 ret = _("IDS_EMAIL_POP_NETWORK_BUSY");
3786                 return g_strdup(ret);
3787         } else if (type == EMAIL_ERROR_LOGIN_ALLOWED_EVERY_15_MINS) {
3788                 snprintf(str, sizeof(str), _("IDS_EMAIL_POP_YOU_CAN_ONLY_LOG_IN_ONCE_EVERY_PD_MINUTES"), 15);
3789                 return g_strdup(str);
3790         } else if (type == EMAIL_ERROR_CONNECTION_FAILURE) {
3791                 ret = dgettext("sys_string", "IDS_COM_POP_CONNECTION_FAILED");
3792                 return g_strdup(ret);
3793         } else if (type == EMAIL_ERROR_LOGIN_FAILURE) {
3794                 ret = _("IDS_EMAIL_POP_LOG_IN_FAILED");
3795                 return g_strdup(ret);
3796         } else if (type == EMAIL_ERROR_AUTHENTICATE) {
3797                 ret = _("IDS_EMAIL_POP_AUTHENTICATION_FAILED");
3798                 return g_strdup(ret);
3799         } else if (type == EMAIL_ERROR_CANCELLED) {
3800                 ret = _("IDS_EMAIL_POP_SENDING_CANCELLED");
3801                 return g_strdup(ret);
3802         } else if (type == EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER) {
3803                 ret = _("IDS_EMAIL_POP_EMAIL_DELETED_FROM_SERVER");
3804                 return g_strdup(ret);
3805         } else if (type == EMAIL_ERROR_NO_SUCH_HOST) {
3806                 ret = _("IDS_EMAIL_POP_HOST_NOT_FOUND");
3807                 return g_strdup(ret);
3808         } else if (type == EMAIL_ERROR_INVALID_SERVER) {
3809                 ret = _("IDS_EMAIL_POP_SERVER_NOT_AVAILABLE");
3810                 return g_strdup(ret);
3811         } else if (type == EMAIL_ERROR_MAIL_MEMORY_FULL) {
3812                 ret = _("IDS_EMAIL_POP_DEVICE_STORAGE_FULL");
3813                 return g_strdup(ret);
3814         } else if (type == EMAIL_ERROR_FAILED_BY_SECURITY_POLICY) {
3815                 ret = _("IDS_EMAIL_POP_DOWNLOADING_ATTACHMENTS_ON_THE_MOBILE_DEVICE_IS_NOT_ALLOWED_BY_EXCHANGE_SERVER_POLICY");
3816                 return g_strdup(ret);
3817         } else if (type == EMAIL_ERROR_ATTACHMENT_SIZE_EXCEED_POLICY_LIMIT) {
3818                 ret = _("IDS_EMAIL_BODY_ATTACHMENT_EXCEEDS_THE_MAXIMUM_SIZE_ALLOWED_BY_THIS_EXCHANGE_SERVER_POLICY_ABB");
3819                 return g_strdup(ret);
3820         } else if (type == EMAIL_ERROR_NETWORK_NOT_AVAILABLE) {
3821                 ret = N_("Network not available");
3822                 return g_strdup(ret);
3823         } else if (type == EMAIL_ERROR_FLIGHT_MODE) {
3824                 ret = N_("Flight mode enabled");
3825                 return g_strdup(ret);
3826         } else if (type == EMAIL_ERROR_NO_RESPONSE) {
3827                 ret = N_("No server response");
3828                 return g_strdup(ret);
3829         } else if (type == EMAIL_ERROR_DISCONNECTED) {
3830                 ret = N_("Disconnected");
3831                 return g_strdup(ret);
3832         } else if (type == EMAIL_ERROR_CONNECTION_BROKEN) {
3833                 ret = N_("Connection broken");
3834                 return g_strdup(ret);
3835         } else {
3836                 snprintf(str, sizeof(str), "%s (%d)", dgettext("sys_string", "IDS_COM_POP_UNKNOWN_ERROR_OCCURRED"), type);
3837                 return g_strdup(str);
3838         }
3839 }
3840
3841 Eina_Bool _composer_mbe_set_focus(void *data)
3842 {
3843         debug_log("");
3844
3845         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3846
3847         debug_log("selected_entry = %x, to_mbe_entry = %x, cc_mbe_entry = %x, bcc_mbe_entry = %x, subject_entry = %x, body_ewkview = %x",
3848                 ugd->selected_entry, ugd->to_mbe_entry, ugd->cc_mbe_entry, ugd->bcc_mbe_entry, ugd->subject_entry, ugd->body_ewkview);
3849
3850         if (ugd->focus_status != COMPOSER_FOCUS_STATUS_NONE) {
3851                 ugd->focus_status = COMPOSER_FOCUS_STATUS_NONE;
3852         }
3853         elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE); // block the focus not to open IME.
3854
3855         if ((ugd->selected_entry == ugd->to_mbe_entry) || (ugd->selected_entry == NULL)) {
3856                 debug_log("TO MBE ENTRY FOCUS!!!");
3857                 elm_object_focus_set(ugd->to_mbe, EINA_TRUE);
3858         } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
3859                 debug_log("CC MBE ENTRY FOCUS!!!");
3860                 elm_object_focus_set(ugd->cc_mbe, EINA_TRUE);
3861         } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
3862                 debug_log("BCC MBE ENTRY FOCUS!!!");
3863                 elm_object_focus_set(ugd->bcc_mbe, EINA_TRUE);
3864         } else if (ugd->selected_entry == ugd->subject_entry) {
3865                 debug_log("SUBJECT ENTRY FOCUS!!!");
3866                 elm_object_focus_set(ugd->subject_editfield, EINA_TRUE);
3867         } else if (ugd->selected_entry == ugd->body_ewkview) {
3868                 debug_log("BODY WEBKIT FOCUS!!!");
3869                 evas_object_focus_set(ugd->body_ewkview, EINA_TRUE);
3870         } else if (ugd->selected_entry == ugd->attachment_contracted_item) {
3871                 debug_log("Attachments FOCUS!!!");
3872                 elm_object_focus_set(ugd->attachment_contracted_item, EINA_TRUE);
3873         } else {
3874                 debug_log("NO ENTRY!!! TO MBE ENTRY will get the focus.");
3875                 elm_object_focus_set(ugd->to_mbe_entry, EINA_TRUE);
3876         }
3877
3878         if (ugd->b_cc_bcc)
3879                 ugd->b_cc_bcc = false;
3880
3881         if (ugd->clipboard_on)
3882                 ugd->clipboard_on = false;
3883
3884         if (ugd->idler_set_focus) {
3885                 ecore_idler_del(ugd->idler_set_focus);
3886                 ugd->idler_set_focus = NULL;
3887         }
3888
3889         return EINA_FALSE;
3890 }
3891
3892 void _composer_resize_body_webview(EmailComposerUGD *ugd, int ime_height)
3893 {
3894         Evas_Coord nWidth = 0, nHeight = 0;
3895
3896         ecore_x_window_size_get(ecore_x_window_root_first_get(), &nWidth, &nHeight);
3897
3898         if (ugd->isHorizontal == false) {
3899                 evas_object_size_hint_min_set(ugd->webkit_ly, 0, nHeight - COMPOSER_NAVI_HEIGHT - COMPOSER_INDI_HEIGHT - ime_height);
3900         }
3901         else {
3902                 evas_object_size_hint_min_set(ugd->webkit_ly, 0, nWidth - COMPOSER_NAVI_HEIGHT - ime_height);
3903         }
3904
3905         if ((ugd->from_mbe != NULL) && (ugd->b_launch_finished == false)) {
3906                 ugd->b_launch_finished = true;
3907                 ugd->bringin_timer = ecore_timer_add(0.5f, _composer_bringin_cb, ugd);
3908         }
3909 }
3910
3911 void _composer_input_panel_resize_cb(void *data, Ecore_IMF_Context *ctx, int value)
3912 {
3913         debug_log("");
3914
3915         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3916
3917         bool ime_state = true; // true: open, false: close
3918         Evas_Coord x = 0, y = 0, w = 0, h = 0;
3919         Evas_Coord cx = 0, cy = 0, cw = 0, ch = 0;
3920
3921         evas_object_geometry_get(ugd->win_main, &x, &y, &w, &h);
3922         ecore_imf_context_input_panel_geometry_get(ctx, &cx, &cy, &cw, &ch);
3923
3924         debug_log("main ==> (x:%d,y:%d,w:%d,h:%d)", x, y, w, h);
3925         debug_log("rect ==> (x:%d,y:%d,w:%d,h:%d)", cx, cy, cw, ch);
3926
3927         if (cy == h)
3928                 ime_state = false;
3929
3930         if (ime_state) {
3931                 _composer_resize_body_webview(ugd, ch);
3932         }
3933         else {
3934                 _composer_resize_body_webview(ugd, 0);
3935         }
3936 }
3937
3938 void _composer_input_panel_state_changed_cb(void *data, Ecore_IMF_Context *ctx, int value)
3939 {
3940         debug_log("");
3941 }
3942
3943 void _composer_display_position(void *data)
3944 {
3945         EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3946         Evas_Coord x = 0, y = 0, w = 0, h = 0;
3947
3948         elm_scroller_region_get(ugd->main_scroller, &x, &y, &w, &h);
3949         debug_log("scroller   = [x:%d, y:%d, w:%d, h:%d]", x, y, w, h);
3950         x = y = w = h = 0;
3951
3952         if (ugd->from_ly) {
3953                 evas_object_geometry_get(ugd->from_ly, &x, &y, &w, &h);
3954                 debug_log("from       = [x:%d, y:%d, w:%d, h:%d]", x, y, w, h);
3955                 x = y = w = h = 0;
3956         }
3957
3958         evas_object_geometry_get(ugd->to_ly, &x, &y, &w, &h);
3959         debug_log("to         = [x:%d, y:%d, w:%d, h:%d]", x, y, w, h);
3960         x = y = w = h = 0;
3961
3962         if (ugd->cc_ly) {
3963                 evas_object_geometry_get(ugd->cc_ly, &x, &y, &w, &h);
3964                 debug_log("cc         = [x:%d, y:%d, w:%d, h:%d]", x, y, w, h);
3965                 x = y = w = h = 0;
3966         }
3967
3968         if (ugd->bcc_ly) {
3969                 evas_object_geometry_get(ugd->bcc_ly, &x, &y, &w, &h);
3970                 debug_log("bcc        = [x:%d, y:%d, w:%d, h:%d]", x, y, w, h);
3971                 x = y = w = h = 0;
3972         }
3973
3974         evas_object_geometry_get(ugd->subject_ly, &x, &y, &w, &h);
3975         debug_log("subject    = [x:%d, y:%d, w:%d, h:%d]", x, y, w, h);
3976         x = y = w = h = 0;
3977
3978         evas_object_geometry_get(ugd->webkit_ly, &x, &y, &w, &h);
3979         debug_log("webview    = [x:%d, y:%d, w:%d, h:%d]", x, y, w, h);
3980         x = y = w = h = 0;
3981 }
3982
3983 static Eina_Bool _composer_print_hit_test_result_hash_fn(const Eina_Hash *hash, const void *key, void *data, void *fdata)
3984 {
3985         // fdata is the third parameter
3986         debug_log("Func data: %s, Hash entry: %s / %s\n", fdata, (const char *)key, data);
3987         return EINA_TRUE;
3988 }
3989
3990 void _composer_print_hit_test_result(Ewk_Hit_Test *hit_test)
3991 {
3992         Eina_Hash *attr_hash = NULL;
3993         debug_log("context: %d", ewk_hit_test_result_context_get(hit_test));
3994         debug_log("linkURI: %s", ewk_hit_test_link_uri_get(hit_test));
3995         debug_log("linkTitle: %s", ewk_hit_test_link_title_get(hit_test));
3996         debug_log("linkLabel: %s", ewk_hit_test_link_label_get(hit_test));
3997         debug_log("imageURI: %s", ewk_hit_test_image_uri_get(hit_test));
3998         debug_log("mediaURI: %s", ewk_hit_test_media_uri_get(hit_test));
3999         debug_log("nodeData.tagName: %s", ewk_hit_test_tag_name_get(hit_test));
4000         debug_log("nodeData.nodeValue: %s", ewk_hit_test_node_value_get(hit_test));
4001         debug_log("imageData.length: %d", ewk_hit_test_image_buffer_length_get(hit_test));
4002         debug_log("imageData.fileNameExtension: %s", ewk_hit_test_image_file_name_extension_get(hit_test));
4003
4004         attr_hash = ewk_hit_test_attribute_hash_get(hit_test);
4005
4006         eina_hash_foreach(attr_hash, _composer_print_hit_test_result_hash_fn, NULL);
4007 }
4008
4009 void _composer_coords_ewk_to_evas(Evas_Object *view, int ewkX, int ewkY, int *evasX, int *evasY)
4010 {
4011         int scrollX, scrollY, viewX, viewY;
4012         ewk_view_scroll_pos_get(view, &scrollX, &scrollY);
4013         evas_object_geometry_get(view, &viewX, &viewY, NULL, NULL);
4014
4015         *evasX = ewkX - scrollX + viewX;
4016         *evasY = ewkY - scrollY + viewY;
4017 }
4018
4019 void _composer_coords_evas_to_ewk(Evas_Object *view, int evasX, int evasY, int *ewkX, int *ewkY)
4020 {
4021         debug_log("evasX:%d, evasY:%d", evasX, evasY);
4022         int scrollX, scrollY, viewX, viewY;
4023         ewk_view_scroll_pos_get(view, &scrollX, &scrollY);
4024         evas_object_geometry_get(view, &viewX, &viewY, NULL, NULL);
4025         debug_log("scrollX:%d, scrollY:%d, viewX:%d, viewY:%d", scrollX, scrollY, viewX, viewY);
4026
4027         *ewkX = evasX + scrollX - viewX;
4028         *ewkY = evasY + scrollY - viewY;
4029 }
4030