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_EAS_DATA_TYPE || 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");
1406 *stripped_text = EM_SAFE_STRDUP(buf);
1410 EM_DEBUG_LOG("Extract the preview text, again");
1412 utf8_encoded_string = (char *)g_convert(buf, byte_read, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1413 if (utf8_encoded_string == NULL) {
1414 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d]", byte_read);
1415 *stripped_text = EM_SAFE_STRDUP(buf);
1421 *stripped_text = EM_SAFE_STRDUP(utf8_encoded_string);
1423 *stripped_text = EM_SAFE_STRDUP(buf);
1435 EM_SAFE_FREE(encoding_type);
1436 EM_SAFE_FREE(utf8_encoded_string);
1438 if (fp_html != NULL)
1441 if (fp_plain != NULL)
1444 EM_DEBUG_FUNC_END("ret [%d]", ret);
1450 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)
1452 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);
1454 int err = EMAIL_ERROR_NONE;
1455 unsigned int byte_read = 0;
1456 unsigned int byte_written = 0;
1457 int local_preview_buffer_length = 0;
1458 char *local_preview_text = NULL;
1459 char *encoding_type = NULL;
1460 char *utf8_encoded_string = NULL;
1461 FILE *fp_html = NULL;
1462 FILE *fp_plain = NULL;
1463 GError *glib_error = NULL;
1466 if (!output_preview_buffer) {
1467 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1468 err = EMAIL_ERROR_INVALID_PARAM;
1472 local_preview_buffer_length = input_preview_buffer_length * 2;
1474 if ( input_html_path ) { /*prevent 26249*/
1475 /* get preview text from html file */
1476 if( (err = em_get_encoding_type_from_file_path(input_html_path, &encoding_type)) != EMAIL_ERROR_NONE) {
1477 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
1481 if (stat(input_html_path, &st_buf) < 0) {
1482 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_html_path);
1483 err = EMAIL_ERROR_FILE_NOT_FOUND;
1487 if (!(fp_html = fopen(input_html_path, "r"))) {
1488 EM_DEBUG_EXCEPTION("fopen failed [%s]", input_html_path);
1489 err = EMAIL_ERROR_SYSTEM_FAILURE;
1493 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
1494 EM_DEBUG_LOG("input_html_file is empty size");
1495 err = EMAIL_ERROR_EMPTY_FILE;
1499 if (!(local_preview_text = (char*)em_malloc(sizeof(char) * (st_buf.st_size + 1)))) {
1500 EM_DEBUG_EXCEPTION("em_malloc failed");
1501 err = EMAIL_ERROR_OUT_OF_MEMORY;
1505 byte_read = fread(local_preview_text, sizeof(char), st_buf.st_size, fp_html);
1507 if(byte_read <= 0) { /*prevent 26249*/
1508 EM_SAFE_FREE(local_preview_text);
1509 if (ferror(fp_html)) {
1510 EM_DEBUG_EXCEPTION("fread failed [%s]", input_html_path);
1511 err = EMAIL_ERROR_SYSTEM_FAILURE;
1516 if ( (err = emcore_strip_HTML(local_preview_text)) != EMAIL_ERROR_NONE) {
1517 EM_DEBUG_EXCEPTION("emcore_strip failed");
1523 if ( !local_preview_text && input_plain_path) { /*prevent 26249*/
1524 /* get preview text from plain text file */
1525 if( (err = em_get_encoding_type_from_file_path(input_plain_path, &encoding_type)) != EMAIL_ERROR_NONE) {
1526 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
1530 memset(&st_buf, 0, sizeof(struct stat));
1531 if (stat(input_plain_path, &st_buf) < 0) {
1532 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_plain_path);
1533 err = EMAIL_ERROR_INVALID_MAIL;
1537 if (!(fp_plain = fopen(input_plain_path, "r"))) {
1538 EM_DEBUG_EXCEPTION("fopen failed [%s]", input_plain_path);
1539 err = EMAIL_ERROR_SYSTEM_FAILURE;
1543 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
1544 EM_DEBUG_LOG("input_text_file is empty size");
1545 err = EMAIL_ERROR_EMPTY_FILE;
1549 if (!(local_preview_text = (char*)em_malloc(sizeof(char) * local_preview_buffer_length))) {
1550 EM_DEBUG_EXCEPTION("em_malloc failed");
1554 byte_read = fread(local_preview_text, sizeof(char), local_preview_buffer_length - 1, fp_plain);
1556 if(byte_read <=0) { /*prevent 26249*/
1557 EM_SAFE_FREE(local_preview_text);
1558 err = EMAIL_ERROR_NULL_VALUE;
1559 if (ferror(fp_plain)) {
1560 EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path);
1561 err = EMAIL_ERROR_SYSTEM_FAILURE;
1565 reg_replace(local_preview_text, CR_STRING, " ");
1566 reg_replace(local_preview_text, LF_STRING, " ");
1567 reg_replace(local_preview_text, TAB_STRING, " ");
1570 if(local_preview_text) {
1571 em_trim_left(local_preview_text);
1572 if(encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
1573 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
1575 if (strcasecmp(encoding_type, "ks_c_5601-1987") == 0 ||
1576 strcasecmp(encoding_type, "ksc5601") == 0 ||
1577 strcasecmp(encoding_type, "cp949") == 0) {
1578 EM_SAFE_FREE(encoding_type);
1579 encoding_type = EM_SAFE_STRDUP("EUC-KR");
1582 utf8_encoded_string = (char*)g_convert (local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1584 if(utf8_encoded_string == NULL) {
1585 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d], EM_SAFE_STRLEN : [%d]", byte_read, EM_SAFE_STRLEN(local_preview_text));
1586 EM_DEBUG_LOG("Error is G_CONVERT_ERROR_ILLEGAL_SEQUENCE");
1588 if (!g_error_matches (glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
1589 EM_DEBUG_EXCEPTION("g_convert failed");
1593 EM_DEBUG_LOG("Extract the preview text, again");
1595 utf8_encoded_string = (char *)g_convert(local_preview_text, byte_read, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1596 if (utf8_encoded_string == NULL) {
1597 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d]", byte_read);
1602 EM_SAFE_FREE(local_preview_text);
1603 local_preview_text = utf8_encoded_string;
1609 if (local_preview_text != NULL)
1610 *output_preview_buffer = EM_SAFE_STRDUP(local_preview_text);
1612 EM_SAFE_FREE(local_preview_text);
1613 EM_SAFE_FREE(encoding_type);
1615 if (fp_html != NULL)
1618 if (fp_plain != NULL)
1621 EM_DEBUG_FUNC_END("err [%d]", err);
1625 INTERNAL_FUNC int emcore_add_transaction_info(int mail_id, int handle , int *err_code)
1627 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%d]", mail_id, handle);
1630 int err = EMAIL_ERROR_NONE ;
1631 em_transaction_info_type_t *pTransinfo = NULL ;
1632 em_transaction_info_type_t *pTemp = NULL;
1634 EM_DEBUG_LOG("g_transaction_info_list[%p]", g_transaction_info_list);
1635 pTransinfo = g_transaction_info_list ;
1637 if (!(pTemp = em_malloc(sizeof(em_transaction_info_type_t)))) {
1638 EM_DEBUG_EXCEPTION("malloc failed...");
1639 err = EMAIL_ERROR_OUT_OF_MEMORY;
1642 pTemp->mail_id = mail_id ;
1643 pTemp->handle = handle;
1646 pTransinfo = pTemp ;
1647 g_transaction_info_list = pTransinfo ;
1650 while (pTransinfo->next)
1651 pTransinfo = pTransinfo->next;
1652 pTransinfo->next = pTemp;
1660 EM_DEBUG_FUNC_END("g_transaction_info_list[%p]", g_transaction_info_list);
1664 INTERNAL_FUNC int emcore_get_handle_by_mailId_from_transaction_info(int mail_id, int *pHandle)
1666 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p]", mail_id, pHandle);
1669 em_transaction_info_type_t *pTransinfo = NULL ;
1671 if (g_transaction_info_list == NULL) {
1672 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
1675 pTransinfo = g_transaction_info_list;
1678 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
1679 if (pTransinfo->mail_id == mail_id) {
1680 *pHandle = pTransinfo->handle;
1682 EM_DEBUG_LOG("*pHandle[%d]", *pHandle);
1686 pTransinfo = pTransinfo->next ;
1687 }while (pTransinfo);
1688 EM_DEBUG_FUNC_END();
1692 INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id )
1694 EM_DEBUG_FUNC_BEGIN("mail_id[%d]", mail_id);
1696 em_transaction_info_type_t *pTransinfo ;
1697 em_transaction_info_type_t *pTemp = NULL;
1699 if (g_transaction_info_list == NULL) {
1700 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
1703 pTransinfo = g_transaction_info_list;
1705 EM_DEBUG_LOG("pTransinfo[%p]", pTransinfo);
1708 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
1709 if (pTransinfo->mail_id == mail_id) {
1710 pTemp = pTransinfo->next ;
1712 EM_SAFE_FREE(pTransinfo) ;
1713 g_transaction_info_list = NULL;
1716 pTransinfo->mail_id = pTransinfo->next->mail_id;
1717 pTransinfo->handle = pTransinfo->next->handle ;
1718 pTransinfo->next = pTransinfo->next->next;
1720 EM_SAFE_FREE(pTemp);
1725 pTransinfo = pTransinfo->next ;
1728 }while (pTransinfo);
1729 EM_DEBUG_FUNC_END();
1736 int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string)
1738 int error_code = EMAIL_ERROR_NONE;
1740 int so, n, nmatch, source_text_length, n_count = 1;
1741 regmatch_t *pmatch = NULL;
1742 regex_t reg_pattern;
1744 if(!input_source_text || !input_old_pattern_string || !input_new_string) {
1745 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1746 error_code = EMAIL_ERROR_INVALID_PARAM;
1750 source_text_length = EM_SAFE_STRLEN(input_source_text);
1752 if (regcomp(®_pattern, input_old_pattern_string, REG_EXTENDED | REG_ICASE) != 0) {
1753 EM_DEBUG_EXCEPTION("regcomp failed");
1757 nmatch = reg_pattern.re_nsub + 1;
1759 EM_DEBUG_LOG("nmatch [%d]", nmatch);
1762 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_DATA");
1763 error_code = EMAIL_ERROR_INVALID_DATA;
1767 pmatch = (regmatch_t*)em_malloc(sizeof(regmatch_t) * nmatch);
1769 if(pmatch == NULL) {
1770 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
1771 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
1775 for (pos = input_new_string; *pos ; pos++) {
1776 if (*pos == '\\' && *(pos + 1) > '0' && *(pos + 1) <= '9') {
1778 so = pmatch[*(pos + 1) - 48].rm_so;
1779 n = pmatch[*(pos + 1) - 48].rm_eo - so;
1781 EM_DEBUG_LOG("so [%d], n [%d]", so, n);
1783 if (so < 0 || EM_SAFE_STRLEN (input_new_string) + n - 1 > source_text_length)
1786 memmove (pos + n, pos + 2, EM_SAFE_STRLEN (pos) - 1);
1787 memmove (pos, input_source_text + so, n);
1792 for (pos = input_source_text; !regexec (®_pattern, pos, 1, pmatch, 0);) {
1793 n = pmatch[0].rm_eo - pmatch[0].rm_so;
1794 pos += pmatch[0].rm_so;
1796 memmove (pos + EM_SAFE_STRLEN (input_new_string), pos + n, EM_SAFE_STRLEN (pos) - n + 1);
1797 memmove (pos, input_new_string, EM_SAFE_STRLEN (input_new_string));
1798 pos += EM_SAFE_STRLEN (input_new_string);
1804 EM_SAFE_FREE(pmatch);
1805 regfree (®_pattern);
1807 EM_DEBUG_FUNC_END("error_code [%d]", error_code);
1812 int emcore_strip_HTML(char *source_string)
1814 EM_DEBUG_FUNC_BEGIN("source_string [%p]", source_string);
1816 int result = EMAIL_ERROR_NONE;
1818 /* strip out CR, LF */
1819 reg_replace(source_string, "(\r|\n)", "");
1821 /* strip out HEAD */
1822 reg_replace(source_string, "<head[^>]*>.*<*/head>", "");
1824 /* strip out STYLE */
1825 reg_replace(source_string, "<style[^>]*>.*<*/style>", "");
1827 /* strip out SCRIPT */
1828 reg_replace(source_string, "<script[^>]*>.*<*/script>", "");
1830 /* strip out ALL TAG & comment */
1831 reg_replace(source_string, "<[^>]*>", "");
1833 /* for remaining comment in some cases */
1834 reg_replace(source_string, "-->", "");
1836 /* strip out html entities */
1837 reg_replace(source_string, "&(quot|#34|#034);", "\"");
1838 reg_replace(source_string, "&(#35|#035);", "#");
1839 reg_replace(source_string, "&(#36|#036);", "$");
1840 reg_replace(source_string, "&(#37|#037);", "%");
1841 reg_replace(source_string, "&(amp|#38|#038);", "&");
1842 reg_replace(source_string, "&(lt|#60|#060);", "<");
1843 reg_replace(source_string, "&(gt|#62|#062);", ">");
1844 reg_replace(source_string, "&(#64|#064);", "@");
1845 reg_replace(source_string, "&(lsquo|rsquo);", "'");
1846 reg_replace(source_string, "&(ldquo|rdquo);", "\"");
1847 reg_replace(source_string, "‚", ",");
1848 reg_replace(source_string, "&(trade|#x2122);", "(TM)");
1850 /* strip out all type of spaces */
1851 reg_replace(source_string, "&(nbsp|#160);", " ");
1852 reg_replace(source_string, "[[:space:]]", " ");
1853 reg_replace(source_string, " +", " ");
1855 EM_DEBUG_FUNC_END();
1859 INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime)
1861 EM_DEBUG_FUNC_BEGIN("mailbox_name(%s) subject(%s), from(%s), uid(%s), datetime(%s)", mailbox_name, subject, from, uid, datetime);
1862 int error_code = EMAIL_ERROR_NONE;
1863 int param_length = 0;
1864 char *param_string = NULL;
1866 if (mailbox_name == NULL || subject == NULL || from == NULL || uid == NULL || datetime == NULL) {
1867 error_code = EMAIL_ERROR_INVALID_PARAM;
1868 EM_DEBUG_EXCEPTION("Invalid parameter, mailbox_name(%p), subject(%p), from(%p), uid(%p), datetime(%p)", mailbox_name, subject, from, uid, datetime);
1872 param_length = strlen(mailbox_name) + strlen(subject) + strlen(from) + strlen(uid) + strlen(datetime) + 5; /*prevent 34358*/
1874 param_string = em_malloc(param_length);
1875 if (param_string == NULL) {
1876 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
1877 EM_DEBUG_EXCEPTION("Memory allocation for 'param_string' is failed");
1881 memset(param_string, 0x00, param_length);
1883 SNPRINTF(param_string, param_length, "%s%c%s%c%s%c%s%c%s", mailbox_name, 0x01, subject, 0x01, from, 0x01, uid, 0x01, datetime);
1885 if (emcore_notify_network_event(NOTI_DOWNLOAD_NEW_MAIL, account_id, param_string, 0, 0) == 0) { /* failed */
1886 error_code = EMAIL_ERROR_UNKNOWN;
1887 EM_DEBUG_EXCEPTION("emcore_notify_network_event is failed");
1893 EM_SAFE_FREE(param_string);
1894 EM_DEBUG_FUNC_END();
1898 #define MAX_TITLE_LENGTH 1024
1900 #ifdef __FEATURE_DRIVING_MODE__
1901 int convert_app_err_to_email_err(int app_error)
1903 int err = EMAIL_ERROR_NONE;
1906 case SERVICE_ERROR_NONE :
1907 err = EMAIL_ERROR_NONE;
1909 case SERVICE_ERROR_INVALID_PARAMETER :
1910 err = EMAIL_ERROR_INVALID_PARAM;
1912 case SERVICE_ERROR_OUT_OF_MEMORY :
1913 err = EMAIL_ERROR_OUT_OF_MEMORY;
1916 err = EMAIL_ERROR_UNKNOWN;
1923 int emcore_start_driving_mode(int account_id) {
1924 EM_DEBUG_FUNC_BEGIN();
1926 int err = SERVICE_ERROR_NONE;
1928 char string_account[10] = { 0 };
1929 service_h service = NULL;
1931 if (vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_DRIVINGMODE, &tts_enable) != 0) {
1932 EM_DEBUG_EXCEPTION("vconf_get_int failed");
1936 EM_DEBUG_LOG("Driving Mode : [%d]", tts_enable);
1942 if (vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_NEWEMAILS, &tts_enable) != 0) {
1943 EM_DEBUG_EXCEPTION("vconf_get_int failed");
1947 EM_DEBUG_LOG("New emails of driving Mode : [%d]", tts_enable);
1952 SNPRINTF(string_account, sizeof(string_account), "%d", account_id);
1954 err = service_create(&service);
1955 if (err != SERVICE_ERROR_NONE) {
1956 EM_DEBUG_EXCEPTION("service_create failed : [%d]", err);
1960 err = service_set_package(service, "com.samsung.email-tts-play");
1961 if (err != SERVICE_ERROR_NONE) {
1962 EM_DEBUG_EXCEPTION("service_set_package failed : [%d]", err);
1966 err = service_add_extra_data(service, "tts_email_account_id", string_account);
1967 if (err != SERVICE_ERROR_NONE) {
1968 EM_DEBUG_EXCEPTION("service_add_extra_data failed : [%d]", err);
1972 err = service_send_launch_request(service, NULL, NULL);
1973 if (err != SERVICE_ERROR_NONE) {
1974 EM_DEBUG_EXCEPTION("service_send_launch_request failed : [%d]", err);
1981 service_destroy(service);
1983 EM_DEBUG_FUNC_END();
1984 return convert_app_err_to_email_err(err);
1986 #endif /* __FEATURE_DRIVING_MODE__ */
1988 int emcore_update_notification_for_unread_mail(int account_id)
1990 EM_DEBUG_FUNC_BEGIN("acccount_id[%d]", account_id);
1992 int i, account_count = 0;
1993 int err = EMAIL_ERROR_NONE;
1994 emstorage_account_tbl_t *p_account_tbl = NULL;
1996 if (!emstorage_get_account_list(&account_count, &p_account_tbl, true, false, &err)) {
1997 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
2001 for (i = 0; i < account_count ; i++) {
2002 if ((err = emcore_add_notification(p_account_tbl[i].account_id, 0, EMAIL_ACTION_NUM)) != EMAIL_ERROR_NONE) {
2003 EM_DEBUG_EXCEPTION("emcore_add_notification failed : [%d]", err);
2007 if ((err = emcore_start_driving_mode(p_account_tbl[i].account_id)) != EMAIL_ERROR_NONE) {
2008 EM_DEBUG_EXCEPTION("emcore_start_driving_mode failed : [%d]", err);
2018 emstorage_free_account(&p_account_tbl, account_count, NULL);
2020 EM_DEBUG_FUNC_END();
2024 INTERNAL_FUNC int emcore_finalize_sync(int account_id, int *error)
2026 EM_DEBUG_FUNC_BEGIN("account_id [%d], error [%p]", account_id, error);
2027 int err = EMAIL_ERROR_NONE, ret = true, result_sync_status = SYNC_STATUS_FINISHED;
2029 if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE)
2030 EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err);
2032 if (!emstorage_get_sync_status_of_account(ALL_ACCOUNT, &result_sync_status, &err))
2033 EM_DEBUG_EXCEPTION("emstorage_get_sync_status_of_account failed [%d]", err);
2035 if (result_sync_status == SYNC_STATUS_HAVE_NEW_MAILS) {
2036 if (!emcore_update_notification_for_unread_mail(ALL_ACCOUNT))
2037 EM_DEBUG_EXCEPTION("emcore_update_notification_for_unread_mail failed");
2039 if (!emcore_display_unread_in_badge())
2040 EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed");
2042 emcore_start_alert();
2044 #ifdef __FEATURE_BLOCKING_MODE__
2045 emcore_set_blocking_mode_status(false);
2046 #endif /* __FEATURE_BLOCKING_MODE__ */
2048 if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE)
2049 EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err);
2052 EM_DEBUG_FUNC_END();
2056 INTERNAL_FUNC int emcore_clear_all_notifications()
2058 int account_count = 0, i;
2059 emstorage_account_tbl_t *account_list;
2060 int error_code = EMAIL_ERROR_NONE;
2062 if(!emstorage_get_account_list(&account_count, &account_list, true, false, &error_code)) {
2063 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed");
2067 for(i = 0; i < account_count; i++) {
2068 emcore_delete_notification_by_account(account_list[i].account_id);
2073 emstorage_free_account(&account_list, account_count, NULL);
2076 EM_DEBUG_FUNC_END("return[%d]", error_code);
2080 #define EAS_EXECUTABLE_PATH "/usr/bin/eas-engine"
2082 INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id)
2084 EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
2085 int error_code = EMAIL_ERROR_NONE;
2087 char vconf_private_id[MAX_PATH] = {0, };
2089 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
2090 if (vconf_get_int(vconf_private_id, &private_id) != 0) {
2091 EM_DEBUG_EXCEPTION("vconf_get_int failed");
2093 EM_DEBUG_FUNC_END();
2097 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
2100 * @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)
2101 * Prepare a linked list of uid ranges with each node having a uid_range and lowest and highest uid in it.
2103 *@author h.gahlaut@samsung.com
2104 * @param[in] id_set Specifies the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
2105 * @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
2106 * @param[in] range_len Specifies the maximum length of string of range allowed.
2107 * @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
2108 * @param[out] err_code Returns the error code.
2109 * @remarks An example of a uid_range formed is 2:6,8,10,14:15,89,
2110 * While using it the caller should remove the ending, (comma)
2111 * @return This function returns true on success or false on failure.
2114 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)
2116 EM_DEBUG_FUNC_BEGIN();
2119 int error = EMAIL_ERROR_NONE;
2121 if (NULL == id_set || id_set_count <= 0 || NULL == uid_range_set) {
2122 EM_DEBUG_EXCEPTION(" Invalid Parameter id_set[%p] id_set_count[%d] uid_range_set[%p]", id_set, id_set_count, uid_range_set);
2123 error = EMAIL_ERROR_INVALID_PARAM;
2128 unsigned long current_uid = 0;
2129 unsigned long first_uid = 0;
2130 unsigned long last_uid = 0;
2131 const int max_subset_string_size = MAX_SUBSET_STRING_SIZE;
2132 char subset_string[MAX_SUBSET_STRING_SIZE] = {0,};
2133 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*/
2135 if (range_len < (max_subset_string_size + 1)) /* 1 for ending NULL character */ {
2136 EM_DEBUG_EXCEPTION(" Invalid Parameter range_len[%d]", range_len);
2137 error = EMAIL_ERROR_INVALID_PARAM;
2141 EM_DEBUG_LOG("id set count[%d] range_len[%d]", id_set_count, range_len);
2144 first_uid = last_uid = current_uid = id_set[i].server_mail_id;
2145 /* Start subset string by putting first server mail id in it from id_set*/
2146 memset(subset_string, 0x00, max_subset_string_size);
2147 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
2150 /* Check if only one server mail id was left in id_set */
2151 if (i >= id_set_count) {
2152 /* No more server mail id left in id_set */
2153 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
2154 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
2160 /* 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 */
2162 current_uid = id_set[i].server_mail_id;
2163 if (current_uid == (last_uid + 1)) {
2164 last_uid = current_uid;
2168 memset(subset_string, 0x00, max_subset_string_size);
2169 if (first_uid != last_uid) /* Form subset string by first_uid:last_uid */
2170 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
2171 else /* Form subset string by first_uid */
2172 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
2174 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
2175 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
2178 /* To Start formation of new subset string break out of inner loop */
2182 } while (i < id_set_count);
2184 /* Flow comes here in two cases :
2185 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
2186 2. due to break statement */
2188 if (last_uid == current_uid) {
2191 memset(subset_string, 0x00, max_subset_string_size);
2192 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
2194 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
2195 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
2200 /* Case 2: Do Nothing */
2204 } while (i < id_set_count);
2209 if (NULL != err_code)
2211 EM_DEBUG_FUNC_END();
2217 * @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)
2218 * 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
2219 * and stores the subset_string in its uid_range. Also sets the lowest and highest uids for the corresponsing uid_range
2221 * @author h.gahlaut@samsung.com
2222 * @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.
2223 * @param[in] range_len Specifies the maximum length of range string allowed.
2224 * @param[in] luid Specifies the lowest uid in subset string
2225 * @param[in] huid Specifies the highest uid in subset string
2226 * @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
2227 * @param[out] err_code Returns the error code.
2229 * @return This function returns true on success or false on failure.
2232 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)
2234 EM_DEBUG_FUNC_BEGIN();
2235 email_uid_range_set *current_node = NULL;
2237 if (NULL == (*uid_range_set)) {
2238 /*This happens only once when list creation starts. Head Node is allocated */
2239 current_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
2240 if (NULL == current_node) {
2241 EM_DEBUG_EXCEPTION("em_malloc failed");
2245 current_node->uid_range = (char *)em_malloc(range_len);
2247 if (NULL == current_node->uid_range) {
2248 EM_DEBUG_EXCEPTION("em_malloc failed");
2249 EM_SAFE_FREE(current_node);
2253 SNPRINTF(current_node->uid_range, range_len, "%s,", subset_string);
2255 current_node->lowest_uid = luid;
2256 current_node->highest_uid = huid;
2257 (*uid_range_set) = current_node;
2259 (*current_node_adr) = current_node;
2263 /* Apart from first call to this function flow will always come here */
2264 current_node = (*current_node_adr);
2265 int len_sub_string = EM_SAFE_STRLEN(subset_string);
2266 int space_left_in_buffer = range_len - EM_SAFE_STRLEN(current_node->uid_range);
2268 if ((len_sub_string + 1 + 1) <= space_left_in_buffer) /* 1 for comma + 1 for ending null character */ {
2269 SNPRINTF(current_node->uid_range + EM_SAFE_STRLEN(current_node->uid_range), space_left_in_buffer, "%s,", subset_string);
2270 current_node->highest_uid = huid;
2273 /* No more space left in uid_range string.If continued on it, it will exceeded max size of range_len */
2274 /* Allocate new node in Uid Range set */
2275 email_uid_range_set *new_node = NULL;
2277 new_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
2279 if (NULL == new_node) {
2280 EM_DEBUG_EXCEPTION("em_malloc failed");
2284 /* Allocate uid_range of new node */
2286 new_node->uid_range = (char *)em_malloc(range_len);
2288 if (NULL == new_node->uid_range) {
2289 EM_DEBUG_EXCEPTION("em_malloc failed");
2290 EM_SAFE_FREE(new_node);
2294 SNPRINTF(new_node->uid_range, range_len, "%s, ", subset_string);
2296 new_node->lowest_uid = luid;
2297 new_node->highest_uid = huid;
2299 current_node->next = new_node;
2301 (*current_node_adr) = new_node;
2304 EM_DEBUG_FUNC_END();
2309 * void emcore_free_uid_range_set(email_uid_range_set **uid_range_head)
2310 * Frees the linked list of uid ranges
2312 * @author h.gahlaut@samsung.com
2313 * @param[in] uid_range_head Head pointer of linked list of uid ranges
2315 * @return This function does not return anything.
2319 void emcore_free_uid_range_set(email_uid_range_set **uid_range_set)
2321 EM_DEBUG_FUNC_BEGIN();
2323 email_uid_range_set *current_node = NULL;
2324 email_uid_range_set *uid_range_head = NULL;
2326 current_node = uid_range_head = (*uid_range_set); /* Make the current node and head ptr point to starting of uid_range_set */
2328 while (current_node) {
2329 uid_range_head = current_node->next; /* Move the head ptr to next node*/
2331 EM_SAFE_FREE(current_node->uid_range);
2332 EM_SAFE_FREE(current_node); /* Free the current node */
2334 current_node = uid_range_head; /* Make the current node point to head ptr */
2337 (*uid_range_set) = NULL;
2338 EM_DEBUG_FUNC_END();
2343 * @fn emcore_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char *** strings, int *string_count, int *err_code)
2344 * Forms comma separated strings of a give max_string_len from an array of numbers
2346 * @author h.gahlaut@samsung.com
2347 * @param[in] numbers Specifies the array of numbers to be converted into comma separated strings.
2348 * @param[in] num_count Specifies the count of numbers in numbers array.
2349 * @param[in] max_string_len Specifies the maximum length of comma separated strings that are to be formed.
2350 * @param[out] strings Returns the base address of a double dimension array which stores the strings.
2351 * @param[out] string_count Returns the number of strings formed.
2352 * @param[out] err_code Returns the error code.
2353 * @remarks If Input to the function is five numbers like 2755 2754 2748 2749 2750 and a given max_string_len is 20.
2354 * Then this function will form two comma separated strings as follows -
2355 * "2755, 2754, 2748"
2357 * @return This function returns true on success or false on failure.
2360 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)
2362 EM_DEBUG_FUNC_BEGIN();
2364 int error = EMAIL_ERROR_NONE;
2367 char **string_list = NULL;
2368 int num_of_strings = 0;
2371 char num[MAX_INTEGER_LENGTH + 1] = {0, };
2373 int space_in_buffer = 0;
2374 int len_of_string_formed = 0;
2376 if (NULL == numbers || num_count <= 0 || \
2377 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. */ {
2378 EM_DEBUG_EXCEPTION("Invalid Parameter numbers[%p] num_count [%d] max_string_len [%d] strings [%p] string_count[%p]", \
2379 numbers, num_count, max_string_len, strings, string_count);
2380 error = EMAIL_ERROR_INVALID_PARAM;
2384 EM_DEBUG_LOG("num_count [%d] max_string_len [%d]", num_count, max_string_len);
2386 string_list = em_malloc(sizeof(char *));
2388 if (NULL == string_list) {
2389 EM_DEBUG_EXCEPTION("em_malloc failed ");
2393 string_list[num_of_strings] = em_malloc(max_string_len);
2395 if (NULL == string_list[num_of_strings]) {
2396 EM_DEBUG_EXCEPTION("em_malloc failed ");
2401 space_in_buffer = max_string_len;
2403 for (j = 0; j < num_count;++j) {
2404 memset(num, 0x00, MAX_INTEGER_LENGTH + 1);
2405 SNPRINTF(num, MAX_INTEGER_LENGTH + 1, "%d", numbers[j]);
2407 num_len = EM_SAFE_STRLEN(num);
2409 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
2411 space_in_buffer = max_string_len - len_of_string_formed ;
2413 if (space_in_buffer >= (num_len+1+1)) /* 1 for comma and 1 for ending NULL */ {
2414 SNPRINTF(string_list[num_of_strings - 1] + len_of_string_formed, max_string_len, "%d,", numbers[j]);
2416 else { /* Removing comma at end of string */
2417 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
2419 temp = (char **)realloc(string_list, sizeof(char *) * (num_of_strings + 1)); /* Allocate new buffer to store a pointer to a new string */
2422 EM_DEBUG_EXCEPTION("realloc failed");
2426 memset(temp + num_of_strings, 0X00, sizeof(char *));
2430 string_list[num_of_strings] = em_malloc(max_string_len);/* Allocate new buffer to store the string */
2432 if (NULL == string_list[num_of_strings]) {
2433 EM_DEBUG_EXCEPTION(" em_malloc failed ");
2437 SNPRINTF(string_list[num_of_strings - 1] , max_string_len, "%d,", numbers[j]);/* Start making new string */
2441 /* Removing comma at end of string */
2442 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
2443 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
2449 emcore_free_comma_separated_strings(&string_list, &num_of_strings);
2452 for (i = 0; i < num_of_strings;++i)
2453 EM_DEBUG_LOG("%s", string_list[i]);
2454 *strings = string_list;
2455 *string_count = num_of_strings;
2459 if (NULL != err_code)
2462 EM_DEBUG_FUNC_END("ret [%d]", ret);
2466 * @fn emcore_free_comma_separated_strings(char *** string_list, int *string_count)
2467 * Frees the double dimensional array of strings.
2469 * @author h.gahlaut@samsung.com
2470 * @param[in] uid_range_head Address of base address of double dimensional array of strings.
2471 * @param[in] string_count Address of variable holding the count of strings.
2473 * @return This function does not return anything.
2475 INTERNAL_FUNC void emcore_free_comma_separated_strings(char *** string_list, int *string_count)
2477 EM_DEBUG_FUNC_BEGIN();
2479 char **str_list = NULL;
2482 if (NULL != string_list) {
2483 str_list = *string_list;
2485 if (0 != *string_count) {
2486 count = *string_count;
2487 for (i = 0; i < count; ++i)
2488 EM_SAFE_FREE(str_list[i]);
2491 EM_SAFE_FREE(str_list);
2492 *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 */
2495 EM_DEBUG_FUNC_END();
2504 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)
2506 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);
2507 int ret = false, err = EMAIL_ERROR_NONE;
2508 char *extcheck = NULL;
2509 char attachment_file_name[MAX_PATH + 1] = { 0, };
2511 if (!source_file_name || !result_file_name) {
2512 EM_DEBUG_EXCEPTION("Invalid Parameter");
2513 err = EMAIL_ERROR_INVALID_PARAM;
2517 strncpy(attachment_file_name, source_file_name, MAX_PATH);
2518 extcheck = strchr(attachment_file_name, '.');
2521 EM_DEBUG_LOG("Extension Exist in the Attachment [%s] ", extcheck);
2522 else { /* No extension attached, So add the Extension based on the subtype */
2524 strcat(attachment_file_name, ".");
2525 strcat(attachment_file_name, sub_type);
2526 EM_DEBUG_LOG("attachment_file_name with extension[%s] ", attachment_file_name);
2529 EM_DEBUG_LOG("UnKnown Extesnsion");
2532 memset(result_file_name, 0 , result_file_name_buffer_length);
2533 EM_SAFE_STRNCPY(result_file_name, attachment_file_name, result_file_name_buffer_length - 1);
2534 EM_DEBUG_LOG("*result_file_name[%s]", result_file_name);
2540 EM_DEBUG_FUNC_END();
2544 #ifdef __FEATURE_LOCAL_ACTIVITY__
2545 INTERNAL_FUNC int emcore_add_activity(emstorage_activity_tbl_t *new_activity, int *err_code)
2547 EM_DEBUG_FUNC_BEGIN();
2549 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", new_activity, err_code);
2551 /* default variable */
2553 int err = EMAIL_ERROR_NONE;
2555 if (!new_activity) {
2556 EM_DEBUG_LOG("\t new_activity[%p]\n", new_activity);
2557 err = EMAIL_ERROR_INVALID_PARAM;
2560 if (!emstorage_add_activity(new_activity, false, &err)) {
2561 EM_DEBUG_LOG("\t emstorage_add_activity falied - %d\n", err);
2574 INTERNAL_FUNC int emcore_delete_activity(emstorage_activity_tbl_t *activity, int *err_code)
2576 EM_DEBUG_FUNC_BEGIN();
2578 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", activity, err_code);
2580 /* default variable */
2582 int err = EMAIL_ERROR_NONE;
2584 EM_DEBUG_LOG("\t new_activity[%p]\n", activity);
2586 err = EMAIL_ERROR_INVALID_PARAM;
2589 if (!emstorage_delete_local_activity(activity, true, &err)) {
2590 EM_DEBUG_LOG("\t emstorage_delete_local_activity falied - %d\n", err);
2603 INTERNAL_FUNC int emcore_get_next_activity_id(int *activity_id, int *err_code)
2605 EM_DEBUG_FUNC_BEGIN();
2608 int err = EMAIL_ERROR_NONE;
2610 if (NULL == activity_id)
2612 EM_DEBUG_EXCEPTION("\t activity_id[%p]", activity_id);
2614 err = EMAIL_ERROR_INVALID_PARAM;
2618 if (false == emstorage_get_next_activity_id(activity_id, &err)) {
2619 EM_DEBUG_LOG("\t emstorage_get_next_activity_id failed - %d\n", err);
2626 if (NULL != err_code) {
2634 #endif /* __FEATURE_LOCAL_ACTIVITY__ */
2637 INTERNAL_FUNC void emcore_free_rule(email_rule_t* rule)
2639 EM_DEBUG_FUNC_BEGIN();
2644 EM_SAFE_FREE(rule->value);
2646 EM_DEBUG_FUNC_END();
2649 INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_string, int *result)
2651 EM_DEBUG_FUNC_BEGIN("file_path : [%s], search_string : [%s]", file_path, search_string);
2652 int error = EMAIL_ERROR_NONE;
2654 int p_result = false;
2657 char *stripped = NULL;
2659 if (!search_string || !file_path || !result) {
2660 EM_DEBUG_EXCEPTION("Invalid parameter");
2661 error = EMAIL_ERROR_INVALID_PARAM;
2665 fp = fopen(file_path, "r");
2667 EM_DEBUG_EXCEPTION("fopen failed");
2668 error = EMAIL_ERROR_SYSTEM_FAILURE;
2672 if (!emcore_get_file_size(file_path, &file_size, &error)) {
2673 EM_DEBUG_EXCEPTION("emcore_get_file_size failed");
2677 buf = em_malloc(file_size);
2679 EM_DEBUG_EXCEPTION("em_malloc failed");
2680 error = EMAIL_ERROR_OUT_OF_MEMORY;
2684 if (fread(buf, sizeof(char), file_size, fp) != file_size) {
2685 EM_DEBUG_EXCEPTION("Get the data from file : failed");
2686 error = EMAIL_ERROR_SYSTEM_FAILURE;
2691 stripped = em_replace_all_string(buf, CRLF_STRING, "");
2692 if (strstr(stripped, search_string))
2697 EM_DEBUG_LOG("Search string[%s] not found",search_string);
2705 EM_SAFE_FREE(stripped); /*prevent 35586*/
2707 EM_DEBUG_FUNC_END("error:[%d]", error);
2711 INTERNAL_FUNC int emcore_load_query_from_file(char *file_path, char ***query_array, int *array_len)
2713 EM_DEBUG_FUNC_BEGIN("file_path : [%s], query_array : [%p]", file_path, *query_array);
2714 int error = EMAIL_ERROR_NONE;
2720 char **result_vector = NULL;
2723 EM_DEBUG_EXCEPTION("Invalid parameter");
2724 error = EMAIL_ERROR_INVALID_PARAM;
2728 fp = fopen(file_path, "r");
2730 EM_DEBUG_EXCEPTION("fopen failed");
2731 error = EMAIL_ERROR_SYSTEM_FAILURE;
2735 if (!emcore_get_file_size(file_path, &file_size, &error)) {
2736 EM_DEBUG_EXCEPTION("emcore_get_file_size failed");
2740 buf = em_malloc(file_size);
2742 EM_DEBUG_EXCEPTION("em_malloc failed");
2743 error = EMAIL_ERROR_OUT_OF_MEMORY;
2747 if (fread(buf, sizeof(char), file_size, fp) != file_size) {
2748 EM_DEBUG_EXCEPTION("Get the data from file : failed");
2749 error = EMAIL_ERROR_SYSTEM_FAILURE;
2753 result_vector = g_strsplit(buf, ";", -1);
2754 if (!result_vector || g_strv_length(result_vector) <= 0) {
2755 EM_DEBUG_EXCEPTION("Parsing sql file failed");
2756 error = EMAIL_ERROR_SYSTEM_FAILURE;
2760 vector_len = g_strv_length(result_vector);
2761 if (vector_len <= 0) {
2762 EM_DEBUG_EXCEPTION("vector length : [%d]", vector_len);
2763 error = EMAIL_ERROR_SYSTEM_FAILURE;
2767 *query_array = (char **)calloc(vector_len, sizeof(char *));
2769 for (i = 0; i < vector_len; i++) {
2770 if (result_vector[i]) {
2771 char *str = g_strconcat(result_vector[i], ";", NULL);
2772 (*query_array)[i] = str;
2777 *array_len = vector_len;
2778 EM_DEBUG_LOG("SQL string array length : [%d]", vector_len);
2788 if (result_vector) {
2789 g_strfreev(result_vector);
2792 EM_DEBUG_FUNC_END("error:[%d]", error);
2796 static int convert_contact_err_to_email_err(int contact_err)
2798 int err = EMAIL_ERROR_NONE;
2800 switch (contact_err) {
2801 case CONTACTS_ERROR_NONE :
2802 err = EMAIL_ERROR_NONE;
2804 case CONTACTS_ERROR_OUT_OF_MEMORY :
2805 err = EMAIL_ERROR_OUT_OF_MEMORY;
2807 case CONTACTS_ERROR_INVALID_PARAMETER :
2808 err = EMAIL_ERROR_INVALID_PARAM;
2810 case CONTACTS_ERROR_NO_DATA :
2811 err = EMAIL_ERROR_DATA_NOT_FOUND;
2813 case CONTACTS_ERROR_DB :
2814 err = EMAIL_ERROR_DB_FAILURE;
2816 case CONTACTS_ERROR_IPC :
2817 err = EMAIL_ERROR_IPC_CONNECTION_FAILURE;
2819 case CONTACTS_ERROR_SYSTEM:
2820 err = EMAIL_ERROR_SYSTEM_FAILURE;
2822 case CONTACTS_ERROR_INTERNAL:
2824 err = EMAIL_ERROR_UNKNOWN;
2830 int emcore_get_mail_contact_info(email_mail_contact_info_t *contact_info, char *full_address, int *err_code)
2832 EM_DEBUG_FUNC_BEGIN("contact_info[%p], full_address[%s], err_code[%p]", contact_info, full_address, err_code);
2835 int err = EMAIL_ERROR_NONE;
2837 if (!emcore_get_mail_contact_info_with_update(contact_info, full_address, 0, &err))
2838 EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info_with_update failed [%d]", err);
2842 if (err_code != NULL)
2848 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)
2850 EM_DEBUG_FUNC_BEGIN();
2851 int contact_err = CONTACTS_ERROR_NONE;
2853 contacts_query_h query = NULL;
2854 contacts_filter_h filter = NULL;
2855 contacts_list_h list = NULL;
2857 if ((contact_err = contacts_query_create(contact_uri, &query)) != CONTACTS_ERROR_NONE) {
2858 EM_DEBUG_EXCEPTION("contacts_query_create failed");
2862 if ((contact_err = contacts_filter_create(contact_uri, &filter)) != CONTACTS_ERROR_NONE) {
2863 EM_DEBUG_EXCEPTION("contacts_filter_create failed");
2867 if ((contact_err = contacts_filter_add_str(filter, address_property_id, CONTACTS_MATCH_EXACTLY, address)) != CONTACTS_ERROR_NONE) {
2868 EM_DEBUG_EXCEPTION("contacts_filter_add_str failed");
2872 if ((contact_err = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND)) != CONTACTS_ERROR_NONE) {
2873 EM_DEBUG_EXCEPTION("contacts_filter_add_operator failed");
2877 if ((contact_err = contacts_filter_add_bool(filter, favorite_property_id, is_favorite)) != CONTACTS_ERROR_NONE) {
2878 EM_DEBUG_EXCEPTION("contacts_filter_add_bool failed");
2882 if ((contact_err = contacts_query_set_filter(query, filter)) != CONTACTS_ERROR_NONE) {
2883 EM_DEBUG_EXCEPTION("contacts_query_set_filter failed");
2887 if ((contact_err = contacts_db_get_records_with_query(query, 0, limit, &list)) != CONTACTS_ERROR_NONE) {
2888 EM_DEBUG_EXCEPTION("contacts_db_get_record_with_query failed");
2892 if ((contact_err = contacts_list_get_current_record_p(list, contacts_record)) != CONTACTS_ERROR_NONE) {
2893 EM_DEBUG_EXCEPTION("contacts_list_get_current_record_p failed");
2900 contacts_query_destroy(query);
2903 contacts_filter_destroy(filter);
2906 contacts_list_destroy(list, false);
2911 int emcore_search_contact_info_by_address(const char *contact_uri, int property_id, char *address, int limit, contacts_record_h *contacts_record)
2913 EM_DEBUG_FUNC_BEGIN();
2914 int contact_err = CONTACTS_ERROR_NONE;
2916 contacts_query_h query = NULL;
2917 contacts_filter_h filter = NULL;
2918 contacts_list_h list = NULL;
2920 if ((contact_err = contacts_query_create(contact_uri, &query)) != CONTACTS_ERROR_NONE) {
2921 EM_DEBUG_EXCEPTION("contacts_query_create failed");
2925 if ((contact_err = contacts_filter_create(contact_uri, &filter)) != CONTACTS_ERROR_NONE) {
2926 EM_DEBUG_EXCEPTION("contacts_filter_create failed");
2930 if ((contact_err = contacts_filter_add_str(filter, property_id, CONTACTS_MATCH_EXACTLY, address)) != CONTACTS_ERROR_NONE) {
2931 EM_DEBUG_EXCEPTION("contacts_filter_add_str failed");
2935 if ((contact_err = contacts_query_set_filter(query, filter)) != CONTACTS_ERROR_NONE) {
2936 EM_DEBUG_EXCEPTION("contacts_query_set_filter failed");
2940 if ((contact_err = contacts_db_get_records_with_query(query, 0, limit, &list)) != CONTACTS_ERROR_NONE) {
2941 EM_DEBUG_EXCEPTION("contacts_db_get_record_with_query failed");
2945 if ((contact_err = contacts_list_get_current_record_p(list, contacts_record)) != CONTACTS_ERROR_NONE) {
2946 EM_DEBUG_EXCEPTION("contacts_list_get_current_record_p failed");
2953 contacts_query_destroy(query);
2956 contacts_filter_destroy(filter);
2959 contacts_list_destroy(list, false);
2964 int emcore_set_contacts_log(int account_id, char *email_address, char *subject, time_t date_time, email_action_t action)
2966 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);
2968 int err = EMAIL_ERROR_NONE;
2969 int contacts_error = CONTACTS_ERROR_NONE;
2971 int action_type = 0;
2973 contacts_record_h phone_record = NULL;
2974 contacts_record_h person_record = NULL;
2976 if ((contacts_error = contacts_connect2()) != CONTACTS_ERROR_NONE) {
2977 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
2981 if ((contacts_error = contacts_record_create(_contacts_phone_log._uri, &phone_record)) != CONTACTS_ERROR_NONE) {
2982 EM_DEBUG_EXCEPTION("contacts_query_create failed [%d]", contacts_error);
2986 /* Set email address */
2987 if ((contacts_error = contacts_record_set_str(phone_record, _contacts_phone_log.address, email_address)) != CONTACTS_ERROR_NONE) {
2988 EM_DEBUG_EXCEPTION("contacts_record_set_str [address] failed [%d]", contacts_error);
2992 /* Search contact person info */
2993 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) {
2994 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contacts_error);
2995 EM_DEBUG_LOG("Not match person");
2997 /* Get person_id in contacts_person_email record */
2998 if (person_record && (contacts_error = contacts_record_get_int(person_record, _contacts_person_email.person_id, &person_id)) != CONTACTS_ERROR_NONE) {
2999 EM_DEBUG_EXCEPTION("contacts_record_get_str failed [%d]", contacts_error);
3003 /* Set the person id */
3004 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.person_id, person_id)) != CONTACTS_ERROR_NONE) {
3005 EM_DEBUG_EXCEPTION("contacts_record_set_int [person id] failed [%d]", contacts_error);
3011 case EMAIL_ACTION_SEND_MAIL :
3012 action_type = CONTACTS_PLOG_TYPE_EMAIL_SENT;
3014 case EMAIL_ACTION_SYNC_HEADER :
3015 action_type = CONTACTS_PLOG_TYPE_EMAIL_RECEIVED;
3018 EM_DEBUG_EXCEPTION("Unknown action type");
3023 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.log_type, action_type)) != CONTACTS_ERROR_NONE) {
3024 EM_DEBUG_EXCEPTION("contacts_record_set_int [log_type] failed [%d]", contacts_error);
3029 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.log_time, (int)date_time)) != CONTACTS_ERROR_NONE) {
3030 EM_DEBUG_EXCEPTION("contacts_record_set_str [address] failed [%d]", contacts_error);
3035 if ((contacts_error = contacts_record_set_str(phone_record, _contacts_phone_log.extra_data2, subject)) != CONTACTS_ERROR_NONE) {
3036 EM_DEBUG_EXCEPTION("contacts_record_set_str [subject] failed [%d]", contacts_error);
3041 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.extra_data1, account_id)) != CONTACTS_ERROR_NONE) {
3042 EM_DEBUG_EXCEPTION("contacts_record_set_int [mail id] failed [%d]", contacts_error);
3046 /* Insert the record in DB */
3047 if ((contacts_error = contacts_db_insert_record(phone_record, NULL)) != CONTACTS_ERROR_NONE) {
3048 EM_DEBUG_EXCEPTION("contacts_db_insert_record failed [%d]",contacts_error );
3054 if (phone_record != NULL)
3055 contacts_record_destroy(phone_record, false);
3057 if (person_record != NULL)
3058 contacts_record_destroy(person_record, false);
3060 err = convert_contact_err_to_email_err(contacts_error);
3062 if ((contacts_error = contacts_disconnect2()) != CONTACTS_ERROR_NONE) {
3063 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
3064 err = convert_contact_err_to_email_err(contacts_error);
3067 EM_DEBUG_FUNC_END("err [%d]", err);
3071 INTERNAL_FUNC int emcore_set_sent_contacts_log(emstorage_mail_tbl_t *input_mail_data)
3073 EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
3076 int err = EMAIL_ERROR_NONE;
3077 char email_address[MAX_EMAIL_ADDRESS_LENGTH];
3078 char *address_array[3] = {input_mail_data->full_address_to, input_mail_data->full_address_cc, input_mail_data->full_address_bcc};
3079 ADDRESS *addr = NULL;
3080 ADDRESS *p_addr = NULL;
3082 for (i = 0; i < 3; i++) {
3083 if (address_array[i] && address_array[i][0] != 0) {
3084 rfc822_parse_adrlist(&addr, address_array[i], NULL);
3085 for (p_addr = addr ; p_addr ;p_addr = p_addr->next) {
3086 SNPRINTF(email_address, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", addr->mailbox, addr->host);
3087 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) {
3088 EM_DEBUG_EXCEPTION("emcore_set_contacts_log failed : [%d]", err);
3094 mail_free_address(&addr);
3103 mail_free_address(&addr);
3105 EM_DEBUG_FUNC_END("err [%d]", err);
3109 INTERNAL_FUNC int emcore_set_received_contacts_log(emstorage_mail_tbl_t *input_mail_data)
3111 EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
3112 int err = EMAIL_ERROR_NONE;
3114 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) {
3115 EM_DEBUG_EXCEPTION("emcore_set_contacts_log failed [%d]", err);
3118 EM_DEBUG_FUNC_END("err [%d]", err);
3122 INTERNAL_FUNC int emcore_delete_contacts_log(int account_id)
3124 EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
3126 int err = EMAIL_ERROR_NONE;
3127 int contacts_error = CONTACTS_ERROR_NONE;
3129 if ((contacts_error = contacts_connect2()) != CONTACTS_ERROR_NONE) {
3130 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
3134 /* Delete record of the account id */
3135 if ((contacts_error = contacts_phone_log_delete(CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1, account_id)) != CONTACTS_ERROR_NONE) {
3136 EM_DEBUG_EXCEPTION("contacts_phone_log_delete failed [%d]", contacts_error);
3141 err = convert_contact_err_to_email_err(contacts_error);
3143 if ((contacts_error = contacts_disconnect2()) != CONTACTS_ERROR_NONE) {
3144 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contacts_error);
3145 err = convert_contact_err_to_email_err(contacts_error);
3148 EM_DEBUG_FUNC_END("err [%d]", err);
3152 INTERNAL_FUNC int emcore_get_mail_display_name(char *email_address, char **contact_display_name, int *err_code)
3154 EM_DEBUG_FUNC_BEGIN("contact_name_value[%s], contact_display_name[%p]", email_address, contact_display_name);
3156 int contact_err = 0;
3158 char *display = NULL;
3159 /* Contact variable */
3160 contacts_record_h record = NULL;
3162 if ((contact_err = contacts_connect2()) != CONTACTS_ERROR_NONE) {
3163 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contact_err);
3167 if ((contact_err = emcore_search_contact_info_by_address(_contacts_contact_email._uri, _contacts_contact_email.email, email_address, 1, &record)) != CONTACTS_ERROR_NONE) {
3168 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed");
3172 if ((contact_err = contacts_list_get_count(list, &list_count)) != CONTACTS_ERROR_NONE) {
3173 EM_DEBUG_EXCEPTION("contacts_list_get_count failed");
3177 if (list_count > 1) {
3178 EM_DEBUG_EXCEPTION("Duplicated contacts info");
3179 contact_err = CONTACTS_ERROR_INTERNAL;
3181 } else if (list_count == 0) {
3182 EM_DEBUG_EXCEPTION("Not found contact info");
3183 contact_err = CONTACTS_ERROR_NO_DATA;
3188 if (contacts_record_get_str(record, _contacts_contact_email.display_name, &display) != CONTACTS_ERROR_NONE) {
3189 EM_DEBUG_EXCEPTION("contacts_record_get_str failed");
3197 contacts_disconnect2();
3200 contacts_record_destroy(record, false);
3203 *contact_display_name = display;
3205 *contact_display_name = NULL;
3206 EM_SAFE_FREE(display);
3209 if (err_code != NULL)
3210 *err_code = convert_contact_err_to_email_err(contact_err);
3216 #ifdef __FEATURE_BLOCKING_MODE__
3218 #define ALLOWED_CONTACT_TYPE_NONE 0
3219 #define ALLOWED_CONTACT_TYPE_ALL 1
3220 #define ALLOWED_CONTACT_TYPE_FAVORITES 2
3221 #define ALLOWED_CONTACT_TYPE_CUSTOM 3
3223 static int blocking_mode_status = false;
3224 static int blocking_mode_of_setting = false;
3226 INTERNAL_FUNC bool emcore_init_blocking_mode_status()
3228 EM_DEBUG_FUNC_BEGIN("blocking_mode_of_setting : [%d]", blocking_mode_of_setting);
3230 if (vconf_get_bool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &blocking_mode_of_setting) != 0) {
3231 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
3235 EM_DEBUG_FUNC_END();
3239 INTERNAL_FUNC void emcore_set_blocking_mode_of_setting(int input_blocking_mode_of_setting)
3241 blocking_mode_of_setting = input_blocking_mode_of_setting;
3244 INTERNAL_FUNC int emcore_get_blocking_mode_status()
3246 EM_DEBUG_FUNC_BEGIN("blocking_mode_status : [%d]", blocking_mode_status);
3247 EM_DEBUG_FUNC_END();
3249 return blocking_mode_status;
3252 INTERNAL_FUNC void emcore_set_blocking_mode_status(int blocking_mode)
3254 blocking_mode_status = blocking_mode;
3257 INTERNAL_FUNC int emcore_check_blocking_mode(char *sender_address, int *blocking_status)
3259 EM_DEBUG_FUNC_BEGIN();
3260 int err = EMAIL_ERROR_NONE;
3261 int contact_error = 0;
3263 int allowed_contact_type = 0; /* 0 : NONE, 1 : All contacts, 2 : Favorites, 3 : Custom */
3264 char *person_id_string = NULL;
3267 contacts_record_h record = NULL;
3269 if (!blocking_mode_of_setting) {
3270 EM_DEBUG_LOG("Blocking mode is OFF");
3274 if (vconf_get_int(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_TYPE, &allowed_contact_type) != 0) {
3275 EM_DEBUG_EXCEPTION("vconf_get_int failed");
3276 err = EMAIL_ERROR_SYSTEM_FAILURE;
3280 if ((contact_error = contacts_connect2()) != CONTACTS_ERROR_NONE) {
3281 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contact_error);
3285 switch (allowed_contact_type) {
3286 case ALLOWED_CONTACT_TYPE_NONE :
3287 EM_DEBUG_LOG("allowed_contact_type is none : bloacking all(notification)");
3288 *blocking_status = true;
3290 case ALLOWED_CONTACT_TYPE_ALL :
3291 EM_DEBUG_LOG("allowed_contact_type is ALL");
3292 /* Search the allowed contact type in contact DB */
3293 if ((contact_error = emcore_search_contact_info_by_address(_contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) {
3294 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed : [%d]", contact_error);
3298 if (record == NULL) {
3299 EM_DEBUG_LOG("No search contact info");
3303 *blocking_status = false;
3306 case ALLOWED_CONTACT_TYPE_FAVORITES :
3307 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) {
3308 EM_DEBUG_EXCEPTION("emcore_search_contact_info failed : [%d]", contact_error);
3312 if (record == NULL) {
3313 EM_DEBUG_LOG("No search contact info");
3317 *blocking_status = false;
3320 case ALLOWED_CONTACT_TYPE_CUSTOM :
3321 person_id_string = vconf_get_str(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_LIST);
3322 if (person_id_string == NULL) {
3323 EM_DEBUG_LOG("Custom allowed contact type is NULL");
3327 if ((contact_error = emcore_search_contact_info_by_address(_contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) {
3328 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed : [%d]", contact_error);
3332 if (record == NULL) {
3333 EM_DEBUG_LOG("No search contact info");
3337 if (contacts_record_get_int(record, _contacts_contact_email.person_id, &person_id) != CONTACTS_ERROR_NONE) {
3338 EM_DEBUG_EXCEPTION("contacts_record_get_str failed");
3342 token = strtok_r(person_id_string, ",", &str);
3344 if (person_id == atoi(token)) {
3345 *blocking_status = false;
3348 } while ((token = strtok_r(NULL, ",", &str)));
3353 EM_DEBUG_EXCEPTION("Invalid parameter : [%d]", allowed_contact_type);
3354 *blocking_status = true;
3355 err = EMAIL_ERROR_INVALID_PARAM;
3360 contacts_disconnect2();
3362 err = convert_contact_err_to_email_err(contact_error);
3364 EM_DEBUG_FUNC_END();
3368 #endif /* __FEATURE_BLOCKING_MODE__ */