4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 /******************************************************************************
24 * File: email-core-utils.c
30 * 2006.08.16 : created
31 *****************************************************************************/
40 #include <glib-object.h>
48 #include <notification.h>
51 #include "email-types.h"
52 #include "email-core-global.h"
53 #include "email-core-utils.h"
54 #include "email-debug-log.h"
55 #include "email-core-mail.h"
56 #include "email-core-event.h"
57 #include "email-core-mailbox.h"
58 #include "email-core-account.h"
59 #include "email-core-mailbox-sync.h"
60 #include "email-core-mime.h"
61 #include "email-core-sound.h"
62 #include "email-core-signal.h"
63 #include "email-utilities.h"
64 #include "email-convert.h"
65 #include "email-internal-types.h"
67 #ifdef __FEATURE_DRIVING_MODE__
68 #include <app_service.h>
69 #endif /* __FEATURE_DRIVING_MODE__ */
71 #define LED_TIMEOUT_SECS 12
72 #define G_DISPLAY_LENGTH 256
74 #define DIR_SEPERATOR_CH '/'
75 #define EMAIL_CH_QUOT '"'
76 #define EMAIL_CH_BRACKET_S '<'
77 #define EMAIL_CH_BRACKET_E '>'
78 #define EMAIL_CH_COMMA ','
79 #define EMAIL_CH_SEMICOLON ';'
80 #define EMAIL_CH_ROUND_BRACKET_S '('
81 #define EMAIL_CH_ROUND_BRACKET_E ')'
82 #define EMAIL_CH_SQUARE_BRACKET_S '['
83 #define EMAIL_CH_SQUARE_BRACKET_E ']'
84 #define EMAIL_CH_SPACE ' '
85 #define EMAIL_NOTI_ICON_PATH EMAILPATH"/res/image/Q02_Notification_email.png"
87 typedef struct _em_transaction_info_type_t {
90 struct _em_transaction_info_type_t *next;
92 } em_transaction_info_type_t;
94 em_transaction_info_type_t *g_transaction_info_list;
96 static email_session_t g_session_list[SESSION_MAX] = { {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},};
98 typedef struct emcore_account_list_t emcore_account_list_t;
99 struct emcore_account_list_t {
100 email_account_t *account;
101 emcore_account_list_t *next;
104 INTERNAL_FUNC char *emcore_convert_mutf7_to_utf8(char *mailbox_name)
106 EM_DEBUG_FUNC_BEGIN();
107 return (char *)(utf8_from_mutf7((unsigned char *)mailbox_name));
110 /* in smtp case, path argument must be ENCODED_PATH_SMTP */
111 int emcore_get_long_encoded_path_with_account_info(email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code)
113 EM_PROFILE_BEGIN(emCorelongEncodedpath);
114 EM_DEBUG_FUNC_BEGIN("account[%p], path[%s], delimiter[%d], long_enc_path[%p], err_code[%p]", account, path, delimiter, long_enc_path, err_code);
117 int error = EMAIL_ERROR_NONE;
120 size_t long_enc_path_len = 0;
122 if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) { /* imap or pop3 */
123 EM_DEBUG_LOG("account->incoming_server_address[%p]", account->incoming_server_address);
124 EM_DEBUG_LOG("account->incoming_server_address[%s]", account->incoming_server_address);
126 if (!account->incoming_server_address) {
127 EM_DEBUG_EXCEPTION("account->incoming_server_address is null");
128 error = EMAIL_ERROR_INVALID_ACCOUNT;
132 long_enc_path_len = EM_SAFE_STRLEN(account->incoming_server_address) + EM_SAFE_STRLEN(path) + 64; /*prevent 34357*/
134 *long_enc_path = em_malloc(long_enc_path_len);
135 if (!*long_enc_path) {
136 EM_DEBUG_EXCEPTION("malloc failed...");
137 error = EMAIL_ERROR_OUT_OF_MEMORY;
143 /* ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}my-mailbox" */
145 SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d",
146 account->incoming_server_address,
147 account->incoming_server_port_number,
148 account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap", account->account_id);
150 if (account->incoming_server_secure_connection & 0x01) {
151 strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
152 /* strcat(p, "/tryssl"); */
155 /* Currently, receiving servers doesn't require tls.
156 if (account->incoming_server_secure_connection & 0x02)
157 strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
159 strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
162 if (account->incoming_server_requires_apop) {
163 EM_DEBUG_LOG("emcore_get_long_encoded_path - incoming_server_requires_apop - %d", account->incoming_server_requires_apop);
164 strncat(p, "/apop", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
165 EM_DEBUG_LOG("long_enc_path - %s", p);
169 long_enc_path_len = EM_SAFE_STRLEN(account->outgoing_server_address) + 64;
171 *long_enc_path = em_malloc(EM_SAFE_STRLEN(account->outgoing_server_address) + 64);
172 if (!*long_enc_path) {
173 EM_DEBUG_EXCEPTION("\t malloc failed...\n");
175 error = EMAIL_ERROR_OUT_OF_MEMORY;
181 /* ex:"mail.test.com:25/smtp" */
183 SNPRINTF(p, long_enc_path_len, "%s:%d/%s",
184 account->outgoing_server_address,
185 account->outgoing_server_port_number,
188 if (account->outgoing_server_need_authentication) {
189 SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d", account->account_id);
192 if (account->outgoing_server_secure_connection & 0x01) {
193 strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
194 /* strcat(p, "/tryssl"); */
196 if (account->outgoing_server_secure_connection & 0x02)
197 strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
199 strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
202 if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) {
203 strncat(p, "}", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
206 char *enc_name = NULL;
208 if (!emcore_get_encoded_mailbox_name(path, &enc_name, &error)) {
209 EM_DEBUG_EXCEPTION("emcore_get_encoded_mailbox_name failed - %d", error);
210 *long_enc_path = NULL;
215 strncat(p, enc_name, long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
216 EM_SAFE_FREE(enc_name);
227 if (err_code != NULL)
229 EM_PROFILE_END(emCorelongEncodedpath);
233 int emcore_get_long_encoded_path(int account_id, char *path, int delimiter, char **long_enc_path, int *err_code)
235 EM_PROFILE_BEGIN(emCorelongEncodedpath);
236 EM_DEBUG_FUNC_BEGIN("account_id[%d], delimiter[%d], long_enc_path[%p], err_code[%p]", account_id, delimiter, long_enc_path, err_code);
239 int error = EMAIL_ERROR_NONE;
240 email_account_t *ref_account = NULL;
242 ref_account = emcore_get_account_reference(account_id);
244 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
245 error = EMAIL_ERROR_INVALID_ACCOUNT;
249 if (emcore_get_long_encoded_path_with_account_info(ref_account, path, delimiter, long_enc_path, &error) == false) {
250 EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path_with_account_info failed [%d]", error);
259 emcore_free_account(ref_account);
260 EM_SAFE_FREE(ref_account);
263 if (err_code != NULL)
265 EM_PROFILE_END(emCorelongEncodedpath);
269 int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code)
271 EM_DEBUG_FUNC_BEGIN("name[%s], enc_name[%p], err_code[%p]", name, enc_name, err_code);
273 if (!name || !enc_name) {
274 if (err_code != NULL)
275 *err_code = EMAIL_ERROR_INVALID_PARAM;
280 /* encoding mailbox name (Charset->UTF8->UTF7) */
282 *enc_name = em_malloc(EM_SAFE_STRLEN(name)+1);
283 if (*enc_name == NULL) {
284 EM_DEBUG_EXCEPTION("malloc failed...");
285 if (err_code != NULL)
286 *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
291 strcpy(*enc_name, name);
293 if (err_code != NULL)
294 *err_code = EMAIL_ERROR_NONE;
300 int emcore_get_temp_file_name(char **filename, int *err_code)
302 EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code);
305 int error = EMAIL_ERROR_NONE;
307 if (filename == NULL) {
308 EM_DEBUG_EXCEPTION("\t filename[%p]\n", filename);
309 error = EMAIL_ERROR_INVALID_PARAM;
313 char tempname[512] = {0x00, };
317 gettimeofday(&tv, NULL);
320 /* Create Directory If deleted by user*/
321 emstorage_create_dir_if_delete();
323 SNPRINTF(tempname, sizeof(tempname), "%s%c%d", MAILTEMP, DIR_SEPERATOR_CH, rand());
325 char *p = EM_SAFE_STRDUP(tempname);
327 EM_DEBUG_EXCEPTION("\t strdup failed...\n");
328 error = EMAIL_ERROR_OUT_OF_MEMORY;
337 if (err_code != NULL)
343 int emcore_get_file_name(char *path, char **filename, int *err_code)
345 EM_DEBUG_FUNC_BEGIN("path[%s], filename[%p], err_code[%p]", path, filename, err_code);
348 int error = EMAIL_ERROR_NONE;
350 if (!path || !filename) {
351 EM_DEBUG_EXCEPTION("path[%p], filename[%p]", path, filename);
353 error = EMAIL_ERROR_INVALID_PARAM;
357 int i = (int)EM_SAFE_STRLEN(path);
361 if (path[i] == DIR_SEPERATOR_CH)
364 *filename = path + i + 1;
369 if (err_code != NULL)
375 int emcore_get_file_size(char *path, int *size, int *err_code)
377 EM_DEBUG_FUNC_BEGIN("path[%s], size[%p], err_code[%p]", path, size, err_code);
380 int error = EMAIL_ERROR_NONE;
382 if ((path == NULL) || (size == NULL)) {
383 EM_DEBUG_EXCEPTION("\t path[%p], size[%p]\n", path, size);
385 error = EMAIL_ERROR_INVALID_PARAM;
391 if (stat(path, &st_buf) < 0) {
392 EM_DEBUG_EXCEPTION("\t stat failed - %s\n", path);
394 error = EMAIL_ERROR_SYSTEM_FAILURE;
398 *size = st_buf.st_size;
403 if (err_code != NULL)
411 static int _emcore_check_host(char *host)
415 return strncmp(host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."));
420 int emcore_get_address_count(char *addr_str, int *count, int *err_code)
422 EM_DEBUG_FUNC_BEGIN("addr_str[%s], count[%p], err_code[%p]", addr_str, count, err_code);
425 int error = EMAIL_ERROR_NONE;
427 ADDRESS *addr = NULL;
428 ADDRESS *p_addr = NULL;
434 EM_DEBUG_EXCEPTION("addr_str[%s], count[%p]", addr_str, count);
435 error = EMAIL_ERROR_INVALID_PARAM;
439 if (addr_str != NULL) {
440 em_skip_whitespace(addr_str, &p);
441 EM_DEBUG_LOG("em_skip_whitespace[p][%s]", p);
444 for (i = 0, j = EM_SAFE_STRLEN(p); i < j; i++)
445 if (p[i] == ';') p[i] = ',';
446 rfc822_parse_adrlist(&addr, p, NULL);
450 for (p_addr = addr, i = 0; p_addr; p_addr = p_addr->next, i++) {
451 if (p_addr->mailbox && p_addr->host) {
452 if (!strncmp(p_addr->mailbox, "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS"))
453 || !strncmp(p_addr->mailbox, "INVALID_ADDRESS", strlen("INVALID_ADDRESS"))
454 || !strncmp(p_addr->host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."))) { /*prevent 34356*/
455 EM_DEBUG_LOG("Invalid address ");
459 if ((!p_addr->mailbox) || (_emcore_check_host(p_addr->host) == 0)) {
460 EM_DEBUG_EXCEPTION("\t invalid address : mailbox[%s], host[%s]\n", p_addr->mailbox, p_addr->host);
462 error = EMAIL_ERROR_INVALID_ADDRESS;
463 /* goto FINISH_OFF; */
469 if (error != EMAIL_ERROR_INVALID_ADDRESS)
474 mail_free_address(&addr);
476 if (err_code != NULL)
482 INTERNAL_FUNC int emcore_set_network_error(int err_code)
484 email_session_t *session = NULL;
486 EM_DEBUG_FUNC_BEGIN();
488 emcore_get_current_session(&session);
493 session->network = err_code;
498 int emcore_get_empty_session(email_session_t **session)
500 EM_DEBUG_FUNC_BEGIN("session[%p]", session);
506 for (i = 0; i < SESSION_MAX; i++) {
507 if (!g_session_list[i].status) {
508 memset(g_session_list+i, 0x00, sizeof(email_session_t));
509 g_session_list[i].tid = GPOINTER_TO_INT(THREAD_SELF());
510 g_session_list[i].status = true;
518 *session = (i != SESSION_MAX) ? &g_session_list[i] : NULL;
520 return (i != SESSION_MAX) ? true : false;
523 int emcore_clear_session(email_session_t *session)
525 EM_DEBUG_FUNC_BEGIN();
528 memset(session, 0x00, sizeof(email_session_t));
533 int emcore_get_current_session(email_session_t **session)
535 EM_DEBUG_FUNC_BEGIN("session[%p]", session);
539 for (i = 0; i < SESSION_MAX; i++) {
540 if (g_session_list[i].tid == GPOINTER_TO_INT(THREAD_SELF())) {
542 *session = g_session_list + i;
549 *session = (i != SESSION_MAX) ? g_session_list + i : NULL;
551 return (i != SESSION_MAX) ? true : false;
554 int emcore_get_mail_count_by_query(int account_id, int priority_sender, int *total_mail, int *unread_mail, int *err_code)
556 EM_DEBUG_FUNC_BEGIN();
559 int err = EMAIL_ERROR_NONE;
561 int type = EMAIL_PRIORITY_SENDER;
562 int unread_count = 0;
564 char *conditional_clause_string = NULL;
567 int is_completed = 0;
568 emstorage_rule_tbl_t *rule = NULL;
570 int filter_count = 0;
571 email_list_filter_t *filter_list = NULL;
573 if (priority_sender) {
575 if (!emstorage_get_rule(ALL_ACCOUNT, type, 0, &rule_count, &is_completed, &rule, true, &err) || !rule) {
576 EM_DEBUG_EXCEPTION("emstorage_get_rule failed");
580 /* Make query for searching unread mail */
581 if (account_id != ALL_ACCOUNT) {
582 filter_count = (rule_count * 2) + 3;
584 filter_count = (rule_count * 2) + 1; // 1 is unseen field.
587 filter_list = em_malloc(sizeof(email_list_filter_t) * filter_count);
588 if (filter_list == NULL) {
589 EM_DEBUG_EXCEPTION("em_malloc failed");
590 err = EMAIL_ERROR_OUT_OF_MEMORY;
594 for (i = 0, count = 0; i < filter_count - 1; i += 2, count++) {
595 filter_list[i].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
596 filter_list[i].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
597 filter_list[i].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FROM;
598 filter_list[i].list_filter_item.rule.key_value.string_type_value = EM_SAFE_STRDUP(rule[count].value);
600 filter_list[i+1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
601 if (i == (filter_count - 2)) {
602 filter_list[i+1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
604 filter_list[i+1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
608 filter_list[i].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
609 filter_list[i].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
610 filter_list[i].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD;
611 filter_list[i].list_filter_item.rule.key_value.integer_type_value = 0;
613 if (account_id != ALL_ACCOUNT) {
614 filter_list[i+1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
615 filter_list[i+1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
617 filter_list[i+2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
618 filter_list[i+2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
619 filter_list[i+2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID;
620 filter_list[i+2].list_filter_item.rule.key_value.integer_type_value = account_id;
623 if ((err = emstorage_write_conditional_clause_for_getting_mail_list(filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
624 EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
628 EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
630 /* Search the mail of priority sender in DB */
631 if ((err = emstorage_query_mail_count(conditional_clause_string, true, &total_count, &unread_count)) != EMAIL_ERROR_NONE) {
632 EM_DEBUG_EXCEPTION("emstorage_query_mail_count failed:[%d]", err);
636 if (!emstorage_get_mail_count(account_id, 0, &total_count, &unread_count, true, &err)) {
637 EM_DEBUG_EXCEPTION(" emstorage_get_mail_count failed - %d", err);
648 emstorage_free_rule(&rule, rule_count, NULL);
651 emstorage_free_list_filter(&filter_list, filter_count);
653 EM_SAFE_FREE(conditional_clause_string);
656 *total_mail = total_count;
659 *unread_mail = unread_count;
667 int emcore_display_unread_in_badge()
669 EM_DEBUG_FUNC_BEGIN();
672 int err = EMAIL_ERROR_NONE;
673 int total_unread_count = 0;
674 int total_mail_count = 0;
675 int badge_ticker = 0;
676 int priority_sender = 0;
679 /* Get the Global noti ticker */
680 if (vconf_get_bool(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, &badge_ticker) != 0) {
681 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
682 err = EMAIL_ERROR_GCONF_FAILURE;
686 /* Get the priority noti ticker */
688 if (vconf_get_bool(VCONF_VIP_NOTI_BADGE_TICKER, &badge_ticker) != 0) {
689 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
690 err = EMAIL_ERROR_GCONF_FAILURE;
695 EM_DEBUG_LOG("Not display the badge");
703 /* Get unread mail count */
704 if (!emcore_get_mail_count_by_query(ALL_ACCOUNT, priority_sender, &total_mail_count, &total_unread_count, &err)) {
705 EM_DEBUG_EXCEPTION("emcore_get_mail_count_by_query failed");
710 badge_error_e badge_err = BADGE_ERROR_NONE;
713 if((badge_err = badge_is_existing("com.samsung.email", &exist)) != BADGE_ERROR_NONE) {
714 EM_DEBUG_EXCEPTION("badge_is_existing failed [%d]", badge_err);
715 err = EMAIL_ERROR_BADGE_API_FAILED;
720 if((badge_err = badge_create("com.samsung.email", "/usr/bin/email-service")) != BADGE_ERROR_NONE) {
721 EM_DEBUG_EXCEPTION("badge_create failed [%d]", badge_err);
722 err = EMAIL_ERROR_BADGE_API_FAILED;
727 if((badge_err = badge_set_count("com.samsung.email", total_unread_count)) != BADGE_ERROR_NONE) {
728 EM_DEBUG_EXCEPTION("badge_set_count failed [%d]", badge_err);
729 err = EMAIL_ERROR_BADGE_API_FAILED;
733 if (total_unread_count <= 0)
743 static int emcore_layout_multi_noti(notification_h noti, int unread_mail, char *email_address, char *account_name)
745 EM_DEBUG_FUNC_BEGIN();
746 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
747 char modified_string[10];
749 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
750 if (noti_err != NOTIFICATION_ERROR_NONE) {
751 EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_SINGLE failed [%d]", noti_err);
755 SNPRINTF(modified_string, sizeof(modified_string), "%d", unread_mail);
757 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
758 if (noti_err != NOTIFICATION_ERROR_NONE) {
759 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
763 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, modified_string, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
764 if (noti_err != NOTIFICATION_ERROR_NONE) {
765 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_EVENT_COUNT failed");
769 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "new emails", "IDS_EMAIL_BODY_NEW_EMAILS", NOTIFICATION_VARIABLE_TYPE_NONE);
770 if (noti_err != NOTIFICATION_ERROR_NONE) {
771 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
775 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, email_address, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
776 if (noti_err != NOTIFICATION_ERROR_NONE) {
777 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
781 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, account_name, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
782 if (noti_err != NOTIFICATION_ERROR_NONE) {
783 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_2 failed");
787 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH);
788 if (noti_err != NOTIFICATION_ERROR_NONE) {
789 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
795 EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err);
799 static int emcore_layout_single_noti(notification_h noti, char *account_name, char *display_sender, time_t time, char *subject)
801 EM_DEBUG_FUNC_BEGIN();
802 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
804 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
805 if (noti_err != NOTIFICATION_ERROR_NONE) {
806 EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_SINGLE failed [%d]", noti_err);
810 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
811 if (noti_err != NOTIFICATION_ERROR_NONE) {
812 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
816 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, account_name, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
817 if (noti_err != NOTIFICATION_ERROR_NONE) {
818 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
822 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, display_sender, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
823 if (noti_err != NOTIFICATION_ERROR_NONE) {
824 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
829 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, time, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
830 if (noti_err != NOTIFICATION_ERROR_NONE) {
831 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_SUB_1 failed");
836 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
837 if (noti_err != NOTIFICATION_ERROR_NONE) {
838 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_2 failed");
842 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH);
843 if (noti_err != NOTIFICATION_ERROR_NONE) {
844 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
850 EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err);
854 static int emcore_add_notification(int account_id, int mail_id, email_action_t action)
856 EM_DEBUG_FUNC_BEGIN();
857 int err = EMAIL_ERROR_NONE;
859 EM_DEBUG_FUNC_END("ret [%d]", err);
863 INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int error)
865 EM_DEBUG_FUNC_BEGIN("id[%d], action[%d], error[%d]", id, action, error);
869 if (action == EMAIL_ACTION_SEND_MAIL && error != EMAIL_ERROR_CANCELLED) {
870 /* In case email is cancelled using cancel button in Outbox there is no need to show Cancel/Retry Pop up */
871 emstorage_mail_tbl_t *mail_table_data = NULL;
873 if (error == 0) /* error 0 means 'this is not error' */
877 EM_DEBUG_LOG("Invalid mail_id");
881 if (!emstorage_get_mail_by_id(id, &mail_table_data, true, NULL)) {
882 EM_DEBUG_LOG("Mail not found");
886 if (emcore_add_notification(mail_table_data->account_id, id, action) != EMAIL_ERROR_NONE) {
887 EM_DEBUG_EXCEPTION("emcore_notification_set error");
889 if (!emstorage_free_mail(&mail_table_data, 1, NULL))
890 EM_DEBUG_EXCEPTION("emstorage_free_mail Failed");
895 if (!emstorage_free_mail(&mail_table_data, 1, NULL))
896 EM_DEBUG_EXCEPTION("emstorage_free_mail Failed");
900 EM_DEBUG_FUNC_END("ret [%d]", ret);
905 /* storage space handling - 210709 */
906 int emcore_get_storage_status(void)
908 EM_DEBUG_FUNC_BEGIN();
909 int storage_status = 0, nError = 0;
913 #ifdef STORAGE_STATUS
914 nError = vconf_get_int(PS_KEY_SYSTEM_STORAGE_MOVI_STATUS,
916 #endif /* STORAGE_STATUS */
919 EM_DEBUG_EXCEPTION("vconf_get_int Failed");
923 return storage_status;
926 int emcore_is_storage_full(int *err_code)
928 EM_DEBUG_FUNC_BEGIN();
931 int err = EMAIL_ERROR_NONE;
932 struct statfs buf = {0};
934 if (statfs(DATA_PATH, &buf) == -1) {
935 EM_DEBUG_EXCEPTION("statfs(\"%s\") failed - %d", DATA_PATH, errno);
936 err = EMAIL_ERROR_SYSTEM_FAILURE;
940 long i_free = (buf.f_bfree * buf.f_bsize) / (1024 * 1024);
941 EM_DEBUG_LOG("f_bfree[%d] f_bsize[%d]", buf.f_bfree, buf.f_bsize);
942 EM_DEBUG_LOG("Free space of storage is[%ld] MB.", i_free);
943 if (i_free < EMAIL_LIMITATION_FREE_SPACE)
944 err = EMAIL_ERROR_MAIL_MEMORY_FULL;
947 if (err == EMAIL_ERROR_MAIL_MEMORY_FULL)
951 if (err_code != NULL)
953 EM_DEBUG_FUNC_END("ret[%d]", ret);
957 int emcore_calc_mail_size(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, int *output_size)
959 EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count[%d], output_size[%p]", input_mail_data, input_attachment_data_list, input_attachment_count, output_size);
962 int mail_size = 0; /* size of the plain text body and attachments */
963 int err = EMAIL_ERROR_NONE;
966 if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count &&input_attachment_data_list) || !output_size) {
967 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
968 err = EMAIL_ERROR_INVALID_PARAM;
972 if (input_mail_data->file_path_plain != NULL) {
973 if (stat(input_mail_data->file_path_plain, &st_buf) < 0) {
974 EM_DEBUG_EXCEPTION("input_mail_data->file_path_plain : stat(\"%s\") failed...", input_mail_data->file_path_plain);
975 err = EMAIL_ERROR_FILE_NOT_FOUND;
979 mail_size += st_buf.st_size;
983 if (input_mail_data->file_path_html != NULL) {
984 if (stat(input_mail_data->file_path_html, &st_buf) < 0) {
985 EM_DEBUG_EXCEPTION("input_mail_data->file_path_html : stat(\"%s\") failed...", input_mail_data->file_path_html);
986 err = EMAIL_ERROR_FILE_NOT_FOUND;
990 mail_size += st_buf.st_size;
993 for(i = 0; i < input_attachment_count; i++) {
994 if (stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0) {
995 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path);
996 err = EMAIL_ERROR_FILE_NOT_FOUND;
999 mail_size += st_buf.st_size;
1002 *output_size = mail_size;
1006 EM_DEBUG_FUNC_END("mail_size [%d]", mail_size);
1011 /* parse the Full mailbox Path and Get the Alias Name of the Mailbox */
1012 char *emcore_get_alias_of_mailbox(const char *mailbox_path)
1014 EM_DEBUG_FUNC_BEGIN();
1015 EM_IF_NULL_RETURN_VALUE(mailbox_path, NULL);
1018 gchar **token_list = NULL;
1019 gchar *mailbox = NULL, *name = NULL;
1020 char *converted_name;
1023 mailbox = g_strdup(mailbox_path);
1024 token_list = g_strsplit_set(mailbox, "/", -1);
1029 while (token_list[index] != NULL)
1032 name = g_strdup(token_list[index - 1]);
1033 if(!name) /* prevent 27459 */
1036 g_strfreev(token_list);
1038 converted_name = emcore_convert_mutf7_to_utf8(name);
1043 EM_DEBUG_FUNC_END();
1044 return converted_name;
1048 static int emcore_get_first_address(const char *full_address, char **alias, char **address)
1050 EM_DEBUG_FUNC_BEGIN();
1052 if (full_address == NULL || alias == NULL || address == NULL){
1053 EM_DEBUG_EXCEPTION("Invalid Param : full_address[%p], alias[%p], address[%p]", full_address, alias, address);
1058 char *alias_start = NULL;
1059 char *alias_end = NULL;
1060 char *alias_cursor = NULL;
1061 char *address_start = NULL;
1062 char *address_end = NULL;
1063 char *first_address = NULL;
1066 s = (char *)strchr((char *)full_address, ';');
1068 first_address = strdup(full_address); /* only one address */
1070 first_address = strndup(full_address, s - full_address); /* over two addresses */
1074 if ((alias_start = (char *)strchr((char *)first_address, '\"'))){
1076 alias_cursor = alias_start;
1077 while ((alias_cursor = (char *)strchr((char *)(alias_cursor), '\"'))){
1078 alias_end = alias_cursor;
1080 if (*alias_cursor == 0)
1083 if (alias_end) { /* there is "alias" */
1084 *alias = strndup(alias_start, alias_end - alias_start);
1085 EM_DEBUG_LOG("alias [%s]", *alias);
1091 if (alias_end == NULL)
1095 if ((address_start = (char *)strchr((char *)s, '<'))){
1097 if ((address_end = (char *)strchr((char *)address_start, '>')))
1098 *address = strndup(address_start, address_end - address_start); /* (alias) <(addr)> ... */
1100 *address = strdup(s);
1103 *address = strdup(s); /* (addr) ; ... : no alias */
1106 EM_SAFE_FREE(first_address);
1107 EM_DEBUG_FUNC_END();
1111 void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data)
1113 EM_DEBUG_FUNC_BEGIN("mail_data [%p]", mail_data);
1115 char *first_alias = NULL;
1116 char *first_address = NULL;
1117 char *recipient = NULL;
1119 /* sender alias & address */
1120 if (emcore_get_first_address(mail_data->full_address_from, &first_alias, &first_address) == true) {
1121 if (first_alias == NULL) {
1122 mail_data->alias_sender = EM_SAFE_STRDUP(first_address);
1125 mail_data->alias_sender = first_alias;
1128 mail_data->email_address_sender = first_address;
1129 first_address = NULL;
1132 /* recipient alias & address */
1133 if (mail_data->full_address_to != NULL)
1134 recipient = mail_data->full_address_to;
1135 else if (mail_data->full_address_cc != NULL)
1136 recipient = mail_data->full_address_cc;
1137 else if (mail_data->full_address_bcc != NULL)
1138 recipient = mail_data->full_address_bcc;
1140 if (emcore_get_first_address(recipient, &first_alias, &first_address) == true) {
1141 if (first_alias == NULL)
1142 mail_data->alias_recipient = EM_SAFE_STRDUP(first_address);
1144 mail_data->alias_recipient = first_alias;
1146 mail_data->email_address_recipient = first_address;
1148 EM_DEBUG_FUNC_END();
1151 struct email_attribute_info {
1152 email_mail_attribute_type attribute_type;
1153 char *attribute_name;
1154 email_mail_attribute_value_type attribute_value_type;
1157 static struct email_attribute_info _mail_attribute_info_array[] = {
1158 {EMAIL_MAIL_ATTRIBUTE_MAIL_ID, "mail_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1159 {EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID, "account_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1160 {EMAIL_MAIL_ATTRIBUTE_MAILBOX_ID, "mailbox_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1161 {EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME, "mailbox_name", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1162 {EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE, "mailbox_type", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1163 {EMAIL_MAIL_ATTRIBUTE_SUBJECT, "subject", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1164 {EMAIL_MAIL_ATTRIBUTE_DATE_TIME, "date_time",EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME},
1165 {EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_STATUS, "server_mail_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1166 {EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME, "server_mailbox_name", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1167 {EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID, "server_mail_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1168 {EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID, "message_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1169 {EMAIL_MAIL_ATTRIBUTE_REFERENCE_MAIL_ID, "reference_mail_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1170 {EMAIL_MAIL_ATTRIBUTE_FROM, "full_address_from", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1171 {EMAIL_MAIL_ATTRIBUTE_TO, "full_address_to", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1172 {EMAIL_MAIL_ATTRIBUTE_CC, "full_address_cc", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1173 {EMAIL_MAIL_ATTRIBUTE_BCC, "full_address_bcc", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1174 {EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS, "body_download_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1175 {EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN, "file_path_plain",EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1176 {EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML,"file_path_html", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1177 {EMAIL_MAIL_ATTRIBUTE_FILE_SIZE,"file_size", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1178 {EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD,"flags_seen_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1179 {EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD,"flags_deleted_field",EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER },
1180 {EMAIL_MAIL_ATTRIBUTE_FLAGS_FLAGGED_FIELD,"flags_flagged_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1181 {EMAIL_MAIL_ATTRIBUTE_FLAGS_ANSWERED_FIELD,"flags_answered_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1182 {EMAIL_MAIL_ATTRIBUTE_FLAGS_RECENT_FIELD,"flags_recent_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1183 {EMAIL_MAIL_ATTRIBUTE_FLAGS_DRAFT_FIELD,"flags_draft_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1184 {EMAIL_MAIL_ATTRIBUTE_FLAGS_FORWARDED_FIELD,"flags_forwarded_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1185 {EMAIL_MAIL_ATTRIBUTE_DRM_STATUS,"drm_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1186 {EMAIL_MAIL_ATTRIBUTE_PRIORITY,"priority", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1187 {EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS,"save_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1188 {EMAIL_MAIL_ATTRIBUTE_LOCK_STATUS,"lock_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1189 {EMAIL_MAIL_ATTRIBUTE_REPORT_STATUS,"report_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1190 {EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT,"attachment_count", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1191 {EMAIL_MAIL_ATTRIBUTE_INLINE_CONTENT_COUNT,"inline_content_count", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1192 {EMAIL_MAIL_ATTRIBUTE_THREAD_ID,"thread_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1193 {EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT,"thread_item_count", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1194 {EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT,"preview_text", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
1195 {EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS,"meeting_request_status", },
1196 {EMAIL_MAIL_ATTRIBUTE_MESSAGE_CLASS,"message_class", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1197 {EMAIL_MAIL_ATTRIBUTE_DIGEST_TYPE,"digest_type", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1198 {EMAIL_MAIL_ATTRIBUTE_SMIME_TYPE,"smime_type", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1199 {EMAIL_MAIL_ATTRIBUTE_SCHEDULED_SENDING_TIME,"scheduled_sending_time", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME},
1200 {EMAIL_MAIL_ATTRIBUTE_EAS_DATA_LENGTH_TYPE,"eas_data_length", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
1201 {EMAIL_MAIL_ATTRIBUTE_EAS_DATA_TYPE,"eas_data", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_BINARY}
1204 INTERNAL_FUNC char* emcore_get_mail_field_name_by_attribute_type(email_mail_attribute_type input_attribute_type)
1206 EM_DEBUG_FUNC_BEGIN("input_attribute_type [%d]", input_attribute_type);
1208 if(input_attribute_type > EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS || input_attribute_type < 0) {
1209 EM_DEBUG_EXCEPTION("Invalid input_attribute_type [%d]", input_attribute_type);
1213 EM_DEBUG_FUNC_END("return [%s]", _mail_attribute_info_array[input_attribute_type].attribute_name);
1214 return _mail_attribute_info_array[input_attribute_type].attribute_name;
1217 INTERNAL_FUNC int emcore_get_attribute_type_by_mail_field_name(char *input_mail_field_name, email_mail_attribute_type *output_mail_attribute_type)
1219 EM_DEBUG_FUNC_BEGIN("input_mail_field_name [%p], output_mail_attribute_type [%p]", input_mail_field_name, output_mail_attribute_type);
1221 int err = EMAIL_ERROR_DATA_NOT_FOUND;
1223 if(!input_mail_field_name || !output_mail_attribute_type) {
1224 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1225 return EMAIL_ERROR_INVALID_PARAM;
1228 for (i = 0; i < EMAIL_MAIL_ATTRIBUTE_END; i++) {
1229 if (EM_SAFE_STRCMP(input_mail_field_name, _mail_attribute_info_array[i].attribute_name) == 0) {
1230 *output_mail_attribute_type = i;
1231 err = EMAIL_ERROR_NONE;
1236 EM_DEBUG_FUNC_END("found mail attribute type [%d]", (int)*output_mail_attribute_type);
1240 INTERNAL_FUNC int emcore_get_mail_attribute_value_type(email_mail_attribute_type input_attribute_type, email_mail_attribute_value_type *output_value_type)
1242 EM_DEBUG_FUNC_BEGIN("input_attribute_type[%d] output_value_type[%p]", input_attribute_type, output_value_type);
1243 int err = EMAIL_ERROR_NONE;
1245 email_mail_attribute_value_type value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE;
1247 if (output_value_type == NULL) {
1248 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1249 err = EMAIL_ERROR_INVALID_PARAM;
1253 for(i = 0; i < EMAIL_MAIL_ATTRIBUTE_END; i++) {
1254 if(input_attribute_type == _mail_attribute_info_array[i].attribute_type) {
1255 value_type = _mail_attribute_info_array[i].attribute_value_type;
1260 *output_value_type = value_type;
1262 EM_DEBUG_LOG("value_type [%d]", value_type);
1265 EM_DEBUG_FUNC_END("err [%d]", err);
1269 #ifdef __FEATURE_BODY_SEARCH__
1270 int emcore_strip_mail_body_from_file(emstorage_mail_tbl_t *mail, char **stripped_text, int *err_code)
1272 EM_DEBUG_FUNC_BEGIN("mail[%p]");
1275 int err = EMAIL_ERROR_NONE;
1277 char *encoding_type = NULL;
1278 char *utf8_encoded_string = NULL;
1279 unsigned int byte_read = 0;
1280 unsigned int byte_written = 0;
1281 GError *glib_error = NULL;
1282 FILE *fp_html = NULL;
1283 FILE *fp_plain = NULL;
1287 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1288 err = EMAIL_ERROR_INVALID_PARAM;
1292 /* read file to buf & strip if html text */
1293 if (mail->file_path_html) {
1294 if((err = em_get_encoding_type_from_file_path(mail->file_path_html, &encoding_type)) != EMAIL_ERROR_NONE) {
1295 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
1299 if (stat(mail->file_path_html, &st_buf) < 0) {
1300 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", mail->file_path_html);
1301 err = EMAIL_ERROR_FILE_NOT_FOUND;
1305 if (!(fp_html = fopen(mail->file_path_html, "r"))) {
1306 EM_DEBUG_EXCEPTION("fopen failed [%s]", mail->file_path_html);
1307 err = EMAIL_ERROR_SYSTEM_FAILURE;
1311 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
1312 EM_DEBUG_LOG("html_file is empty size");
1313 err = EMAIL_ERROR_EMPTY_FILE;
1317 if (!(buf = (char*)em_malloc(sizeof(char)*(st_buf.st_size + 1)))) {
1318 EM_DEBUG_EXCEPTION("em_malloc failed");
1319 err = EMAIL_ERROR_OUT_OF_MEMORY;
1323 byte_read = fread(buf, sizeof(char), st_buf.st_size, fp_html);
1325 if (byte_read <= 0) {
1327 if (ferror(fp_html)) {
1328 EM_DEBUG_EXCEPTION("fread failed [%s]", mail->file_path_html);
1329 err = EMAIL_ERROR_SYSTEM_FAILURE;
1333 if ((err = emcore_strip_HTML(buf)) != EMAIL_ERROR_NONE) {
1334 EM_DEBUG_EXCEPTION("emcore_strip failed");
1340 if (!buf && mail->file_path_plain) {
1341 if ((err = em_get_encoding_type_from_file_path(mail->file_path_plain, &encoding_type)) != EMAIL_ERROR_NONE) {
1342 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
1346 memset(&st_buf, 0, sizeof(struct stat));
1347 if (stat(mail->file_path_plain, &st_buf) < 0) {
1348 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", mail->file_path_plain);
1349 err = EMAIL_ERROR_INVALID_MAIL;
1353 if (!(fp_plain = fopen(mail->file_path_plain, "r"))) {
1354 EM_DEBUG_EXCEPTION("fopen failed [%s]", mail->file_path_plain);
1355 err = EMAIL_ERROR_SYSTEM_FAILURE;
1359 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
1360 EM_DEBUG_LOG("text_file is empty size");
1361 err = EMAIL_ERROR_EMPTY_FILE;
1365 if (!(buf = (char*)em_malloc(sizeof(char)*(st_buf.st_size + 1)))) {
1366 EM_DEBUG_EXCEPTION("em_malloc failed");
1370 byte_read = fread(buf, sizeof(char), st_buf.st_size, fp_plain);
1372 if (byte_read <= 0) {
1374 err = EMAIL_ERROR_NULL_VALUE;
1375 if (ferror(fp_plain)) {
1376 EM_DEBUG_EXCEPTION("fread failed [%s]", mail->file_path_plain);
1377 err = EMAIL_ERROR_SYSTEM_FAILURE;
1381 reg_replace(buf, CR_STRING, " ");
1382 reg_replace(buf, LF_STRING, " ");
1383 reg_replace(buf, TAB_STRING, " ");
1388 if(encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
1389 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
1391 if (strcasecmp(encoding_type, "ks_c_5601-1987") == 0 ||
1392 strcasecmp(encoding_type, "ksc5601") == 0 ||
1393 strcasecmp(encoding_type, "cp949") == 0) {
1394 EM_SAFE_FREE(encoding_type);
1395 encoding_type = EM_SAFE_STRDUP("EUC-KR");
1398 utf8_encoded_string = (char*)g_convert(buf, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1400 if(utf8_encoded_string == NULL) {
1401 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d], EM_SAFE_STRLEN : [%d]", byte_read, EM_SAFE_STRLEN(buf));
1402 EM_DEBUG_LOG("Error is G_CONVERT_ERROR_ILLEGAL_SEQUENCE");
1404 if (!g_error_matches(glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
1405 EM_DEBUG_EXCEPTION("g_convert failed");
1409 EM_DEBUG_LOG("Extract the preview text, again");
1411 utf8_encoded_string = (char *)g_convert(buf, byte_read, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1412 if (utf8_encoded_string == NULL) {
1413 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d]", byte_read);
1419 *stripped_text = EM_SAFE_STRDUP(utf8_encoded_string);
1421 *stripped_text = EM_SAFE_STRDUP(buf);
1433 EM_SAFE_FREE(encoding_type);
1434 EM_SAFE_FREE(utf8_encoded_string);
1436 if (fp_html != NULL)
1439 if (fp_plain != NULL)
1442 EM_DEBUG_FUNC_END("ret [%d]", ret);
1448 int emcore_get_preview_text_from_file(const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer)
1450 EM_DEBUG_FUNC_BEGIN("input_plain_path[%p], input_html_path[%p], input_preview_buffer_length [%d], output_preview_buffer[%p]", input_plain_path, input_html_path, input_preview_buffer_length, output_preview_buffer);
1452 int err = EMAIL_ERROR_NONE;
1453 unsigned int byte_read = 0;
1454 unsigned int byte_written = 0;
1455 int local_preview_buffer_length = 0;
1456 char *local_preview_text = NULL;
1457 char *encoding_type = NULL;
1458 char *utf8_encoded_string = NULL;
1459 FILE *fp_html = NULL;
1460 FILE *fp_plain = NULL;
1461 GError *glib_error = NULL;
1464 if (!output_preview_buffer) {
1465 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1466 err = EMAIL_ERROR_INVALID_PARAM;
1470 local_preview_buffer_length = input_preview_buffer_length * 2;
1472 if ( input_html_path ) { /*prevent 26249*/
1473 /* get preview text from html file */
1474 if( (err = em_get_encoding_type_from_file_path(input_html_path, &encoding_type)) != EMAIL_ERROR_NONE) {
1475 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
1479 if (stat(input_html_path, &st_buf) < 0) {
1480 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_html_path);
1481 err = EMAIL_ERROR_FILE_NOT_FOUND;
1485 if (!(fp_html = fopen(input_html_path, "r"))) {
1486 EM_DEBUG_EXCEPTION("fopen failed [%s]", input_html_path);
1487 err = EMAIL_ERROR_SYSTEM_FAILURE;
1491 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
1492 EM_DEBUG_LOG("input_html_file is empty size");
1493 err = EMAIL_ERROR_EMPTY_FILE;
1497 if (!(local_preview_text = (char*)em_malloc(sizeof(char) * (st_buf.st_size + 1)))) {
1498 EM_DEBUG_EXCEPTION("em_malloc failed");
1499 err = EMAIL_ERROR_OUT_OF_MEMORY;
1503 byte_read = fread(local_preview_text, sizeof(char), st_buf.st_size, fp_html);
1505 if(byte_read <= 0) { /*prevent 26249*/
1506 EM_SAFE_FREE(local_preview_text);
1507 if (ferror(fp_html)) {
1508 EM_DEBUG_EXCEPTION("fread failed [%s]", input_html_path);
1509 err = EMAIL_ERROR_SYSTEM_FAILURE;
1514 if ( (err = emcore_strip_HTML(local_preview_text)) != EMAIL_ERROR_NONE) {
1515 EM_DEBUG_EXCEPTION("emcore_strip failed");
1521 if ( !local_preview_text && input_plain_path) { /*prevent 26249*/
1522 /* get preview text from plain text file */
1523 if( (err = em_get_encoding_type_from_file_path(input_plain_path, &encoding_type)) != EMAIL_ERROR_NONE) {
1524 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
1528 memset(&st_buf, 0, sizeof(struct stat));
1529 if (stat(input_plain_path, &st_buf) < 0) {
1530 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_plain_path);
1531 err = EMAIL_ERROR_INVALID_MAIL;
1535 if (!(fp_plain = fopen(input_plain_path, "r"))) {
1536 EM_DEBUG_EXCEPTION("fopen failed [%s]", input_plain_path);
1537 err = EMAIL_ERROR_SYSTEM_FAILURE;
1541 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
1542 EM_DEBUG_LOG("input_text_file is empty size");
1543 err = EMAIL_ERROR_EMPTY_FILE;
1547 if (!(local_preview_text = (char*)em_malloc(sizeof(char) * local_preview_buffer_length))) {
1548 EM_DEBUG_EXCEPTION("em_malloc failed");
1552 byte_read = fread(local_preview_text, sizeof(char), local_preview_buffer_length - 1, fp_plain);
1554 if(byte_read <=0) { /*prevent 26249*/
1555 EM_SAFE_FREE(local_preview_text);
1556 err = EMAIL_ERROR_NULL_VALUE;
1557 if (ferror(fp_plain)) {
1558 EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path);
1559 err = EMAIL_ERROR_SYSTEM_FAILURE;
1563 reg_replace(local_preview_text, CR_STRING, " ");
1564 reg_replace(local_preview_text, LF_STRING, " ");
1565 reg_replace(local_preview_text, TAB_STRING, " ");
1568 if(local_preview_text) {
1569 em_trim_left(local_preview_text);
1570 if(encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
1571 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
1573 if (strcasecmp(encoding_type, "ks_c_5601-1987") == 0 ||
1574 strcasecmp(encoding_type, "ksc5601") == 0 ||
1575 strcasecmp(encoding_type, "cp949") == 0) {
1576 EM_SAFE_FREE(encoding_type);
1577 encoding_type = EM_SAFE_STRDUP("EUC-KR");
1580 utf8_encoded_string = (char*)g_convert (local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1582 if(utf8_encoded_string == NULL) {
1583 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d], EM_SAFE_STRLEN : [%d]", byte_read, EM_SAFE_STRLEN(local_preview_text));
1584 EM_DEBUG_LOG("Error is G_CONVERT_ERROR_ILLEGAL_SEQUENCE");
1586 if (!g_error_matches (glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
1587 EM_DEBUG_EXCEPTION("g_convert failed");
1591 EM_DEBUG_LOG("Extract the preview text, again");
1593 utf8_encoded_string = (char *)g_convert(local_preview_text, byte_read, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1594 if (utf8_encoded_string == NULL) {
1595 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d]", byte_read);
1600 EM_SAFE_FREE(local_preview_text);
1601 local_preview_text = utf8_encoded_string;
1607 if (local_preview_text != NULL)
1608 *output_preview_buffer = EM_SAFE_STRDUP(local_preview_text);
1610 EM_SAFE_FREE(local_preview_text);
1611 EM_SAFE_FREE(encoding_type);
1613 if (fp_html != NULL)
1616 if (fp_plain != NULL)
1619 EM_DEBUG_FUNC_END("err [%d]", err);
1623 INTERNAL_FUNC int emcore_add_transaction_info(int mail_id, int handle , int *err_code)
1625 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%d]", mail_id, handle);
1628 int err = EMAIL_ERROR_NONE ;
1629 em_transaction_info_type_t *pTransinfo = NULL ;
1630 em_transaction_info_type_t *pTemp = NULL;
1632 EM_DEBUG_LOG("g_transaction_info_list[%p]", g_transaction_info_list);
1633 pTransinfo = g_transaction_info_list ;
1635 if (!(pTemp = em_malloc(sizeof(em_transaction_info_type_t)))) {
1636 EM_DEBUG_EXCEPTION("malloc failed...");
1637 err = EMAIL_ERROR_OUT_OF_MEMORY;
1640 pTemp->mail_id = mail_id ;
1641 pTemp->handle = handle;
1644 pTransinfo = pTemp ;
1645 g_transaction_info_list = pTransinfo ;
1648 while (pTransinfo->next)
1649 pTransinfo = pTransinfo->next;
1650 pTransinfo->next = pTemp;
1658 EM_DEBUG_FUNC_END("g_transaction_info_list[%p]", g_transaction_info_list);
1662 INTERNAL_FUNC int emcore_get_handle_by_mailId_from_transaction_info(int mail_id, int *pHandle)
1664 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p]", mail_id, pHandle);
1667 em_transaction_info_type_t *pTransinfo = NULL ;
1669 if (g_transaction_info_list == NULL) {
1670 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
1673 pTransinfo = g_transaction_info_list;
1676 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
1677 if (pTransinfo->mail_id == mail_id) {
1678 *pHandle = pTransinfo->handle;
1680 EM_DEBUG_LOG("*pHandle[%d]", *pHandle);
1684 pTransinfo = pTransinfo->next ;
1685 }while (pTransinfo);
1686 EM_DEBUG_FUNC_END();
1690 INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id )
1692 EM_DEBUG_FUNC_BEGIN("mail_id[%d]", mail_id);
1694 em_transaction_info_type_t *pTransinfo ;
1695 em_transaction_info_type_t *pTemp = NULL;
1697 if (g_transaction_info_list == NULL) {
1698 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
1701 pTransinfo = g_transaction_info_list;
1703 EM_DEBUG_LOG("pTransinfo[%p]", pTransinfo);
1706 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
1707 if (pTransinfo->mail_id == mail_id) {
1708 pTemp = pTransinfo->next ;
1710 EM_SAFE_FREE(pTransinfo) ;
1711 g_transaction_info_list = NULL;
1714 pTransinfo->mail_id = pTransinfo->next->mail_id;
1715 pTransinfo->handle = pTransinfo->next->handle ;
1716 pTransinfo->next = pTransinfo->next->next;
1718 EM_SAFE_FREE(pTemp);
1723 pTransinfo = pTransinfo->next ;
1726 }while (pTransinfo);
1727 EM_DEBUG_FUNC_END();
1734 int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string)
1736 int error_code = EMAIL_ERROR_NONE;
1738 int so, n, nmatch, source_text_length, n_count = 1;
1739 regmatch_t *pmatch = NULL;
1740 regex_t reg_pattern;
1742 if(!input_source_text || !input_old_pattern_string || !input_new_string) {
1743 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1744 error_code = EMAIL_ERROR_INVALID_PARAM;
1748 source_text_length = EM_SAFE_STRLEN(input_source_text);
1750 if (regcomp(®_pattern, input_old_pattern_string, REG_ICASE) != 0) {
1751 EM_DEBUG_EXCEPTION("regcomp failed");
1755 nmatch = reg_pattern.re_nsub + 1;
1757 EM_DEBUG_LOG("nmatch [%d]", nmatch);
1760 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_DATA");
1761 error_code = EMAIL_ERROR_INVALID_DATA;
1765 pmatch = (regmatch_t*)em_malloc(sizeof(regmatch_t) * nmatch);
1767 if(pmatch == NULL) {
1768 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
1769 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
1773 for (pos = input_new_string; *pos ; pos++) {
1774 if (*pos == '\\' && *(pos + 1) > '0' && *(pos + 1) <= '9') {
1776 so = pmatch[*(pos + 1) - 48].rm_so;
1777 n = pmatch[*(pos + 1) - 48].rm_eo - so;
1779 EM_DEBUG_LOG("so [%d], n [%d]", so, n);
1781 if (so < 0 || EM_SAFE_STRLEN (input_new_string) + n - 1 > source_text_length)
1784 memmove (pos + n, pos + 2, EM_SAFE_STRLEN (pos) - 1);
1785 memmove (pos, input_source_text + so, n);
1790 for (pos = input_source_text; !regexec (®_pattern, pos, 1, pmatch, 0);) {
1791 n = pmatch[0].rm_eo - pmatch[0].rm_so;
1792 pos += pmatch[0].rm_so;
1794 memmove (pos + EM_SAFE_STRLEN (input_new_string), pos + n, EM_SAFE_STRLEN (pos) - n + 1);
1795 memmove (pos, input_new_string, EM_SAFE_STRLEN (input_new_string));
1796 pos += EM_SAFE_STRLEN (input_new_string);
1802 EM_SAFE_FREE(pmatch);
1803 regfree (®_pattern);
1805 EM_DEBUG_FUNC_END("error_code [%d]", error_code);
1810 int emcore_strip_HTML(char *source_string)
1812 EM_DEBUG_FUNC_BEGIN("source_string [%p]", source_string);
1814 int result = EMAIL_ERROR_NONE;
1817 reg_replace(source_string, "\r", "");
1820 reg_replace(source_string, "\n", "");
1822 /* strip out HEAD */
1823 reg_replace(source_string, "<head[^>]*>", "<head>");
1824 reg_replace(source_string, "<*/head>", "</head>");
1825 reg_replace(source_string, "<head>.*</head>", "");
1827 /* strip out STYLE */
1828 reg_replace(source_string, "<style[^>]*>", "<style>");
1829 reg_replace(source_string, "<*/style>", "</style>");
1830 reg_replace(source_string, "<style>.*</style>", "");
1832 /* strip out SCRIPT */
1833 reg_replace(source_string, "<script[^>]*>", "<script>");
1834 reg_replace(source_string, "<*/script>", "</script>");
1835 reg_replace(source_string, "<script>.*</script>", "");
1837 /* strip out ALL TAG & comment */
1838 reg_replace(source_string, "<[^>]*>", "");
1840 /* for remaining comment in some cases */
1841 reg_replace(source_string, "-->", "");
1843 /* strip out html entities */
1844 /*"&(quot|#34);""&(amp|#38);""&(lt|#60);""&(gt|#62);""&(nbsp|#160);"
1845 "&(iexcl|#161);""&(cent|#162);""&(pound|#163);""&(copy|#169);"*/
1846 reg_replace(source_string, "<", "<");
1847 reg_replace(source_string, ">", ">");
1848 reg_replace(source_string, """, "\'");
1849 reg_replace(source_string, " ", " ");
1851 reg_replace(source_string, " +", " ");
1853 EM_DEBUG_FUNC_END();
1857 INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime)
1859 EM_DEBUG_FUNC_BEGIN("mailbox_name(%s) subject(%s), from(%s), uid(%s), datetime(%s)", mailbox_name, subject, from, uid, datetime);
1860 int error_code = EMAIL_ERROR_NONE;
1861 int param_length = 0;
1862 char *param_string = NULL;
1864 if (mailbox_name == NULL || subject == NULL || from == NULL || uid == NULL || datetime == NULL) {
1865 error_code = EMAIL_ERROR_INVALID_PARAM;
1866 EM_DEBUG_EXCEPTION("Invalid parameter, mailbox_name(%p), subject(%p), from(%p), uid(%p), datetime(%p)", mailbox_name, subject, from, uid, datetime);
1870 param_length = strlen(mailbox_name) + strlen(subject) + strlen(from) + strlen(uid) + strlen(datetime) + 5; /*prevent 34358*/
1872 param_string = em_malloc(param_length);
1873 if (param_string == NULL) {
1874 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
1875 EM_DEBUG_EXCEPTION("Memory allocation for 'param_string' is failed");
1879 memset(param_string, 0x00, param_length);
1881 SNPRINTF(param_string, param_length, "%s%c%s%c%s%c%s%c%s", mailbox_name, 0x01, subject, 0x01, from, 0x01, uid, 0x01, datetime);
1883 if (emcore_notify_network_event(NOTI_DOWNLOAD_NEW_MAIL, account_id, param_string, 0, 0) == 0) { /* failed */
1884 error_code = EMAIL_ERROR_UNKNOWN;
1885 EM_DEBUG_EXCEPTION("emcore_notify_network_event is failed");
1891 EM_SAFE_FREE(param_string);
1892 EM_DEBUG_FUNC_END();
1896 #define MAX_TITLE_LENGTH 1024
1898 #ifdef __FEATURE_DRIVING_MODE__
1899 int convert_app_err_to_email_err(int app_error)
1901 int err = EMAIL_ERROR_NONE;
1904 case SERVICE_ERROR_NONE :
1905 err = EMAIL_ERROR_NONE;
1907 case SERVICE_ERROR_INVALID_PARAMETER :
1908 err = EMAIL_ERROR_INVALID_PARAM;
1910 case SERVICE_ERROR_OUT_OF_MEMORY :
1911 err = EMAIL_ERROR_OUT_OF_MEMORY;
1914 err = EMAIL_ERROR_UNKNOWN;
1921 int emcore_start_driving_mode(int account_id) {
1922 EM_DEBUG_FUNC_BEGIN();
1924 int err = SERVICE_ERROR_NONE;
1926 char string_account[10] = { 0 };
1927 service_h service = NULL;
1929 if (vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_DRIVINGMODE, &tts_enable) != 0) {
1930 EM_DEBUG_EXCEPTION("vconf_get_int failed");
1934 EM_DEBUG_LOG("Driving Mode : [%d]", tts_enable);
1940 if (vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_NEWEMAILS, &tts_enable) != 0) {
1941 EM_DEBUG_EXCEPTION("vconf_get_int failed");
1945 EM_DEBUG_LOG("New emails of driving Mode : [%d]", tts_enable);
1950 SNPRINTF(string_account, sizeof(string_account), "%d", account_id);
1952 err = service_create(&service);
1953 if (err != SERVICE_ERROR_NONE) {
1954 EM_DEBUG_EXCEPTION("service_create failed : [%d]", err);
1958 err = service_set_package(service, "com.samsung.email-tts-play");
1959 if (err != SERVICE_ERROR_NONE) {
1960 EM_DEBUG_EXCEPTION("service_set_package failed : [%d]", err);
1964 err = service_add_extra_data(service, "tts_email_account_id", string_account);
1965 if (err != SERVICE_ERROR_NONE) {
1966 EM_DEBUG_EXCEPTION("service_add_extra_data failed : [%d]", err);
1970 err = service_send_launch_request(service, NULL, NULL);
1971 if (err != SERVICE_ERROR_NONE) {
1972 EM_DEBUG_EXCEPTION("service_send_launch_request failed : [%d]", err);
1979 service_destroy(service);
1981 EM_DEBUG_FUNC_END();
1982 return convert_app_err_to_email_err(err);
1984 #endif /* __FEATURE_DRIVING_MODE__ */
1986 int emcore_update_notification_for_unread_mail(int account_id)
1988 EM_DEBUG_FUNC_BEGIN("acccount_id[%d]", account_id);
1990 int i, account_count = 0;
1991 int err = EMAIL_ERROR_NONE;
1992 emstorage_account_tbl_t *p_account_tbl = NULL;
1994 if (!emstorage_get_account_list(&account_count, &p_account_tbl, true, false, &err)) {
1995 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
1999 for (i = 0; i < account_count ; i++) {
2000 if ((err = emcore_add_notification(p_account_tbl[i].account_id, 0, EMAIL_ACTION_NUM)) != EMAIL_ERROR_NONE) {
2001 EM_DEBUG_EXCEPTION("emcore_add_notification failed : [%d]", err);
2005 if ((err = emcore_start_driving_mode(p_account_tbl[i].account_id)) != EMAIL_ERROR_NONE) {
2006 EM_DEBUG_EXCEPTION("emcore_start_driving_mode failed : [%d]", err);
2016 emstorage_free_account(&p_account_tbl, account_count, NULL);
2018 EM_DEBUG_FUNC_END();
2022 INTERNAL_FUNC int emcore_finalize_sync(int account_id, int *error)
2024 EM_DEBUG_FUNC_BEGIN("account_id [%d], error [%p]", account_id, error);
2025 int err = EMAIL_ERROR_NONE, ret = true, result_sync_status = SYNC_STATUS_FINISHED;
2027 if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE)
2028 EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err);
2030 if (!emstorage_get_sync_status_of_account(ALL_ACCOUNT, &result_sync_status, &err))
2031 EM_DEBUG_EXCEPTION("emstorage_get_sync_status_of_account failed [%d]", err);
2033 if (result_sync_status == SYNC_STATUS_HAVE_NEW_MAILS) {
2034 if (!emcore_update_notification_for_unread_mail(ALL_ACCOUNT))
2035 EM_DEBUG_EXCEPTION("emcore_update_notification_for_unread_mail failed");
2037 if (!emcore_display_unread_in_badge())
2038 EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed");
2040 emcore_start_alert();
2042 #ifdef __FEATURE_BLOCKING_MODE__
2043 emcore_set_blocking_mode_status(false);
2044 #endif /* __FEATURE_BLOCKING_MODE__ */
2046 if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE)
2047 EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err);
2050 EM_DEBUG_FUNC_END();
2054 INTERNAL_FUNC int emcore_clear_all_notifications()
2056 int account_count = 0, i;
2057 emstorage_account_tbl_t *account_list;
2058 int error_code = EMAIL_ERROR_NONE;
2060 if(!emstorage_get_account_list(&account_count, &account_list, true, false, &error_code)) {
2061 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed");
2065 for(i = 0; i < account_count; i++) {
2066 emcore_delete_notification_by_account(account_list[i].account_id);
2071 emstorage_free_account(&account_list, account_count, NULL);
2074 EM_DEBUG_FUNC_END("return[%d]", error_code);
2078 #define EAS_EXECUTABLE_PATH "/usr/bin/eas-engine"
2080 INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id)
2082 EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
2083 int error_code = EMAIL_ERROR_NONE;
2085 char vconf_private_id[MAX_PATH] = {0, };
2087 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
2088 if (vconf_get_int(vconf_private_id, &private_id) != 0) {
2089 EM_DEBUG_EXCEPTION("vconf_get_int failed");
2091 EM_DEBUG_FUNC_END();
2095 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
2098 * @fn emcore_convert_to_uid_range_set(email_id_set_t* id_set, int id_set_count, email_uid_range_set **uid_range_set, int range_len, int *err_code)
2099 * Prepare a linked list of uid ranges with each node having a uid_range and lowest and highest uid in it.
2101 *@author h.gahlaut@samsung.com
2102 * @param[in] id_set Specifies the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
2103 * @param[in] id_set_count Specifies the no. of cells in id_set array i.e. no. of sets of mail_ids and server_mail_ids
2104 * @param[in] range_len Specifies the maximum length of string of range allowed.
2105 * @param[out] uid_range_set Returns the uid_ranges formed in the form of a linked list with head stored in uid_range_set pointer
2106 * @param[out] err_code Returns the error code.
2107 * @remarks An example of a uid_range formed is 2:6,8,10,14:15,89,
2108 * While using it the caller should remove the ending, (comma)
2109 * @return This function returns true on success or false on failure.
2112 INTERNAL_FUNC int emcore_convert_to_uid_range_set(email_id_set_t *id_set, int id_set_count, email_uid_range_set **uid_range_set, int range_len, int *err_code)
2114 EM_DEBUG_FUNC_BEGIN();
2117 int error = EMAIL_ERROR_NONE;
2119 if (NULL == id_set || id_set_count <= 0 || NULL == uid_range_set) {
2120 EM_DEBUG_EXCEPTION(" Invalid Parameter id_set[%p] id_set_count[%d] uid_range_set[%p]", id_set, id_set_count, uid_range_set);
2121 error = EMAIL_ERROR_INVALID_PARAM;
2126 unsigned long current_uid = 0;
2127 unsigned long first_uid = 0;
2128 unsigned long last_uid = 0;
2129 const int max_subset_string_size = MAX_SUBSET_STRING_SIZE;
2130 char subset_string[MAX_SUBSET_STRING_SIZE] = {0,};
2131 email_uid_range_set *current_node = NULL; /* current_node denotes the current node under processing in the linked list of uid_range_set that is to be formed*/
2133 if (range_len < (max_subset_string_size + 1)) /* 1 for ending NULL character */ {
2134 EM_DEBUG_EXCEPTION(" Invalid Parameter range_len[%d]", range_len);
2135 error = EMAIL_ERROR_INVALID_PARAM;
2139 EM_DEBUG_LOG("id set count[%d] range_len[%d]", id_set_count, range_len);
2142 first_uid = last_uid = current_uid = id_set[i].server_mail_id;
2143 /* Start subset string by putting first server mail id in it from id_set*/
2144 memset(subset_string, 0x00, max_subset_string_size);
2145 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
2148 /* Check if only one server mail id was left in id_set */
2149 if (i >= id_set_count) {
2150 /* No more server mail id left in id_set */
2151 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
2152 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
2158 /* More server mail id are present in id_set. Find out if first:last_uid is to be formed or only first_uid will be subset string */
2160 current_uid = id_set[i].server_mail_id;
2161 if (current_uid == (last_uid + 1)) {
2162 last_uid = current_uid;
2166 memset(subset_string, 0x00, max_subset_string_size);
2167 if (first_uid != last_uid) /* Form subset string by first_uid:last_uid */
2168 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
2169 else /* Form subset string by first_uid */
2170 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
2172 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
2173 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
2176 /* To Start formation of new subset string break out of inner loop */
2180 } while (i < id_set_count);
2182 /* Flow comes here in two cases :
2183 1. id_set ended and has continuous numbers at end of id_set so form subset string by first_uid:last_uid . in this case last_uid == current_uid
2184 2. due to break statement */
2186 if (last_uid == current_uid) {
2189 memset(subset_string, 0x00, max_subset_string_size);
2190 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
2192 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
2193 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
2198 /* Case 2: Do Nothing */
2202 } while (i < id_set_count);
2207 if (NULL != err_code)
2209 EM_DEBUG_FUNC_END();
2215 * @fn emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_range_set **uid_range_set, int range_len, unsigned long luid, unsigned long huid)
2216 * Appends the subset_string to uid range if the uid range has not exceeded maximum length(range_len), otherwise creates a new node in linked list of uid range set
2217 * and stores the subset_string in its uid_range. Also sets the lowest and highest uids for the corresponsing uid_range
2219 * @author h.gahlaut@samsung.com
2220 * @param[in] subset_string Specifies the subset string to be appended. A subset string can be like X:Y or X where X and Y are uids.
2221 * @param[in] range_len Specifies the maximum length of range string allowed.
2222 * @param[in] luid Specifies the lowest uid in subset string
2223 * @param[in] huid Specifies the highest uid in subset string
2224 * @param[out] uid_range_set Returns the uid_ranges formed in the form of a linked list with head stored in uid_range_set pointer
2225 * @param[out] err_code Returns the error code.
2227 * @return This function returns true on success or false on failure.
2230 int emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_range_set **current_node_adr, email_uid_range_set **uid_range_set, int range_len, unsigned long luid, unsigned long huid)
2232 EM_DEBUG_FUNC_BEGIN();
2233 email_uid_range_set *current_node = NULL;
2235 if (NULL == (*uid_range_set)) {
2236 /*This happens only once when list creation starts. Head Node is allocated */
2237 current_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
2238 if (NULL == current_node) {
2239 EM_DEBUG_EXCEPTION("em_malloc failed");
2243 current_node->uid_range = (char *)em_malloc(range_len);
2245 if (NULL == current_node->uid_range) {
2246 EM_DEBUG_EXCEPTION("em_malloc failed");
2247 EM_SAFE_FREE(current_node);
2251 SNPRINTF(current_node->uid_range, range_len, "%s,", subset_string);
2253 current_node->lowest_uid = luid;
2254 current_node->highest_uid = huid;
2255 (*uid_range_set) = current_node;
2257 (*current_node_adr) = current_node;
2261 /* Apart from first call to this function flow will always come here */
2262 current_node = (*current_node_adr);
2263 int len_sub_string = EM_SAFE_STRLEN(subset_string);
2264 int space_left_in_buffer = range_len - EM_SAFE_STRLEN(current_node->uid_range);
2266 if ((len_sub_string + 1 + 1) <= space_left_in_buffer) /* 1 for comma + 1 for ending null character */ {
2267 SNPRINTF(current_node->uid_range + EM_SAFE_STRLEN(current_node->uid_range), space_left_in_buffer, "%s,", subset_string);
2268 current_node->highest_uid = huid;
2271 /* No more space left in uid_range string.If continued on it, it will exceeded max size of range_len */
2272 /* Allocate new node in Uid Range set */
2273 email_uid_range_set *new_node = NULL;
2275 new_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
2277 if (NULL == new_node) {
2278 EM_DEBUG_EXCEPTION("em_malloc failed");
2282 /* Allocate uid_range of new node */
2284 new_node->uid_range = (char *)em_malloc(range_len);
2286 if (NULL == new_node->uid_range) {
2287 EM_DEBUG_EXCEPTION("em_malloc failed");
2288 EM_SAFE_FREE(new_node);
2292 SNPRINTF(new_node->uid_range, range_len, "%s, ", subset_string);
2294 new_node->lowest_uid = luid;
2295 new_node->highest_uid = huid;
2297 current_node->next = new_node;
2299 (*current_node_adr) = new_node;
2302 EM_DEBUG_FUNC_END();
2307 * void emcore_free_uid_range_set(email_uid_range_set **uid_range_head)
2308 * Frees the linked list of uid ranges
2310 * @author h.gahlaut@samsung.com
2311 * @param[in] uid_range_head Head pointer of linked list of uid ranges
2313 * @return This function does not return anything.
2317 void emcore_free_uid_range_set(email_uid_range_set **uid_range_set)
2319 EM_DEBUG_FUNC_BEGIN();
2321 email_uid_range_set *current_node = NULL;
2322 email_uid_range_set *uid_range_head = NULL;
2324 current_node = uid_range_head = (*uid_range_set); /* Make the current node and head ptr point to starting of uid_range_set */
2326 while (current_node) {
2327 uid_range_head = current_node->next; /* Move the head ptr to next node*/
2329 EM_SAFE_FREE(current_node->uid_range);
2330 EM_SAFE_FREE(current_node); /* Free the current node */
2332 current_node = uid_range_head; /* Make the current node point to head ptr */
2335 (*uid_range_set) = NULL;
2336 EM_DEBUG_FUNC_END();
2341 * @fn emcore_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char *** strings, int *string_count, int *err_code)
2342 * Forms comma separated strings of a give max_string_len from an array of numbers
2344 * @author h.gahlaut@samsung.com
2345 * @param[in] numbers Specifies the array of numbers to be converted into comma separated strings.
2346 * @param[in] num_count Specifies the count of numbers in numbers array.
2347 * @param[in] max_string_len Specifies the maximum length of comma separated strings that are to be formed.
2348 * @param[out] strings Returns the base address of a double dimension array which stores the strings.
2349 * @param[out] string_count Returns the number of strings formed.
2350 * @param[out] err_code Returns the error code.
2351 * @remarks If Input to the function is five numbers like 2755 2754 2748 2749 2750 and a given max_string_len is 20.
2352 * Then this function will form two comma separated strings as follows -
2353 * "2755, 2754, 2748"
2355 * @return This function returns true on success or false on failure.
2358 INTERNAL_FUNC int emcore_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char *** strings, int *string_count, int *err_code)
2360 EM_DEBUG_FUNC_BEGIN();
2362 int error = EMAIL_ERROR_NONE;
2365 char **string_list = NULL;
2366 int num_of_strings = 0;
2369 char num[MAX_INTEGER_LENGTH + 1] = {0, };
2371 int space_in_buffer = 0;
2372 int len_of_string_formed = 0;
2374 if (NULL == numbers || num_count <= 0 || \
2375 max_string_len < (MAX_INTEGER_LENGTH + 2)|| NULL == strings || NULL == string_count) /* 32767, is the highest integer possible in string.This requires 7 bytes of storage in character type array (1 byte for ending NULL and 1 byte for ending comma) so max_string_len should not be less than worst case possible. */ {
2376 EM_DEBUG_EXCEPTION("Invalid Parameter numbers[%p] num_count [%d] max_string_len [%d] strings [%p] string_count[%p]", \
2377 numbers, num_count, max_string_len, strings, string_count);
2378 error = EMAIL_ERROR_INVALID_PARAM;
2382 EM_DEBUG_LOG("num_count [%d] max_string_len [%d]", num_count, max_string_len);
2384 string_list = em_malloc(sizeof(char *));
2386 if (NULL == string_list) {
2387 EM_DEBUG_EXCEPTION("em_malloc failed ");
2391 string_list[num_of_strings] = em_malloc(max_string_len);
2393 if (NULL == string_list[num_of_strings]) {
2394 EM_DEBUG_EXCEPTION("em_malloc failed ");
2399 space_in_buffer = max_string_len;
2401 for (j = 0; j < num_count;++j) {
2402 memset(num, 0x00, MAX_INTEGER_LENGTH + 1);
2403 SNPRINTF(num, MAX_INTEGER_LENGTH + 1, "%d", numbers[j]);
2405 num_len = EM_SAFE_STRLEN(num);
2407 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
2409 space_in_buffer = max_string_len - len_of_string_formed ;
2411 if (space_in_buffer >= (num_len+1+1)) /* 1 for comma and 1 for ending NULL */ {
2412 SNPRINTF(string_list[num_of_strings - 1] + len_of_string_formed, max_string_len, "%d,", numbers[j]);
2414 else { /* Removing comma at end of string */
2415 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
2417 temp = (char **)realloc(string_list, sizeof(char *) * (num_of_strings + 1)); /* Allocate new buffer to store a pointer to a new string */
2420 EM_DEBUG_EXCEPTION("realloc failed");
2424 memset(temp + num_of_strings, 0X00, sizeof(char *));
2428 string_list[num_of_strings] = em_malloc(max_string_len);/* Allocate new buffer to store the string */
2430 if (NULL == string_list[num_of_strings]) {
2431 EM_DEBUG_EXCEPTION(" em_malloc failed ");
2435 SNPRINTF(string_list[num_of_strings - 1] , max_string_len, "%d,", numbers[j]);/* Start making new string */
2439 /* Removing comma at end of string */
2440 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
2441 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
2447 emcore_free_comma_separated_strings(&string_list, &num_of_strings);
2450 for (i = 0; i < num_of_strings;++i)
2451 EM_DEBUG_LOG("%s", string_list[i]);
2452 *strings = string_list;
2453 *string_count = num_of_strings;
2457 if (NULL != err_code)
2460 EM_DEBUG_FUNC_END("ret [%d]", ret);
2464 * @fn emcore_free_comma_separated_strings(char *** string_list, int *string_count)
2465 * Frees the double dimensional array of strings.
2467 * @author h.gahlaut@samsung.com
2468 * @param[in] uid_range_head Address of base address of double dimensional array of strings.
2469 * @param[in] string_count Address of variable holding the count of strings.
2471 * @return This function does not return anything.
2473 INTERNAL_FUNC void emcore_free_comma_separated_strings(char *** string_list, int *string_count)
2475 EM_DEBUG_FUNC_BEGIN();
2477 char **str_list = NULL;
2480 if (NULL != string_list) {
2481 str_list = *string_list;
2483 if (0 != *string_count) {
2484 count = *string_count;
2485 for (i = 0; i < count; ++i)
2486 EM_SAFE_FREE(str_list[i]);
2489 EM_SAFE_FREE(str_list);
2490 *string_list = NULL; /* This makes the pointer to be freed as NULL in calling function and saves it from being a dangling pointer for sometime in calling function */
2493 EM_DEBUG_FUNC_END();
2502 int emcore_make_attachment_file_name_with_extension(char *source_file_name, char *sub_type, char *result_file_name, int result_file_name_buffer_length, int *err_code)
2504 EM_DEBUG_FUNC_BEGIN("source_file_name[%s], sub_type[%s], result_file_name_buffer_length[%d] ", source_file_name, sub_type, result_file_name_buffer_length);
2505 int ret = false, err = EMAIL_ERROR_NONE;
2506 char *extcheck = NULL;
2507 char attachment_file_name[MAX_PATH + 1] = { 0, };
2509 if (!source_file_name || !result_file_name) {
2510 EM_DEBUG_EXCEPTION("Invalid Parameter");
2511 err = EMAIL_ERROR_INVALID_PARAM;
2515 strncpy(attachment_file_name, source_file_name, MAX_PATH);
2516 extcheck = strchr(attachment_file_name, '.');
2519 EM_DEBUG_LOG("Extension Exist in the Attachment [%s] ", extcheck);
2520 else { /* No extension attached, So add the Extension based on the subtype */
2522 strcat(attachment_file_name, ".");
2523 strcat(attachment_file_name, sub_type);
2524 EM_DEBUG_LOG("attachment_file_name with extension[%s] ", attachment_file_name);
2527 EM_DEBUG_LOG("UnKnown Extesnsion");
2530 memset(result_file_name, 0 , result_file_name_buffer_length);
2531 EM_SAFE_STRNCPY(result_file_name, attachment_file_name, result_file_name_buffer_length - 1);
2532 EM_DEBUG_LOG("*result_file_name[%s]", result_file_name);
2538 EM_DEBUG_FUNC_END();
2542 #ifdef __FEATURE_LOCAL_ACTIVITY__
2543 INTERNAL_FUNC int emcore_add_activity(emstorage_activity_tbl_t *new_activity, int *err_code)
2545 EM_DEBUG_FUNC_BEGIN();
2547 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", new_activity, err_code);
2549 /* default variable */
2551 int err = EMAIL_ERROR_NONE;
2553 if (!new_activity) {
2554 EM_DEBUG_LOG("\t new_activity[%p]\n", new_activity);
2555 err = EMAIL_ERROR_INVALID_PARAM;
2558 if (!emstorage_add_activity(new_activity, false, &err)) {
2559 EM_DEBUG_LOG("\t emstorage_add_activity falied - %d\n", err);
2572 INTERNAL_FUNC int emcore_delete_activity(emstorage_activity_tbl_t *activity, int *err_code)
2574 EM_DEBUG_FUNC_BEGIN();
2576 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", activity, err_code);
2578 /* default variable */
2580 int err = EMAIL_ERROR_NONE;
2582 EM_DEBUG_LOG("\t new_activity[%p]\n", activity);
2584 err = EMAIL_ERROR_INVALID_PARAM;
2587 if (!emstorage_delete_local_activity(activity, true, &err)) {
2588 EM_DEBUG_LOG("\t emstorage_delete_local_activity falied - %d\n", err);
2601 INTERNAL_FUNC int emcore_get_next_activity_id(int *activity_id, int *err_code)
2603 EM_DEBUG_FUNC_BEGIN();
2606 int err = EMAIL_ERROR_NONE;
2608 if (NULL == activity_id)
2610 EM_DEBUG_EXCEPTION("\t activity_id[%p]", activity_id);
2612 err = EMAIL_ERROR_INVALID_PARAM;
2616 if (false == emstorage_get_next_activity_id(activity_id, &err)) {
2617 EM_DEBUG_LOG("\t emstorage_get_next_activity_id failed - %d\n", err);
2624 if (NULL != err_code) {
2632 #endif /* __FEATURE_LOCAL_ACTIVITY__ */
2635 INTERNAL_FUNC void emcore_free_rule(email_rule_t* rule)
2637 EM_DEBUG_FUNC_BEGIN();
2642 EM_SAFE_FREE(rule->value);
2644 EM_DEBUG_FUNC_END();
2647 INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_string, int *result)
2649 EM_DEBUG_FUNC_BEGIN("file_path : [%s], search_string : [%s]", file_path, search_string);
2650 int error = EMAIL_ERROR_NONE;
2652 int p_result = false;
2655 char *stripped = NULL;
2657 if (!search_string || !file_path || !result) {
2658 EM_DEBUG_EXCEPTION("Invalid parameter");
2659 error = EMAIL_ERROR_INVALID_PARAM;
2663 fp = fopen(file_path, "r");
2665 EM_DEBUG_EXCEPTION("fopen failed");
2666 error = EMAIL_ERROR_SYSTEM_FAILURE;
2670 if (!emcore_get_file_size(file_path, &file_size, &error)) {
2671 EM_DEBUG_EXCEPTION("emcore_get_file_size failed");
2675 buf = em_malloc(file_size);
2677 EM_DEBUG_EXCEPTION("em_malloc failed");
2678 error = EMAIL_ERROR_OUT_OF_MEMORY;
2682 if (fread(buf, sizeof(char), file_size, fp) != file_size) {
2683 EM_DEBUG_EXCEPTION("Get the data from file : failed");
2684 error = EMAIL_ERROR_SYSTEM_FAILURE;
2689 stripped = em_replace_all_string(buf, CRLF_STRING, "");
2690 if (strstr(stripped, search_string))
2695 EM_DEBUG_LOG("Search string[%s] not found",search_string);
2703 EM_SAFE_FREE(stripped); /*prevent 35586*/
2705 EM_DEBUG_FUNC_END("error:[%d]", error);
2709 INTERNAL_FUNC int emcore_load_query_from_file(char *file_path, char ***query_array, int *array_len)
2711 EM_DEBUG_FUNC_BEGIN("file_path : [%s], query_array : [%p]", file_path, *query_array);
2712 int error = EMAIL_ERROR_NONE;
2718 char **result_vector = NULL;
2721 EM_DEBUG_EXCEPTION("Invalid parameter");
2722 error = EMAIL_ERROR_INVALID_PARAM;
2726 fp = fopen(file_path, "r");
2728 EM_DEBUG_EXCEPTION("fopen failed");
2729 error = EMAIL_ERROR_SYSTEM_FAILURE;
2733 if (!emcore_get_file_size(file_path, &file_size, &error)) {
2734 EM_DEBUG_EXCEPTION("emcore_get_file_size failed");
2738 buf = em_malloc(file_size);
2740 EM_DEBUG_EXCEPTION("em_malloc failed");
2741 error = EMAIL_ERROR_OUT_OF_MEMORY;
2745 if (fread(buf, sizeof(char), file_size, fp) != file_size) {
2746 EM_DEBUG_EXCEPTION("Get the data from file : failed");
2747 error = EMAIL_ERROR_SYSTEM_FAILURE;
2751 result_vector = g_strsplit(buf, ";", -1);
2752 if (!result_vector || g_strv_length(result_vector) <= 0) {
2753 EM_DEBUG_EXCEPTION("Parsing sql file failed");
2754 error = EMAIL_ERROR_SYSTEM_FAILURE;
2758 vector_len = g_strv_length(result_vector);
2759 if (vector_len <= 0) {
2760 EM_DEBUG_EXCEPTION("vector length : [%d]", vector_len);
2761 error = EMAIL_ERROR_SYSTEM_FAILURE;
2765 *query_array = (char **)calloc(vector_len, sizeof(char *));
2767 for (i = 0; i < vector_len; i++) {
2768 if (result_vector[i]) {
2769 char *str = g_strconcat(result_vector[i], ";", NULL);
2770 (*query_array)[i] = str;
2775 *array_len = vector_len;
2776 EM_DEBUG_LOG("SQL string array length : [%d]", vector_len);
2786 if (result_vector) {
2787 g_strfreev(result_vector);
2790 EM_DEBUG_FUNC_END("error:[%d]", error);
2794 static int convert_contact_err_to_email_err(int contact_err)
2796 int err = EMAIL_ERROR_NONE;
2798 switch (contact_err) {
2799 case CONTACTS_ERROR_NONE :
2800 err = EMAIL_ERROR_NONE;
2802 case CONTACTS_ERROR_OUT_OF_MEMORY :
2803 err = EMAIL_ERROR_OUT_OF_MEMORY;
2805 case CONTACTS_ERROR_INVALID_PARAMETER :
2806 err = EMAIL_ERROR_INVALID_PARAM;
2808 case CONTACTS_ERROR_NO_DATA :
2809 err = EMAIL_ERROR_DATA_NOT_FOUND;
2811 case CONTACTS_ERROR_DB :
2812 err = EMAIL_ERROR_DB_FAILURE;
2814 case CONTACTS_ERROR_IPC :
2815 err = EMAIL_ERROR_IPC_CONNECTION_FAILURE;
2817 case CONTACTS_ERROR_SYSTEM:
2818 err = EMAIL_ERROR_SYSTEM_FAILURE;
2820 case CONTACTS_ERROR_INTERNAL:
2822 err = EMAIL_ERROR_UNKNOWN;
2828 int emcore_get_mail_contact_info(email_mail_contact_info_t *contact_info, char *full_address, int *err_code)
2830 EM_DEBUG_FUNC_BEGIN("contact_info[%p], full_address[%s], err_code[%p]", contact_info, full_address, err_code);
2833 int err = EMAIL_ERROR_NONE;
2835 if (!emcore_get_mail_contact_info_with_update(contact_info, full_address, 0, &err))
2836 EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info_with_update failed [%d]", err);
2840 if (err_code != NULL)
2846 int emcore_search_contact_info(const char *contact_uri, int address_property_id, char *address, int favorite_property_id, bool is_favorite, int limit, contacts_record_h *contacts_record)
2848 EM_DEBUG_FUNC_BEGIN();
2849 int contact_err = CONTACTS_ERROR_NONE;
2851 contacts_query_h query = NULL;
2852 contacts_filter_h filter = NULL;
2853 contacts_list_h list = NULL;
2855 if ((contact_err = contacts_query_create(contact_uri, &query)) != CONTACTS_ERROR_NONE) {
2856 EM_DEBUG_EXCEPTION("contacts_query_create failed");
2860 if ((contact_err = contacts_filter_create(contact_uri, &filter)) != CONTACTS_ERROR_NONE) {
2861 EM_DEBUG_EXCEPTION("contacts_filter_create failed");
2865 if ((contact_err = contacts_filter_add_str(filter, address_property_id, CONTACTS_MATCH_EXACTLY, address)) != CONTACTS_ERROR_NONE) {
2866 EM_DEBUG_EXCEPTION("contacts_filter_add_str failed");
2870 if ((contact_err = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND)) != CONTACTS_ERROR_NONE) {
2871 EM_DEBUG_EXCEPTION("contacts_filter_add_operator failed");
2875 if ((contact_err = contacts_filter_add_bool(filter, favorite_property_id, is_favorite)) != CONTACTS_ERROR_NONE) {
2876 EM_DEBUG_EXCEPTION("contacts_filter_add_bool failed");
2880 if ((contact_err = contacts_query_set_filter(query, filter)) != CONTACTS_ERROR_NONE) {
2881 EM_DEBUG_EXCEPTION("contacts_query_set_filter failed");
2885 if ((contact_err = contacts_db_get_records_with_query(query, 0, limit, &list)) != CONTACTS_ERROR_NONE) {
2886 EM_DEBUG_EXCEPTION("contacts_db_get_record_with_query failed");
2890 if ((contact_err = contacts_list_get_current_record_p(list, contacts_record)) != CONTACTS_ERROR_NONE) {
2891 EM_DEBUG_EXCEPTION("contacts_list_get_current_record_p failed");
2898 contacts_query_destroy(query);
2901 contacts_filter_destroy(filter);
2904 contacts_list_destroy(list, false);
2909 int emcore_search_contact_info_by_address(const char *contact_uri, int property_id, char *address, int limit, contacts_record_h *contacts_record)
2911 EM_DEBUG_FUNC_BEGIN();
2912 int contact_err = CONTACTS_ERROR_NONE;
2914 contacts_query_h query = NULL;
2915 contacts_filter_h filter = NULL;
2916 contacts_list_h list = NULL;
2918 if ((contact_err = contacts_query_create(contact_uri, &query)) != CONTACTS_ERROR_NONE) {
2919 EM_DEBUG_EXCEPTION("contacts_query_create failed");
2923 if ((contact_err = contacts_filter_create(contact_uri, &filter)) != CONTACTS_ERROR_NONE) {
2924 EM_DEBUG_EXCEPTION("contacts_filter_create failed");
2928 if ((contact_err = contacts_filter_add_str(filter, property_id, CONTACTS_MATCH_EXACTLY, address)) != CONTACTS_ERROR_NONE) {
2929 EM_DEBUG_EXCEPTION("contacts_filter_add_str failed");
2933 if ((contact_err = contacts_query_set_filter(query, filter)) != CONTACTS_ERROR_NONE) {
2934 EM_DEBUG_EXCEPTION("contacts_query_set_filter failed");
2938 if ((contact_err = contacts_db_get_records_with_query(query, 0, limit, &list)) != CONTACTS_ERROR_NONE) {
2939 EM_DEBUG_EXCEPTION("contacts_db_get_record_with_query failed");
2943 if ((contact_err = contacts_list_get_current_record_p(list, contacts_record)) != CONTACTS_ERROR_NONE) {
2944 EM_DEBUG_EXCEPTION("contacts_list_get_current_record_p failed");
2951 contacts_query_destroy(query);
2954 contacts_filter_destroy(filter);
2957 contacts_list_destroy(list, false);
2962 int emcore_set_contacts_log(int account_id, char *email_address, char *subject, time_t date_time, email_action_t action)
2964 EM_DEBUG_FUNC_BEGIN("account_id : [%d], address : [%p], subject : [%s], action : [%d], date_time : [%d]", account_id, email_address, subject, action, (int)date_time);
2966 int err = EMAIL_ERROR_NONE;
2967 int contacts_error = CONTACTS_ERROR_NONE;
2969 int action_type = 0;
2971 contacts_record_h phone_record = NULL;
2972 contacts_record_h person_record = NULL;
2974 if ((contacts_error = contacts_connect2()) != CONTACTS_ERROR_NONE) {
2975 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
2979 if ((contacts_error = contacts_record_create(_contacts_phone_log._uri, &phone_record)) != CONTACTS_ERROR_NONE) {
2980 EM_DEBUG_EXCEPTION("contacts_query_create failed [%d]", contacts_error);
2984 /* Set email address */
2985 if ((contacts_error = contacts_record_set_str(phone_record, _contacts_phone_log.address, email_address)) != CONTACTS_ERROR_NONE) {
2986 EM_DEBUG_EXCEPTION("contacts_record_set_str [address] failed [%d]", contacts_error);
2990 /* Search contact person info */
2991 if ((contacts_error = emcore_search_contact_info_by_address(_contacts_person_email._uri, _contacts_person_email.email, email_address, 1, &person_record)) != CONTACTS_ERROR_NONE) {
2992 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contacts_error);
2993 EM_DEBUG_LOG("Not match person");
2995 /* Get person_id in contacts_person_email record */
2996 if (person_record && (contacts_error = contacts_record_get_int(person_record, _contacts_person_email.person_id, &person_id)) != CONTACTS_ERROR_NONE) {
2997 EM_DEBUG_EXCEPTION("contacts_record_get_str failed [%d]", contacts_error);
3001 /* Set the person id */
3002 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.person_id, person_id)) != CONTACTS_ERROR_NONE) {
3003 EM_DEBUG_EXCEPTION("contacts_record_set_int [person id] failed [%d]", contacts_error);
3009 case EMAIL_ACTION_SEND_MAIL :
3010 action_type = CONTACTS_PLOG_TYPE_EMAIL_SENT;
3012 case EMAIL_ACTION_SYNC_HEADER :
3013 action_type = CONTACTS_PLOG_TYPE_EMAIL_RECEIVED;
3016 EM_DEBUG_EXCEPTION("Unknown action type");
3021 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.log_type, action_type)) != CONTACTS_ERROR_NONE) {
3022 EM_DEBUG_EXCEPTION("contacts_record_set_int [log_type] failed [%d]", contacts_error);
3027 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.log_time, (int)date_time)) != CONTACTS_ERROR_NONE) {
3028 EM_DEBUG_EXCEPTION("contacts_record_set_str [address] failed [%d]", contacts_error);
3033 if ((contacts_error = contacts_record_set_str(phone_record, _contacts_phone_log.extra_data2, subject)) != CONTACTS_ERROR_NONE) {
3034 EM_DEBUG_EXCEPTION("contacts_record_set_str [subject] failed [%d]", contacts_error);
3039 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.extra_data1, account_id)) != CONTACTS_ERROR_NONE) {
3040 EM_DEBUG_EXCEPTION("contacts_record_set_int [mail id] failed [%d]", contacts_error);
3044 /* Insert the record in DB */
3045 if ((contacts_error = contacts_db_insert_record(phone_record, NULL)) != CONTACTS_ERROR_NONE) {
3046 EM_DEBUG_EXCEPTION("contacts_db_insert_record failed [%d]",contacts_error );
3052 if (phone_record != NULL)
3053 contacts_record_destroy(phone_record, false);
3055 if (person_record != NULL)
3056 contacts_record_destroy(person_record, false);
3058 err = convert_contact_err_to_email_err(contacts_error);
3060 if ((contacts_error = contacts_disconnect2()) != CONTACTS_ERROR_NONE) {
3061 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
3062 err = convert_contact_err_to_email_err(contacts_error);
3065 EM_DEBUG_FUNC_END("err [%d]", err);
3069 INTERNAL_FUNC int emcore_set_sent_contacts_log(emstorage_mail_tbl_t *input_mail_data)
3071 EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
3074 int err = EMAIL_ERROR_NONE;
3075 char email_address[MAX_EMAIL_ADDRESS_LENGTH];
3076 char *address_array[3] = {input_mail_data->full_address_to, input_mail_data->full_address_cc, input_mail_data->full_address_bcc};
3077 ADDRESS *addr = NULL;
3078 ADDRESS *p_addr = NULL;
3080 for (i = 0; i < 3; i++) {
3081 if (address_array[i] && address_array[i][0] != 0) {
3082 rfc822_parse_adrlist(&addr, address_array[i], NULL);
3083 for (p_addr = addr ; p_addr ;p_addr = p_addr->next) {
3084 SNPRINTF(email_address, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", addr->mailbox, addr->host);
3085 if ((err = emcore_set_contacts_log(input_mail_data->account_id, email_address, input_mail_data->subject, input_mail_data->date_time, EMAIL_ACTION_SEND_MAIL)) != EMAIL_ERROR_NONE) {
3086 EM_DEBUG_EXCEPTION("emcore_set_contacts_log failed : [%d]", err);
3092 mail_free_address(&addr);
3101 mail_free_address(&addr);
3103 EM_DEBUG_FUNC_END("err [%d]", err);
3107 INTERNAL_FUNC int emcore_set_received_contacts_log(emstorage_mail_tbl_t *input_mail_data)
3109 EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
3110 int err = EMAIL_ERROR_NONE;
3112 if ((err = emcore_set_contacts_log(input_mail_data->account_id, input_mail_data->email_address_sender, input_mail_data->subject, input_mail_data->date_time, EMAIL_ACTION_SYNC_HEADER)) != EMAIL_ERROR_NONE) {
3113 EM_DEBUG_EXCEPTION("emcore_set_contacts_log failed [%d]", err);
3116 EM_DEBUG_FUNC_END("err [%d]", err);
3120 INTERNAL_FUNC int emcore_delete_contacts_log(int account_id)
3122 EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
3124 int err = EMAIL_ERROR_NONE;
3125 int contacts_error = CONTACTS_ERROR_NONE;
3127 if ((contacts_error = contacts_connect2()) != CONTACTS_ERROR_NONE) {
3128 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
3132 /* Delete record of the account id */
3133 if ((contacts_error = contacts_phone_log_delete(CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1, account_id)) != CONTACTS_ERROR_NONE) {
3134 EM_DEBUG_EXCEPTION("contacts_phone_log_delete failed [%d]", contacts_error);
3139 err = convert_contact_err_to_email_err(contacts_error);
3141 if ((contacts_error = contacts_disconnect2()) != CONTACTS_ERROR_NONE) {
3142 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
3143 err = convert_contact_err_to_email_err(contacts_error);
3146 EM_DEBUG_FUNC_END("err [%d]", err);
3150 INTERNAL_FUNC int emcore_get_mail_display_name(char *email_address, char **contact_display_name, int *err_code)
3152 EM_DEBUG_FUNC_BEGIN("contact_name_value[%s], contact_display_name[%p]", email_address, contact_display_name);
3154 int contact_err = 0;
3156 char *display = NULL;
3157 /* Contact variable */
3158 contacts_record_h record = NULL;
3160 if ((contact_err = contacts_connect2()) != CONTACTS_ERROR_NONE) {
3161 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contact_err);
3165 if ((contact_err = emcore_search_contact_info_by_address(_contacts_contact_email._uri, _contacts_contact_email.email, email_address, 1, &record)) != CONTACTS_ERROR_NONE) {
3166 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed");
3170 if ((contact_err = contacts_list_get_count(list, &list_count)) != CONTACTS_ERROR_NONE) {
3171 EM_DEBUG_EXCEPTION("contacts_list_get_count failed");
3175 if (list_count > 1) {
3176 EM_DEBUG_EXCEPTION("Duplicated contacts info");
3177 contact_err = CONTACTS_ERROR_INTERNAL;
3179 } else if (list_count == 0) {
3180 EM_DEBUG_EXCEPTION("Not found contact info");
3181 contact_err = CONTACTS_ERROR_NO_DATA;
3186 if (contacts_record_get_str(record, _contacts_contact_email.display_name, &display) != CONTACTS_ERROR_NONE) {
3187 EM_DEBUG_EXCEPTION("contacts_record_get_str failed");
3195 contacts_disconnect2();
3198 contacts_record_destroy(record, false);
3201 *contact_display_name = display;
3203 *contact_display_name = NULL;
3204 EM_SAFE_FREE(display);
3207 if (err_code != NULL)
3208 *err_code = convert_contact_err_to_email_err(contact_err);
3214 #ifdef __FEATURE_BLOCKING_MODE__
3216 #define ALLOWED_CONTACT_TYPE_NONE 0
3217 #define ALLOWED_CONTACT_TYPE_ALL 1
3218 #define ALLOWED_CONTACT_TYPE_FAVORITES 2
3219 #define ALLOWED_CONTACT_TYPE_CUSTOM 3
3221 static int blocking_mode_status = false;
3222 static int blocking_mode_of_setting = false;
3224 INTERNAL_FUNC bool emcore_init_blocking_mode_status()
3226 EM_DEBUG_FUNC_BEGIN("blocking_mode_of_setting : [%d]", blocking_mode_of_setting);
3228 if (vconf_get_bool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &blocking_mode_of_setting) != 0) {
3229 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
3233 EM_DEBUG_FUNC_END();
3237 INTERNAL_FUNC void emcore_set_blocking_mode_of_setting(int input_blocking_mode_of_setting)
3239 blocking_mode_of_setting = input_blocking_mode_of_setting;
3242 INTERNAL_FUNC int emcore_get_blocking_mode_status()
3244 return blocking_mode_status;
3247 INTERNAL_FUNC void emcore_set_blocking_mode_status(int blocking_mode)
3249 blocking_mode_status = blocking_mode;
3252 INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking_status)
3254 EM_DEBUG_FUNC_BEGIN();
3255 int err = EMAIL_ERROR_NONE;
3256 int contact_error = 0;
3258 int allowed_contact_type = 0; /* 0 : NONE, 1 : All contacts, 2 : Favorites, 3 : Custom */
3259 char *person_id_string = NULL;
3262 contacts_record_h record = NULL;
3264 if (!blocking_mode_of_setting) {
3265 EM_DEBUG_LOG("Blocking mode is OFF");
3269 if (vconf_get_int(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_TYPE, &allowed_contact_type) != 0) {
3270 EM_DEBUG_EXCEPTION("vconf_get_int failed");
3271 err = EMAIL_ERROR_SYSTEM_FAILURE;
3275 if ((contact_error = contacts_connect2()) != CONTACTS_ERROR_NONE) {
3276 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contact_error);
3280 switch (allowed_contact_type) {
3281 case ALLOWED_CONTACT_TYPE_NONE :
3282 EM_DEBUG_LOG("allowed_contact_type is none : bloacking all(notification)");
3283 *blocking_status = true;
3285 case ALLOWED_CONTACT_TYPE_ALL :
3286 EM_DEBUG_LOG("allowed_contact_type is ALL");
3287 /* Search the allowed contact type in contact DB */
3288 if ((contact_error = emcore_search_contact_info_by_address(_contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) {
3289 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed : [%d]", contact_error);
3293 if (record == NULL) {
3294 EM_DEBUG_LOG("No search contact info");
3298 *blocking_status = false;
3301 case ALLOWED_CONTACT_TYPE_FAVORITES :
3302 if ((contact_error = emcore_search_contact_info(_contacts_person_email._uri, _contacts_person_email.email, sender_address, _contacts_person_email.is_favorite, true, 1, &record)) != CONTACTS_ERROR_NONE) {
3303 EM_DEBUG_EXCEPTION("emcore_search_contact_info failed : [%d]", contact_error);
3307 if (record == NULL) {
3308 EM_DEBUG_LOG("No search contact info");
3312 *blocking_status = false;
3315 case ALLOWED_CONTACT_TYPE_CUSTOM :
3316 person_id_string = vconf_get_str(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_LIST);
3317 if (person_id_string == NULL) {
3318 EM_DEBUG_LOG("Custom allowed contact type is NULL");
3322 if ((contact_error = emcore_search_contact_info_by_address(_contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) {
3323 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed : [%d]", contact_error);
3327 if (record == NULL) {
3328 EM_DEBUG_LOG("No search contact info");
3332 if (contacts_record_get_int(record, _contacts_contact_email.person_id, &person_id) != CONTACTS_ERROR_NONE) {
3333 EM_DEBUG_EXCEPTION("contacts_record_get_str failed");
3337 token = strtok_r(person_id_string, ",", &str);
3339 if (person_id == atoi(token)) {
3340 *blocking_status = false;
3343 } while ((token = strtok_r(NULL, ",", &str)));
3348 EM_DEBUG_EXCEPTION("Invalid parameter : [%d]", allowed_contact_type);
3349 *blocking_status = true;
3350 err = EMAIL_ERROR_INVALID_PARAM;
3355 contacts_disconnect2();
3357 err = convert_contact_err_to_email_err(contact_error);
3359 EM_DEBUG_FUNC_END();
3363 #endif /* __FEATURE_BLOCKING_MODE__ */