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"
66 #define LED_TIMEOUT_SECS 12
67 #define G_DISPLAY_LENGTH 256
69 #define DIR_SEPERATOR_CH '/'
70 #define EMAIL_CH_QUOT '"'
71 #define EMAIL_CH_BRACKET_S '<'
72 #define EMAIL_CH_BRACKET_E '>'
73 #define EMAIL_CH_COMMA ','
74 #define EMAIL_CH_SEMICOLON ';'
75 #define EMAIL_CH_ROUND_BRACKET_S '('
76 #define EMAIL_CH_ROUND_BRACKET_E ')'
77 #define EMAIL_CH_SQUARE_BRACKET_S '['
78 #define EMAIL_CH_SQUARE_BRACKET_E ']'
79 #define EMAIL_CH_SPACE ' '
80 #define EMAIL_NOTI_ICON_PATH EMAILPATH"/res/image/Q02_Notification_email.png"
81 #define VCONF_KEY_UNREAD_MAIL_COUNT "db/badge/com.samsung.email"
83 typedef struct _em_transaction_info_type_t {
86 struct _em_transaction_info_type_t *next;
88 } em_transaction_info_type_t;
90 em_transaction_info_type_t *g_transaction_info_list;
92 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},};
94 typedef struct emcore_account_list_t emcore_account_list_t;
95 struct emcore_account_list_t {
96 email_account_t *account;
97 emcore_account_list_t *next;
100 INTERNAL_FUNC char *emcore_convert_mutf7_to_utf8(char *mailbox_name)
102 EM_DEBUG_FUNC_BEGIN();
103 return (char *)(utf8_from_mutf7((unsigned char *)mailbox_name));
106 /* in smtp case, path argument must be ENCODED_PATH_SMTP */
107 int emcore_get_long_encoded_path_with_account_info(email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code)
109 EM_PROFILE_BEGIN(emCorelongEncodedpath);
110 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);
113 int error = EMAIL_ERROR_NONE;
116 size_t long_enc_path_len = 0;
118 if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) { /* imap or pop3 */
119 EM_DEBUG_LOG("account->incoming_server_address[%p]", account->incoming_server_address);
120 EM_DEBUG_LOG("account->incoming_server_address[%s]", account->incoming_server_address);
122 if (!account->incoming_server_address) {
123 EM_DEBUG_EXCEPTION("account->incoming_server_address is null");
124 error = EMAIL_ERROR_INVALID_ACCOUNT;
128 long_enc_path_len = EM_SAFE_STRLEN(account->incoming_server_address) + EM_SAFE_STRLEN(path) + 64; /*prevent 34357*/
130 *long_enc_path = em_malloc(long_enc_path_len);
131 if (!*long_enc_path) {
132 EM_DEBUG_EXCEPTION("malloc failed...");
133 error = EMAIL_ERROR_OUT_OF_MEMORY;
139 /* ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}my-mailbox" */
141 SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d",
142 account->incoming_server_address,
143 account->incoming_server_port_number,
144 account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap", account->account_id);
146 if (account->incoming_server_secure_connection & 0x01) {
147 strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
148 /* strcat(p, "/tryssl"); */
151 /* Currently, receiving servers doesn't require tls.
152 if (account->incoming_server_secure_connection & 0x02)
153 strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
155 strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
158 if (account->incoming_server_requires_apop) {
159 EM_DEBUG_LOG("emcore_get_long_encoded_path - incoming_server_requires_apop - %d", account->incoming_server_requires_apop);
160 strncat(p, "/apop", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
161 EM_DEBUG_LOG("long_enc_path - %s", p);
165 long_enc_path_len = EM_SAFE_STRLEN(account->outgoing_server_address) + 64;
167 *long_enc_path = em_malloc(EM_SAFE_STRLEN(account->outgoing_server_address) + 64);
168 if (!*long_enc_path) {
169 EM_DEBUG_EXCEPTION("\t malloc failed...\n");
171 error = EMAIL_ERROR_OUT_OF_MEMORY;
177 /* ex:"mail.test.com:25/smtp" */
179 SNPRINTF(p, long_enc_path_len, "%s:%d/%s",
180 account->outgoing_server_address,
181 account->outgoing_server_port_number,
184 if (account->outgoing_server_need_authentication) {
185 SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d", account->account_id);
188 if (account->outgoing_server_secure_connection & 0x01) {
189 strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
190 /* strcat(p, "/tryssl"); */
192 if (account->outgoing_server_secure_connection & 0x02)
193 strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
195 strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
198 if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) {
199 strncat(p, "}", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
202 char *enc_name = NULL;
204 if (!emcore_get_encoded_mailbox_name(path, &enc_name, &error)) {
205 EM_DEBUG_EXCEPTION("emcore_get_encoded_mailbox_name failed - %d", error);
206 *long_enc_path = NULL;
211 strncat(p, enc_name, long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
212 EM_SAFE_FREE(enc_name);
223 if (err_code != NULL)
225 EM_PROFILE_END(emCorelongEncodedpath);
229 int emcore_get_long_encoded_path(int account_id, char *path, int delimiter, char **long_enc_path, int *err_code)
231 EM_PROFILE_BEGIN(emCorelongEncodedpath);
232 EM_DEBUG_FUNC_BEGIN("account_id[%d], delimiter[%d], long_enc_path[%p], err_code[%p]", account_id, delimiter, long_enc_path, err_code);
235 int error = EMAIL_ERROR_NONE;
236 email_account_t *ref_account = NULL;
238 ref_account = emcore_get_account_reference(account_id);
240 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
241 error = EMAIL_ERROR_INVALID_ACCOUNT;
245 if (emcore_get_long_encoded_path_with_account_info(ref_account, path, delimiter, long_enc_path, &error) == false) {
246 EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path_with_account_info failed [%d]", error);
255 emcore_free_account(ref_account);
256 EM_SAFE_FREE(ref_account);
259 if (err_code != NULL)
261 EM_PROFILE_END(emCorelongEncodedpath);
265 int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code)
267 EM_DEBUG_FUNC_BEGIN("name[%s], enc_name[%p], err_code[%p]", name, enc_name, err_code);
269 if (!name || !enc_name) {
270 if (err_code != NULL)
271 *err_code = EMAIL_ERROR_INVALID_PARAM;
276 /* encoding mailbox name (Charset->UTF8->UTF7) */
278 *enc_name = em_malloc(EM_SAFE_STRLEN(name)+1);
279 if (*enc_name == NULL) {
280 EM_DEBUG_EXCEPTION("malloc failed...");
281 if (err_code != NULL)
282 *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
287 strcpy(*enc_name, name);
289 if (err_code != NULL)
290 *err_code = EMAIL_ERROR_NONE;
296 int emcore_get_temp_file_name(char **filename, int *err_code)
298 EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code);
301 int error = EMAIL_ERROR_NONE;
303 if (filename == NULL) {
304 EM_DEBUG_EXCEPTION("\t filename[%p]\n", filename);
305 error = EMAIL_ERROR_INVALID_PARAM;
309 char tempname[512] = {0x00, };
313 gettimeofday(&tv, NULL);
316 /* Create Directory If deleted by user*/
317 emstorage_create_dir_if_delete();
319 SNPRINTF(tempname, sizeof(tempname), "%s%c%d", MAILTEMP, DIR_SEPERATOR_CH, rand());
321 char *p = EM_SAFE_STRDUP(tempname);
323 EM_DEBUG_EXCEPTION("\t strdup failed...\n");
324 error = EMAIL_ERROR_OUT_OF_MEMORY;
333 if (err_code != NULL)
339 int emcore_get_file_name(char *path, char **filename, int *err_code)
341 EM_DEBUG_FUNC_BEGIN("path[%s], filename[%p], err_code[%p]", path, filename, err_code);
344 int error = EMAIL_ERROR_NONE;
346 if (!path || !filename) {
347 EM_DEBUG_EXCEPTION("path[%p], filename[%p]", path, filename);
349 error = EMAIL_ERROR_INVALID_PARAM;
353 int i = (int)EM_SAFE_STRLEN(path);
357 if (path[i] == DIR_SEPERATOR_CH)
360 *filename = path + i + 1;
365 if (err_code != NULL)
371 int emcore_get_file_size(char *path, int *size, int *err_code)
373 EM_DEBUG_FUNC_BEGIN("path[%s], size[%p], err_code[%p]", path, size, err_code);
376 int error = EMAIL_ERROR_NONE;
378 if ((path == NULL) || (size == NULL)) {
379 EM_DEBUG_EXCEPTION("\t path[%p], size[%p]\n", path, size);
381 error = EMAIL_ERROR_INVALID_PARAM;
387 if (stat(path, &st_buf) < 0) {
388 EM_DEBUG_EXCEPTION("\t stat failed - %s\n", path);
390 error = EMAIL_ERROR_SYSTEM_FAILURE;
394 *size = st_buf.st_size;
399 if (err_code != NULL)
407 static int _emcore_check_host(char *host)
411 return strncmp(host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."));
416 int emcore_get_address_count(char *addr_str, int *count, int *err_code)
418 EM_DEBUG_FUNC_BEGIN("addr_str[%s], count[%p], err_code[%p]", addr_str, count, err_code);
421 int error = EMAIL_ERROR_NONE;
423 ADDRESS *addr = NULL;
424 ADDRESS *p_addr = NULL;
430 EM_DEBUG_EXCEPTION("addr_str[%s], count[%p]", addr_str, count);
431 error = EMAIL_ERROR_INVALID_PARAM;
435 if (addr_str != NULL) {
436 em_skip_whitespace(addr_str, &p);
437 EM_DEBUG_LOG("em_skip_whitespace[p][%s]", p);
440 for (i = 0, j = EM_SAFE_STRLEN(p); i < j; i++)
441 if (p[i] == ';') p[i] = ',';
442 rfc822_parse_adrlist(&addr, p, NULL);
446 for (p_addr = addr, i = 0; p_addr; p_addr = p_addr->next, i++) {
447 if (p_addr->mailbox && p_addr->host) {
448 if (!strncmp(p_addr->mailbox, "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS"))
449 || !strncmp(p_addr->mailbox, "INVALID_ADDRESS", strlen("INVALID_ADDRESS"))
450 || !strncmp(p_addr->host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."))) { /*prevent 34356*/
451 EM_DEBUG_LOG("Invalid address ");
455 if ((!p_addr->mailbox) || (_emcore_check_host(p_addr->host) == 0)) {
456 EM_DEBUG_EXCEPTION("\t invalid address : mailbox[%s], host[%s]\n", p_addr->mailbox, p_addr->host);
458 error = EMAIL_ERROR_INVALID_ADDRESS;
459 /* goto FINISH_OFF; */
465 if (error != EMAIL_ERROR_INVALID_ADDRESS)
470 mail_free_address(&addr);
472 if (err_code != NULL)
478 INTERNAL_FUNC int emcore_set_network_error(int err_code)
480 email_session_t *session = NULL;
482 EM_DEBUG_FUNC_BEGIN();
484 emcore_get_current_session(&session);
489 session->network = err_code;
494 int emcore_get_empty_session(email_session_t **session)
496 EM_DEBUG_FUNC_BEGIN("session[%p]", session);
502 for (i = 0; i < SESSION_MAX; i++) {
503 if (!g_session_list[i].status) {
504 memset(g_session_list+i, 0x00, sizeof(email_session_t));
505 g_session_list[i].tid = GPOINTER_TO_INT(THREAD_SELF());
506 g_session_list[i].status = true;
514 *session = (i != SESSION_MAX) ? &g_session_list[i] : NULL;
516 return (i != SESSION_MAX) ? true : false;
519 int emcore_clear_session(email_session_t *session)
521 EM_DEBUG_FUNC_BEGIN();
524 memset(session, 0x00, sizeof(email_session_t));
529 int emcore_get_current_session(email_session_t **session)
531 EM_DEBUG_FUNC_BEGIN("session[%p]", session);
535 for (i = 0; i < SESSION_MAX; i++) {
536 if (g_session_list[i].tid == GPOINTER_TO_INT(THREAD_SELF())) {
538 *session = g_session_list + i;
545 *session = (i != SESSION_MAX) ? g_session_list + i : NULL;
547 return (i != SESSION_MAX) ? true : false;
550 int emcore_get_mail_count_by_query(int account_id, int priority_sender, int *total_mail, int *unread_mail, int *err_code)
552 EM_DEBUG_FUNC_BEGIN();
555 int err = EMAIL_ERROR_NONE;
557 int type = EMAIL_PRIORITY_SENDER;
558 int unread_count = 0;
560 char *conditional_clause_string = NULL;
563 int is_completed = 0;
564 emstorage_rule_tbl_t *rule = NULL;
566 int filter_count = 0;
567 email_list_filter_t *filter_list = NULL;
569 if (priority_sender) {
571 if (!emstorage_get_rule(ALL_ACCOUNT, type, 0, &rule_count, &is_completed, &rule, true, &err) || !rule) {
572 EM_DEBUG_EXCEPTION("emstorage_get_rule failed");
576 /* Make query for searching unread mail */
577 if (account_id != ALL_ACCOUNT) {
578 filter_count = (rule_count * 2) + 3;
580 filter_count = (rule_count * 2) + 1; // 1 is unseen field.
583 filter_list = em_malloc(sizeof(email_list_filter_t) * filter_count);
584 if (filter_list == NULL) {
585 EM_DEBUG_EXCEPTION("em_malloc failed");
586 err = EMAIL_ERROR_OUT_OF_MEMORY;
590 for (i = 0, count = 0; i < filter_count - 1; i += 2, count++) {
591 filter_list[i].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
592 filter_list[i].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
593 filter_list[i].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FROM;
594 filter_list[i].list_filter_item.rule.key_value.string_type_value = EM_SAFE_STRDUP(rule[count].value);
596 filter_list[i+1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
597 if (i == (filter_count - 2)) {
598 filter_list[i+1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
600 filter_list[i+1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
604 filter_list[i].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
605 filter_list[i].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
606 filter_list[i].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD;
607 filter_list[i].list_filter_item.rule.key_value.integer_type_value = 0;
609 if (account_id != ALL_ACCOUNT) {
610 filter_list[i+1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
611 filter_list[i+1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
613 filter_list[i+2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
614 filter_list[i+2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
615 filter_list[i+2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID;
616 filter_list[i+2].list_filter_item.rule.key_value.integer_type_value = account_id;
619 if ((err = emstorage_write_conditional_clause_for_getting_mail_list(filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
620 EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
624 EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
626 /* Search the mail of priority sender in DB */
627 if ((err = emstorage_query_mail_count(conditional_clause_string, true, &total_count, &unread_count)) != EMAIL_ERROR_NONE) {
628 EM_DEBUG_EXCEPTION("emstorage_query_mail_count failed:[%d]", err);
632 if (!emstorage_get_mail_count(account_id, NULL, &total_count, &unread_count, true, &err)) {
633 EM_DEBUG_EXCEPTION(" emstorage_get_mail_count failed - %d", err);
644 emstorage_free_rule(&rule, rule_count, NULL);
647 emstorage_free_list_filter(&filter_list, filter_count);
649 EM_SAFE_FREE(conditional_clause_string);
652 *total_mail = total_count;
655 *unread_mail = unread_count;
663 int emcore_display_unread_in_badge()
665 EM_DEBUG_FUNC_BEGIN();
668 int err = EMAIL_ERROR_NONE;
669 int total_unread_count = 0;
670 int total_mail_count = 0;
671 int badge_ticker = 0;
672 int priority_sender = 0;
675 /* Get the Global noti ticker */
676 if (vconf_get_bool(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, &badge_ticker) != 0) {
677 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
678 err = EMAIL_ERROR_GCONF_FAILURE;
682 /* Get the priority noti ticker */
684 if (vconf_get_bool(VCONF_VIP_NOTI_BADGE_TICKER, &badge_ticker) != 0) {
685 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
686 err = EMAIL_ERROR_GCONF_FAILURE;
691 EM_DEBUG_LOG("Not display the badge");
699 /* Get unread mail count */
700 if (!emcore_get_mail_count_by_query(ALL_ACCOUNT, priority_sender, &total_mail_count, &total_unread_count, &err)) {
701 EM_DEBUG_EXCEPTION("emcore_get_mail_count_by_query failed");
705 /* temporarily disable : set unread count to badge */
706 if (vconf_set_int(VCONF_KEY_UNREAD_MAIL_COUNT, total_unread_count) != 0) {
707 EM_DEBUG_EXCEPTION("vconf_set_int failed");
708 err = EMAIL_ERROR_GCONF_FAILURE;
713 badge_error_e badge_err = BADGE_ERROR_NONE;
716 if((badge_err = badge_is_existing("com.samsung.email", &exist)) != BADGE_ERROR_NONE) {
717 EM_DEBUG_EXCEPTION("badge_is_existing failed [%d]", badge_err);
718 err = EMAIL_ERROR_BADGE_API_FAILED;
723 if((badge_err = badge_create("com.samsung.email", "/usr/bin/email-service")) != BADGE_ERROR_NONE) {
724 EM_DEBUG_EXCEPTION("badge_create failed [%d]", badge_err);
725 err = EMAIL_ERROR_BADGE_API_FAILED;
730 if((badge_err = badge_set_count("com.samsung.email", total_unread_count)) != BADGE_ERROR_NONE) {
731 EM_DEBUG_EXCEPTION("badge_set_count failed [%d]", badge_err);
732 err = EMAIL_ERROR_BADGE_API_FAILED;
736 if (total_unread_count <= 0)
746 static int emcore_layout_multi_noti(notification_h noti, int unread_mail, char *email_address, char *account_name)
748 EM_DEBUG_FUNC_BEGIN();
749 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
750 char modified_string[10];
752 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
753 if (noti_err != NOTIFICATION_ERROR_NONE) {
754 EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_SINGLE failed [%d]", noti_err);
758 SNPRINTF(modified_string, sizeof(modified_string), "%d", unread_mail);
760 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
761 if (noti_err != NOTIFICATION_ERROR_NONE) {
762 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
766 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, modified_string, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
767 if (noti_err != NOTIFICATION_ERROR_NONE) {
768 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_EVENT_COUNT failed");
772 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "new emails", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
773 if (noti_err != NOTIFICATION_ERROR_NONE) {
774 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
778 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, email_address, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
779 if (noti_err != NOTIFICATION_ERROR_NONE) {
780 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
784 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, account_name, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
785 if (noti_err != NOTIFICATION_ERROR_NONE) {
786 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_2 failed");
790 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH);
791 if (noti_err != NOTIFICATION_ERROR_NONE) {
792 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
798 EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err);
802 static int emcore_layout_single_noti(notification_h noti, char *account_name, char *display_sender, time_t time, char *subject)
804 EM_DEBUG_FUNC_BEGIN();
805 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
807 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
808 if (noti_err != NOTIFICATION_ERROR_NONE) {
809 EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_SINGLE failed [%d]", noti_err);
813 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
814 if (noti_err != NOTIFICATION_ERROR_NONE) {
815 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
819 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, account_name, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
820 if (noti_err != NOTIFICATION_ERROR_NONE) {
821 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
825 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, display_sender, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
826 if (noti_err != NOTIFICATION_ERROR_NONE) {
827 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
832 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, time, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
833 if (noti_err != NOTIFICATION_ERROR_NONE) {
834 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_SUB_1 failed");
839 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
840 if (noti_err != NOTIFICATION_ERROR_NONE) {
841 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_2 failed");
845 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH);
846 if (noti_err != NOTIFICATION_ERROR_NONE) {
847 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
853 EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err);
857 static int emcore_add_notification(int account_id, int mail_id, email_action_t action)
859 EM_DEBUG_FUNC_BEGIN();
860 int err = EMAIL_ERROR_NONE;
862 EM_DEBUG_FUNC_END("ret [%d]", err);
866 INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int error)
868 EM_DEBUG_FUNC_BEGIN("id[%d], action[%d], error[%d]", id, action, error);
872 if (action == EMAIL_ACTION_SEND_MAIL && error != EMAIL_ERROR_CANCELLED) {
873 /* In case email is cancelled using cancel button in Outbox there is no need to show Cancel/Retry Pop up */
874 emstorage_mail_tbl_t *mail_table_data = NULL;
876 if (error == 0) /* error 0 means 'this is not error' */
880 EM_DEBUG_LOG("Invalid mail_id");
884 if (!emstorage_get_mail_by_id(id, &mail_table_data, true, NULL)) {
885 EM_DEBUG_LOG("Mail not found");
889 if (emcore_add_notification(mail_table_data->account_id, id, action) != EMAIL_ERROR_NONE) {
890 EM_DEBUG_EXCEPTION("emcore_notification_set error");
892 if (!emstorage_free_mail(&mail_table_data, 1, NULL))
893 EM_DEBUG_EXCEPTION("emstorage_free_mail Failed");
898 if (!emstorage_free_mail(&mail_table_data, 1, NULL))
899 EM_DEBUG_EXCEPTION("emstorage_free_mail Failed");
903 EM_DEBUG_FUNC_END("ret [%d]", ret);
908 /* storage space handling - 210709 */
909 int emcore_get_storage_status(void)
911 EM_DEBUG_FUNC_BEGIN();
912 int storage_status = 0, nError = 0;
916 #ifdef STORAGE_STATUS
917 nError = vconf_get_int(PS_KEY_SYSTEM_STORAGE_MOVI_STATUS,
919 #endif /* STORAGE_STATUS */
922 EM_DEBUG_EXCEPTION("vconf_get_int Failed");
926 return storage_status;
929 int emcore_is_storage_full(int *err_code)
931 EM_DEBUG_FUNC_BEGIN();
934 int err = EMAIL_ERROR_NONE;
935 struct statfs buf = {0};
937 if (statfs(DATA_PATH, &buf) == -1) {
938 EM_DEBUG_EXCEPTION("statfs(\"%s\") failed - %d", DATA_PATH, errno);
939 err = EMAIL_ERROR_SYSTEM_FAILURE;
943 long i_free = (buf.f_bfree * buf.f_bsize) / (1024 * 1024);
944 EM_DEBUG_LOG("f_bfree[%d] f_bsize[%d]", buf.f_bfree, buf.f_bsize);
945 EM_DEBUG_LOG("Free space of storage is[%ld] MB.", i_free);
946 if (i_free < EMAIL_LIMITATION_FREE_SPACE)
947 err = EMAIL_ERROR_MAIL_MEMORY_FULL;
950 if (err == EMAIL_ERROR_MAIL_MEMORY_FULL)
954 if (err_code != NULL)
956 EM_DEBUG_FUNC_END("ret[%d]", ret);
960 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)
962 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);
965 int mail_size = 0; /* size of the plain text body and attachments */
966 int err = EMAIL_ERROR_NONE;
969 if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count &&input_attachment_data_list) || !output_size) {
970 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
971 err = EMAIL_ERROR_INVALID_PARAM;
975 if (input_mail_data->file_path_plain != NULL) {
976 if (stat(input_mail_data->file_path_plain, &st_buf) < 0) {
977 EM_DEBUG_EXCEPTION("input_mail_data->file_path_plain : stat(\"%s\") failed...", input_mail_data->file_path_plain);
978 err = EMAIL_ERROR_INVALID_MAIL;
982 mail_size += st_buf.st_size;
986 if (input_mail_data->file_path_html != NULL) {
987 if (stat(input_mail_data->file_path_html, &st_buf) < 0) {
988 EM_DEBUG_EXCEPTION("input_mail_data->file_path_html : stat(\"%s\") failed...", input_mail_data->file_path_html);
989 err = EMAIL_ERROR_INVALID_MAIL;
993 mail_size += st_buf.st_size;
996 for(i = 0; i < input_attachment_count; i++) {
997 if (stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0) {
998 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path);
999 err = EMAIL_ERROR_INVALID_MAIL;
1002 mail_size += st_buf.st_size;
1005 *output_size = mail_size;
1009 EM_DEBUG_FUNC_END("mail_size [%d]", mail_size);
1014 /* parse the Full mailbox Path and Get the Alias Name of the Mailbox */
1015 char *emcore_get_alias_of_mailbox(const char *mailbox_path)
1017 EM_DEBUG_FUNC_BEGIN();
1018 EM_IF_NULL_RETURN_VALUE(mailbox_path, NULL);
1021 gchar **token_list = NULL;
1022 gchar *mailbox = NULL, *name = NULL;
1023 char *converted_name;
1026 mailbox = g_strdup(mailbox_path);
1027 token_list = g_strsplit_set(mailbox, "/", -1);
1032 while (token_list[index] != NULL)
1035 name = g_strdup(token_list[index - 1]);
1036 if(!name) /* prevent 27459 */
1039 g_strfreev(token_list);
1041 converted_name = emcore_convert_mutf7_to_utf8(name);
1046 EM_DEBUG_FUNC_END();
1047 return converted_name;
1051 static int emcore_get_first_address(const char *full_address, char **alias, char **address)
1053 EM_DEBUG_FUNC_BEGIN();
1055 if (full_address == NULL || alias == NULL || address == NULL){
1056 EM_DEBUG_EXCEPTION("Invalid Param : full_address[%p], alias[%p], address[%p]", full_address, alias, address);
1061 char *alias_start = NULL;
1062 char *alias_end = NULL;
1063 char *alias_cursor = NULL;
1064 char *address_start = NULL;
1065 char *address_end = NULL;
1066 char *first_address = NULL;
1069 s = (char *)strchr((char *)full_address, ';');
1071 first_address = strdup(full_address); /* only one address */
1073 first_address = strndup(full_address, s - full_address); /* over two addresses */
1077 if ((alias_start = (char *)strchr((char *)first_address, '\"'))){
1079 alias_cursor = alias_start;
1080 while ((alias_cursor = (char *)strchr((char *)(alias_cursor), '\"'))){
1081 alias_end = alias_cursor;
1083 if (*alias_cursor == 0)
1086 if (alias_end) { /* there is "alias" */
1087 *alias = strndup(alias_start, alias_end - alias_start);
1088 EM_DEBUG_LOG("alias [%s]", *alias);
1094 if (alias_end == NULL)
1098 if ((address_start = (char *)strchr((char *)s, '<'))){
1100 if ((address_end = (char *)strchr((char *)address_start, '>')))
1101 *address = strndup(address_start, address_end - address_start); /* (alias) <(addr)> ... */
1103 *address = strdup(s);
1106 *address = strdup(s); /* (addr) ; ... : no alias */
1109 EM_SAFE_FREE(first_address);
1110 EM_DEBUG_FUNC_END();
1114 void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data)
1116 EM_DEBUG_FUNC_BEGIN("mail_data [%p]", mail_data);
1118 char *first_alias = NULL;
1119 char *first_address = NULL;
1120 char *recipient = NULL;
1122 /* sender alias & address */
1123 if (emcore_get_first_address(mail_data->full_address_from, &first_alias, &first_address) == true) {
1124 if (first_alias == NULL) {
1125 mail_data->alias_sender = EM_SAFE_STRDUP(first_address);
1128 mail_data->alias_sender = first_alias;
1131 mail_data->email_address_sender = first_address;
1132 first_address = NULL;
1135 /* recipient alias & address */
1136 if (mail_data->full_address_to != NULL)
1137 recipient = mail_data->full_address_to;
1138 else if (mail_data->full_address_cc != NULL)
1139 recipient = mail_data->full_address_cc;
1140 else if (mail_data->full_address_bcc != NULL)
1141 recipient = mail_data->full_address_bcc;
1143 if (emcore_get_first_address(recipient, &first_alias, &first_address) == true) {
1144 if (first_alias == NULL)
1145 mail_data->alias_recipient = EM_SAFE_STRDUP(first_address);
1147 mail_data->alias_recipient = first_alias;
1149 mail_data->email_address_recipient = first_address;
1151 EM_DEBUG_FUNC_END();
1155 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)
1157 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);
1159 int err = EMAIL_ERROR_NONE;
1160 unsigned int byte_read = 0;
1161 unsigned int byte_written = 0;
1162 int local_preview_buffer_length = 0;
1163 char *local_preview_text = NULL;
1164 char *encoding_type = NULL;
1165 char *utf8_encoded_string = NULL;
1166 FILE *fp_html = NULL;
1167 FILE *fp_plain = NULL;
1168 GError *glib_error = NULL;
1171 if (!output_preview_buffer) {
1172 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1173 err = EMAIL_ERROR_INVALID_PARAM;
1177 local_preview_buffer_length = input_preview_buffer_length * 2;
1179 if ( input_html_path ) { /*prevent 26249*/
1180 /* get preview text from html file */
1181 if( (err = em_get_encoding_type_from_file_path(input_html_path, &encoding_type)) != EMAIL_ERROR_NONE) {
1182 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
1186 if (stat(input_html_path, &st_buf) < 0) {
1187 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_html_path);
1188 err = EMAIL_ERROR_INVALID_MAIL;
1192 if (!(fp_html = fopen(input_html_path, "r"))) {
1193 EM_DEBUG_EXCEPTION("fopen failed [%s]", input_html_path);
1194 err = EMAIL_ERROR_SYSTEM_FAILURE;
1198 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
1199 EM_DEBUG_LOG("input_html_file is empty size");
1200 err = EMAIL_ERROR_EMPTY_FILE;
1204 if (!(local_preview_text = (char*)em_malloc(sizeof(char) * (st_buf.st_size + 1)))) {
1205 EM_DEBUG_EXCEPTION("em_malloc failed");
1206 err = EMAIL_ERROR_OUT_OF_MEMORY;
1210 byte_read = fread(local_preview_text, sizeof(char), st_buf.st_size, fp_html);
1212 if(byte_read <= 0) { /*prevent 26249*/
1213 EM_SAFE_FREE(local_preview_text);
1214 if (ferror(fp_html)) {
1215 EM_DEBUG_EXCEPTION("fread failed [%s]", input_html_path);
1216 err = EMAIL_ERROR_SYSTEM_FAILURE;
1221 if ( (err = emcore_strip_HTML(local_preview_text)) != EMAIL_ERROR_NONE) {
1222 EM_DEBUG_EXCEPTION("emcore_strip failed");
1228 if ( !local_preview_text && input_plain_path) { /*prevent 26249*/
1229 /* get preview text from plain text file */
1230 if( (err = em_get_encoding_type_from_file_path(input_plain_path, &encoding_type)) != EMAIL_ERROR_NONE) {
1231 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
1235 memset(&st_buf, 0, sizeof(struct stat));
1236 if (stat(input_plain_path, &st_buf) < 0) {
1237 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_plain_path);
1238 err = EMAIL_ERROR_INVALID_MAIL;
1242 if (!(fp_plain = fopen(input_plain_path, "r"))) {
1243 EM_DEBUG_EXCEPTION("fopen failed [%s]", input_plain_path);
1244 err = EMAIL_ERROR_SYSTEM_FAILURE;
1248 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
1249 EM_DEBUG_LOG("input_text_file is empty size");
1250 err = EMAIL_ERROR_EMPTY_FILE;
1254 if (!(local_preview_text = (char*)em_malloc(sizeof(char) * local_preview_buffer_length))) {
1255 EM_DEBUG_EXCEPTION("em_malloc failed");
1259 byte_read = fread(local_preview_text, sizeof(char), local_preview_buffer_length - 1, fp_plain);
1261 if(byte_read <=0) { /*prevent 26249*/
1262 EM_SAFE_FREE(local_preview_text);
1263 err = EMAIL_ERROR_NULL_VALUE;
1264 if (ferror(fp_plain)) {
1265 EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path);
1266 err = EMAIL_ERROR_SYSTEM_FAILURE;
1270 reg_replace(local_preview_text, CR_STRING, " ");
1271 reg_replace(local_preview_text, LF_STRING, " ");
1272 reg_replace(local_preview_text, TAB_STRING, " ");
1275 if(local_preview_text) {
1276 em_trim_left(local_preview_text);
1277 EM_DEBUG_LOG("local_preview_text : [%s]", local_preview_text);
1278 if(encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
1279 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
1280 utf8_encoded_string = (char*)g_convert (local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1282 if(utf8_encoded_string == NULL) {
1283 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d], EM_SAFE_STRLEN : [%d]", byte_read, EM_SAFE_STRLEN(local_preview_text));
1284 EM_DEBUG_LOG("Error is G_CONVERT_ERROR_ILLEGAL_SEQUENCE");
1286 if (!g_error_matches (glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
1287 EM_DEBUG_EXCEPTION("g_convert failed");
1291 EM_DEBUG_LOG("Extract the preview text, again");
1293 utf8_encoded_string = (char *)g_convert(local_preview_text, byte_read, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1294 if (utf8_encoded_string == NULL) {
1295 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d]", byte_read);
1300 EM_SAFE_FREE(local_preview_text);
1301 local_preview_text = utf8_encoded_string;
1307 if (local_preview_text != NULL)
1308 *output_preview_buffer = EM_SAFE_STRDUP(local_preview_text);
1310 EM_SAFE_FREE(local_preview_text);
1311 EM_SAFE_FREE(encoding_type);
1313 if (fp_html != NULL)
1316 if (fp_plain != NULL)
1319 EM_DEBUG_FUNC_END("err [%d]", err);
1323 INTERNAL_FUNC int emcore_add_transaction_info(int mail_id, int handle , int *err_code)
1325 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%d]", mail_id, handle);
1328 int err = EMAIL_ERROR_NONE ;
1329 em_transaction_info_type_t *pTransinfo = NULL ;
1330 em_transaction_info_type_t *pTemp = NULL;
1332 EM_DEBUG_LOG("g_transaction_info_list[%p]", g_transaction_info_list);
1333 pTransinfo = g_transaction_info_list ;
1335 if (!(pTemp = em_malloc(sizeof(em_transaction_info_type_t)))) {
1336 EM_DEBUG_EXCEPTION("malloc failed...");
1337 err = EMAIL_ERROR_OUT_OF_MEMORY;
1340 pTemp->mail_id = mail_id ;
1341 pTemp->handle = handle;
1344 pTransinfo = pTemp ;
1345 g_transaction_info_list = pTransinfo ;
1348 while (pTransinfo->next)
1349 pTransinfo = pTransinfo->next;
1350 pTransinfo->next = pTemp;
1358 EM_DEBUG_FUNC_END("g_transaction_info_list[%p]", g_transaction_info_list);
1362 INTERNAL_FUNC int emcore_get_handle_by_mailId_from_transaction_info(int mail_id, int *pHandle)
1364 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p]", mail_id, pHandle);
1367 em_transaction_info_type_t *pTransinfo = NULL ;
1369 if (g_transaction_info_list == NULL) {
1370 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
1373 pTransinfo = g_transaction_info_list;
1376 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
1377 if (pTransinfo->mail_id == mail_id) {
1378 *pHandle = pTransinfo->handle;
1380 EM_DEBUG_LOG("*pHandle[%d]", *pHandle);
1384 pTransinfo = pTransinfo->next ;
1385 }while (pTransinfo);
1386 EM_DEBUG_FUNC_END();
1390 INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id )
1392 EM_DEBUG_FUNC_BEGIN("mail_id[%d]", mail_id);
1394 em_transaction_info_type_t *pTransinfo ;
1395 em_transaction_info_type_t *pTemp = NULL;
1397 if (g_transaction_info_list == NULL) {
1398 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
1401 pTransinfo = g_transaction_info_list;
1403 EM_DEBUG_LOG("pTransinfo[%p]", pTransinfo);
1406 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
1407 if (pTransinfo->mail_id == mail_id) {
1408 pTemp = pTransinfo->next ;
1410 EM_SAFE_FREE(pTransinfo) ;
1411 g_transaction_info_list = NULL;
1414 pTransinfo->mail_id = pTransinfo->next->mail_id;
1415 pTransinfo->handle = pTransinfo->next->handle ;
1416 pTransinfo->next = pTransinfo->next->next;
1418 EM_SAFE_FREE(pTemp);
1423 pTransinfo = pTransinfo->next ;
1426 }while (pTransinfo);
1427 EM_DEBUG_FUNC_END();
1434 int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string)
1436 EM_DEBUG_FUNC_BEGIN("input_source_text [%p], input_old_pattern_string [%p], input_new_string [%p]", input_source_text, input_old_pattern_string, input_new_string);
1437 int error_code = EMAIL_ERROR_NONE;
1439 int so, n, nmatch, source_text_length, n_count = 1;
1440 regmatch_t *pmatch = NULL;
1441 regex_t reg_pattern;
1443 if(!input_source_text || !input_old_pattern_string || !input_new_string) {
1444 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1445 error_code = EMAIL_ERROR_INVALID_PARAM;
1449 source_text_length = EM_SAFE_STRLEN(input_source_text);
1451 regcomp(®_pattern, input_old_pattern_string, REG_ICASE);
1453 nmatch = reg_pattern.re_nsub + 1;
1455 EM_DEBUG_LOG("nmatch [%d]", nmatch);
1458 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_DATA");
1459 error_code = EMAIL_ERROR_INVALID_DATA;
1463 pmatch = (regmatch_t*)em_malloc(sizeof(regmatch_t) * nmatch);
1465 if(pmatch == NULL) {
1466 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
1467 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
1471 for (pos = input_new_string; *pos ; pos++) {
1472 if (*pos == '\\' && *(pos + 1) > '0' && *(pos + 1) <= '9') {
1474 so = pmatch[*(pos + 1) - 48].rm_so;
1475 n = pmatch[*(pos + 1) - 48].rm_eo - so;
1477 EM_DEBUG_LOG("so [%d], n [%d]", so, n);
1479 if (so < 0 || EM_SAFE_STRLEN (input_new_string) + n - 1 > source_text_length)
1482 memmove (pos + n, pos + 2, EM_SAFE_STRLEN (pos) - 1);
1483 memmove (pos, input_source_text + so, n);
1488 for (pos = input_source_text; !regexec (®_pattern, pos, 1, pmatch, 0);) {
1489 n = pmatch[0].rm_eo - pmatch[0].rm_so;
1490 pos += pmatch[0].rm_so;
1492 memmove (pos + EM_SAFE_STRLEN (input_new_string), pos + n, EM_SAFE_STRLEN (pos) - n + 1);
1493 memmove (pos, input_new_string, EM_SAFE_STRLEN (input_new_string));
1494 pos += EM_SAFE_STRLEN (input_new_string);
1500 EM_SAFE_FREE(pmatch);
1501 regfree (®_pattern);
1503 EM_DEBUG_FUNC_END("error_code [%d]", error_code);
1508 int emcore_strip_HTML(char *source_string)
1510 EM_DEBUG_FUNC_BEGIN("source_string [%p]", source_string);
1512 int result = EMAIL_ERROR_NONE;
1514 reg_replace(source_string, CR_STRING, " ");
1515 reg_replace(source_string, LF_STRING, " ");
1516 reg_replace(source_string, "<head[^>]*>", "<head>"); /* "<()*head([^>])*>", "<head>" */
1517 reg_replace(source_string, "<*/head>", "</head>"); /* "(<()*(/)()*head()*>)", "</head>" */
1518 reg_replace(source_string, "<head>.*</head>", ""); /* "(<head>).*(</head>)", "" */
1519 reg_replace(source_string, "<style[^>]*>.*</style>", "");
1521 reg_replace(source_string, "<*/p>", " ");
1522 reg_replace(source_string, "<br>", " ");
1525 reg_replace(source_string, "<[^>]*>", "");
1529 /* reg_replace(source_string, "•", " * "); */
1531 /* "‹", "< */
1532 /* reg_replace(source_string, "‹", "<"); */
1534 /* "›", "> */
1535 /* reg_replace(source_string, "›", ">"); */
1537 /* "™", "(tm) */
1538 /* reg_replace(source_string, "™", "(tm)"); */
1541 /* reg_replace(source_string, "⁄", "/"); */
1544 reg_replace(source_string, "<", "<");
1547 reg_replace(source_string, ">", ">");
1549 /* "©", "(c) */
1550 /* reg_replace(source_string, "©", "(c)"); */
1553 reg_replace(source_string, """, "\'");
1556 reg_replace(source_string, " ", " ");
1558 reg_replace(source_string, " ", " ");
1560 EM_DEBUG_FUNC_END();
1565 /* emcore_send_noti_for_new_mail is not used currently because DBUS could not send very long message.*/
1566 /* But I think it can be used to notify incomming new mail for replacing NOTI_MAIL_ADD with some modification(uid should be replaced with mail_id). */
1567 /* This notification is including addtional information comparing NOTI_MAIL_ADD. */
1568 /* By this change, email application will be able to add email item without additional DB query. */
1569 /* It might improve performance of sync email. */
1570 /* kyuho.jo 2010-09-07 */
1572 INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime)
1574 EM_DEBUG_FUNC_BEGIN("mailbox_name(%s) subject(%s), from(%s), uid(%s), datetime(%s)", mailbox_name, subject, from, uid, datetime);
1575 int error_code = EMAIL_ERROR_NONE;
1576 int param_length = 0;
1577 char *param_string = NULL;
1579 if (mailbox_name == NULL || subject == NULL || from == NULL || uid == NULL || datetime == NULL) {
1580 error_code = EMAIL_ERROR_INVALID_PARAM;
1581 EM_DEBUG_EXCEPTION("Invalid parameter, mailbox_name(%p), subject(%p), from(%p), uid(%p), datetime(%p)", mailbox_name, subject, from, uid, datetime);
1585 param_length = strlen(mailbox_name) + strlen(subject) + strlen(from) + strlen(uid) + strlen(datetime) + 5; /*prevent 34358*/
1587 param_string = em_malloc(param_length);
1588 if (param_string == NULL) {
1589 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
1590 EM_DEBUG_EXCEPTION("Memory allocation for 'param_string' is failed");
1594 memset(param_string, 0x00, param_length);
1596 SNPRINTF(param_string, param_length, "%s%c%s%c%s%c%s%c%s", mailbox_name, 0x01, subject, 0x01, from, 0x01, uid, 0x01, datetime);
1598 if (emcore_notify_network_event(NOTI_DOWNLOAD_NEW_MAIL, account_id, param_string, 0, 0) == 0) { /* failed */
1599 error_code = EMAIL_ERROR_UNKNOWN;
1600 EM_DEBUG_EXCEPTION("emcore_notify_network_event is failed");
1606 EM_SAFE_FREE(param_string);
1607 EM_DEBUG_FUNC_END();
1611 #define MAX_TITLE_LENGTH 1024
1612 int emcore_update_notification_for_unread_mail(int account_id)
1614 EM_DEBUG_FUNC_BEGIN("acccount_id[%d]", account_id);
1616 int i, account_count = 0;
1617 int err = EMAIL_ERROR_NONE;
1618 emstorage_account_tbl_t *p_account_tbl = NULL;
1620 if (!emstorage_get_account_list(&account_count, &p_account_tbl, true, false, &err)) {
1621 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
1625 for (i = 0; i < account_count ; i++) {
1626 if (emcore_add_notification(p_account_tbl[i].account_id, 0, EMAIL_ACTION_NUM) != EMAIL_ERROR_NONE) {
1627 EM_DEBUG_EXCEPTION("emcore_add_notification failed");
1637 emstorage_free_account(&p_account_tbl, account_count, NULL);
1639 EM_DEBUG_FUNC_END();
1643 INTERNAL_FUNC int emcore_finalize_sync(int account_id, int *error)
1645 EM_DEBUG_FUNC_BEGIN("account_id [%d], error [%p]", account_id, error);
1646 int err = EMAIL_ERROR_NONE, ret = true, result_sync_status = SYNC_STATUS_FINISHED;
1648 if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE)
1649 EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err);
1651 if (!emstorage_get_sync_status_of_account(ALL_ACCOUNT, &result_sync_status, &err))
1652 EM_DEBUG_EXCEPTION("emstorage_get_sync_status_of_account failed [%d]", err);
1654 if (result_sync_status == SYNC_STATUS_HAVE_NEW_MAILS) {
1655 if (!emcore_update_notification_for_unread_mail(ALL_ACCOUNT))
1656 EM_DEBUG_EXCEPTION("emcore_update_notification_for_unread_mail failed");
1658 if (!emcore_display_unread_in_badge())
1659 EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed");
1661 emcore_start_alert();
1663 if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE)
1664 EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err);
1667 EM_DEBUG_FUNC_END();
1671 INTERNAL_FUNC int emcore_clear_all_notifications()
1673 int account_count = 0, i;
1674 emstorage_account_tbl_t *account_list;
1675 int error_code = EMAIL_ERROR_NONE;
1677 if(!emstorage_get_account_list(&account_count, &account_list, true, false, &error_code)) {
1678 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed");
1682 for(i = 0; i < account_count; i++) {
1683 emcore_delete_notification_by_account(account_list[i].account_id);
1688 emstorage_free_account(&account_list, account_count, NULL);
1691 EM_DEBUG_FUNC_END("return[%d]", error_code);
1695 #define EAS_EXECUTABLE_PATH "/usr/bin/eas-engine"
1697 INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id)
1699 EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
1700 int error_code = EMAIL_ERROR_NONE;
1702 char vconf_private_id[MAX_PATH] = {0, };
1704 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1705 if (vconf_get_int(vconf_private_id, &private_id) != 0) {
1706 EM_DEBUG_EXCEPTION("vconf_get_int failed");
1708 EM_DEBUG_FUNC_END();
1712 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
1715 * @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)
1716 * Prepare a linked list of uid ranges with each node having a uid_range and lowest and highest uid in it.
1718 *@author h.gahlaut@samsung.com
1719 * @param[in] id_set Specifies the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
1720 * @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
1721 * @param[in] range_len Specifies the maximum length of string of range allowed.
1722 * @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
1723 * @param[out] err_code Returns the error code.
1724 * @remarks An example of a uid_range formed is 2:6,8,10,14:15,89,
1725 * While using it the caller should remove the ending, (comma)
1726 * @return This function returns true on success or false on failure.
1729 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)
1731 EM_DEBUG_FUNC_BEGIN();
1734 int error = EMAIL_ERROR_NONE;
1736 if (NULL == id_set || id_set_count <= 0 || NULL == uid_range_set) {
1737 EM_DEBUG_EXCEPTION(" Invalid Parameter id_set[%p] id_set_count[%d] uid_range_set[%p]", id_set, id_set_count, uid_range_set);
1738 error = EMAIL_ERROR_INVALID_PARAM;
1743 unsigned long current_uid = 0;
1744 unsigned long first_uid = 0;
1745 unsigned long last_uid = 0;
1746 const int max_subset_string_size = MAX_SUBSET_STRING_SIZE;
1747 char subset_string[MAX_SUBSET_STRING_SIZE] = {0,};
1748 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*/
1750 if (range_len < (max_subset_string_size + 1)) /* 1 for ending NULL character */ {
1751 EM_DEBUG_EXCEPTION(" Invalid Parameter range_len[%d]", range_len);
1752 error = EMAIL_ERROR_INVALID_PARAM;
1756 EM_DEBUG_LOG("id set count[%d] range_len[%d]", id_set_count, range_len);
1759 first_uid = last_uid = current_uid = id_set[i].server_mail_id;
1760 /* Start subset string by putting first server mail id in it from id_set*/
1761 memset(subset_string, 0x00, max_subset_string_size);
1762 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
1765 /* Check if only one server mail id was left in id_set */
1766 if (i >= id_set_count) {
1767 /* No more server mail id left in id_set */
1768 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
1769 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
1775 /* 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 */
1777 current_uid = id_set[i].server_mail_id;
1778 if (current_uid == (last_uid + 1)) {
1779 last_uid = current_uid;
1783 memset(subset_string, 0x00, max_subset_string_size);
1784 if (first_uid != last_uid) /* Form subset string by first_uid:last_uid */
1785 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
1786 else /* Form subset string by first_uid */
1787 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
1789 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
1790 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
1793 /* To Start formation of new subset string break out of inner loop */
1797 } while (i < id_set_count);
1799 /* Flow comes here in two cases :
1800 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
1801 2. due to break statement */
1803 if (last_uid == current_uid) {
1806 memset(subset_string, 0x00, max_subset_string_size);
1807 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
1809 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
1810 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
1815 /* Case 2: Do Nothing */
1819 } while (i < id_set_count);
1824 if (NULL != err_code)
1826 EM_DEBUG_FUNC_END();
1832 * @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)
1833 * 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
1834 * and stores the subset_string in its uid_range. Also sets the lowest and highest uids for the corresponsing uid_range
1836 * @author h.gahlaut@samsung.com
1837 * @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.
1838 * @param[in] range_len Specifies the maximum length of range string allowed.
1839 * @param[in] luid Specifies the lowest uid in subset string
1840 * @param[in] huid Specifies the highest uid in subset string
1841 * @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
1842 * @param[out] err_code Returns the error code.
1844 * @return This function returns true on success or false on failure.
1847 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)
1849 EM_DEBUG_FUNC_BEGIN();
1850 email_uid_range_set *current_node = NULL;
1852 if (NULL == (*uid_range_set)) {
1853 /*This happens only once when list creation starts. Head Node is allocated */
1854 current_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
1855 if (NULL == current_node) {
1856 EM_DEBUG_EXCEPTION("em_malloc failed");
1860 current_node->uid_range = (char *)em_malloc(range_len);
1862 if (NULL == current_node->uid_range) {
1863 EM_DEBUG_EXCEPTION("em_malloc failed");
1864 EM_SAFE_FREE(current_node);
1868 SNPRINTF(current_node->uid_range, range_len, "%s,", subset_string);
1870 current_node->lowest_uid = luid;
1871 current_node->highest_uid = huid;
1872 (*uid_range_set) = current_node;
1874 (*current_node_adr) = current_node;
1878 /* Apart from first call to this function flow will always come here */
1879 current_node = (*current_node_adr);
1880 int len_sub_string = EM_SAFE_STRLEN(subset_string);
1881 int space_left_in_buffer = range_len - EM_SAFE_STRLEN(current_node->uid_range);
1883 if ((len_sub_string + 1 + 1) <= space_left_in_buffer) /* 1 for comma + 1 for ending null character */ {
1884 SNPRINTF(current_node->uid_range + EM_SAFE_STRLEN(current_node->uid_range), space_left_in_buffer, "%s,", subset_string);
1885 current_node->highest_uid = huid;
1888 /* No more space left in uid_range string.If continued on it, it will exceeded max size of range_len */
1889 /* Allocate new node in Uid Range set */
1890 email_uid_range_set *new_node = NULL;
1892 new_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
1894 if (NULL == new_node) {
1895 EM_DEBUG_EXCEPTION("em_malloc failed");
1899 /* Allocate uid_range of new node */
1901 new_node->uid_range = (char *)em_malloc(range_len);
1903 if (NULL == new_node->uid_range) {
1904 EM_DEBUG_EXCEPTION("em_malloc failed");
1905 EM_SAFE_FREE(new_node);
1909 SNPRINTF(new_node->uid_range, range_len, "%s, ", subset_string);
1911 new_node->lowest_uid = luid;
1912 new_node->highest_uid = huid;
1914 current_node->next = new_node;
1916 (*current_node_adr) = new_node;
1919 EM_DEBUG_FUNC_END();
1924 * void emcore_free_uid_range_set(email_uid_range_set **uid_range_head)
1925 * Frees the linked list of uid ranges
1927 * @author h.gahlaut@samsung.com
1928 * @param[in] uid_range_head Head pointer of linked list of uid ranges
1930 * @return This function does not return anything.
1934 void emcore_free_uid_range_set(email_uid_range_set **uid_range_set)
1936 EM_DEBUG_FUNC_BEGIN();
1938 email_uid_range_set *current_node = NULL;
1939 email_uid_range_set *uid_range_head = NULL;
1941 current_node = uid_range_head = (*uid_range_set); /* Make the current node and head ptr point to starting of uid_range_set */
1943 while (current_node) {
1944 uid_range_head = current_node->next; /* Move the head ptr to next node*/
1946 EM_SAFE_FREE(current_node->uid_range);
1947 EM_SAFE_FREE(current_node); /* Free the current node */
1949 current_node = uid_range_head; /* Make the current node point to head ptr */
1952 (*uid_range_set) = NULL;
1953 EM_DEBUG_FUNC_END();
1958 * @fn emcore_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char *** strings, int *string_count, int *err_code)
1959 * Forms comma separated strings of a give max_string_len from an array of numbers
1961 * @author h.gahlaut@samsung.com
1962 * @param[in] numbers Specifies the array of numbers to be converted into comma separated strings.
1963 * @param[in] num_count Specifies the count of numbers in numbers array.
1964 * @param[in] max_string_len Specifies the maximum length of comma separated strings that are to be formed.
1965 * @param[out] strings Returns the base address of a double dimension array which stores the strings.
1966 * @param[out] string_count Returns the number of strings formed.
1967 * @param[out] err_code Returns the error code.
1968 * @remarks If Input to the function is five numbers like 2755 2754 2748 2749 2750 and a given max_string_len is 20.
1969 * Then this function will form two comma separated strings as follows -
1970 * "2755, 2754, 2748"
1972 * @return This function returns true on success or false on failure.
1975 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)
1977 EM_DEBUG_FUNC_BEGIN();
1979 int error = EMAIL_ERROR_NONE;
1982 char **string_list = NULL;
1983 int num_of_strings = 0;
1986 char num[MAX_INTEGER_LENGTH + 1] = {0, };
1988 int space_in_buffer = 0;
1989 int len_of_string_formed = 0;
1991 if (NULL == numbers || num_count <= 0 || \
1992 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. */ {
1993 EM_DEBUG_EXCEPTION("Invalid Parameter numbers[%p] num_count [%d] max_string_len [%d] strings [%p] string_count[%p]", \
1994 numbers, num_count, max_string_len, strings, string_count);
1995 error = EMAIL_ERROR_INVALID_PARAM;
1999 EM_DEBUG_LOG("num_count [%d] max_string_len [%d]", num_count, max_string_len);
2001 string_list = em_malloc(sizeof(char *));
2003 if (NULL == string_list) {
2004 EM_DEBUG_EXCEPTION("em_malloc failed ");
2008 string_list[num_of_strings] = em_malloc(max_string_len);
2010 if (NULL == string_list[num_of_strings]) {
2011 EM_DEBUG_EXCEPTION("em_malloc failed ");
2016 space_in_buffer = max_string_len;
2018 for (j = 0; j < num_count;++j) {
2019 memset(num, 0x00, MAX_INTEGER_LENGTH + 1);
2020 SNPRINTF(num, MAX_INTEGER_LENGTH + 1, "%d", numbers[j]);
2022 num_len = EM_SAFE_STRLEN(num);
2024 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
2026 space_in_buffer = max_string_len - len_of_string_formed ;
2028 if (space_in_buffer >= (num_len+1+1)) /* 1 for comma and 1 for ending NULL */ {
2029 SNPRINTF(string_list[num_of_strings - 1] + len_of_string_formed, max_string_len, "%d,", numbers[j]);
2031 else { /* Removing comma at end of string */
2032 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
2034 temp = (char **)realloc(string_list, sizeof(char *) * (num_of_strings + 1)); /* Allocate new buffer to store a pointer to a new string */
2037 EM_DEBUG_EXCEPTION("realloc failed");
2041 memset(temp + num_of_strings, 0X00, sizeof(char *));
2045 string_list[num_of_strings] = em_malloc(max_string_len);/* Allocate new buffer to store the string */
2047 if (NULL == string_list[num_of_strings]) {
2048 EM_DEBUG_EXCEPTION(" em_malloc failed ");
2052 SNPRINTF(string_list[num_of_strings - 1] , max_string_len, "%d,", numbers[j]);/* Start making new string */
2056 /* Removing comma at end of string */
2057 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
2058 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
2064 emcore_free_comma_separated_strings(&string_list, &num_of_strings);
2067 for (i = 0; i < num_of_strings;++i)
2068 EM_DEBUG_LOG("%s", string_list[i]);
2069 *strings = string_list;
2070 *string_count = num_of_strings;
2074 if (NULL != err_code)
2077 EM_DEBUG_FUNC_END("ret [%d]", ret);
2081 * @fn emcore_free_comma_separated_strings(char *** string_list, int *string_count)
2082 * Frees the double dimensional array of strings.
2084 * @author h.gahlaut@samsung.com
2085 * @param[in] uid_range_head Address of base address of double dimensional array of strings.
2086 * @param[in] string_count Address of variable holding the count of strings.
2088 * @return This function does not return anything.
2090 INTERNAL_FUNC void emcore_free_comma_separated_strings(char *** string_list, int *string_count)
2092 EM_DEBUG_FUNC_BEGIN();
2094 char **str_list = NULL;
2097 if (NULL != string_list) {
2098 str_list = *string_list;
2100 if (0 != *string_count) {
2101 count = *string_count;
2102 for (i = 0; i < count; ++i)
2103 EM_SAFE_FREE(str_list[i]);
2106 EM_SAFE_FREE(str_list);
2107 *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 */
2110 EM_DEBUG_FUNC_END();
2119 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)
2121 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);
2122 int ret = false, err = EMAIL_ERROR_NONE;
2123 char *extcheck = NULL;
2124 char attachment_file_name[MAX_PATH + 1] = { 0, };
2126 if (!source_file_name || !result_file_name) {
2127 EM_DEBUG_EXCEPTION("Invalid Parameter");
2128 err = EMAIL_ERROR_INVALID_PARAM;
2132 strncpy(attachment_file_name, source_file_name, MAX_PATH);
2133 extcheck = strchr(attachment_file_name, '.');
2136 EM_DEBUG_LOG("Extension Exist in the Attachment [%s] ", extcheck);
2137 else { /* No extension attached, So add the Extension based on the subtype */
2139 strcat(attachment_file_name, ".");
2140 strcat(attachment_file_name, sub_type);
2141 EM_DEBUG_LOG("attachment_file_name with extension[%s] ", attachment_file_name);
2144 EM_DEBUG_LOG("UnKnown Extesnsion");
2147 memset(result_file_name, 0 , result_file_name_buffer_length);
2148 EM_SAFE_STRNCPY(result_file_name, attachment_file_name, result_file_name_buffer_length - 1);
2149 EM_DEBUG_LOG("*result_file_name[%s]", result_file_name);
2155 EM_DEBUG_FUNC_END();
2159 #ifdef __FEATURE_LOCAL_ACTIVITY__
2160 INTERNAL_FUNC int emcore_add_activity(emstorage_activity_tbl_t *new_activity, int *err_code)
2162 EM_DEBUG_FUNC_BEGIN();
2164 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", new_activity, err_code);
2166 /* default variable */
2168 int err = EMAIL_ERROR_NONE;
2170 if (!new_activity) {
2171 EM_DEBUG_LOG("\t new_activity[%p]\n", new_activity);
2172 err = EMAIL_ERROR_INVALID_PARAM;
2175 if (!emstorage_add_activity(new_activity, false, &err)) {
2176 EM_DEBUG_LOG("\t emstorage_add_activity falied - %d\n", err);
2189 INTERNAL_FUNC int emcore_delete_activity(emstorage_activity_tbl_t *activity, int *err_code)
2191 EM_DEBUG_FUNC_BEGIN();
2193 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", activity, err_code);
2195 /* default variable */
2197 int err = EMAIL_ERROR_NONE;
2199 EM_DEBUG_LOG("\t new_activity[%p]\n", activity);
2201 err = EMAIL_ERROR_INVALID_PARAM;
2204 if (!emstorage_delete_local_activity(activity, true, &err)) {
2205 EM_DEBUG_LOG("\t emstorage_delete_local_activity falied - %d\n", err);
2218 INTERNAL_FUNC int emcore_get_next_activity_id(int *activity_id, int *err_code)
2220 EM_DEBUG_FUNC_BEGIN();
2223 int err = EMAIL_ERROR_NONE;
2225 if (NULL == activity_id)
2227 EM_DEBUG_EXCEPTION("\t activity_id[%p]", activity_id);
2229 err = EMAIL_ERROR_INVALID_PARAM;
2233 if (false == emstorage_get_next_activity_id(activity_id, &err)) {
2234 EM_DEBUG_LOG("\t emstorage_get_next_activity_id failed - %d\n", err);
2241 if (NULL != err_code) {
2249 #endif /* __FEATURE_LOCAL_ACTIVITY__ */
2252 INTERNAL_FUNC void emcore_free_rule(email_rule_t* rule)
2254 EM_DEBUG_FUNC_BEGIN();
2259 EM_SAFE_FREE(rule->value);
2261 EM_DEBUG_FUNC_END();
2264 INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_string, int *result)
2266 EM_DEBUG_FUNC_BEGIN("file_path : [%s], search_string : [%s]", file_path, search_string);
2267 int error = EMAIL_ERROR_NONE;
2269 int p_result = false;
2272 char *stripped = NULL;
2274 if (!search_string || !file_path || !result) {
2275 EM_DEBUG_EXCEPTION("Invalid parameter");
2276 error = EMAIL_ERROR_INVALID_PARAM;
2280 fp = fopen(file_path, "r");
2282 EM_DEBUG_EXCEPTION("fopen failed");
2283 error = EMAIL_ERROR_SYSTEM_FAILURE;
2287 if (!emcore_get_file_size(file_path, &file_size, &error)) {
2288 EM_DEBUG_EXCEPTION("emcore_get_file_size failed");
2292 buf = em_malloc(file_size);
2294 EM_DEBUG_EXCEPTION("em_malloc failed");
2295 error = EMAIL_ERROR_OUT_OF_MEMORY;
2299 if (fread(buf, sizeof(char), file_size, fp) != file_size) {
2300 EM_DEBUG_EXCEPTION("Get the data from file : failed");
2301 error = EMAIL_ERROR_SYSTEM_FAILURE;
2306 stripped = em_replace_all_string(buf, CRLF_STRING, "");
2307 if (strstr(stripped, search_string))
2312 EM_DEBUG_LOG("Search string[%s] not found",search_string);
2320 EM_SAFE_FREE(stripped); /*prevent 35586*/
2322 EM_DEBUG_FUNC_END("error:[%d]", error);