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