2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
18 #include <glib/gprintf.h>
21 #include <appcore-common.h>
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"
34 #include "email-engine.h"
35 #include "email-utils.h"
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"
43 #define DIVIDE_LINE "\n\n-----------------------------------\n"
45 #define DEFAULT_SIGNATURE _("IDS_EMAIL_BODY_SENT_USING_TIZEN_MOBILE")
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>"
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);
56 extern void _composer_free_initial_email_content(EmailComposerUGD *ugd);
58 void _composer_make_html_body(EmailComposerUGD *ugd);
60 extern char *icu_locale;
61 extern enum appcore_time_format icu_timeformat;
63 const gchar *email_composer_get_html_tag(const gchar char_val)
65 const gchar *tag = NULL;
85 gchar *email_composer_get_parse_string(const gchar *text, gint size)
88 RETURN_VAL_IF_FAIL(STR_VALID(text), NULL);
94 guint old_offset = 0, offset = 0;
96 for (i = 0; i < size; ++i) {
98 const gchar *tag = email_composer_get_html_tag(text[i]);
100 /* If need, convert text to html format. */
104 if (i > old_offset) {
105 offset = i - old_offset;
106 buff = g_strndup(&text[old_offset], offset);
108 html = g_strconcat(temp, buff, tag, NULL);
110 html = g_strconcat(buff, tag, NULL);
119 html = g_strconcat(temp, tag, NULL);
121 html = g_strconcat(tag, NULL);
134 /* If not terminated. */
135 if (old_offset < size) {
138 buff = g_strndup(&text[old_offset], size - old_offset);
139 html = g_strconcat(temp, buff, NULL);
147 return html ? html : g_strndup(text, size);
151 The following API splits a given filepath string into 'directory path' or 'filename'
153 char *email_composer_parse_filepath(const char *path, Eina_Bool directorypathORfilename)
156 RETURN_VAL_IF_FAIL(STR_VALID(path), NULL);
158 char *file_path = NULL;
160 int size = STR_LEN((char *)path);
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. */
167 file_path = g_strndup(path + i + 1, size - i + 1); /* filename is copied. */
175 char *email_composer_parse_get_filepath_from_path(const char *path)
177 RETURN_VAL_IF_FAIL(STR_VALID(path), NULL);
179 char *file_path = NULL;
181 int size = STR_LEN((char *)path);
183 for (i = (size - 1); i >= 0; --i) {
184 if (path[i] == '/') {
185 file_path = g_strndup(path, i + 1);
193 * Changes inline images path from absolute to relative, in a given html content.
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
198 * @return true or false
201 Eina_Bool email_composer_change_image_paths_to_relative(char *src_html_content, char **dest_buffer)
205 if (src_html_content == NULL || dest_buffer == NULL) {
206 debug_log("NULL arguments passed");
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.");
222 Eina_Bool success_flag = EINA_TRUE;
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"))) {
227 if (!(temp = strstr(point1, "src=")) && !(temp = strstr(point1, "SRC="))) {
228 debug_log("1. No src=");
229 success_flag = EINA_FALSE;
234 if (point1 == NULL) {
235 debug_log("2. No file path");
236 success_flag = EINA_FALSE;
240 strncat(buffer, src_str, point1 - src_str);
242 debug_log("point1[0] = %c", point1[0]);
244 if (point1[0] == '/') {
246 point2 = strstr(point1, "\"");
247 if (point2 == NULL) {
248 debug_log("3. No end quotation");
249 success_flag = EINA_FALSE;
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);
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;
263 strncat(buffer, file_path, strlen(file_path));
270 if (success_flag == EINA_FALSE) {
276 strncat(buffer, src_str, strlen(src_str));
277 *dest_buffer = buffer;
282 Eina_Bool email_composer_save_file(const gchar *path, const gchar *buf, gsize len)
284 debug_log("path (%s)", path);
286 Eina_Bool success_flag = EINA_TRUE;
288 if (STR_LEN((gchar *)buf) >= 0 && len >= 0) {
289 int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
291 ssize_t nwrite = write(fd, (const void *)buf, (size_t) len);
292 debug_log("nwrite(%d)", nwrite);
294 debug_log("fail to write");
295 success_flag = EINA_FALSE;
300 debug_log("fail to open");
301 success_flag = EINA_FALSE;
304 debug_log("check the buf!!");
305 success_flag = EINA_FALSE;
311 Eina_List *email_composer_change_str_to_EinaList(EmailComposerUGD *ugd, const char *str, char *token)
315 Eina_List *list = NULL;
317 debug_log("str = %s", str);
320 debug_log("token = %s", token);
322 p = strtok((char *)str, token);
325 debug_log("str = %s", p);
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;
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);
338 list = eina_list_append(list, p);
342 p = strtok(NULL, token);
344 debug_log("str = %s", p);
348 list = eina_list_append(list, str);
354 Eina_List *email_composer_change_GList_to_EinaList(GList * l)
358 Eina_List *list = NULL;
361 int count = g_list_length(l);
364 for (i = 0; i < count; i++) {
365 char *string = g_list_nth_data(l, i);
366 debug_log("%d = %s", i, string);
369 list = eina_list_append(list, string);
374 debug_log("count is 0!!");
379 int _composer_add_mailbox_folder(EmailComposerUGD *ugd, email_mailbox_type_e mailbox_type)
383 int nResult = EMAIL_ERROR_NONE;
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);
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);
394 nResult = _composer_make_mail(ugd);
395 if (nResult < COMPOSER_ERROR_NONE) {
396 debug_log("error in _composer_make_mail(%d)", nResult);
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);
403 debug_log("attachment_list = %x, attachment_count = %d",
404 ugd->new_mail_info->attachment_list, ugd->new_mail_info->mail_data->attachment_count);
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);
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;
419 return COMPOSER_ERROR_NONE;
422 int _composer_move_mailbox_folder(EmailComposerUGD *ugd, email_mailbox_type_e mailbox_type)
426 int nResult = EMAIL_ERROR_NONE;
428 int mail_ids[1] = { 0, };
429 mail_ids[0] = ugd->nExistingMailID;
431 debug_log("id = %d", mail_ids[0]);
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);
439 nResult = _composer_make_mail(ugd);
440 if (nResult < COMPOSER_ERROR_NONE) {
441 debug_log("error in _composer_make_mail(%d)", nResult);
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);
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;
458 return COMPOSER_ERROR_NONE;
461 int _composer_make_mail(EmailComposerUGD *ugd)
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;
479 ugd->new_mail_info->mail_data->report_status = EMAIL_MAIL_REPORT_NONE;
481 if (ugd->tracking_option[0] == 1) {
482 ugd->new_mail_info->mail_data->report_status |= EMAIL_MAIL_REQUEST_MDN;
484 if (ugd->tracking_option[1] == 1) {
485 ugd->new_mail_info->mail_data->report_status |= EMAIL_MAIL_REQUEST_DSN;
487 debug_log("ugd->new_mail_info->mail_data->report_status = %d", ugd->new_mail_info->mail_data->report_status);
489 ugd->new_mail_info->mail_data->priority = ugd->priority_option;
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;
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);
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);
502 if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->to_mbe)) != NULL) {
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;
508 if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->cc_mbe)) != NULL) {
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;
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;
520 ugd->new_mail_info->mail_data->subject = elm_entry_markup_to_utf8(elm_entry_entry_get(ugd->subject_entry));
522 if (EINA_TRUE == ugd->has_body_html) {
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;
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;
538 char *html_content = NULL;
539 char *html_content_processed = NULL;
540 //Eina_List *images_list = NULL;
541 char *plain_text_content = NULL;
543 html_content = g_strdup(ugd->latest_html_content);
545 if (html_content == NULL) {
546 debug_log("ugd->latest_html_content is null");
547 return COMPOSER_ERROR_MAKE_MAIL_FAIL;
550 debug_log("\nhtml_content:\n%s", html_content);
553 if (ugd->listOfImageUrls == NULL) {
554 debug_log("No images found or ERROR");
555 html_content_processed = html_content;
560 Eina_List *inline_list = NULL;
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);
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);
574 return COMPOSER_ERROR_MAKE_MAIL_FAIL;
576 debug_log("\nhtml_source_processed:\n%s", html_content_processed);
578 _composer_attachment_create_list(ugd, inline_list, EINA_TRUE);
580 g_free(html_content);
583 html_content_processed = html_content;
586 //eina_list_free(images_list);
587 //images_list = NULL;
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;
597 g_free(html_content_processed);
598 html_content_processed = NULL;
601 plain_text_content = g_strdup(ugd->plain_content);
603 if (NULL == plain_text_content) {
604 debug_log("ugd->plain_content is NULL");
605 return COMPOSER_ERROR_MAKE_MAIL_FAIL;
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;
613 g_free(plain_text_content);
614 plain_text_content = NULL;
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);
620 int nAttachmentObjListCount = eina_list_count(ugd->attachment_item_obj_list);
621 debug_log("nAttachmentObjListCount : %d", nAttachmentObjListCount);
623 if (nAttachmentObjListCount > 0) {
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;
631 ugd->new_mail_info->mail_data->attachment_count = nAttachmentObjListCount;
633 debug_log("ugd->new_mail_info->attachment_count : %d", ugd->new_mail_info->mail_data->attachment_count);
635 ugd->new_mail_info->attachment_list = (email_attachment_data_t *)calloc(nAttachmentObjListCount, sizeof(email_attachment_data_t));
638 Eina_Iterator *it = NULL;
639 Evas_Object *attachment_obj = NULL;
640 email_attachment_data_t *attachment_data;
642 it = eina_list_iterator_new(ugd->attachment_item_obj_list);
644 while (eina_iterator_next(it, (void **)&attachment_obj)) {
646 attachment_data = evas_object_data_get(attachment_obj, "attachment_data");
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);
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);
668 ugd->new_mail_info->mail_data->flags_draft_field = 1;
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);
676 debug_log("existing mail id = %d, %d", ugd->nExistingMailID, ugd->existing_mail_info->mail_data->mail_id);
678 return COMPOSER_ERROR_NONE;
681 EmailRecpInfo *_composer_separate_save_recipient_char(EmailComposerUGD *ugd, char *recipient)
684 if (!ugd || !recipient) {
685 debug_log("Function arguments NULL");
688 debug_log("separate recipient char = %s", recipient);
692 if (recipient[0] == ' ') {
693 temp = g_strdup(recipient++);
694 debug_log("temp = %s", temp);
696 temp = g_strdup(recipient);
697 debug_log("temp = %s", temp);
704 gchar **vector = NULL;
706 vector = g_strsplit_set(temp, "\"<>", -1);
708 if (vector == NULL) {
709 debug_log("vector == NULL");
714 EmailRecpInfo *ri = (EmailRecpInfo *) calloc(1, sizeof(EmailRecpInfo));
717 debug_log("Memory allocation failed.");
723 gint tok_cnt = g_strv_length(vector);
725 debug_log("tok_cnt = %d", tok_cnt);
726 debug_log("temp = %s", temp);
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]);
738 } else if (tok_cnt == 3) {
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]);
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]);
765 ri->selected_email_idx = 0;
767 ri->is_contact_info = false;
768 ri->is_always_bcc = false;
769 ri->is_from_addr = false;
777 void _composer_convert_ps_to_br(char *input)
779 const char *char_ps = "<ps>";
784 while ((ptr = strstr(input, char_ps))) {
792 email_attachment_data_t *_composer_attach_mail_body(EmailComposerUGD *ugd)
794 email_attachment_data_t *body_attch = NULL;
796 body_attch = (email_attachment_data_t *) calloc(1, sizeof(email_attachment_data_t));
798 debug_log("Memory allocation failed.");
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;
810 int _composer_send_mail(EmailComposerUGD *ugd)
814 if (!ugd->account_info->account) {
815 debug_log("account is NULL");
816 return COMPOSER_ERROR_SEND_FAIL;
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);
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.
826 Correct process will be as below -
828 1) Add new edited email to Outbox.
829 2) Delete the old email from Drafts / Outbox */
831 if (0 < ugd->mailbox_info->mailbox_id) {
832 int ret = _composer_add_mailbox_folder(ugd, EMAIL_MAILBOX_TYPE_OUTBOX);
834 if (ret < COMPOSER_ERROR_NONE) {
835 debug_log("error in _composer_add_mailbox_folder(%d)", ret);
836 return COMPOSER_ERROR_SEND_FAIL;
839 int sync = EMAIL_DELETE_LOCAL_AND_SERVER;
841 /* Retrieve mailbox type from email-service and store it to identify Outbox */
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;
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);
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;
855 debug_critical("mailbox name is null");
856 return COMPOSER_ERROR_SEND_FAIL;
860 int ret = _composer_add_mailbox_folder(ugd, EMAIL_MAILBOX_TYPE_OUTBOX);
862 if (ret < COMPOSER_ERROR_NONE) {
863 debug_log("error in _composer_add_mailbox_folder(%d)", ret);
864 return COMPOSER_ERROR_SEND_FAIL;
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;
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);
886 return COMPOSER_ERROR_NONE;
889 int _composer_make_recipient_char_to_list(EmailComposerUGD *ugd, Evas_Object *obj, char **dest)
893 char result[MAX_RECIPIENT_ADDRESSES_LEN] = { 0, };
895 debug_log("obj = %p", obj);
897 Elm_Object_Item *mbe_item;
898 mbe_item = elm_multibuttonentry_first_item_get(obj);
899 debug_log("mbe_item = %p", mbe_item);
905 ri = (EmailRecpInfo *) elm_object_item_data_get(mbe_item);
907 return COMPOSER_ERROR_GET_DATA_FAIL;
909 index = ri->selected_email_idx;
911 debug_log("display name = %s", ri->display_name);
912 debug_log("email_addr = %s", ri->email_list[index].email_addr);
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);
918 snprintf(result, sizeof(result), "<%s>", ri->email_list[index].email_addr);
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);
923 snprintf(result + strlen(result), sizeof(result) - strlen(result), ";<%s>", ri->email_list[index].email_addr);
926 mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
929 debug_log("result = %s", result);
931 *dest = g_strdup(result);
933 return COMPOSER_ERROR_NONE;
936 void _composer_save_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
940 debug_log("data is NULL");
944 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
946 char *pszBtnText = (char *)elm_object_text_get(obj);
947 debug_log("selected button text = %s", pszBtnText);
949 if (pszBtnText && strcmp(pszBtnText, dgettext("sys_string", "IDS_COM_SK_YES")) == 0) {
951 int ret = _composer_add_mailbox_folder(ugd, EMAIL_MAILBOX_TYPE_DRAFT);
953 if (ret < COMPOSER_ERROR_NONE) {
954 debug_log("Failed save in Drafts(%d)", ret);
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);
961 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti/*obj*/);
964 evas_object_del(ugd->composer_noti);
965 ugd->composer_noti = NULL;
967 ugd->idler_save_draft = ecore_idler_add(_composer_show_fail_to_save, ugd);
969 debug_log("Succeed in saving in Drafts");
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);
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.");
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);
985 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti/*obj*/);
988 evas_object_del(ugd->composer_noti);
989 ugd->composer_noti = NULL;
991 ugd->idler_save_draft = ecore_idler_add(_composer_show_success_to_save, ugd);
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);
1000 Eina_Bool _composer_show_fail_to_save(void *data)
1002 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
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;
1011 ugd->b_sending = false;
1013 if (ugd->composer_noti) {
1014 evas_object_del(ugd->composer_noti);
1015 ugd->composer_noti = NULL;
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);
1023 Eina_Bool _composer_show_success_to_save(void *data)
1025 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
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;
1034 ugd->b_sending = false;
1036 if (ugd->composer_noti) {
1037 evas_object_del(ugd->composer_noti);
1038 ugd->composer_noti = NULL;
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);
1046 static void _composer_save_draft_response_cb(void *data, Evas_Object *obj, void *event_info)
1050 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1052 ugd->idler_save_draft = ecore_idler_add(_composer_idler_destroy, ugd);
1055 static void _composer_save_draft_fail_response_cb(void *data, Evas_Object *obj, void *event_info)
1059 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1061 ugd->idler_save_draft = ecore_idler_add(_composer_idler_return, ugd);
1064 Eina_Bool _composer_popup_end_cb(void *data)
1068 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1069 _composer_popup_end(ugd, COMPOSER_ERROR_NONE);
1074 void _composer_popup_end(EmailComposerUGD *ugd, int close_sg)
1078 if (ugd->send_timer) {
1079 debug_log("delete send_timer");
1080 ecore_timer_del(ugd->send_timer);
1081 ugd->send_timer = NULL;
1084 if (ugd->composer_noti) {
1085 evas_object_del(ugd->composer_noti);
1086 ugd->composer_noti = NULL;
1089 if (close_sg == COMPOSER_ERROR_NONE)
1090 ug_destroy_me(ugd->ug_main);
1092 elm_object_disabled_set(ugd->send_btn, EINA_FALSE);
1093 elm_object_disabled_set(ugd->cancel_btn, EINA_FALSE);
1095 ugd->bSendBtnDisabled = false;
1099 void _composer_make_default_thumbnail(Evas_Object *eo, char *pszImgPath, int nItemType)
1103 char thumb_path[MAX_ATTACHMENT_FILE_LEN + 1] = { 0, };
1105 if (eo == NULL || pszImgPath == NULL)
1108 debug_log("Image path = %s", pszImgPath);
1110 Evas_Object *icon = eo;
1112 if (nItemType == COMPOSER_ATTACHMENT_ITEM_IMAGE) {
1113 debug_log("Thumbnail type - image");
1115 int err = _composer_attachment_make_ethumb(pszImgPath, thumb_path);
1117 if (err != COMPOSER_ERROR_NONE)
1118 elm_icon_file_set(icon, ATTACHMENT_IMAGE_FILE_PATH, NULL);
1120 debug_log("Thumbnail path = %s", thumb_path);
1122 elm_icon_file_set(icon, thumb_path, NULL);
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);
1131 gchar **vector = NULL;
1132 gint tok_cnt = g_strv_length(vector);
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);
1143 elm_icon_file_set(icon, ATTACHMENT_ETC_FILE_PATH, NULL);
1146 elm_icon_file_set(icon, ATTACHMENT_ETC_FILE_PATH, NULL);
1152 Evas_Object *_composer_load_edj(Evas_Object *parent, const char *file, const char *group)
1158 eo = elm_layout_add(parent);
1160 r = elm_layout_file_set(eo, file, group);
1162 evas_object_del(eo);
1166 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1172 Evas_Object *_composer_create_navigation_layout(Evas_Object *parent)
1175 Evas_Object *navi_bar;
1177 navi_bar = elm_naviframe_add(parent);
1178 elm_object_part_content_set(parent, "elm.swallow.content", navi_bar);
1180 evas_object_show(navi_bar);
1185 Evas_Object *_composer_create_composer_layout(Evas_Object *parent)
1188 Evas_Object *layout;
1190 layout = elm_layout_add(parent);
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);
1200 Evas_Object *_composer_create_outer_layout(Evas_Object *parent)
1203 Evas_Object *layout/*, *bg*/;
1205 layout = elm_layout_add(parent);
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);
1216 Evas_Object *_composer_create_main_scroller(Evas_Object *parent)
1219 Evas_Object *scroller;
1221 scroller = elm_scroller_add(parent);
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);
1230 Evas_Object *_composer_create_box(Evas_Object *parent)
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);
1239 elm_object_focus_allow_set(box, EINA_FALSE);
1244 void _composer_set_mail_info(EmailComposerUGD *ugd)
1248 _composer_add_to_address(ugd);
1249 _composer_add_cc_address(ugd);
1250 _composer_add_bcc_address(ugd);
1252 _composer_add_subject(ugd);
1253 _composer_add_body(ugd);
1255 if (ugd->composer_type != RUN_COMPOSER_EDIT) {
1256 _composer_add_origin_msg(ugd);
1259 bool need_download = false;
1261 if (ugd->composer_type == RUN_COMPOSER_FORWARD && ugd->account_info->account->options.forward_with_files) {
1263 if (ugd->existing_mail_info->mail_data->attachment_count > 0) {
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;
1275 _composer_add_attachment(ugd);
1277 if (need_download) {
1278 _composer_show_download_attachment_popup(ugd);
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);
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);
1290 if (plain_charset) {
1291 Ewk_Setting *ewkSetting = ewk_view_setting_get(ugd->body_ewkview);
1293 if (ewkSetting == NULL)
1294 debug_log("ewkSetting is NULL.");
1296 ewk_setting_default_encoding_set(ewkSetting, plain_charset);
1297 g_free(plain_charset);
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);
1303 Ewk_Setting *ewkSetting = ewk_view_setting_get(ugd->body_ewkview);
1305 if (ewkSetting == NULL)
1306 debug_log("ewkSetting is NULL.");
1308 ewk_setting_default_encoding_set(ewkSetting, charset);
1315 if (EINA_TRUE == ugd->has_body_html) {
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);
1322 ewk_view_uri_set(ugd->body_ewkview, file_path);
1326 void _composer_show_download_attachment_popup(EmailComposerUGD *ugd)
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"));
1334 snprintf(msg, sizeof(msg), _("IDS_EMAIL_POP_DOWNLOAD_ATTACHMENT_Q"));
1336 if (ugd->dn_noti_popup) {
1337 evas_object_del(ugd->dn_noti_popup);
1338 ugd->dn_noti_popup = NULL;
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);
1344 static void _composer_attachment_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
1349 debug_log("data is NULL");
1353 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1355 char *pszBtnText = (char *)elm_object_text_get(obj);
1356 debug_log("selected button text = %s", pszBtnText);
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);
1363 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->dn_noti_popup/*obj*/);
1366 evas_object_del(ugd->dn_noti_popup);
1367 ugd->dn_noti_popup = NULL;
1369 if (pszBtnText && strcmp(pszBtnText, dgettext("sys_string", "IDS_COM_SK_OK")) == 0) {
1370 _composer_download_attachment(ugd);
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);
1379 Eina_Bool _composer_show_progress_popup(void *data)
1381 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1383 Evas_Object *progressbar;
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;
1393 ugd->fw_dn_total_cnt = ugd->fw_dn_cnt;
1395 char buf[128] = { 0, };
1397 snprintf(buf, sizeof(buf), "%s [0/%d]", _("IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"), ugd->fw_dn_cnt);
1399 debug_log("popup count = %d", eina_list_count(ugd->popup_list));
1400 debug_log("dn_noti_popup: %p", ugd->dn_noti_popup);
1402 evas_object_del(ugd->dn_noti_popup);
1403 ugd->dn_noti_popup = NULL;
1405 if (ugd->dn_prog_popup) {
1406 evas_object_del(ugd->dn_prog_popup);
1407 ugd->dn_prog_popup = NULL;
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);
1412 ugd->dn_prog_popup = popup;
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;
1420 Evas_Object *box = elm_box_add(popup);
1422 progressbar = elm_progressbar_add(popup);
1424 elm_object_style_set(progressbar, "list_progress");
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);
1433 elm_box_pack_end(box, label);
1434 elm_box_pack_end(box, progressbar);
1436 elm_object_content_set(popup, box);
1441 static void _composer_dn_prog_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
1445 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1447 char *pszBtnText = (char *)elm_object_text_get(obj);
1448 debug_log("selected button text = %s", pszBtnText);
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);
1456 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->dn_prog_popup/*obj*/);
1459 if (ugd->dn_prog_popup) {
1460 evas_object_del(ugd->dn_prog_popup);
1461 ugd->dn_prog_popup = NULL;
1464 _composer_cancel_download_attachment(ugd);
1466 ugd->selected_entry = ugd->to_mbe_entry;
1467 ugd->idler_set_focus = ecore_idler_add(_composer_mbe_set_focus, ugd);
1472 void _composer_download_attachment(EmailComposerUGD *ugd)
1476 int att_cnt = g_list_length(ugd->fw_attachment_list);
1478 debug_log("att_cnt = %d", att_cnt);
1480 ugd->fw_dn_cnt = att_cnt;
1483 service_h service = NULL;
1485 ret = service_create(&service);
1486 debug_log("service_create: %d", ret);
1488 debug_log("service create failed");
1492 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_SAVE_ALL, "SAVE_ALL");
1493 debug_log("service_add_extra_data: %d", ret);
1495 ug_send_result(ugd->ug_main, service);
1497 ret = service_destroy(service);
1498 debug_log("service_destroy: %d", ret);
1500 ugd->idler_show_progress = ecore_idler_add(_composer_show_progress_popup, ugd);
1503 void _composer_update_attachment_info(EmailComposerUGD *ugd, int index)
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);
1513 if (info->index == index) {
1514 info->downloaded = true;
1515 info->path = email_engine_get_attachment_path(info->attach_id);
1522 void _composer_attachment_cancel_download(EmailComposerUGD *ugd)
1526 int att_cnt = g_list_length(ugd->fw_attachment_list);
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]);
1537 void _composer_cancel_download_attachment(EmailComposerUGD *ugd)
1542 service_h service = NULL;
1544 ret = service_create(&service);
1545 debug_log("service_create: %d", ret);
1547 debug_log("service create failed");
1551 ret = service_add_extra_data(service, EMAIL_BUNDLE_KEY_CANCEL_ALL, "CANCEL_ALL");
1552 debug_log("service_add_extra_data: %d", ret);
1554 ug_send_result(ugd->ug_main, service);
1556 ret = service_destroy(service);
1557 debug_log("service_destroy: %d", ret);
1560 const char *_composer_get_sent_time(EmailComposerMail *mail_info)
1565 time = mail_info->mail_data->date_time;
1567 char *formatted_date = NULL;
1569 if (icu_timeformat == APPCORE_TIME_FORMAT_12)
1570 formatted_date = email_get_date_text(icu_locale, "yMMMEEEdhms", &time);
1572 formatted_date = email_get_date_text(icu_locale, "yMMMEEEdHms", &time);
1574 debug_log("date&time: %d [%s]", time, formatted_date);
1576 return formatted_date;
1579 char *_composer_get_wday(int tm_wday)
1584 wday = (char *)g_malloc0(10 * sizeof(char));
1588 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_SUN"));
1591 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_MON"));
1594 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_TUE"));
1597 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_WED"));
1600 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_THU"));
1603 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_FRI"));
1606 snprintf(wday, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_SAT"));
1615 char *_composer_get_month(int tm_mon)
1620 mon = (char *)g_malloc0(10 * sizeof(char));
1624 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_JAN"));
1627 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_FEB"));
1630 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_MAR"));
1633 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_APR"));
1636 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_MAY"));
1639 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_JUN"));
1642 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_JUL"));
1645 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_AUG"));
1648 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_SEP"));
1651 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_OCT"));
1654 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_NOV"));
1657 snprintf(mon, 10, "%s", dgettext("sys_string", "IDS_COM_BODY_DEC"));
1666 bool _composer_is_valid_email(const char *addr)
1668 char *token1 = NULL;
1669 char *token2 = NULL;
1671 debug_log("addr = %s", addr);
1673 if (addr[0] == '\0') {
1677 token1 = strchr(addr, '@');
1679 debug_log("there is no @");
1683 if (strchr(&token1[1], '@')) {
1684 debug_log("there is too many @");
1688 token2 = strchr(token1, '.');
1690 debug_log("there is no .");
1694 if ((token2 == token1 + 1) || (*(token2 + 1) == '\0')) {
1695 debug_log("Should be xxx.xxx");
1702 bool _composer_check_recipient_is_duplicated(EmailComposerUGD *ugd, Evas_Object *obj, EmailRecpInfo * ri)
1706 bool isDuplicated = false;
1708 Elm_Object_Item *mbe_item;
1709 EmailRecpInfo *iter_ri = NULL;
1711 mbe_item = elm_multibuttonentry_first_item_get(obj);
1714 iter_ri = elm_object_item_data_get(mbe_item);
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;
1723 mbe_item = elm_multibuttonentry_item_next_get(mbe_item);
1726 return isDuplicated;
1729 Eina_Bool _composer_idler_destroy(void *data)
1732 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
1734 elm_object_tree_focus_allow_set(ugd->c_layout, EINA_FALSE); // block the focus not to open IME.
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;
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);
1746 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
1749 evas_object_del(ugd->composer_noti);
1750 ugd->composer_noti = NULL;
1752 ug_destroy_me(ugd->ug_main);
1757 Eina_Bool _composer_idler_return(void *data)
1760 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
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;
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);
1772 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti);
1775 evas_object_del(ugd->composer_noti);
1776 ugd->composer_noti = NULL;
1781 void _composer_entry_filter_remove_markup(void *data, Evas_Object *entry, char **text)
1784 if (text == NULL || *text == NULL) {
1785 debug_log("New Text is NULL");
1789 char *preedit_str = NULL;
1790 char *utf8_text = NULL;
1791 char *convert_text = NULL;
1793 /* Check preeditting text and return if it exist */
1794 preedit_str = strstr(*text, "<preedit_sel>");
1798 /* Convert from markup text to utf8 text from entry */
1799 utf8_text = elm_entry_markup_to_utf8(*text);
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);
1806 *text = strdup(convert_text);
1813 void _composer_add_to_address(EmailComposerUGD *ugd)
1817 Elm_Object_Item *item;
1818 Eina_Bool overflow_flag = TRUE;
1819 Eina_Bool invalid_address_flag = FALSE;
1821 char *from_addr = NULL;
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)) {
1827 char *from_temp = g_strdup(ugd->existing_mail_info->mail_data->full_address_from);
1829 EmailRecpInfo *ri = _composer_separate_save_recipient_char(ugd, from_temp);
1832 debug_log("display_name = %s, email_address = %s", ri->display_name, ri->email_list[0].email_addr);
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);
1837 if (ugd->composer_noti) {
1838 evas_object_del(ugd->composer_noti);
1839 ugd->composer_noti = NULL;
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);
1848 if (ri && !ri_used) {
1849 if (ri->display_name) {
1850 free(ri->display_name);
1851 ri->display_name = NULL;
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)) {
1865 char *temp_name[MAX_RECIPIENT_ADDRESS_LEN];
1867 email_address_info_t *addrs_info = NULL;
1869 int duplicate_cnt = 0;
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);
1879 token = strtok(temp, ";");
1880 debug_log("to = %s\ntoken = %s", temp, token);
1884 while (token != NULL && (overflow_flag = (i < (MAX_RECIPIENT_COUNT)))) {
1885 temp_name[i] = g_strdup(token);
1887 token = strtok(NULL, ";");
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);
1894 if (ugd->composer_noti) {
1895 evas_object_del(ugd->composer_noti);
1896 ugd->composer_noti = NULL;
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);
1904 if (max >= MAX_RECIPIENT_COUNT)
1905 max = MAX_RECIPIENT_COUNT - 1;
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]);
1914 debug_critical("_composer_separate_save_recipient_char returned NULL");
1919 debug_log("display_name = %s, email_address = %s", ri->display_name, ri->email_list[0].email_addr);
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);
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)) {
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");
1933 addrs_info = (email_address_info_t *) g_list_nth_data(ugd->to_list, i);
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);
1938 item = elm_multibuttonentry_item_append(ugd->to_mbe, ri->display_name, NULL, ri);
1940 item = elm_multibuttonentry_item_append(ugd->to_mbe, ri->display_name, NULL, ri);
1947 if (ri && !ri_used) {
1948 if (ri->display_name) {
1949 free(ri->display_name);
1950 ri->display_name = NULL;
1958 if (duplicate_cnt) {
1959 if (ugd->composer_noti) {
1960 evas_object_del(ugd->composer_noti);
1961 ugd->composer_noti = NULL;
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);
1967 if (invalid_address_flag) {
1968 if (ugd->composer_noti) {
1969 evas_object_del(ugd->composer_noti);
1970 ugd->composer_noti = NULL;
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);
1981 elm_multibuttonentry_expanded_set(ugd->to_mbe, FALSE);
1984 void _composer_add_cc_address(EmailComposerUGD *ugd)
1988 Elm_Object_Item *item;
1990 Eina_Bool overflow_flag = TRUE;
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) {
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)) {
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;
2009 char *temp_name[MAX_RECIPIENT_ADDRESS_LEN];
2011 email_address_info_t *addrs_info = NULL;
2013 int duplicate_cnt = 0;
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);
2023 token = strtok(temp, ";");
2024 debug_log("cc = %s\ntoken = %s", temp, token);
2028 while (token != NULL && (overflow_flag = (i < (MAX_RECIPIENT_COUNT)))) {
2029 temp_name[i] = g_strdup(token);
2031 token = strtok(NULL, ";");
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);
2038 if (ugd->composer_noti) {
2039 evas_object_del(ugd->composer_noti);
2040 ugd->composer_noti = NULL;
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);
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]);
2055 debug_critical("_composer_separate_save_recipient_char returned NULL");
2058 debug_log("display_name = %s, email_address = %s", ri->display_name, ri->email_list[0].email_addr);
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;
2066 if (!_composer_check_recipient_is_duplicated(ugd, ugd->cc_mbe, ri)) {
2068 addrs_info = (email_address_info_t *) g_list_nth_data(ugd->cc_list, i);
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);
2073 item = elm_multibuttonentry_item_append(ugd->cc_mbe, ri->display_name, NULL, (void *)ri);
2075 item = elm_multibuttonentry_item_append(ugd->cc_mbe, ri->display_name, NULL, (void *)ri);
2079 if (ri->display_name) {
2080 free(ri->display_name);
2081 ri->display_name = NULL;
2090 if (duplicate_cnt) {
2091 if (ugd->composer_noti) {
2092 evas_object_del(ugd->composer_noti);
2093 ugd->composer_noti = NULL;
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);
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) {
2106 if (ugd->cc_mbe == NULL) {
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;
2118 elm_multibuttonentry_expanded_set(ugd->cc_mbe, FALSE);
2121 void _composer_add_bcc_address(EmailComposerUGD *ugd)
2125 Elm_Object_Item *item;
2127 Eina_Bool overflow_flag = TRUE;
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) {
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)) {
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;
2146 char *temp_name[MAX_RECIPIENT_ADDRESS_LEN];
2148 email_address_info_t *addrs_info = NULL;
2150 int duplicate_cnt = 0;
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);
2160 token = strtok(temp, ";");
2161 debug_log("bcc = %s\ntoken = %s", temp, token);
2165 while (token != NULL && (overflow_flag = (i < (MAX_RECIPIENT_COUNT)))) {
2166 temp_name[i] = g_strdup(token);
2168 token = strtok(NULL, ";");
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);
2175 if (ugd->composer_noti) {
2176 evas_object_del(ugd->composer_noti);
2177 ugd->composer_noti = NULL;
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);
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]);
2192 debug_critical("_composer_separate_save_recipient_char returned NULL");
2195 debug_log("display_name = %s, email_address = %s", ri->display_name, ri->email_list[0].email_addr);
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;
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);
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);
2210 item = elm_multibuttonentry_item_append(ugd->bcc_mbe, ri->display_name, NULL, (void *)ri);
2212 item = elm_multibuttonentry_item_append(ugd->bcc_mbe, ri->display_name, NULL, (void *)ri);
2216 if (ri->display_name) {
2217 free(ri->display_name);
2218 ri->display_name = NULL;
2227 if (duplicate_cnt) {
2228 if (ugd->composer_noti) {
2229 evas_object_del(ugd->composer_noti);
2230 ugd->composer_noti = NULL;
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);
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) {
2243 if (ugd->bcc_mbe == NULL) {
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;
2255 elm_multibuttonentry_expanded_set(ugd->bcc_mbe, FALSE);
2258 void _composer_add_from_address(EmailComposerUGD *ugd)
2262 EmailRecpInfo *ri = (EmailRecpInfo *) calloc(1, sizeof(EmailRecpInfo));
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);
2268 ri->is_contact_info = false;
2269 ri->is_always_bcc = false;
2270 ri->is_from_addr = true;
2272 debug_log("display_name : %s", ri->display_name);
2273 debug_log("email_addr : %s", ri->email_list[0].email_addr);
2275 elm_multibuttonentry_item_append(ugd->from_mbe, ri->display_name, NULL, ri);
2278 void _composer_add_subject(EmailComposerUGD *ugd)
2283 if (ugd->existing_mail_info->mail_data) {
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);
2289 temp = elm_entry_utf8_to_markup("");
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];
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);
2300 snprintf(subject_temp, MAX_SUBJECT_LEN, "%s: ", _("IDS_EMAIL_BODY_FWD_T_EMAIL_PREFIX_ABB"));
2302 if (ugd->existing_mail_info->mail_data->subject) {
2303 p = strchr(ugd->existing_mail_info->mail_data->subject, ':');
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);
2308 snprintf(subject_temp, MAX_SUBJECT_LEN, "%s: %s", _("IDS_EMAIL_BODY_RE"), ugd->existing_mail_info->mail_data->subject);
2310 snprintf(subject_temp, MAX_SUBJECT_LEN, "%s: ", _("IDS_EMAIL_BODY_RE"));
2314 temp = elm_entry_utf8_to_markup(subject_temp);
2315 elm_entry_entry_set(ugd->subject_entry, temp);
2317 } else if (ugd->new_mail_info->mail_data) {
2319 if (ugd->composer_type == RUN_COMPOSER_EXTERNAL) {
2321 if (ugd->new_mail_info->mail_data->subject)
2322 temp = elm_entry_utf8_to_markup(ugd->new_mail_info->mail_data->subject);
2324 temp = elm_entry_utf8_to_markup("");
2326 elm_entry_entry_set(ugd->subject_entry, temp);
2330 if (elm_entry_is_empty(ugd->subject_entry))
2331 elm_object_signal_emit(ugd->subject_editfield, "elm,state,guidetext,show", "elm");
2333 elm_object_signal_emit(ugd->subject_editfield, "elm,state,guidetext,hide", "elm");
2335 debug_log("Freed subject :%s", temp);
2342 void _composer_add_body(EmailComposerUGD *ugd)
2345 char *full_text = NULL;
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");
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);
2363 char szMetaViewportInfo[TEMP_BUFFER_SIZE + 1] = { 0x00, };
2364 strncpy(szMetaViewportInfo, HTML_META_INFORMATION, TEMP_BUFFER_SIZE);
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);
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);
2379 debug_log("full text:\n%s", full_text);
2384 debug_log("full_text :%s", full_text);
2391 void _composer_make_html_body(EmailComposerUGD *ugd)
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;
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, };
2406 char szMetaViewportInfo[TEMP_BUFFER_SIZE + 1] = { 0x00, };
2408 const char *sent_time = NULL;
2410 char *temp_name[MAX_RECIPIENT_ADDRESS_LEN];
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);
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);
2426 token = strtok(NULL, ";");
2427 debug_log(">> temp_name[%d] = %s, token = %s", i, temp_name[i], token);
2429 if (i == MAX_RECIPIENT_COUNT)
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]);
2446 debug_log("display_name = %s, email_address = %s", ri->display_name, ri->email_list[0].email_addr);
2448 s_len = strlen(ri->display_name) + (!t ? 1 : strlen(t) + 3);
2449 debug_log("len = %d", s_len);
2452 s = realloc(t, s_len);
2454 s = (char *)malloc(s_len);
2457 debug_error("memory allocation failed");
2458 if (ri->display_name) {
2459 free(ri->display_name);
2460 ri->display_name = NULL;
2468 memset(s, 0x00, s_len);
2470 memset(s + strlen(s), 0x00, s_len - strlen(s));
2472 sprintf(s + strlen(s), "%s%s", (t ? "; " : ""), ri->display_name);
2476 recipients_list = t;
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);
2482 if (ri->display_name) {
2483 free(ri->display_name);
2484 ri->display_name = NULL;
2495 if (ugd->existing_mail_info->mail_data->full_address_from) {
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);
2502 sent_time = _composer_get_sent_time(ugd->existing_mail_info);
2504 snprintf(text_for_sent, sizeof(text_for_sent), "<b>%s</b> %s<br>\n", _("IDS_EMAIL_BODY_SENT_C"), sent_time);
2507 if (recipients_list) {
2508 snprintf(text_for_to, sizeof(text_for_to), ADDED_TEXT, dgettext("sys_string", "IDS_COM_BODY_TO"), recipients_list);
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);
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);
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);
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)) {
2528 encoded_text = eina_str_convert("UTF-8", "EUC-KR", text_for_original_info);
2530 if (NULL != encoded_text) {
2531 free(text_for_original_info);
2532 text_for_original_info = encoded_text;
2533 encoded_text = NULL;
2536 g_free(html_charset);
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);
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);
2549 html_text_for_body = g_strdup("\n");
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);
2558 debug_log("Empty html body");
2559 text_for_original_info = g_strdup("\n");
2560 html_text_for_body = g_strdup("\n");
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");
2568 strncpy(szMetaViewportInfo, HTML_META_INFORMATION, TEMP_BUFFER_SIZE);
2570 if (ugd->composer_type != RUN_COMPOSER_EDIT && (ugd->account_info->account->options).add_signature) {
2571 char signature_text[128] = { 0, };
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);
2577 full_text = g_strconcat(szMetaViewportInfo, text_for_original_info, html_text_for_body, signature_text, NULL);
2579 full_text = g_strconcat(szMetaViewportInfo, text_for_original_info, html_text_for_body, NULL);
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));
2586 debug_log("full text:\n%s", full_text);
2588 free(recipients_list);
2589 free((char *)sent_time);
2590 free(text_for_original_info);
2592 free(html_text_for_body);
2596 void _composer_add_origin_msg(EmailComposerUGD *ugd)
2600 _composer_make_html_body(ugd);
2603 /* Creates symbolic links to all the inline images */
2604 void _composer_add_softlink_to_inline_images(EmailComposerUGD *ugd)
2609 char *inline_image_name = NULL;
2610 char *softlink_path = NULL;
2611 char *temp_save_name = NULL;
2613 if (ugd->existing_mail_info->mail_data == NULL)
2616 if (ugd->existing_mail_info->mail_data->body_download_status && ugd->existing_mail_info->mail_data->attachment_count > 0) {
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. */
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);
2631 debug_log("softlink_path :%s", softlink_path);
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);
2639 // attachment_temp_list = attachment_temp_list->next;
2644 void _composer_add_attachment(EmailComposerUGD *ugd)
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) {
2651 email_attachment_data_t *fwd_attachment_data_list = ugd->existing_mail_info->attachment_list;
2654 int nTotalAttachmentSize = 0;
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;
2664 _composer_attachment_expand_items(ugd);
2667 for (i = 0; i < ugd->existing_mail_info->mail_data->attachment_count; i++) {
2669 if (i >= MAX_ATTACHMENT_ITEM)
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. */
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;
2679 if (nTotalAttachmentSize / 1024 > MAX_ATTACHMENT_SIZE) {
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);
2684 if (ugd->composer_noti) {
2685 evas_object_del(ugd->composer_noti);
2686 ugd->composer_noti = NULL;
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);
2693 email_attachment_data_t *attachment_data = (email_attachment_data_t *)calloc(1, sizeof(email_attachment_data_t));
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;
2700 _composer_attachment_create_list_box(ugd, attachment_data);
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));
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);
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);
2726 ugd->fw_attachment_list = g_list_append(ugd->fw_attachment_list, attachment_info);
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);
2739 Evas_Object *_composer_popup_create(Evas_Object *parent, EmailComposerUGD *ugd)
2743 Evas_Object *popup, *window;
2745 window = _composer_create_sub_window(parent);
2746 ugd->popup_win = window;
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);
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);
2761 evas_object_show(popup);
2762 evas_object_show(window);
2767 void _composer_popup_delete(Evas_Object *popup)
2773 Evas_Object *window = evas_object_data_del(popup, "window");
2776 debug_log("Window Delete");
2777 evas_object_del(window);
2779 debug_log("PopUp Delete");
2780 evas_object_del(popup);
2785 * This API gets the latest recipients list from mbe and checks for change from the initial list
2787 * @param [in] mbe multibuttonentry(to,cc or bcc)
2788 * @param [in] initial_recipients_list contains the list of recipients when composer launched
2790 * @return true if recipients modified or false
2792 bool _composer_check_recipients_modified(Evas_Object *mbe, Eina_List **initial_recipients_list)
2796 if (!mbe || !initial_recipients_list)
2799 const Eina_List *current_list = NULL;
2800 Eina_List *mbe_initial_list = *initial_recipients_list;
2801 bool is_modified = false;
2803 current_list = elm_multibuttonentry_items_get(mbe);
2805 if ((!mbe_initial_list && current_list) || (mbe_initial_list && !current_list)) {
2807 } else if (mbe_initial_list && current_list) {
2808 if (current_list->accounting->count != mbe_initial_list->accounting->count) {
2811 Eina_List *l1 = mbe_initial_list;
2812 const Eina_List *l2 = current_list;
2815 for (index = 0; index < current_list->accounting->count; index++) {
2816 if (eina_list_data_get(l1) != eina_list_data_get(l2)) {
2820 l1 = eina_list_next(l1);
2821 l2 = eina_list_next(l2);
2830 * This API checks whether email content has been modified from the original content
2832 * @param [in] data EmailComposerUGD data
2834 * @return true if mail is modified or false
2836 bool _composer_check_mail_is_modified(void *data)
2842 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2844 bool is_modified = false;
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)) {
2856 bool is_attach_modified = false;
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);
2864 if (nInitialListCount != nAttachmentCount) {
2865 is_attach_modified = true;
2868 int nInitialListCount = eina_list_count(ugd->attach_initial_list);
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;
2879 if (is_attach_modified) {
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;
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) {
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*/
2905 _composer_free_initial_email_content(ugd);
2911 bool _composer_check_recipient_is_empty(void *data)
2917 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
2919 if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->to_mbe)) != NULL) {
2922 if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->cc_mbe)) != NULL) {
2925 if (elm_object_item_text_get(elm_multibuttonentry_first_item_get(ugd->bcc_mbe)) != NULL) {
2932 Evas_Object *_composer_create_sub_window(Evas_Object *parent)
2938 unsigned char *prop_data = NULL;
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;
2951 eo = elm_win_add(parent, "composer_sub_win", ELM_WIN_DIALOG_BASIC);
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);
2957 ecore_x_window_geometry_get(ecore_x_window_root_get(ecore_x_window_focus_get()), &x, &y, &w, &h);
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);
2961 if (ret && prop_data)
2962 memcpy(&rotation, prop_data, sizeof(int));
2965 evas_object_resize(eo, w, h);
2966 evas_object_move(eo, x, y);
2969 elm_win_rotation_with_resize_set(eo, rotation);
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);
2974 evas_object_show(eo);
2976 debug_log("Fail to make SubWindow");
2981 void _composer_unfocus_and_save(void *data)
2985 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
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);
3005 void _composer_change_text_to_textblock(char *input, char **output, char *matched_word, char *prefix, char *postfix)
3009 char *found = (char *)strcasestr(input, matched_word);
3015 int idx = found - input;
3016 int buf_len = strlen(input) + strlen(prefix) + strlen(postfix) + 1;
3018 temp = (char *)malloc(buf_len * sizeof(char));
3024 memset(temp, 0x00, buf_len);
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';
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))
3043 Evas_Object *notify;
3046 notify = _composer_popup_create(ugd->main_layout, ugd);
3048 notify = elm_popup_add(ugd->main_layout);
3050 debug_log("notify: %p", notify);
3052 debug_log("elm_popup_add returns NULL");
3055 evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3058 elm_object_part_text_set(notify, "title,text", title);
3062 elm_object_text_set(notify, content);
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);
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);
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);
3097 evas_object_show(notify);
3099 ugd->popup_list = eina_list_append(ugd->popup_list, notify);
3101 debug_log("notify = %x, %p", notify, notify);
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))
3110 Evas_Object *notify;
3113 notify = _composer_popup_create(ugd->main_layout, ugd);
3115 notify = elm_popup_add(ugd->main_layout);
3117 debug_log("notify: %p", notify);
3119 debug_log("elm_popup_add returns NULL");
3122 evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3125 elm_object_part_text_set(notify, "title,text", title);
3129 elm_object_text_set(notify, content);
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);
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);
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);
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);
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);
3188 evas_object_show(notify);
3190 ugd->popup_list = eina_list_append(ugd->popup_list, notify);
3195 void _composer_noti_response_cb(void *data, Evas_Object *obj, void *event_info)
3199 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3201 elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE); // block the focus not to open IME.
3203 Evas_Object *mbe = NULL;
3205 if (ugd->selected_entry == ugd->to_mbe_entry) {
3207 } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
3209 } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
3213 // elm_multibuttonentry_item_unselect_all(mbe);
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);
3220 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_noti/*obj*/);
3222 debug_log("@@@ b_sending = %d", ugd->b_sending);
3224 if (!_composer_check_popup_exist(ugd))
3225 ugd->idler_set_focus = ecore_idler_add(_composer_mbe_set_focus, ugd);
3229 ugd->b_sending = false;
3231 evas_object_del(ugd->composer_noti);
3232 ugd->composer_noti = NULL;
3235 void _composer_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
3239 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3241 Evas_Object *mbe = NULL;
3243 if (ugd->selected_entry == ugd->to_mbe_entry) {
3245 } else if (ugd->selected_entry == ugd->cc_mbe_entry) {
3247 } else if (ugd->selected_entry == ugd->bcc_mbe_entry) {
3251 // elm_multibuttonentry_item_unselect_all(mbe);
3252 elm_object_tree_focus_allow_set(ugd->c_layout, EINA_TRUE);
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);
3259 ugd->popup_list = eina_list_remove(ugd->popup_list, ugd->composer_popup/*obj*/);
3261 debug_log("@@@ b_sending = %d", ugd->b_sending);
3263 if (!_composer_check_popup_exist(ugd))
3264 ugd->idler_set_focus = ecore_idler_add(_composer_mbe_set_focus, ugd);
3268 ugd->b_sending = false;
3270 evas_object_del(ugd->composer_popup);
3271 ugd->composer_popup = NULL;
3272 ugd->is_mbe_selected = false;
3275 Eina_Bool _composer_check_popup_exist(EmailComposerUGD *ugd)
3279 if (!ugd) return EINA_FALSE;
3281 debug_log("popup list count = %d", eina_list_count(ugd->popup_list));
3282 if (eina_list_count(ugd->popup_list) > 0)
3288 int _composer_get_account_list(EmailComposerUGD *ugd)
3292 int err = email_get_account_list(&ugd->account_info->account_list, &ugd->account_info->account_count);
3294 if (err != EMAIL_ERROR_NONE) {
3295 debug_log("[email-composer] email_account_get_list error");
3296 return COMPOSER_ERROR_NO_ACCOUNT_LIST;
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);
3304 debug_log("[email-composer] account count = %d", ugd->account_info->account_count);
3306 return COMPOSER_ERROR_NONE;
3309 char *_composer_get_email_addr_from_account_id(EmailComposerUGD *ugd, int account_id)
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);
3322 char *_composer_get_service_fail_type(int type)
3327 char str[MAX_STR_LEN] = { 0, };
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);
3372 snprintf(str, sizeof(str), "%s (%d)", dgettext("sys_string", "IDS_COM_POP_INTERNAL_ERROR"), type);
3373 return g_strdup(str);
3377 Eina_Bool _composer_mbe_set_focus(void *data)
3381 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
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);
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);
3405 debug_log("NO ENTRY!!! TO MBE ENTRY will get the focus.");
3406 elm_object_focus_set(ugd->to_mbe_entry, EINA_TRUE);
3410 ugd->b_cc_bcc = false;
3412 if (ugd->clipboard_on)
3413 ugd->clipboard_on = false;
3415 if (ugd->idler_set_focus) {
3416 ecore_idler_del(ugd->idler_set_focus);
3417 ugd->idler_set_focus = NULL;
3423 void _composer_resize_body_webview(EmailComposerUGD *ugd, int ime_height)
3425 int nWidth, nHeight;
3426 // Evas_Coord x = 0, y = 0, w = 0, h = 0;
3428 _composer_display_position(ugd);
3430 ecore_x_window_size_get(ecore_x_window_root_first_get(), &nWidth, &nHeight);
3432 Evas_Coord x, y, w, h;
3434 debug_log(" === ime_height %d", ime_height);
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);
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);
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);
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);
3449 evas_object_size_hint_min_set(ugd->webkit_ly, 0, nWidth - COMPOSER_NAVI_HEIGHT - ime_height);
3453 void _composer_input_panel_state_changed_cb(void *data, Ecore_IMF_Context *ctx, int value)
3457 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3459 debug_log("ugd->selected_entry : %d", ugd->selected_entry);
3461 if (ugd->selected_entry != ugd->body_ewkview) {
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);
3467 debug_log("IME status changed to %d", value);
3470 case ECORE_IMF_INPUT_PANEL_STATE_HIDE: /* :1 */
3471 _composer_resize_body_webview(ugd, 0);
3474 case ECORE_IMF_INPUT_PANEL_STATE_SHOW: /* :0 */
3475 ugd->ime_height = h;
3476 _composer_resize_body_webview(ugd, h);
3479 default: /* ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW :2 */
3486 void _composer_display_position(void *data)
3488 EmailComposerUGD *ugd = (EmailComposerUGD *)data;
3489 Evas_Coord x = 0, y = 0, w = 0, h = 0;
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);
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);
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);
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);
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);
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);
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);
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);
3530 static Eina_Bool _composer_print_hit_test_result_hash_fn(const Eina_Hash *hash, const void *key, void *data, void *fdata)
3532 // fdata is the third parameter
3533 debug_log("Func data: %s, Hash entry: %s / %s\n", fdata, (const char *)key, data);
3537 void _composer_print_hit_test_result(Ewk_Hit_Test *hit_test)
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));
3551 attr_hash = ewk_hit_test_attribute_hash_get(hit_test);
3553 eina_hash_foreach(attr_hash, _composer_print_hit_test_result_hash_fn, NULL);
3556 void _composer_coords_ewk_to_evas(Evas_Object *view, int ewkX, int ewkY, int *evasX, int *evasY)
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);
3562 *evasX = ewkX - scrollX + viewX;
3563 *evasY = ewkY - scrollY + viewY;
3566 void _composer_coords_evas_to_ewk(Evas_Object *view, int evasX, int evasY, int *ewkX, int *ewkY)
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);
3574 *ewkX = evasX + scrollX - viewX;
3575 *ewkY = evasY + scrollY - viewY;
3578 void _composer_set_option_tray_menu(int num, EmailComposerUGD *ugd)
3582 Evas_Object *btn = NULL;
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);
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"));
3606 elm_object_text_set(btn, _("IDS_EMAIL_OPT_ADD_CC_BCC"));
3609 evas_object_smart_callback_add(ugd->cc_btn, "clicked", _composer_cbar_cc_clicked, ugd);
3611 case EMAIL_COMPOSER_SAVE_AS_DRAFT_BTN : // Save as draft btn
3613 Evas_Object *cbar = NULL;
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);
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);
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);
3648 case EMAIL_COMPOSER_DUMMY_BTN : // Dummy btn
3649 ugd->dummy_btn = NULL;
3651 default : // never get here!
3652 debug_log("default");
3655 evas_object_show(btn);
3658 void _composer_unset_option_tray_menu(int num, EmailComposerUGD *ugd)
3662 elm_object_item_del(ugd->controlbar_item[num]);
3663 ugd->controlbar_item[num] = NULL;
3666 case EMAIL_COMPOSER_ADD_ME_BTN : // Add me btn
3667 evas_object_del(ugd->add_me_btn);
3668 ugd->add_me_btn = NULL;
3670 case EMAIL_COMPOSER_ADD_CC_BCC_BTN : // Add Cc/Bcc btn
3671 evas_object_del(ugd->cc_btn);
3674 case EMAIL_COMPOSER_SAVE_AS_DRAFT_BTN : // Save as draft btn
3676 evas_object_del(ugd->save_as_draft_btn);
3677 ugd->save_as_draft_btn = NULL;
3680 case EMAIL_COMPOSER_PRIORITY_BTN : // Priority btn
3681 evas_object_del(ugd->priority_btn);
3682 ugd->priority_btn = NULL;
3684 case EMAIL_COMPOSER_TRACKING_BTN : // Tracking btn
3685 evas_object_del(ugd->tracking_btn);
3686 ugd->tracking_btn = NULL;
3688 case EMAIL_COMPOSER_DUMMY_BTN : // Dummy btn
3689 evas_object_del(ugd->dummy_btn);
3690 ugd->dummy_btn = NULL;
3692 default : // never get here!
3693 debug_log("default");