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