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