4 * Copyright (c) 2000 - 2011 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/org.tizen.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 static emcore_account_list_t **g_account_reference = NULL;
102 INTERNAL_FUNC char *emcore_convert_mutf7_to_utf8(char *mailbox_name)
104 EM_DEBUG_FUNC_BEGIN();
105 return (char *)(utf8_from_mutf7((unsigned char *)mailbox_name));
108 INTERNAL_FUNC int emcore_set_account_reference(emcore_account_list_t **account_list, int account_num, int *err_code)
110 g_account_reference = (emcore_account_list_t **)account_list;
114 /* in smtp case, path argument must be ENCODED_PATH_SMTP */
115 int emcore_get_long_encoded_path_with_account_info(email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code)
117 EM_PROFILE_BEGIN(emCorelongEncodedpath);
118 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);
121 int error = EMAIL_ERROR_NONE;
124 size_t long_enc_path_len = 0;
126 if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) { /* imap or pop3 */
127 EM_DEBUG_LOG("account->incoming_server_address[%p]", account->incoming_server_address);
128 EM_DEBUG_LOG("account->incoming_server_address[%s]", account->incoming_server_address);
130 if (!account->incoming_server_address) {
131 EM_DEBUG_EXCEPTION("account->incoming_server_address is null");
132 error = EMAIL_ERROR_INVALID_ACCOUNT;
136 long_enc_path_len = EM_SAFE_STRLEN(account->incoming_server_address) + EM_SAFE_STRLEN(path) + 64; /*prevent 34357*/
138 *long_enc_path = em_malloc(long_enc_path_len);
139 if (!*long_enc_path) {
140 EM_DEBUG_EXCEPTION("malloc failed...");
141 error = EMAIL_ERROR_OUT_OF_MEMORY;
147 /* ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}my-mailbox" */
149 SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d",
150 account->incoming_server_address,
151 account->incoming_server_port_number,
152 account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap", account->account_id);
154 if (account->incoming_server_secure_connection & 0x01) {
155 strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
156 /* strcat(p, "/tryssl"); */
159 /* Currently, receiving servers doesn't require tls.
160 if (account->incoming_server_secure_connection & 0x02)
161 strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
163 strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
166 if (account->incoming_server_requires_apop) {
167 EM_DEBUG_LOG("emcore_get_long_encoded_path - incoming_server_requires_apop - %d", account->incoming_server_requires_apop);
168 strncat(p, "/apop", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
169 EM_DEBUG_LOG("long_enc_path - %s", p);
173 long_enc_path_len = EM_SAFE_STRLEN(account->outgoing_server_address) + 64;
175 *long_enc_path = em_malloc(EM_SAFE_STRLEN(account->outgoing_server_address) + 64);
176 if (!*long_enc_path) {
177 EM_DEBUG_EXCEPTION("\t malloc failed...\n");
179 error = EMAIL_ERROR_OUT_OF_MEMORY;
185 /* ex:"mail.test.com:25/smtp" */
187 SNPRINTF(p, long_enc_path_len, "%s:%d/%s",
188 account->outgoing_server_address,
189 account->outgoing_server_port_number,
192 if (account->outgoing_server_need_authentication) {
193 SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d", account->account_id);
196 if (account->outgoing_server_secure_connection & 0x01) {
197 strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
198 /* strcat(p, "/tryssl"); */
200 if (account->outgoing_server_secure_connection & 0x02)
201 strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
203 strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
206 if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) {
207 strncat(p, "}", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
210 char *enc_name = NULL;
212 if (!emcore_get_encoded_mailbox_name(path, &enc_name, &error)) {
213 EM_DEBUG_EXCEPTION("emcore_get_encoded_mailbox_name failed - %d", error);
214 *long_enc_path = NULL;
219 strncat(p, enc_name, long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
220 EM_SAFE_FREE(enc_name);
231 if (err_code != NULL)
233 EM_PROFILE_END(emCorelongEncodedpath);
237 int emcore_get_long_encoded_path(int account_id, char *path, int delimiter, char **long_enc_path, int *err_code)
239 EM_PROFILE_BEGIN(emCorelongEncodedpath);
240 EM_DEBUG_FUNC_BEGIN("account_id[%d], delimiter[%d], long_enc_path[%p], err_code[%p]", account_id, delimiter, long_enc_path, err_code);
243 int error = EMAIL_ERROR_NONE;
245 email_account_t *ref_account = emcore_get_account_reference(account_id);
247 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
248 error = EMAIL_ERROR_INVALID_ACCOUNT;
252 if (emcore_get_long_encoded_path_with_account_info(ref_account, path, delimiter, long_enc_path, &error) == false) {
253 EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path_with_account_info failed [%d]", error);
260 if (err_code != NULL)
262 EM_PROFILE_END(emCorelongEncodedpath);
266 int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code)
268 EM_DEBUG_FUNC_BEGIN("name[%s], enc_name[%p], err_code[%p]", name, enc_name, err_code);
270 if (!name || !enc_name) {
271 if (err_code != NULL)
272 *err_code = EMAIL_ERROR_INVALID_PARAM;
277 /* encoding mailbox name (Charset->UTF8->UTF7) */
279 *enc_name = em_malloc(EM_SAFE_STRLEN(name)+1);
280 if (*enc_name == NULL) {
281 EM_DEBUG_EXCEPTION("malloc failed...");
282 if (err_code != NULL)
283 *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
288 strcpy(*enc_name, name);
290 if (err_code != NULL)
291 *err_code = EMAIL_ERROR_NONE;
297 int emcore_get_temp_file_name(char **filename, int *err_code)
299 EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code);
302 int error = EMAIL_ERROR_NONE;
304 if (filename == NULL) {
305 EM_DEBUG_EXCEPTION("\t filename[%p]\n", filename);
306 error = EMAIL_ERROR_INVALID_PARAM;
310 char tempname[512] = {0x00, };
314 gettimeofday(&tv, NULL);
317 /* Create Directory If deleted by user*/
318 emstorage_create_dir_if_delete();
320 SNPRINTF(tempname, sizeof(tempname), "%s%c%d", MAILTEMP, DIR_SEPERATOR_CH, rand());
322 char *p = EM_SAFE_STRDUP(tempname);
324 EM_DEBUG_EXCEPTION("\t strdup failed...\n");
325 error = EMAIL_ERROR_OUT_OF_MEMORY;
334 if (err_code != NULL)
340 int emcore_get_file_name(char *path, char **filename, int *err_code)
342 EM_DEBUG_FUNC_BEGIN("path[%s], filename[%p], err_code[%p]", path, filename, err_code);
345 int error = EMAIL_ERROR_NONE;
347 if (!path || !filename) {
348 EM_DEBUG_EXCEPTION("path[%p], filename[%p]", path, filename);
350 error = EMAIL_ERROR_INVALID_PARAM;
354 int i = (int)EM_SAFE_STRLEN(path);
358 if (path[i] == DIR_SEPERATOR_CH)
361 *filename = path + i + 1;
366 if (err_code != NULL)
372 int emcore_get_file_size(char *path, int *size, int *err_code)
374 EM_DEBUG_FUNC_BEGIN("path[%s], size[%p], err_code[%p]", path, size, err_code);
377 int error = EMAIL_ERROR_NONE;
379 if ((path == NULL) || (size == NULL)) {
380 EM_DEBUG_EXCEPTION("\t path[%p], size[%p]\n", path, size);
382 error = EMAIL_ERROR_INVALID_PARAM;
388 if (stat(path, &st_buf) < 0) {
389 EM_DEBUG_EXCEPTION("\t stat failed - %s\n", path);
391 error = EMAIL_ERROR_SYSTEM_FAILURE;
395 *size = st_buf.st_size;
400 if (err_code != NULL)
408 static int _emcore_check_host(char *host)
412 return strncmp(host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."));
417 int emcore_get_address_count(char *addr_str, int *count, int *err_code)
419 EM_DEBUG_FUNC_BEGIN("addr_str[%s], count[%p], err_code[%p]", addr_str, count, err_code);
422 int error = EMAIL_ERROR_NONE;
424 ADDRESS *addr = NULL;
425 ADDRESS *p_addr = NULL;
431 EM_DEBUG_EXCEPTION("addr_str[%s], count[%p]", addr_str, count);
432 error = EMAIL_ERROR_INVALID_PARAM;
436 if (addr_str != NULL) {
437 em_skip_whitespace(addr_str, &p);
438 EM_DEBUG_LOG("em_skip_whitespace[p][%s]", p);
441 for (i = 0, j = EM_SAFE_STRLEN(p); i < j; i++)
442 if (p[i] == ';') p[i] = ',';
443 rfc822_parse_adrlist(&addr, p, NULL);
447 for (p_addr = addr, i = 0; p_addr; p_addr = p_addr->next, i++) {
448 if (p_addr->mailbox && p_addr->host) {
449 if (!strncmp(p_addr->mailbox, "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS"))
450 || !strncmp(p_addr->mailbox, "INVALID_ADDRESS", strlen("INVALID_ADDRESS"))
451 || !strncmp(p_addr->host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."))) { /*prevent 34356*/
452 EM_DEBUG_LOG("Invalid address ");
456 if ((!p_addr->mailbox) || (_emcore_check_host(p_addr->host) == 0)) {
457 EM_DEBUG_EXCEPTION("\t invalid address : mailbox[%s], host[%s]\n", p_addr->mailbox, p_addr->host);
459 error = EMAIL_ERROR_INVALID_ADDRESS;
460 /* goto FINISH_OFF; */
466 if (error != EMAIL_ERROR_INVALID_ADDRESS)
471 mail_free_address(&addr);
473 if (err_code != NULL)
479 INTERNAL_FUNC int emcore_set_network_error(int err_code)
481 email_session_t *session = NULL;
483 EM_DEBUG_FUNC_BEGIN();
485 emcore_get_current_session(&session);
490 session->network = err_code;
495 int emcore_get_empty_session(email_session_t **session)
497 EM_DEBUG_FUNC_BEGIN("session[%p]", session);
503 for (i = 0; i < SESSION_MAX; i++) {
504 if (!g_session_list[i].status) {
505 memset(g_session_list+i, 0x00, sizeof(email_session_t));
506 g_session_list[i].tid = GPOINTER_TO_INT(THREAD_SELF());
507 g_session_list[i].status = true;
515 *session = (i != SESSION_MAX) ? &g_session_list[i] : NULL;
517 return (i != SESSION_MAX) ? true : false;
520 int emcore_clear_session(email_session_t *session)
522 EM_DEBUG_FUNC_BEGIN();
525 memset(session, 0x00, sizeof(email_session_t));
530 int emcore_get_current_session(email_session_t **session)
532 EM_DEBUG_FUNC_BEGIN("session[%p]", session);
536 for (i = 0; i < SESSION_MAX; i++) {
537 if (g_session_list[i].tid == GPOINTER_TO_INT(THREAD_SELF())) {
539 *session = g_session_list + i;
546 *session = (i != SESSION_MAX) ? g_session_list + i : NULL;
548 return (i != SESSION_MAX) ? true : false;
551 int emcore_get_mail_count_by_query(int account_id, int priority_sender, int *total_mail, int *unread_mail, int *err_code)
553 EM_DEBUG_FUNC_BEGIN();
556 int err = EMAIL_ERROR_NONE;
558 int type = EMAIL_PRIORITY_SENDER;
559 int unread_count = 0;
561 char *conditional_clause_string = NULL;
564 int is_completed = 0;
565 emstorage_rule_tbl_t *rule = NULL;
567 int filter_count = 0;
568 email_list_filter_t *filter_list = NULL;
570 if (priority_sender) {
572 if (!emstorage_get_rule(ALL_ACCOUNT, type, 0, &rule_count, &is_completed, &rule, true, &err) || !rule) {
573 EM_DEBUG_EXCEPTION("emstorage_get_rule failed");
577 /* Make query for searching unread mail */
578 if (account_id != ALL_ACCOUNT) {
579 filter_count = (rule_count * 2) + 3;
581 filter_count = (rule_count * 2) + 1; // 1 is unseen field.
584 filter_list = em_malloc(sizeof(email_list_filter_t) * filter_count);
585 if (filter_list == NULL) {
586 EM_DEBUG_EXCEPTION("em_malloc failed");
587 err = EMAIL_ERROR_OUT_OF_MEMORY;
591 for (i = 0, count = 0; i < filter_count - 1; i += 2, count++) {
592 filter_list[i].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
593 filter_list[i].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
594 filter_list[i].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FROM;
595 filter_list[i].list_filter_item.rule.key_value.string_type_value = EM_SAFE_STRDUP(rule[count].value);
597 filter_list[i+1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
598 if (i == (filter_count - 2)) {
599 filter_list[i+1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
601 filter_list[i+1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
605 filter_list[i].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
606 filter_list[i].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
607 filter_list[i].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD;
608 filter_list[i].list_filter_item.rule.key_value.integer_type_value = 0;
610 if (account_id != ALL_ACCOUNT) {
611 filter_list[i+1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
612 filter_list[i+1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
614 filter_list[i+2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
615 filter_list[i+2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
616 filter_list[i+2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID;
617 filter_list[i+2].list_filter_item.rule.key_value.integer_type_value = account_id;
620 if ((err = emstorage_write_conditional_clause_for_getting_mail_list(filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
621 EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
625 EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
627 /* Search the mail of priority sender in DB */
628 if ((err = emstorage_query_mail_count(conditional_clause_string, true, &total_count, &unread_count)) != EMAIL_ERROR_NONE) {
629 EM_DEBUG_EXCEPTION("emstorage_query_mail_count failed:[%d]", err);
633 if (!emstorage_get_mail_count(account_id, NULL, &total_count, &unread_count, true, &err)) {
634 EM_DEBUG_EXCEPTION(" emstorage_get_mail_count failed - %d", err);
645 emstorage_free_rule(&rule, rule_count, NULL);
648 emstorage_free_list_filter(&filter_list, filter_count);
650 EM_SAFE_FREE(conditional_clause_string);
653 *total_mail = total_count;
656 *unread_mail = unread_count;
664 int emcore_display_unread_in_badge()
666 EM_DEBUG_FUNC_BEGIN();
669 int err = EMAIL_ERROR_NONE;
670 int total_unread_count = 0;
671 int total_mail_count = 0;
672 int badge_ticker = 0;
673 int priority_sender = 0;
676 /* Get the Global noti ticker */
677 if (vconf_get_bool(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, &badge_ticker) != 0) {
678 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
679 err = EMAIL_ERROR_GCONF_FAILURE;
683 /* Get the priority noti ticker */
685 if (vconf_get_bool(VCONF_VIP_NOTI_BADGE_TICKER, &badge_ticker) != 0) {
686 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
687 err = EMAIL_ERROR_GCONF_FAILURE;
692 EM_DEBUG_LOG("Not display the badge");
700 /* Get unread mail count */
701 if (!emcore_get_mail_count_by_query(ALL_ACCOUNT, priority_sender, &total_mail_count, &total_unread_count, &err)) {
702 EM_DEBUG_EXCEPTION("emcore_get_mail_count_by_query failed");
706 /* temporarily disable : set unread count to badge */
707 if (vconf_set_int(VCONF_KEY_UNREAD_MAIL_COUNT, total_unread_count) != 0) {
708 EM_DEBUG_EXCEPTION("vconf_set_int failed");
709 err = EMAIL_ERROR_GCONF_FAILURE;
714 badge_error_e badge_err = BADGE_ERROR_NONE;
717 if((badge_err = badge_is_existing("org.tizen.email", &exist)) != BADGE_ERROR_NONE) {
718 EM_DEBUG_EXCEPTION("badge_is_existing failed [%d]", badge_err);
719 err = EMAIL_ERROR_BADGE_API_FAILED;
724 if((badge_err = badge_create("org.tizen.email", "/usr/bin/email-service")) != BADGE_ERROR_NONE) {
725 EM_DEBUG_EXCEPTION("badge_create failed [%d]", badge_err);
726 err = EMAIL_ERROR_BADGE_API_FAILED;
731 if((badge_err = badge_set_count("org.tizen.email", total_unread_count)) != BADGE_ERROR_NONE) {
732 EM_DEBUG_EXCEPTION("badge_set_count failed [%d]", badge_err);
733 err = EMAIL_ERROR_BADGE_API_FAILED;
737 if (total_unread_count <= 0)
747 static int emcore_layout_multi_noti(notification_h noti, int unread_mail, char *email_address, char *account_name)
749 EM_DEBUG_FUNC_BEGIN();
750 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
751 char modified_string[10];
753 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
754 if (noti_err != NOTIFICATION_ERROR_NONE) {
755 EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_SINGLE failed [%d]", noti_err);
759 SNPRINTF(modified_string, sizeof(modified_string), "%d", unread_mail);
761 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
762 if (noti_err != NOTIFICATION_ERROR_NONE) {
763 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
767 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, modified_string, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
768 if (noti_err != NOTIFICATION_ERROR_NONE) {
769 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_EVENT_COUNT failed");
773 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "new emails", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
774 if (noti_err != NOTIFICATION_ERROR_NONE) {
775 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
779 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, email_address, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
780 if (noti_err != NOTIFICATION_ERROR_NONE) {
781 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
785 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, account_name, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
786 if (noti_err != NOTIFICATION_ERROR_NONE) {
787 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_2 failed");
791 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH);
792 if (noti_err != NOTIFICATION_ERROR_NONE) {
793 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
799 EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err);
803 static int emcore_layout_single_noti(notification_h noti, char *account_name, char *display_sender, time_t time, char *subject)
805 EM_DEBUG_FUNC_BEGIN();
806 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
808 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
809 if (noti_err != NOTIFICATION_ERROR_NONE) {
810 EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_SINGLE failed [%d]", noti_err);
814 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
815 if (noti_err != NOTIFICATION_ERROR_NONE) {
816 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
820 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, account_name, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
821 if (noti_err != NOTIFICATION_ERROR_NONE) {
822 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
826 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, display_sender, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
827 if (noti_err != NOTIFICATION_ERROR_NONE) {
828 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
833 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, time, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
834 if (noti_err != NOTIFICATION_ERROR_NONE) {
835 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_SUB_1 failed");
840 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
841 if (noti_err != NOTIFICATION_ERROR_NONE) {
842 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_2 failed");
846 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH);
847 if (noti_err != NOTIFICATION_ERROR_NONE) {
848 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
854 EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err);
858 static int emcore_add_notification(int account_id, int mail_id, email_action_t action)
860 EM_DEBUG_FUNC_BEGIN();
861 int err = EMAIL_ERROR_NONE;
863 EM_DEBUG_FUNC_END("ret [%d]", err);
867 INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int error)
869 EM_DEBUG_FUNC_BEGIN("id[%d], action[%d], error[%d]", id, action, error);
873 if (action == EMAIL_ACTION_SEND_MAIL && error != EMAIL_ERROR_CANCELLED) {
874 /* In case email is cancelled using cancel button in Outbox there is no need to show Cancel/Retry Pop up */
875 emstorage_mail_tbl_t *mail_table_data = NULL;
877 if (error == 0) /* error 0 means 'this is not error' */
881 EM_DEBUG_LOG("Invalid mail_id");
885 if (!emstorage_get_mail_by_id(id, &mail_table_data, true, NULL)) {
886 EM_DEBUG_LOG("Mail not found");
890 if (emcore_add_notification(mail_table_data->account_id, id, action) != EMAIL_ERROR_NONE) {
891 EM_DEBUG_EXCEPTION("emcore_notification_set error");
893 if (!emstorage_free_mail(&mail_table_data, 1, NULL))
894 EM_DEBUG_EXCEPTION("emstorage_free_mail Failed");
899 if (!emstorage_free_mail(&mail_table_data, 1, NULL))
900 EM_DEBUG_EXCEPTION("emstorage_free_mail Failed");
904 EM_DEBUG_FUNC_END("ret [%d]", ret);
909 /* storage space handling - 210709 */
910 int emcore_get_storage_status(void)
912 EM_DEBUG_FUNC_BEGIN();
913 int storage_status = 0, nError = 0;
917 #ifdef STORAGE_STATUS
918 nError = vconf_get_int(PS_KEY_SYSTEM_STORAGE_MOVI_STATUS,
920 #endif /* STORAGE_STATUS */
923 EM_DEBUG_EXCEPTION("vconf_get_int Failed");
927 return storage_status;
930 int emcore_is_storage_full(int *err_code)
932 EM_DEBUG_FUNC_BEGIN();
935 int err = EMAIL_ERROR_NONE;
936 struct statfs buf = {0};
938 if (statfs(DATA_PATH, &buf) == -1) {
939 EM_DEBUG_EXCEPTION("statfs(\"%s\") failed - %d", DATA_PATH, errno);
940 err = EMAIL_ERROR_SYSTEM_FAILURE;
944 long i_free = (buf.f_bfree * buf.f_bsize) / (1024 * 1024);
945 EM_DEBUG_LOG("f_bfree[%d] f_bsize[%d]", buf.f_bfree, buf.f_bsize);
946 EM_DEBUG_LOG("Free space of storage is[%ld] MB.", i_free);
947 if (i_free < EMAIL_LIMITATION_FREE_SPACE)
948 err = EMAIL_ERROR_MAIL_MEMORY_FULL;
951 if (err == EMAIL_ERROR_MAIL_MEMORY_FULL)
955 if (err_code != NULL)
957 EM_DEBUG_FUNC_END("ret[%d]", ret);
961 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)
963 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);
966 int mail_size = 0; /* size of the plain text body and attachments */
967 int err = EMAIL_ERROR_NONE;
970 if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count &&input_attachment_data_list) || !output_size) {
971 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
972 err = EMAIL_ERROR_INVALID_PARAM;
976 if (input_mail_data->file_path_plain != NULL) {
977 if (stat(input_mail_data->file_path_plain, &st_buf) < 0) {
978 EM_DEBUG_EXCEPTION("input_mail_data->file_path_plain : stat(\"%s\") failed...", input_mail_data->file_path_plain);
979 err = EMAIL_ERROR_INVALID_MAIL;
983 mail_size += st_buf.st_size;
987 if (input_mail_data->file_path_html != NULL) {
988 if (stat(input_mail_data->file_path_html, &st_buf) < 0) {
989 EM_DEBUG_EXCEPTION("input_mail_data->file_path_html : stat(\"%s\") failed...", input_mail_data->file_path_html);
990 err = EMAIL_ERROR_INVALID_MAIL;
994 mail_size += st_buf.st_size;
997 for(i = 0; i < input_attachment_count; i++) {
998 if (stat(input_attachment_data_list[i].attachment_path, &st_buf) < 0) {
999 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path);
1000 err = EMAIL_ERROR_INVALID_MAIL;
1003 mail_size += st_buf.st_size;
1006 *output_size = mail_size;
1010 EM_DEBUG_FUNC_END("mail_size [%d]", mail_size);
1015 /* parse the Full mailbox Path and Get the Alias Name of the Mailbox */
1016 char *emcore_get_alias_of_mailbox(const char *mailbox_path)
1018 EM_DEBUG_FUNC_BEGIN();
1019 EM_IF_NULL_RETURN_VALUE(mailbox_path, NULL);
1022 gchar **token_list = NULL;
1023 gchar *mailbox = NULL, *name = NULL;
1024 char *converted_name;
1027 mailbox = g_strdup(mailbox_path);
1028 token_list = g_strsplit_set(mailbox, "/", -1);
1033 while (token_list[index] != NULL)
1036 name = g_strdup(token_list[index - 1]);
1037 if(!name) /* prevent 27459 */
1040 g_strfreev(token_list);
1042 converted_name = emcore_convert_mutf7_to_utf8(name);
1047 EM_DEBUG_FUNC_END();
1048 return converted_name;
1052 static int emcore_get_first_address(const char *full_address, char **alias, char **address)
1054 EM_DEBUG_FUNC_BEGIN();
1056 if (full_address == NULL || alias == NULL || address == NULL){
1057 EM_DEBUG_EXCEPTION("Invalid Param : full_address[%p], alias[%p], address[%p]", full_address, alias, address);
1062 char *alias_start = NULL;
1063 char *alias_end = NULL;
1064 char *alias_cursor = NULL;
1065 char *address_start = NULL;
1066 char *address_end = NULL;
1067 char *first_address = NULL;
1070 s = (char *)strchr((char *)full_address, ';');
1072 first_address = strdup(full_address); /* only one address */
1074 first_address = strndup(full_address, s - full_address); /* over two addresses */
1078 if ((alias_start = (char *)strchr((char *)first_address, '\"'))){
1080 alias_cursor = alias_start;
1081 while ((alias_cursor = (char *)strchr((char *)(alias_cursor), '\"'))){
1082 alias_end = alias_cursor;
1084 if (*alias_cursor == 0)
1087 if (alias_end) { /* there is "alias" */
1088 *alias = strndup(alias_start, alias_end - alias_start);
1089 EM_DEBUG_LOG("alias [%s]", *alias);
1095 if (alias_end == NULL)
1099 if ((address_start = (char *)strchr((char *)s, '<'))){
1101 if ((address_end = (char *)strchr((char *)address_start, '>')))
1102 *address = strndup(address_start, address_end - address_start); /* (alias) <(addr)> ... */
1104 *address = strdup(s);
1107 *address = strdup(s); /* (addr) ; ... : no alias */
1110 EM_SAFE_FREE(first_address);
1111 EM_DEBUG_FUNC_END();
1115 void emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data)
1117 EM_DEBUG_FUNC_BEGIN("mail_data [%p]", mail_data);
1119 char *first_alias = NULL;
1120 char *first_address = NULL;
1121 char *recipient = NULL;
1123 /* sender alias & address */
1124 if (emcore_get_first_address(mail_data->full_address_from, &first_alias, &first_address) == true) {
1125 if (first_alias == NULL) {
1126 mail_data->alias_sender = EM_SAFE_STRDUP(first_address);
1129 mail_data->alias_sender = first_alias;
1132 mail_data->email_address_sender = first_address;
1133 first_address = NULL;
1136 /* recipient alias & address */
1137 if (mail_data->full_address_to != NULL)
1138 recipient = mail_data->full_address_to;
1139 else if (mail_data->full_address_cc != NULL)
1140 recipient = mail_data->full_address_cc;
1141 else if (mail_data->full_address_bcc != NULL)
1142 recipient = mail_data->full_address_bcc;
1144 if (emcore_get_first_address(recipient, &first_alias, &first_address) == true) {
1145 if (first_alias == NULL)
1146 mail_data->alias_recipient = EM_SAFE_STRDUP(first_address);
1148 mail_data->alias_recipient = first_alias;
1150 mail_data->email_address_recipient = first_address;
1152 EM_DEBUG_FUNC_END();
1156 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)
1158 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);
1160 int err = EMAIL_ERROR_NONE;
1161 unsigned int byte_read = 0;
1162 unsigned int byte_written = 0;
1163 int local_preview_buffer_length = 0;
1164 char *local_preview_text = NULL;
1165 char *encoding_type = NULL;
1166 char *utf8_encoded_string = NULL;
1167 FILE *fp_html = NULL;
1168 FILE *fp_plain = NULL;
1169 GError *glib_error = NULL;
1172 if (!output_preview_buffer) {
1173 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1174 err = EMAIL_ERROR_INVALID_PARAM;
1178 local_preview_buffer_length = input_preview_buffer_length * 2;
1180 if ( input_html_path != NULL) {
1181 /* get preview text from html file */
1182 if( (err = em_get_encoding_type_from_file_path(input_html_path, &encoding_type)) != EMAIL_ERROR_NONE) {
1183 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
1187 if (stat(input_html_path, &st_buf) < 0) {
1188 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_html_path);
1189 err = EMAIL_ERROR_INVALID_MAIL;
1193 if (!(fp_html = fopen(input_html_path, "r"))) {
1194 EM_DEBUG_EXCEPTION("fopen failed [%s]", input_html_path);
1195 err = EMAIL_ERROR_SYSTEM_FAILURE;
1199 if (!(local_preview_text = (char*)em_malloc(sizeof(char) * (st_buf.st_size + 1)))) {
1200 EM_DEBUG_EXCEPTION("em_malloc failed");
1201 err = EMAIL_ERROR_OUT_OF_MEMORY;
1205 byte_read = fread(local_preview_text, sizeof(char), st_buf.st_size, fp_html);
1207 if (ferror(fp_html)) {
1208 EM_DEBUG_EXCEPTION("fread failed [%s]", input_html_path);
1209 err = EMAIL_ERROR_SYSTEM_FAILURE;
1213 if ( (err = emcore_strip_HTML(local_preview_text)) != EMAIL_ERROR_NONE) {
1214 EM_DEBUG_EXCEPTION("emcore_strip failed");
1219 if ( (local_preview_text == NULL || (local_preview_text && EM_SAFE_STRLEN(local_preview_text) == 0) ) && input_plain_path != NULL) {
1220 /* get preview text from plain text file */
1221 if( (err = em_get_encoding_type_from_file_path(input_plain_path, &encoding_type)) != EMAIL_ERROR_NONE) {
1222 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%s]", err);
1226 if (!(fp_plain = fopen(input_plain_path, "r"))) {
1227 EM_DEBUG_EXCEPTION("fopen failed [%s]", input_plain_path);
1228 err = EMAIL_ERROR_SYSTEM_FAILURE;
1232 if (!(local_preview_text = (char*)em_malloc(sizeof(char) * local_preview_buffer_length))) {
1233 EM_DEBUG_EXCEPTION("em_malloc failed");
1237 byte_read = fread(local_preview_text, sizeof(char), local_preview_buffer_length - 1, fp_plain);
1239 if (ferror(fp_plain)) {
1240 EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path);
1241 err = EMAIL_ERROR_SYSTEM_FAILURE;
1245 reg_replace(local_preview_text, CR_STRING, " ");
1246 reg_replace(local_preview_text, LF_STRING, " ");
1247 reg_replace(local_preview_text, TAB_STRING, " ");
1250 if(local_preview_text) {
1251 em_trim_left(local_preview_text);
1252 EM_DEBUG_LOG("local_preview_text : [%s]", local_preview_text);
1253 if(encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
1254 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
1255 utf8_encoded_string = (char*)g_convert (local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1257 if(utf8_encoded_string == NULL) {
1258 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d], EM_SAFE_STRLEN : [%d]", byte_read, EM_SAFE_STRLEN(local_preview_text));
1259 EM_DEBUG_LOG("Error is G_CONVERT_ERROR_ILLEGAL_SEQUENCE");
1261 if (!g_error_matches (glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
1262 EM_DEBUG_EXCEPTION("g_convert failed");
1266 EM_DEBUG_LOG("Extract the preview text, again");
1268 utf8_encoded_string = (char *)g_convert(local_preview_text, byte_read, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
1269 if (utf8_encoded_string == NULL) {
1270 EM_DEBUG_EXCEPTION("g_convert failed : byte_read[%d]", byte_read);
1275 EM_SAFE_FREE(local_preview_text);
1276 local_preview_text = utf8_encoded_string;
1282 if (local_preview_text != NULL)
1283 *output_preview_buffer = EM_SAFE_STRDUP(local_preview_text);
1285 EM_SAFE_FREE(local_preview_text);
1286 EM_SAFE_FREE(encoding_type);
1288 if (fp_html != NULL)
1291 if (fp_plain != NULL)
1294 EM_DEBUG_FUNC_END("err [%d]", err);
1298 INTERNAL_FUNC int emcore_add_transaction_info(int mail_id, int handle , int *err_code)
1300 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%d]", mail_id, handle);
1303 int err = EMAIL_ERROR_NONE ;
1304 em_transaction_info_type_t *pTransinfo = NULL ;
1305 em_transaction_info_type_t *pTemp = NULL;
1307 EM_DEBUG_LOG("g_transaction_info_list[%p]", g_transaction_info_list);
1308 pTransinfo = g_transaction_info_list ;
1310 if (!(pTemp = em_malloc(sizeof(em_transaction_info_type_t)))) {
1311 EM_DEBUG_EXCEPTION("malloc failed...");
1312 err = EMAIL_ERROR_OUT_OF_MEMORY;
1315 pTemp->mail_id = mail_id ;
1316 pTemp->handle = handle;
1319 pTransinfo = pTemp ;
1320 g_transaction_info_list = pTransinfo ;
1323 while (pTransinfo->next)
1324 pTransinfo = pTransinfo->next;
1325 pTransinfo->next = pTemp;
1333 EM_DEBUG_FUNC_END("g_transaction_info_list[%p]", g_transaction_info_list);
1337 INTERNAL_FUNC int emcore_get_handle_by_mailId_from_transaction_info(int mail_id, int *pHandle)
1339 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p]", mail_id, pHandle);
1342 em_transaction_info_type_t *pTransinfo = NULL ;
1344 if (g_transaction_info_list == NULL) {
1345 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
1348 pTransinfo = g_transaction_info_list;
1351 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
1352 if (pTransinfo->mail_id == mail_id) {
1353 *pHandle = pTransinfo->handle;
1355 EM_DEBUG_LOG("*pHandle[%d]", *pHandle);
1359 pTransinfo = pTransinfo->next ;
1360 }while (pTransinfo);
1361 EM_DEBUG_FUNC_END();
1365 INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id )
1367 EM_DEBUG_FUNC_BEGIN("mail_id[%d]", mail_id);
1369 em_transaction_info_type_t *pTransinfo ;
1370 em_transaction_info_type_t *pTemp = NULL;
1372 if (g_transaction_info_list == NULL) {
1373 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
1376 pTransinfo = g_transaction_info_list;
1378 EM_DEBUG_LOG("pTransinfo[%p]", pTransinfo);
1381 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
1382 if (pTransinfo->mail_id == mail_id) {
1383 pTemp = pTransinfo->next ;
1385 EM_SAFE_FREE(pTransinfo) ;
1386 g_transaction_info_list = NULL;
1389 pTransinfo->mail_id = pTransinfo->next->mail_id;
1390 pTransinfo->handle = pTransinfo->next->handle ;
1391 pTransinfo->next = pTransinfo->next->next;
1393 EM_SAFE_FREE(pTemp);
1398 pTransinfo = pTransinfo->next ;
1401 }while (pTransinfo);
1402 EM_DEBUG_FUNC_END();
1409 int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string)
1411 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);
1412 int error_code = EMAIL_ERROR_NONE;
1414 int so, n, nmatch, source_text_length, n_count = 1;
1415 regmatch_t *pmatch = NULL;
1416 regex_t reg_pattern;
1418 if(!input_source_text || !input_old_pattern_string || !input_new_string) {
1419 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1420 error_code = EMAIL_ERROR_INVALID_PARAM;
1424 source_text_length = EM_SAFE_STRLEN(input_source_text);
1426 regcomp(®_pattern, input_old_pattern_string, REG_ICASE);
1428 nmatch = reg_pattern.re_nsub + 1;
1430 EM_DEBUG_LOG("nmatch [%d]", nmatch);
1433 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_DATA");
1434 error_code = EMAIL_ERROR_INVALID_DATA;
1438 pmatch = (regmatch_t*)em_malloc(sizeof(regmatch_t) * nmatch);
1440 if(pmatch == NULL) {
1441 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
1442 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
1446 for (pos = input_new_string; *pos ; pos++) {
1447 if (*pos == '\\' && *(pos + 1) > '0' && *(pos + 1) <= '9') {
1449 so = pmatch[*(pos + 1) - 48].rm_so;
1450 n = pmatch[*(pos + 1) - 48].rm_eo - so;
1452 EM_DEBUG_LOG("so [%d], n [%d]", so, n);
1454 if (so < 0 || EM_SAFE_STRLEN (input_new_string) + n - 1 > source_text_length)
1457 memmove (pos + n, pos + 2, EM_SAFE_STRLEN (pos) - 1);
1458 memmove (pos, input_source_text + so, n);
1463 for (pos = input_source_text; !regexec (®_pattern, pos, 1, pmatch, 0);) {
1464 n = pmatch[0].rm_eo - pmatch[0].rm_so;
1465 pos += pmatch[0].rm_so;
1467 memmove (pos + EM_SAFE_STRLEN (input_new_string), pos + n, EM_SAFE_STRLEN (pos) - n + 1);
1468 memmove (pos, input_new_string, EM_SAFE_STRLEN (input_new_string));
1469 pos += EM_SAFE_STRLEN (input_new_string);
1475 EM_SAFE_FREE(pmatch);
1476 regfree (®_pattern);
1478 EM_DEBUG_FUNC_END("error_code [%d]", error_code);
1483 int emcore_strip_HTML(char *source_string)
1485 EM_DEBUG_FUNC_BEGIN("source_string [%p]", source_string);
1487 int result = EMAIL_ERROR_NONE;
1489 reg_replace(source_string, CR_STRING, " ");
1490 reg_replace(source_string, LF_STRING, " ");
1491 reg_replace(source_string, "<head[^>]*>", "<head>"); /* "<()*head([^>])*>", "<head>" */
1492 reg_replace(source_string, "<*/head>", "</head>"); /* "(<()*(/)()*head()*>)", "</head>" */
1493 reg_replace(source_string, "<head>.*</head>", ""); /* "(<head>).*(</head>)", "" */
1494 reg_replace(source_string, "<style[^>]*>.*</style>", "");
1496 reg_replace(source_string, "<*/p>", " ");
1497 reg_replace(source_string, "<br>", " ");
1500 reg_replace(source_string, "<[^>]*>", "");
1504 /* reg_replace(source_string, "•", " * "); */
1506 /* "‹", "< */
1507 /* reg_replace(source_string, "‹", "<"); */
1509 /* "›", "> */
1510 /* reg_replace(source_string, "›", ">"); */
1512 /* "™", "(tm) */
1513 /* reg_replace(source_string, "™", "(tm)"); */
1516 /* reg_replace(source_string, "⁄", "/"); */
1519 reg_replace(source_string, "<", "<");
1522 reg_replace(source_string, ">", ">");
1524 /* "©", "(c) */
1525 /* reg_replace(source_string, "©", "(c)"); */
1528 reg_replace(source_string, """, "\'");
1531 reg_replace(source_string, " ", " ");
1533 reg_replace(source_string, " ", " ");
1535 EM_DEBUG_FUNC_END();
1540 /* emcore_send_noti_for_new_mail is not used currently because DBUS could not send very long message.*/
1541 /* 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). */
1542 /* This notification is including addtional information comparing NOTI_MAIL_ADD. */
1543 /* By this change, email application will be able to add email item without additional DB query. */
1544 /* It might improve performance of sync email. */
1545 /* kyuho.jo 2010-09-07 */
1547 INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime)
1549 EM_DEBUG_FUNC_BEGIN("mailbox_name(%s) subject(%s), from(%s), uid(%s), datetime(%s)", mailbox_name, subject, from, uid, datetime);
1550 int error_code = EMAIL_ERROR_NONE;
1551 int param_length = 0;
1552 char *param_string = NULL;
1554 if (mailbox_name == NULL || subject == NULL || from == NULL || uid == NULL || datetime == NULL) {
1555 error_code = EMAIL_ERROR_INVALID_PARAM;
1556 EM_DEBUG_EXCEPTION("Invalid parameter, mailbox_name(%p), subject(%p), from(%p), uid(%p), datetime(%p)", mailbox_name, subject, from, uid, datetime);
1560 param_length = strlen(mailbox_name) + strlen(subject) + strlen(from) + strlen(uid) + strlen(datetime) + 5; /*prevent 34358*/
1562 param_string = em_malloc(param_length);
1563 if (param_string == NULL) {
1564 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
1565 EM_DEBUG_EXCEPTION("Memory allocation for 'param_string' is failed");
1569 memset(param_string, 0x00, param_length);
1571 SNPRINTF(param_string, param_length, "%s%c%s%c%s%c%s%c%s", mailbox_name, 0x01, subject, 0x01, from, 0x01, uid, 0x01, datetime);
1573 if (emcore_notify_network_event(NOTI_DOWNLOAD_NEW_MAIL, account_id, param_string, 0, 0) == 0) { /* failed */
1574 error_code = EMAIL_ERROR_UNKNOWN;
1575 EM_DEBUG_EXCEPTION("emcore_notify_network_event is failed");
1581 EM_SAFE_FREE(param_string);
1582 EM_DEBUG_FUNC_END();
1586 #define MAX_TITLE_LENGTH 1024
1587 int emcore_update_notification_for_unread_mail(int account_id)
1589 EM_DEBUG_FUNC_BEGIN("acccount_id[%d]", account_id);
1591 int i, account_count = 0;
1592 int err = EMAIL_ERROR_NONE;
1593 emstorage_account_tbl_t *p_account_tbl = NULL;
1595 if (!emstorage_get_account_list(&account_count, &p_account_tbl, true, false, &err)) {
1596 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
1600 for (i = 0; i < account_count ; i++) {
1601 if (emcore_add_notification(p_account_tbl[i].account_id, 0, EMAIL_ACTION_NUM) != EMAIL_ERROR_NONE) {
1602 EM_DEBUG_EXCEPTION("emcore_add_notification failed");
1612 emstorage_free_account(&p_account_tbl, account_count, NULL);
1614 EM_DEBUG_FUNC_END();
1618 INTERNAL_FUNC int emcore_finalize_sync(int account_id, int *error)
1620 EM_DEBUG_FUNC_BEGIN("account_id [%d], error [%p]", account_id, error);
1621 int err = EMAIL_ERROR_NONE, ret = true, result_sync_status = SYNC_STATUS_FINISHED;
1623 if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_SYNCING)) != EMAIL_ERROR_NONE)
1624 EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err);
1626 if (!emstorage_get_sync_status_of_account(ALL_ACCOUNT, &result_sync_status, &err))
1627 EM_DEBUG_EXCEPTION("emstorage_get_sync_status_of_account failed [%d]", err);
1629 if (result_sync_status == SYNC_STATUS_HAVE_NEW_MAILS) {
1630 if (!emcore_update_notification_for_unread_mail(ALL_ACCOUNT))
1631 EM_DEBUG_EXCEPTION("emcore_update_notification_for_unread_mail failed");
1633 if (!emcore_display_unread_in_badge())
1634 EM_DEBUG_EXCEPTION("emcore_display_unread_in_badge failed");
1636 emcore_start_alert();
1638 if ((err = emcore_update_sync_status_of_account(account_id, SET_TYPE_MINUS, SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE)
1639 EM_DEBUG_EXCEPTION("emcore_update_sync_status_of_account failed [%d]", err);
1642 EM_DEBUG_FUNC_END();
1646 INTERNAL_FUNC int emcore_clear_all_notifications()
1648 int account_count = 0, i;
1649 emstorage_account_tbl_t *account_list;
1650 int error_code = EMAIL_ERROR_NONE;
1652 if(!emstorage_get_account_list(&account_count, &account_list, true, false, &error_code)) {
1653 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed");
1657 for(i = 0; i < account_count; i++) {
1658 emcore_delete_notification_by_account(account_list[i].account_id);
1663 emstorage_free_account(&account_list, account_count, NULL);
1666 EM_DEBUG_FUNC_END("return[%d]", error_code);
1670 #define EAS_EXECUTABLE_PATH "/usr/bin/eas-engine"
1672 INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id)
1674 EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
1675 int error_code = EMAIL_ERROR_NONE;
1677 char vconf_private_id[MAX_PATH] = {0, };
1679 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1680 if (vconf_get_int(vconf_private_id, &private_id) != 0) {
1681 EM_DEBUG_EXCEPTION("vconf_get_int failed");
1683 EM_DEBUG_FUNC_END();
1687 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
1690 * @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)
1691 * Prepare a linked list of uid ranges with each node having a uid_range and lowest and highest uid in it.
1693 *@author h.gahlaut@samsung.com
1694 * @param[in] id_set Specifies the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
1695 * @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
1696 * @param[in] range_len Specifies the maximum length of string of range allowed.
1697 * @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
1698 * @param[out] err_code Returns the error code.
1699 * @remarks An example of a uid_range formed is 2:6,8,10,14:15,89,
1700 * While using it the caller should remove the ending, (comma)
1701 * @return This function returns true on success or false on failure.
1704 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)
1706 EM_DEBUG_FUNC_BEGIN();
1709 int error = EMAIL_ERROR_NONE;
1711 if (NULL == id_set || id_set_count <= 0 || NULL == uid_range_set) {
1712 EM_DEBUG_EXCEPTION(" Invalid Parameter id_set[%p] id_set_count[%d] uid_range_set[%p]", id_set, id_set_count, uid_range_set);
1713 error = EMAIL_ERROR_INVALID_PARAM;
1718 unsigned long current_uid = 0;
1719 unsigned long first_uid = 0;
1720 unsigned long last_uid = 0;
1721 const int max_subset_string_size = MAX_SUBSET_STRING_SIZE;
1722 char subset_string[MAX_SUBSET_STRING_SIZE] = {0,};
1723 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*/
1725 if (range_len < (max_subset_string_size + 1)) /* 1 for ending NULL character */ {
1726 EM_DEBUG_EXCEPTION(" Invalid Parameter range_len[%d]", range_len);
1727 error = EMAIL_ERROR_INVALID_PARAM;
1731 EM_DEBUG_LOG("id set count[%d] range_len[%d]", id_set_count, range_len);
1734 first_uid = last_uid = current_uid = id_set[i].server_mail_id;
1735 /* Start subset string by putting first server mail id in it from id_set*/
1736 memset(subset_string, 0x00, max_subset_string_size);
1737 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
1740 /* Check if only one server mail id was left in id_set */
1741 if (i >= id_set_count) {
1742 /* No more server mail id left in id_set */
1743 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
1744 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
1750 /* 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 */
1752 current_uid = id_set[i].server_mail_id;
1753 if (current_uid == (last_uid + 1)) {
1754 last_uid = current_uid;
1758 memset(subset_string, 0x00, max_subset_string_size);
1759 if (first_uid != last_uid) /* Form subset string by first_uid:last_uid */
1760 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
1761 else /* Form subset string by first_uid */
1762 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
1764 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
1765 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
1768 /* To Start formation of new subset string break out of inner loop */
1772 } while (i < id_set_count);
1774 /* Flow comes here in two cases :
1775 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
1776 2. due to break statement */
1778 if (last_uid == current_uid) {
1781 memset(subset_string, 0x00, max_subset_string_size);
1782 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
1784 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
1785 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
1790 /* Case 2: Do Nothing */
1794 } while (i < id_set_count);
1799 if (NULL != err_code)
1801 EM_DEBUG_FUNC_END();
1807 * @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)
1808 * 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
1809 * and stores the subset_string in its uid_range. Also sets the lowest and highest uids for the corresponsing uid_range
1811 * @author h.gahlaut@samsung.com
1812 * @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.
1813 * @param[in] range_len Specifies the maximum length of range string allowed.
1814 * @param[in] luid Specifies the lowest uid in subset string
1815 * @param[in] huid Specifies the highest uid in subset string
1816 * @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
1817 * @param[out] err_code Returns the error code.
1819 * @return This function returns true on success or false on failure.
1822 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)
1824 EM_DEBUG_FUNC_BEGIN();
1825 email_uid_range_set *current_node = NULL;
1827 if (NULL == (*uid_range_set)) {
1828 /*This happens only once when list creation starts. Head Node is allocated */
1829 current_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
1830 if (NULL == current_node) {
1831 EM_DEBUG_EXCEPTION("em_malloc failed");
1835 current_node->uid_range = (char *)em_malloc(range_len);
1837 if (NULL == current_node->uid_range) {
1838 EM_DEBUG_EXCEPTION("em_malloc failed");
1839 EM_SAFE_FREE(current_node);
1843 SNPRINTF(current_node->uid_range, range_len, "%s,", subset_string);
1845 current_node->lowest_uid = luid;
1846 current_node->highest_uid = huid;
1847 (*uid_range_set) = current_node;
1849 (*current_node_adr) = current_node;
1853 /* Apart from first call to this function flow will always come here */
1854 current_node = (*current_node_adr);
1855 int len_sub_string = EM_SAFE_STRLEN(subset_string);
1856 int space_left_in_buffer = range_len - EM_SAFE_STRLEN(current_node->uid_range);
1858 if ((len_sub_string + 1 + 1) <= space_left_in_buffer) /* 1 for comma + 1 for ending null character */ {
1859 SNPRINTF(current_node->uid_range + EM_SAFE_STRLEN(current_node->uid_range), space_left_in_buffer, "%s,", subset_string);
1860 current_node->highest_uid = huid;
1863 /* No more space left in uid_range string.If continued on it, it will exceeded max size of range_len */
1864 /* Allocate new node in Uid Range set */
1865 email_uid_range_set *new_node = NULL;
1867 new_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
1869 if (NULL == new_node) {
1870 EM_DEBUG_EXCEPTION("em_malloc failed");
1874 /* Allocate uid_range of new node */
1876 new_node->uid_range = (char *)em_malloc(range_len);
1878 if (NULL == new_node->uid_range) {
1879 EM_DEBUG_EXCEPTION("em_malloc failed");
1880 EM_SAFE_FREE(new_node);
1884 SNPRINTF(new_node->uid_range, range_len, "%s, ", subset_string);
1886 new_node->lowest_uid = luid;
1887 new_node->highest_uid = huid;
1889 current_node->next = new_node;
1891 (*current_node_adr) = new_node;
1894 EM_DEBUG_FUNC_END();
1899 * void emcore_free_uid_range_set(email_uid_range_set **uid_range_head)
1900 * Frees the linked list of uid ranges
1902 * @author h.gahlaut@samsung.com
1903 * @param[in] uid_range_head Head pointer of linked list of uid ranges
1905 * @return This function does not return anything.
1909 void emcore_free_uid_range_set(email_uid_range_set **uid_range_set)
1911 EM_DEBUG_FUNC_BEGIN();
1913 email_uid_range_set *current_node = NULL;
1914 email_uid_range_set *uid_range_head = NULL;
1916 current_node = uid_range_head = (*uid_range_set); /* Make the current node and head ptr point to starting of uid_range_set */
1918 while (current_node) {
1919 uid_range_head = current_node->next; /* Move the head ptr to next node*/
1921 EM_SAFE_FREE(current_node->uid_range);
1922 EM_SAFE_FREE(current_node); /* Free the current node */
1924 current_node = uid_range_head; /* Make the current node point to head ptr */
1927 (*uid_range_set) = NULL;
1928 EM_DEBUG_FUNC_END();
1933 * @fn emcore_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char *** strings, int *string_count, int *err_code)
1934 * Forms comma separated strings of a give max_string_len from an array of numbers
1936 * @author h.gahlaut@samsung.com
1937 * @param[in] numbers Specifies the array of numbers to be converted into comma separated strings.
1938 * @param[in] num_count Specifies the count of numbers in numbers array.
1939 * @param[in] max_string_len Specifies the maximum length of comma separated strings that are to be formed.
1940 * @param[out] strings Returns the base address of a double dimension array which stores the strings.
1941 * @param[out] string_count Returns the number of strings formed.
1942 * @param[out] err_code Returns the error code.
1943 * @remarks If Input to the function is five numbers like 2755 2754 2748 2749 2750 and a given max_string_len is 20.
1944 * Then this function will form two comma separated strings as follows -
1945 * "2755, 2754, 2748"
1947 * @return This function returns true on success or false on failure.
1950 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)
1952 EM_DEBUG_FUNC_BEGIN();
1954 int error = EMAIL_ERROR_NONE;
1957 char **string_list = NULL;
1958 int num_of_strings = 0;
1961 char num[MAX_INTEGER_LENGTH + 1] = {0, };
1963 int space_in_buffer = 0;
1964 int len_of_string_formed = 0;
1966 if (NULL == numbers || num_count <= 0 || \
1967 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. */ {
1968 EM_DEBUG_EXCEPTION("Invalid Parameter numbers[%p] num_count [%d] max_string_len [%d] strings [%p] string_count[%p]", \
1969 numbers, num_count, max_string_len, strings, string_count);
1970 error = EMAIL_ERROR_INVALID_PARAM;
1974 EM_DEBUG_LOG("num_count [%d] max_string_len [%d]", num_count, max_string_len);
1976 string_list = em_malloc(sizeof(char *));
1978 if (NULL == string_list) {
1979 EM_DEBUG_EXCEPTION("em_malloc failed ");
1983 string_list[num_of_strings] = em_malloc(max_string_len);
1985 if (NULL == string_list[num_of_strings]) {
1986 EM_DEBUG_EXCEPTION("em_malloc failed ");
1991 space_in_buffer = max_string_len;
1993 for (j = 0; j < num_count;++j) {
1994 memset(num, 0x00, MAX_INTEGER_LENGTH + 1);
1995 SNPRINTF(num, MAX_INTEGER_LENGTH + 1, "%d", numbers[j]);
1997 num_len = EM_SAFE_STRLEN(num);
1999 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
2001 space_in_buffer = max_string_len - len_of_string_formed ;
2003 if (space_in_buffer >= (num_len+1+1)) /* 1 for comma and 1 for ending NULL */ {
2004 SNPRINTF(string_list[num_of_strings - 1] + len_of_string_formed, max_string_len, "%d,", numbers[j]);
2006 else { /* Removing comma at end of string */
2007 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
2009 temp = (char **)realloc(string_list, sizeof(char *) * (num_of_strings + 1)); /* Allocate new buffer to store a pointer to a new string */
2012 EM_DEBUG_EXCEPTION("realloc failed");
2016 memset(temp + num_of_strings, 0X00, sizeof(char *));
2020 string_list[num_of_strings] = em_malloc(max_string_len);/* Allocate new buffer to store the string */
2022 if (NULL == string_list[num_of_strings]) {
2023 EM_DEBUG_EXCEPTION(" em_malloc failed ");
2027 SNPRINTF(string_list[num_of_strings - 1] , max_string_len, "%d,", numbers[j]);/* Start making new string */
2031 /* Removing comma at end of string */
2032 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
2033 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
2039 emcore_free_comma_separated_strings(&string_list, &num_of_strings);
2042 for (i = 0; i < num_of_strings;++i)
2043 EM_DEBUG_LOG("%s", string_list[i]);
2044 *strings = string_list;
2045 *string_count = num_of_strings;
2049 if (NULL != err_code)
2052 EM_DEBUG_FUNC_END("ret [%d]", ret);
2056 * @fn emcore_free_comma_separated_strings(char *** string_list, int *string_count)
2057 * Frees the double dimensional array of strings.
2059 * @author h.gahlaut@samsung.com
2060 * @param[in] uid_range_head Address of base address of double dimensional array of strings.
2061 * @param[in] string_count Address of variable holding the count of strings.
2063 * @return This function does not return anything.
2065 INTERNAL_FUNC void emcore_free_comma_separated_strings(char *** string_list, int *string_count)
2067 EM_DEBUG_FUNC_BEGIN();
2069 char **str_list = NULL;
2072 if (NULL != string_list) {
2073 str_list = *string_list;
2075 if (0 != *string_count) {
2076 count = *string_count;
2077 for (i = 0; i < count; ++i)
2078 EM_SAFE_FREE(str_list[i]);
2081 EM_SAFE_FREE(str_list);
2082 *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 */
2085 EM_DEBUG_FUNC_END();
2094 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)
2096 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);
2097 int ret = false, err = EMAIL_ERROR_NONE;
2098 char *extcheck = NULL;
2099 char attachment_file_name[MAX_PATH + 1] = { 0, };
2101 if (!source_file_name || !result_file_name) {
2102 EM_DEBUG_EXCEPTION("Invalid Parameter");
2103 err = EMAIL_ERROR_INVALID_PARAM;
2107 strncpy(attachment_file_name, source_file_name, MAX_PATH);
2108 extcheck = strchr(attachment_file_name, '.');
2111 EM_DEBUG_LOG("Extension Exist in the Attachment [%s] ", extcheck);
2112 else { /* No extension attached, So add the Extension based on the subtype */
2114 strcat(attachment_file_name, ".");
2115 strcat(attachment_file_name, sub_type);
2116 EM_DEBUG_LOG("attachment_file_name with extension[%s] ", attachment_file_name);
2119 EM_DEBUG_LOG("UnKnown Extesnsion");
2122 memset(result_file_name, 0 , result_file_name_buffer_length);
2123 EM_SAFE_STRNCPY(result_file_name, attachment_file_name, result_file_name_buffer_length - 1);
2124 EM_DEBUG_LOG("*result_file_name[%s]", result_file_name);
2130 EM_DEBUG_FUNC_END();
2134 #ifdef __FEATURE_LOCAL_ACTIVITY__
2135 INTERNAL_FUNC int emcore_add_activity(emstorage_activity_tbl_t *new_activity, int *err_code)
2137 EM_DEBUG_FUNC_BEGIN();
2139 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", new_activity, err_code);
2141 /* default variable */
2143 int err = EMAIL_ERROR_NONE;
2145 if (!new_activity) {
2146 EM_DEBUG_LOG("\t new_activity[%p]\n", new_activity);
2147 err = EMAIL_ERROR_INVALID_PARAM;
2150 if (!emstorage_add_activity(new_activity, false, &err)) {
2151 EM_DEBUG_LOG("\t emstorage_add_activity falied - %d\n", err);
2164 INTERNAL_FUNC int emcore_delete_activity(emstorage_activity_tbl_t *activity, int *err_code)
2166 EM_DEBUG_FUNC_BEGIN();
2168 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", activity, err_code);
2170 /* default variable */
2172 int err = EMAIL_ERROR_NONE;
2174 EM_DEBUG_LOG("\t new_activity[%p]\n", activity);
2176 err = EMAIL_ERROR_INVALID_PARAM;
2179 if (!emstorage_delete_local_activity(activity, true, &err)) {
2180 EM_DEBUG_LOG("\t emstorage_delete_local_activity falied - %d\n", err);
2193 INTERNAL_FUNC int emcore_get_next_activity_id(int *activity_id, int *err_code)
2195 EM_DEBUG_FUNC_BEGIN();
2198 int err = EMAIL_ERROR_NONE;
2200 if (NULL == activity_id)
2202 EM_DEBUG_EXCEPTION("\t activity_id[%p]", activity_id);
2204 err = EMAIL_ERROR_INVALID_PARAM;
2208 if (false == emstorage_get_next_activity_id(activity_id, &err)) {
2209 EM_DEBUG_LOG("\t emstorage_get_next_activity_id failed - %d\n", err);
2216 if (NULL != err_code) {
2224 #endif /* __FEATURE_LOCAL_ACTIVITY__ */
2227 INTERNAL_FUNC void emcore_free_rule(email_rule_t* rule)
2229 EM_DEBUG_FUNC_BEGIN();
2234 EM_SAFE_FREE(rule->value);
2236 EM_DEBUG_FUNC_END();
2239 INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_string, int *result)
2241 EM_DEBUG_FUNC_BEGIN("file_path : [%s], search_string : [%s]", file_path, search_string);
2242 int error = EMAIL_ERROR_NONE;
2248 if (search_string == NULL || file_path == NULL) {
2249 EM_DEBUG_EXCEPTION("Invalid parameter");
2250 error = EMAIL_ERROR_INVALID_PARAM;
2254 fp = fopen(file_path, "r");
2256 EM_DEBUG_EXCEPTION("fopen failed");
2257 error = EMAIL_ERROR_SYSTEM_FAILURE;
2261 if (!emcore_get_file_size(file_path, &file_size, &error)) {
2262 EM_DEBUG_EXCEPTION("emcore_get_file_size failed");
2266 buf = em_malloc(file_size);
2268 EM_DEBUG_EXCEPTION("em_malloc failed");
2269 error = EMAIL_ERROR_OUT_OF_MEMORY;
2273 if (fread(buf, sizeof(char), file_size, fp) != file_size) {
2274 EM_DEBUG_EXCEPTION("Get the data from file : failed");
2275 error = EMAIL_ERROR_SYSTEM_FAILURE;
2279 buf = em_replace_all_string(buf, CRLF_STRING, "");
2280 if (!strstr(buf, search_string)) {
2281 EM_DEBUG_LOG("Not found string");
2295 EM_DEBUG_FUNC_END("error:[%d]", error);