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 *****************************************************************************/
42 #include <glib-object.h>
50 #include <notification.h>
51 #include <notification_type.h>
52 #include <notification_internal.h>
53 #include <notification_text_domain.h>
55 #include <badge_internal.h>
56 #ifdef __FEATURE_USE_DRM_API__
57 #include <drm_client_types.h>
58 #include <drm_client.h>
59 #endif /* __FEATURE_USE_DRM_API__ */
62 #include <curl/curl.h>
64 #include <contacts_internal.h>
66 #include "email-types.h"
67 #include "email-core-global.h"
68 #include "email-core-utils.h"
69 #include "email-debug-log.h"
70 #include "email-core-mail.h"
71 #include "email-core-event.h"
72 #include "email-core-mailbox.h"
73 #include "email-core-account.h"
74 #include "email-core-mailbox-sync.h"
75 #include "email-core-mime.h"
76 #include "email-core-gmime.h"
77 #include "email-core-signal.h"
78 #include "email-daemon.h"
79 #include "email-utilities.h"
80 #include "email-convert.h"
81 #include "email-internal-types.h"
82 #include "email-device.h"
83 #include "email-core-container.h"
86 #include "email-dbus-activation.h"
89 #include <app_control.h>
90 #include <app_control_internal.h>
92 #define LED_TIMEOUT_SECS 12
93 #define G_DISPLAY_LENGTH 256
95 #define DIR_SEPERATOR_CH '/'
96 #define EMAIL_CH_QUOT '"'
97 #define EMAIL_CH_BRACKET_S '<'
98 #define EMAIL_CH_BRACKET_E '>'
99 #define EMAIL_CH_COMMA ','
100 #define EMAIL_CH_SEMICOLON ';'
101 #define EMAIL_CH_ROUND_BRACKET_S '('
102 #define EMAIL_CH_ROUND_BRACKET_E ')'
103 #define EMAIL_CH_SQUARE_BRACKET_S '['
104 #define EMAIL_CH_SQUARE_BRACKET_E ']'
105 #define EMAIL_CH_SPACE ' '
106 #define EMAIL_NOTI_ICON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "org.tizen.quickpanel/shared/res/noti_icons/E-mail/noti_email.png")
107 #define EMAIL_NOTI_INDICATOR_ICON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "org.tizen.indicator/res/icons/Event/B03_Event_email.png")
108 #define EMAIL_NOTI_MAX_MAIL_ID 100
109 //#define TEST TZ_SYS_RO_APPS
111 typedef struct _em_transaction_info_type_t {
114 struct _em_transaction_info_type_t *next;
116 } em_transaction_info_type_t;
118 em_transaction_info_type_t *g_transaction_info_list;
120 __thread email_session_t g_session = {0};
121 static notification_h g_sending_noti_handle = NULL;
122 typedef struct emcore_account_list_t emcore_account_list_t;
123 struct emcore_account_list_t {
124 email_account_t *account;
125 emcore_account_list_t *next;
128 #include <gmime/gmime.h>
130 INTERNAL_FUNC char *emcore_convert_mutf7_to_utf8(char *mailbox_name)
132 EM_DEBUG_FUNC_BEGIN("mailbox_name[%p]", mailbox_name);
135 char *result_mailbox_name = NULL;
136 char *mutf7_text = NULL;
140 if (mailbox_name == NULL) {
141 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
145 EM_DEBUG_LOG_SEC("mailbox_name[%s]", mailbox_name);
147 cursor = mutf7_text = EM_SAFE_STRDUP(mailbox_name);
149 if (mutf7_text == NULL) {
150 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
154 for (; *cursor; ++cursor)
157 if (!is_base64) *cursor = '&';
175 cd = g_mime_iconv_open("UTF-8", "UTF-7");
178 result_mailbox_name = g_mime_iconv_strdup(cd, mutf7_text);
180 EM_DEBUG_LOG_SEC("result_mailbox_name[%s]", result_mailbox_name);
182 if (result_mailbox_name) {
183 cursor = result_mailbox_name;
184 for (; *cursor; ++cursor) {
196 result_mailbox_name = (char *)utf8_from_mutf7((unsigned char *)mailbox_name);
197 EM_DEBUG_LOG_SEC("result_mailbox_name[%s]", result_mailbox_name);
198 if (result_mailbox_name == NULL)
199 result_mailbox_name = EM_SAFE_STRDUP(mutf7_text);
202 EM_DEBUG_LOG_SEC("result_mailbox_name[%s]", result_mailbox_name);
205 g_mime_iconv_close(cd);
207 EM_SAFE_FREE(mutf7_text);
209 EM_DEBUG_FUNC_END("result_mailbox_name[%p]", result_mailbox_name);
210 return result_mailbox_name;
213 /* in smtp case, path argument must be ENCODED_PATH_SMTP */
214 int emcore_get_long_encoded_path_with_account_info(char *multi_user_name, email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code)
216 EM_PROFILE_BEGIN(emCorelongEncodedpath);
217 EM_DEBUG_FUNC_BEGIN_SEC("account[%p], path[%s], delimiter[%d], long_enc_path[%p], err_code[%p]", account, path, delimiter, long_enc_path, err_code);
220 int error = EMAIL_ERROR_NONE;
222 email_authentication_method_t authentication_method = 0;
224 size_t long_enc_path_len = 0;
226 if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) { /* imap or pop3 */
227 EM_DEBUG_LOG_SEC("account->incoming_server_address[%p]", account->incoming_server_address);
228 EM_DEBUG_LOG_SEC("account->incoming_server_address[%s]", account->incoming_server_address);
230 if (!account->incoming_server_address) {
231 EM_DEBUG_EXCEPTION("account->incoming_server_address is null");
232 error = EMAIL_ERROR_INVALID_ACCOUNT;
236 long_enc_path_len = EM_SAFE_STRLEN(account->incoming_server_address) + EM_SAFE_STRLEN(path) + 256; /*prevent 34357*/
238 *long_enc_path = em_malloc(long_enc_path_len);
239 if (!*long_enc_path) {
240 EM_DEBUG_EXCEPTION("malloc failed...");
241 error = EMAIL_ERROR_OUT_OF_MEMORY;
247 /* ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}my-mailbox" */
249 if (multi_user_name) {
250 SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d%s%s",
251 account->incoming_server_address,
252 account->incoming_server_port_number,
253 account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap",
255 TOKEN_FOR_MULTI_USER,
258 SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d",
259 account->incoming_server_address,
260 account->incoming_server_port_number,
261 account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap",
262 account->account_id);
265 if (account->incoming_server_secure_connection & 0x01) {
266 strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
267 /* strcat(p, "/tryssl"); */
268 } else if (account->incoming_server_secure_connection & 0x02) {
269 strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
272 authentication_method = account->incoming_server_authentication_method;
274 if (account->incoming_server_requires_apop) {
275 strncat(p, "/apop", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
278 long_enc_path_len = EM_SAFE_STRLEN(account->outgoing_server_address) + 64;
280 *long_enc_path = em_malloc(EM_SAFE_STRLEN(account->outgoing_server_address) + 64);
281 if (!*long_enc_path) {
282 EM_DEBUG_EXCEPTION("\t malloc failed...\n");
283 error = EMAIL_ERROR_OUT_OF_MEMORY;
289 /* ex:"mail.test.com:25/smtp" */
291 SNPRINTF(p, long_enc_path_len, "%s:%d/%s",
292 account->outgoing_server_address,
293 account->outgoing_server_port_number,
296 if (account->outgoing_server_need_authentication > 0) {
297 if (multi_user_name) {
298 SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d%s%s",
300 TOKEN_FOR_MULTI_USER,
303 SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d",
304 account->account_id);
307 if (account->outgoing_server_need_authentication == EMAIL_AUTHENTICATION_METHOD_XOAUTH2) {
308 strncat(p, "/xoauth2", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
312 if (account->outgoing_server_secure_connection & 0x01) {
313 strncat(p, "/ssl/force_tls_v1_0", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
314 /* strcat(p, "/tryssl"); */
315 } else if (account->outgoing_server_secure_connection & 0x02)
316 strncat(p, "/tls/force_tls_v1_0", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
318 strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
320 authentication_method = account->outgoing_server_need_authentication;
323 #ifdef FEATURE_CORE_DEBUG
324 strncat(p, "/debug", long_enc_path_len-(strlen("/debug")+1));
327 /* Authentication method */
328 switch (authentication_method) {
329 case EMAIL_AUTHENTICATION_METHOD_DEFAULT:
330 strncat(p, "/needauth", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
332 case EMAIL_AUTHENTICATION_METHOD_XOAUTH2:
333 strncat(p, "/xoauth2", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
335 case EMAIL_AUTHENTICATION_METHOD_NO_AUTH:
340 if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) {
341 strncat(p, "}", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
344 strncat(p, path, long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
349 EM_DEBUG_LOG_SEC("long_enc_path [%s]", *long_enc_path);
357 if (err_code != NULL)
359 EM_PROFILE_END(emCorelongEncodedpath);
363 int emcore_get_long_encoded_path(char *multi_user_name, int account_id, char *path, int delimiter, char **long_enc_path, int *err_code)
365 EM_PROFILE_BEGIN(emCorelongEncodedpath);
366 EM_DEBUG_FUNC_BEGIN("account_id[%d], delimiter[%d], long_enc_path[%p], err_code[%p]", account_id, delimiter, long_enc_path, err_code);
369 int error = EMAIL_ERROR_NONE;
370 email_account_t *ref_account = NULL;
372 ref_account = emcore_get_account_reference(multi_user_name, account_id, false);
374 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
375 error = EMAIL_ERROR_INVALID_ACCOUNT;
379 if (emcore_get_long_encoded_path_with_account_info(multi_user_name, ref_account, path, delimiter, long_enc_path, &error) == false) {
380 EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path_with_account_info failed [%d]", error);
389 emcore_free_account(ref_account);
390 EM_SAFE_FREE(ref_account);
393 if (err_code != NULL)
395 EM_PROFILE_END(emCorelongEncodedpath);
399 int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code)
401 EM_DEBUG_FUNC_BEGIN_SEC("name[%s], enc_name[%p], err_code[%p]", name, enc_name, err_code);
403 if (!name || !enc_name) {
404 if (err_code != NULL)
405 *err_code = EMAIL_ERROR_INVALID_PARAM;
410 /* encoding mailbox name (Charset->UTF8->UTF7) */
411 char *last_slash = NULL;
412 char *last_word = NULL;
413 char *last_enc_word = NULL;
414 char *ret_enc_name = NULL;
415 int err = EMAIL_ERROR_NONE;
418 last_slash = rindex(name, '/');
419 last_word = (last_slash) ? last_slash+1 : name;
421 EM_DEBUG_EXCEPTION("Wrong mailbox [%s]", name);
422 err = EMAIL_ERROR_INVALID_PARAM;
427 /* convert the last mailbox folder to utf7 char */
428 last_enc_word = (char*)utf8_to_mutf7((unsigned char*)last_word);
429 if (!last_enc_word) {
430 EM_DEBUG_EXCEPTION("utf8_to_mutf7 failed");
431 err = EMAIL_ERROR_INVALID_PARAM;
436 /* if last word of mailbox name is ASCII, use input */
437 if (!strcmp(last_enc_word, last_word)) {
438 EM_DEBUG_LOG_SEC("NOT UTF-8 [%s]", last_word);
439 ret_enc_name = strdup(name);
443 EM_DEBUG_LOG_SEC("UTF-7 [%s](%d)->[%s](%d)", last_word, strlen(last_word), last_enc_word, strlen(last_enc_word));
445 /* if last word of mailbox name is UTF-8, replace it */
446 /* it is not a subfolder */
448 ret_enc_name = strdup(last_enc_word);
449 } else { /* it is a subfolder */
450 /*temprarily NULL assigned*/
452 int len = strlen(name) + 1 + strlen(last_enc_word); /* including '/' */
453 ret_enc_name = em_malloc(len + 1); /* NULL */
455 EM_DEBUG_EXCEPTION("malloc failed...");
456 err = EMAIL_ERROR_OUT_OF_MEMORY;
461 snprintf(ret_enc_name, len+1, "%s/%s", name, last_enc_word);
465 EM_DEBUG_LOG_SEC("utf-7 encoding complete!! name[%s], enc_name[%s]", name, ret_enc_name);
468 EM_SAFE_FREE(last_enc_word);
469 *enc_name = ret_enc_name;
470 if (err_code != NULL)
473 EM_DEBUG_FUNC_END("result [%s]", *enc_name);
477 int emcore_get_temp_file_name(char **filename, int *err_code)
479 EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code);
482 int error = EMAIL_ERROR_NONE;
483 if (filename == NULL) {
484 EM_DEBUG_EXCEPTION("\t filename[%p]\n", filename);
485 error = EMAIL_ERROR_INVALID_PARAM;
489 char tempname[512] = {0x00, };
493 gettimeofday(&tv, NULL);
496 /* Create Directory If deleted by user*/
497 emstorage_create_dir_if_delete();
499 SNPRINTF(tempname, sizeof(tempname), "%s%c%d", MAILTEMP, DIR_SEPERATOR_CH, rand());
501 char *p = EM_SAFE_STRDUP(tempname);
503 EM_DEBUG_EXCEPTION("\t strdup failed...\n");
504 error = EMAIL_ERROR_OUT_OF_MEMORY;
513 if (err_code != NULL)
519 int emcore_get_file_name(char *path, char **filename, int *err_code)
521 EM_DEBUG_FUNC_BEGIN_SEC("path[%s], filename[%p], err_code[%p]", path, filename, err_code);
524 int error = EMAIL_ERROR_NONE;
526 if (!path || !filename) {
527 EM_DEBUG_EXCEPTION("path[%p], filename[%p]", path, filename);
529 error = EMAIL_ERROR_INVALID_PARAM;
533 int i = (int)EM_SAFE_STRLEN(path);
537 if (path[i] == DIR_SEPERATOR_CH)
540 *filename = path + i + 1;
545 if (err_code != NULL)
551 INTERNAL_FUNC int emcore_get_file_size(char *path, int *size, int *err_code)
553 EM_DEBUG_FUNC_BEGIN("path[%s], size[%p], err_code[%p]", path, size, err_code);
556 int error = EMAIL_ERROR_NONE;
558 if ((path == NULL) || (size == NULL)) {
559 EM_DEBUG_EXCEPTION("\t path[%p], size[%p]\n", path, size);
561 error = EMAIL_ERROR_INVALID_PARAM;
567 if (stat(path, &st_buf) < 0) {
568 EM_DEBUG_EXCEPTION("\t stat failed - %s\n", path);
570 error = EMAIL_ERROR_SYSTEM_FAILURE;
574 *size = st_buf.st_size;
579 if (err_code != NULL)
585 INTERNAL_FUNC int emcore_check_drm_file(char *path, int *err_code)
587 EM_DEBUG_FUNC_BEGIN("path[%s], err_code[%p]", path, err_code);
590 int error = EMAIL_ERROR_NONE;
593 EM_DEBUG_EXCEPTION("path[%p]", path);
594 error = EMAIL_ERROR_INVALID_PARAM;
598 #ifdef __FEATURE_USE_DRM_API__
600 drm_bool_type_e isdrm;
601 drm_ret = drm_is_drm_file(path, &isdrm);
602 if (drm_ret != DRM_RETURN_SUCCESS || isdrm != DRM_TRUE) {
603 EM_DEBUG_LOG("file is not drm file");
604 error = EMAIL_ERROR_SYSTEM_FAILURE;
609 #endif /* __FEATURE_USE_DRM_API__ */
613 if (err_code != NULL)
620 INTERNAL_FUNC int emcore_check_drm_is_ringtone(char *ringtone_path, int *err_code)
622 EM_DEBUG_FUNC_BEGIN("ringtone_path[%s], err_code[%p]", ringtone_path, err_code);
625 int error = EMAIL_ERROR_NONE;
627 if (ringtone_path == NULL) {
628 EM_DEBUG_EXCEPTION("path[%p]", ringtone_path);
629 error = EMAIL_ERROR_INVALID_PARAM;
633 #ifdef __FEATURE_USE_DRM_API__
635 drm_bool_type_e allowed = DRM_UNKNOWN;
636 drm_action_allowed_data_s data;
637 memset(&data, 0x00, sizeof(drm_action_allowed_data_s));
638 strncpy(data.file_path, ringtone_path, strlen(ringtone_path));
639 data.data = (int)DRM_SETAS_RINGTONE;
641 drm_ret = drm_is_action_allowed(DRM_HAS_VALID_SETAS_STATUS, &data, &allowed);
643 if (drm_ret != DRM_RETURN_SUCCESS || allowed != DRM_TRUE) {
644 EM_DEBUG_LOG("fail to drm_is_action_allowed [0x%x]", drm_ret);
645 error = EMAIL_ERROR_SYSTEM_FAILURE;
649 EM_DEBUG_LOG("allowed [DRM_TRUE]");
651 #endif /* __FEATURE_USE_DRM_API__ */
655 if (err_code != NULL)
662 static int _emcore_check_host(char *host)
666 return strncmp(host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."));
671 int emcore_get_address_count(char *addr_str, int *count, int *err_code)
673 EM_DEBUG_FUNC_BEGIN("addr_str[%s], count[%p], err_code[%p]", addr_str, count, err_code);
676 int error = EMAIL_ERROR_NONE;
678 ADDRESS *addr = NULL;
679 ADDRESS *p_addr = NULL;
685 EM_DEBUG_EXCEPTION("addr_str[%s], count[%p]", addr_str, count);
686 error = EMAIL_ERROR_INVALID_PARAM;
690 if (addr_str != NULL) {
691 em_skip_whitespace(addr_str, &p);
692 EM_DEBUG_LOG("em_skip_whitespace[p][%s]", p);
695 for (i = 0, j = EM_SAFE_STRLEN(p); i < j; i++)
696 if (p[i] == ';') p[i] = ',';
697 rfc822_parse_adrlist(&addr, p, NULL);
701 for (p_addr = addr, i = 0; p_addr; p_addr = p_addr->next, i++) {
702 if (p_addr->mailbox && p_addr->host) {
703 if (!strncmp(p_addr->mailbox, "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS"))
704 || !strncmp(p_addr->mailbox, "INVALID_ADDRESS", strlen("INVALID_ADDRESS"))
705 || !strncmp(p_addr->host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."))) { /*prevent 34356*/
706 EM_DEBUG_LOG("Invalid address ");
710 if ((!p_addr->mailbox) || (_emcore_check_host(p_addr->host) == 0)) {
711 EM_DEBUG_EXCEPTION_SEC("\t invalid address : mailbox[%s], host[%s]\n", p_addr->mailbox, p_addr->host);
713 error = EMAIL_ERROR_INVALID_ADDRESS;
714 /* goto FINISH_OFF; */
720 if (error != EMAIL_ERROR_INVALID_ADDRESS)
725 mail_free_address(&addr);
727 if (err_code != NULL)
733 INTERNAL_FUNC int emcore_set_network_error(int err_code)
735 email_session_t *session = NULL;
737 EM_DEBUG_FUNC_BEGIN();
739 emcore_get_current_session(&session);
744 session->network = err_code;
749 INTERNAL_FUNC int emcore_get_empty_session(email_session_t **session)
751 EM_DEBUG_FUNC_BEGIN("session[%p]", session);
753 *session = &g_session;
759 INTERNAL_FUNC int emcore_clear_session(email_session_t *session)
761 EM_DEBUG_FUNC_BEGIN();
764 memset(session, 0x00, sizeof(email_session_t));
770 INTERNAL_FUNC int emcore_get_current_session(email_session_t **session)
772 EM_DEBUG_FUNC_BEGIN("session[%p]", session);
774 *session = &g_session;
780 INTERNAL_FUNC int emcore_get_mail_count_by_query(char *multi_user_name, int account_id, int mailbox_type, int priority_sender, int *total_mail, int *unread_mail, int *err_code)
782 EM_DEBUG_FUNC_BEGIN("account_id : [%d], mailbox_type : [%d], priority_sender : [%d]", account_id, mailbox_type, priority_sender);
785 int err = EMAIL_ERROR_NONE;
787 int type = EMAIL_PRIORITY_SENDER;
788 int unread_count = 0;
790 char *conditional_clause_string = NULL;
793 int is_completed = 0;
794 emstorage_rule_tbl_t *rule = NULL;
796 int filter_count = 0;
797 email_list_filter_t *filter_list = NULL;
800 if (priority_sender) {
801 if (!emstorage_get_rule(multi_user_name, ALL_ACCOUNT, type, 0, &rule_count, &is_completed, &rule, true, &err)) {
802 EM_DEBUG_EXCEPTION("emstorage_get_rule failed");
805 if (err == EMAIL_ERROR_FILTER_NOT_FOUND) {
806 EM_DEBUG_LOG("no rule found");
807 ret = true; /*it is not an error*/
812 EM_DEBUG_LOG_DEV("rule count [%d]", rule_count);
814 /* Make query for searching unread mail */
815 filter_count = 3; /* unseen field requires one filter, "flags_seen_field = 0"
816 and "deleted_flag = 0" */
819 filter_count += (rule_count * 2) + 2; /* one rule requires two filters,"A" "OR", plus two more operator "(" and ")" */
822 if (account_id != ALL_ACCOUNT) {
823 filter_count += 2; /* two filters, "AND" "account_id = x" */
827 filter_count += 2; /* two filters, "AND" "mailbox_type = x" */
829 filter_list = em_malloc(sizeof(email_list_filter_t) * filter_count);
830 if (filter_list == NULL) {
831 EM_DEBUG_EXCEPTION("em_mallocfailed");
832 err = EMAIL_ERROR_OUT_OF_MEMORY;
838 /* priority sender only, convert one rule to two filters which is composed of from_address and or/and */
839 /* example: (from_A OR from_B) AND ... */
840 if (rule_count > 0) {
841 /* first, add left parenthesis to from address clause, "(" */
842 filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
843 filter_list[0].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_LEFT_PARENTHESIS;
845 for (i = 0; i < rule_count; i++) {
846 /*array at odd index(1, 3, 5,..) has rule values, "from_A" */
848 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
849 filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
850 filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FROM;
851 filter_list[k].list_filter_item.rule.key_value.string_type_value = EM_SAFE_STRDUP(rule[i].value2);
853 /*array at even index(2, 4, 6,..) has either AND ,or OR*/
854 if (i != (rule_count - 1)) { /*if it is not the last rule, "OR" */
855 filter_list[++k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
856 filter_list[k].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
858 } else { /* ")" "AND" */
859 filter_list[++k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
860 filter_list[k].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_RIGHT_PARENTHESIS;
862 filter_list[++k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
863 filter_list[k].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
869 /*rule value, unseen +1*/
870 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
871 filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
872 filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD;
873 filter_list[k++].list_filter_item.rule.key_value.integer_type_value = 0;
875 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
876 filter_list[k++].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
878 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
879 filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_NOT_EQUAL;
880 filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS;
881 filter_list[k++].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAIL_STATUS_SAVED_OFFLINE;
883 /*account_id requires two filters*/
884 if (account_id != ALL_ACCOUNT) {
885 /* odd index, logical operator */
886 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
887 filter_list[k++].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
889 /* even index, rule value */
890 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
891 filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
892 filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID;
893 filter_list[k++].list_filter_item.rule.key_value.integer_type_value = account_id;
896 /*mailbox_type requires two filters*/
898 /* odd index, logical operator */
899 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
900 filter_list[k++].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
902 /* even index, rule value */
903 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
904 filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
905 filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE;
906 filter_list[k++].list_filter_item.rule.key_value.integer_type_value = mailbox_type;
909 if ((err = emstorage_write_conditional_clause_for_getting_mail_list(multi_user_name, filter_list, filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
910 EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
914 EM_DEBUG_LOG_DEV("conditional_clause_string[%s]", conditional_clause_string);
916 /* Search the mail of priority sender in DB */
917 if ((err = emstorage_query_mail_count(multi_user_name, conditional_clause_string, true, &total_count, &unread_count)) != EMAIL_ERROR_NONE) {
918 EM_DEBUG_EXCEPTION("emstorage_query_mail_count failed:[%d]", err);
927 emstorage_free_rule(&rule, rule_count, NULL);
930 emstorage_free_list_filter(&filter_list, filter_count);
932 EM_SAFE_FREE(conditional_clause_string);
935 *total_mail = total_count;
938 *unread_mail = unread_count;
946 INTERNAL_FUNC int emcore_display_badge_count(char *multi_user_name, int count)
948 EM_DEBUG_FUNC_BEGIN();
950 int err = EMAIL_ERROR_NONE;
951 badge_error_e badge_err = BADGE_ERROR_NONE;
953 void *join_zone = NULL;
955 if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
956 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
960 if ((badge_err = badge_is_existing("org.tizen.email", &exist)) != BADGE_ERROR_NONE) {
961 EM_DEBUG_EXCEPTION("badge_is_existing failed [%d]", badge_err);
962 err = EMAIL_ERROR_BADGE_API_FAILED;
968 if ((badge_err = badge_create("org.tizen.email", "/usr/bin/email-service")) != BADGE_ERROR_NONE) {
969 EM_DEBUG_EXCEPTION("badge_create failed [%d]", badge_err);
970 err = EMAIL_ERROR_BADGE_API_FAILED;
975 if ((badge_err = badge_set_count("org.tizen.email", count)) != BADGE_ERROR_NONE) {
976 EM_DEBUG_EXCEPTION("badge_set_count failed [%d]", badge_err);
977 if (badge_err != BADGE_ERROR_SERVICE_NOT_READY) {
978 err = EMAIL_ERROR_BADGE_API_FAILED;
982 /* Badge callback function : When the badge service ready, call the callback function */
983 badge_err = badge_add_deferred_task(emcore_display_unread_in_badge, NULL);
984 if (badge_err != BADGE_ERROR_NONE) {
985 EM_DEBUG_EXCEPTION("badge_add_deferred_task failed : [%d]", badge_err);
986 err = EMAIL_ERROR_BADGE_API_FAILED;
994 emcore_unset_join_zone(join_zone);
1000 void emcore_display_unread_in_badge(void *data)
1002 EM_DEBUG_FUNC_BEGIN();
1004 int err = EMAIL_ERROR_NONE;
1005 int total_unread_count = 0;
1006 int total_mail_count = 0;
1009 if (!emcore_get_mail_count_by_query((char *)data, ALL_ACCOUNT,
1010 EMAIL_MAILBOX_TYPE_INBOX, 0,
1011 &total_mail_count, &total_unread_count,
1013 EM_DEBUG_EXCEPTION("emcore_get_mail_count_by_query failed");
1017 unseen = total_unread_count;
1022 if ((err = emcore_display_badge_count((char *)data, 0)) != EMAIL_ERROR_NONE) {
1023 EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err);
1026 if ((err = emcore_display_badge_count((char *)data, unseen)) != EMAIL_ERROR_NONE) {
1027 EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err);
1031 EM_DEBUG_FUNC_END();
1034 static int emcore_layout_multi_noti(notification_h noti, int unread_mail, char *email_address, char *account_name)
1036 EM_DEBUG_FUNC_BEGIN("unread_count %d", unread_mail);
1037 char temp_buffer[512] = {0};
1038 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1040 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
1041 if (noti_err != NOTIFICATION_ERROR_NONE) {
1042 EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_MULTIPLE failed [%d]", noti_err);
1046 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "New emails", dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_MBODY_NEW_EMAILS_ABB"), NOTIFICATION_VARIABLE_TYPE_NONE);
1047 if (noti_err != NOTIFICATION_ERROR_NONE) {
1048 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
1052 SNPRINTF(temp_buffer, sizeof(temp_buffer), "%d", unread_mail);
1053 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, temp_buffer, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1054 if (noti_err != NOTIFICATION_ERROR_NONE) {
1055 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_EVENT_COUNT failed");
1060 SNPRINTF(temp_buffer, sizeof(temp_buffer), "%s, %s", email_address, account_name);
1062 SNPRINTF(temp_buffer, sizeof(temp_buffer), "%s", email_address);
1064 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, temp_buffer, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1065 if (noti_err != NOTIFICATION_ERROR_NONE) {
1066 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
1070 noti_err = notification_set_time(noti, time(NULL));
1071 if (noti_err != NOTIFICATION_ERROR_NONE) {
1072 EM_DEBUG_EXCEPTION("notification_set_time failed");
1076 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH);
1077 if (noti_err != NOTIFICATION_ERROR_NONE) {
1078 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1082 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, EMAIL_NOTI_INDICATOR_ICON_PATH);
1083 if (noti_err != NOTIFICATION_ERROR_NONE) {
1084 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1088 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, EMAIL_NOTI_ICON_PATH);
1089 if (noti_err != NOTIFICATION_ERROR_NONE) {
1090 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1096 EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err);
1100 static int emcore_layout_single_noti(notification_h noti, char *account_name, int ids, char *display_sender, time_t time, char *subject, int display_status)
1102 EM_DEBUG_FUNC_BEGIN();
1103 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1105 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
1106 if (noti_err != NOTIFICATION_ERROR_NONE) {
1107 EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_SINGLE failed [%d]", noti_err);
1112 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", dgettext(NATIVE_EMAIL_DOMAIN, "IDS_ST_HEADER_EMAIL"), NOTIFICATION_VARIABLE_TYPE_NONE);
1114 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, display_sender, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1116 if (noti_err != NOTIFICATION_ERROR_NONE) {
1117 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
1121 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, account_name, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1122 if (noti_err != NOTIFICATION_ERROR_NONE) {
1123 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
1128 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, NULL, display_sender, NOTIFICATION_VARIABLE_TYPE_NONE);
1130 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, display_sender, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1132 if (noti_err != NOTIFICATION_ERROR_NONE) {
1133 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
1138 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1140 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, "New email", dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_NEW_EMAIL_RECEIVED_ABB"), NOTIFICATION_VARIABLE_TYPE_NONE);
1142 if (noti_err != NOTIFICATION_ERROR_NONE) {
1143 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
1147 noti_err = notification_set_time(noti, time);
1148 if (noti_err != NOTIFICATION_ERROR_NONE) {
1149 EM_DEBUG_EXCEPTION("notification_set_time failed");
1153 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH);
1154 if (noti_err != NOTIFICATION_ERROR_NONE) {
1155 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1159 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, EMAIL_NOTI_INDICATOR_ICON_PATH);
1160 if (noti_err != NOTIFICATION_ERROR_NONE) {
1161 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1165 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, EMAIL_NOTI_ICON_PATH);
1166 if (noti_err != NOTIFICATION_ERROR_NONE) {
1167 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1172 EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err);
1176 static int emcore_get_alert_type(int vibrate_status)
1178 EM_DEBUG_FUNC_BEGIN();
1179 int global_sound_status = 0;
1180 int global_vibe_status = 0;
1181 int email_vibe_status = 0;
1183 int alert_type = EMAIL_ALERT_TYPE_MUTE;
1184 #ifdef __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__
1185 int voicerecoder_state = 0;
1186 #endif /* __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__ */
1188 if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &global_sound_status) != 0) {
1189 EM_DEBUG_LOG("vconf_get_bool for VCONFKEY_SETAPPL_SOUND_STATUS_BOOL failed");
1193 if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &global_vibe_status) != 0) {
1194 EM_DEBUG_LOG("vconf_get_bool for VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOLfailed");
1198 EM_DEBUG_LOG("global_sound_status [%d] global_vibe_status [%d]", global_sound_status, global_vibe_status);
1200 if (global_sound_status || global_vibe_status) {
1201 #ifdef __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__
1202 if (vconf_get_int(VCONFKEY_VOICERECORDER_STATE, &voicerecoder_state) != 0) {
1203 EM_DEBUG_LOG("vconf_get_int for VCONFKEY_VOICERECORDER_STATE failed");
1205 EM_DEBUG_LOG("voicerecoder_state [%d]", voicerecoder_state);
1206 #endif /* __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__ */
1208 if (vconf_get_int(VCONFKEY_CALL_STATE, &call_state) != 0) {
1209 EM_DEBUG_LOG("vconf_get_int for VCONFKEY_CALL_STATE failed");
1211 EM_DEBUG_LOG("call_state [%d] ", call_state);
1213 email_vibe_status = vibrate_status;
1215 EM_DEBUG_LOG("email_vibe_status [%d] ", email_vibe_status);
1216 #ifdef __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__
1217 if (voicerecoder_state == VCONFKEY_VOICERECORDER_RECORDING) {
1218 alert_type = EMAIL_ALERT_TYPE_VIB;
1219 EM_DEBUG_LOG("voice recorder is on recording...");
1221 /* else if (call_state > VCONFKEY_CALL_OFF && call_state < VCONFKEY_CALL_STATE_MAX) { */
1222 #endif /* __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__ */
1224 if (call_state > VCONFKEY_CALL_OFF && call_state < VCONFKEY_CALL_STATE_MAX) {
1225 EM_DEBUG_LOG("Calling");
1226 if (global_sound_status)
1227 alert_type = EMAIL_ALERT_TYPE_MELODY;
1229 alert_type = EMAIL_ALERT_TYPE_NONE;
1230 } else if (global_sound_status && email_vibe_status) {
1231 alert_type = EMAIL_ALERT_TYPE_MELODY_AND_VIB;
1232 } else if (global_sound_status) {
1233 alert_type = EMAIL_ALERT_TYPE_MELODY;
1234 } else if (global_vibe_status) {
1235 alert_type = EMAIL_ALERT_TYPE_VIB;
1241 EM_DEBUG_FUNC_END("alert_type [%d]", alert_type);
1245 static char *emcore_get_sound_file_path(int default_ringtone_status, char *alert_ringtone_path)
1247 EM_DEBUG_FUNC_BEGIN();
1249 int use_default_ring_tone = 0;
1251 use_default_ring_tone = default_ringtone_status;
1253 EM_DEBUG_LOG("use_default_ring_tone [%d]", use_default_ring_tone);
1255 if (use_default_ring_tone)
1256 ret = vconf_get_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
1258 ret = EM_SAFE_STRDUP(alert_ringtone_path);
1260 if ((emcore_check_drm_file(ret, NULL)) && (!emcore_check_drm_is_ringtone(ret, NULL))) {
1261 EM_DEBUG_LOG_DEV("The ringtone is not allowed DRM. : [%s]", ret);
1263 ret = EM_SAFE_STRDUP(vconf_get_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR));
1266 EM_DEBUG_FUNC_END("ret [%s]", ret);
1270 #if 0 //using notification_status_message_post instead of calling email-app toast - change date: 30/9/2014
1271 INTERNAL_FUNC int emcore_show_toast_popup(char *input_popup_string)
1273 int err = EMAIL_ERROR_NONE;
1274 int ret = APP_CONTROL_ERROR_NONE;
1275 app_control_h svc_handle = NULL;
1277 ret = app_control_create(&svc_handle);
1279 if (ret != APP_CONTROL_ERROR_NONE || !svc_handle) {
1280 EM_DEBUG_LOG("app_control_create() failed! ret:[%d]", ret);
1281 err = EMAIL_ERROR_SYSTEM_FAILURE;
1285 ret = app_control_set_app_id(svc_handle, "org.tizen.email-tts-play");
1286 if (ret != APP_CONTROL_ERROR_NONE) {
1287 EM_DEBUG_LOG("app_control_set_app_id() failed! ret:[%d]", ret);
1288 err = EMAIL_ERROR_SYSTEM_FAILURE;
1292 ret = app_control_add_extra_data(svc_handle, "email_misc_work_type", "1003");
1293 if (ret != APP_CONTROL_ERROR_NONE) {
1294 EM_DEBUG_LOG("app_control_add_extra_data() failed! ret:[%d]", ret);
1295 err = EMAIL_ERROR_SYSTEM_FAILURE;
1299 ret = app_control_add_extra_data(svc_handle, "popup_string", input_popup_string);
1300 if (ret != APP_CONTROL_ERROR_NONE) {
1301 EM_DEBUG_LOG("app_control_add_extra_data() failed! ret:[%d]", ret);
1302 err = EMAIL_ERROR_SYSTEM_FAILURE;
1306 ret = app_control_send_launch_request(svc_handle, NULL, NULL);
1307 if (ret != APP_CONTROL_ERROR_NONE) {
1308 EM_DEBUG_LOG("app_control_send_launch_request() failed! ret:[%d]", ret);
1309 err = EMAIL_ERROR_SYSTEM_FAILURE;
1316 ret = app_control_destroy(svc_handle);
1317 if (ret != APP_CONTROL_ERROR_NONE) {
1318 EM_DEBUG_LOG("app_control_destroy() failed! ret:[%d]", ret);
1319 err = EMAIL_ERROR_SYSTEM_FAILURE;
1328 INTERNAL_FUNC int emcore_add_notification(char *multi_user_name, int account_id, int mail_id, int unread_mail_count, int vip_unread_mail_count, int input_play_alert_tone, int sending_error, unsigned long display)
1330 EM_DEBUG_FUNC_BEGIN("account_id[%d] mail_id[%d] unread_mail_count[%d] input_play_alert_tone[%d]", account_id, mail_id, unread_mail_count, input_play_alert_tone);
1331 int err = EMAIL_ERROR_NONE;
1332 #ifdef __FEATURE_NOTIFICATION_ENABLE__
1338 int unread_mail_count_t = 0;
1339 char *mailbox_name = NULL;
1340 char vconf_private_id[MAX_PATH] = {0, };
1341 notification_h noti = NULL;
1342 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1343 notification_vibration_type_e noti_vibe_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1344 emstorage_account_tbl_t *account_tbl = NULL;
1345 emstorage_mail_tbl_t *p_mail_data = NULL;
1346 int display_status = false;
1347 EMAIL_ALERT_TYPE alert_type = EMAIL_ALERT_TYPE_NONE;
1348 char *alert_tone_path = NULL;
1349 void *join_zone = NULL;
1351 /* For service bundle */
1352 char buf[256] = {0,};
1353 char **value = NULL;
1354 app_control_h service = NULL;
1357 if (!emstorage_get_account_by_id(multi_user_name, account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_tbl, true, &err)) {
1358 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err);
1362 if (!account_tbl->options.notification_status) {
1363 EM_DEBUG_LOG("Notification disabled");
1367 /* Get the unread mail id */
1368 if (!emstorage_get_unread_mailid(multi_user_name, account_id, 0, &p_mail_id, &unread_mail_count_t, &err)) {
1369 EM_DEBUG_EXCEPTION("emstorage_get_unread_mailid failed [%d]", err);
1373 unseen = unread_mail_count_t;
1374 display_status = account_tbl->options.display_content_status;
1376 /* Load the previous noti */
1377 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1378 if (vconf_get_int(vconf_private_id, &private_id) != 0) {
1379 EM_DEBUG_EXCEPTION("vconf_get_int failed");
1382 /* Turn display on to blink LED */
1383 // emdevice_change_display_state(DISPLAY_STATE_ON);
1385 if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
1386 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
1390 noti = notification_load(NULL, private_id);
1392 EM_DEBUG_EXCEPTION("notification_load failed");
1393 noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
1395 EM_DEBUG_EXCEPTION("notification_new failed");
1396 err = EMAIL_ERROR_SYSTEM_FAILURE;
1400 if ((noti_err = notification_set_pkgname(noti, NATIVE_EMAIL_APPLICATION_PKG)) != NOTIFICATION_ERROR_NONE) {
1401 EM_DEBUG_EXCEPTION("notification_set_pkgname failed [%d]", noti_err);
1402 err = EMAIL_ERROR_SYSTEM_FAILURE;
1409 if (input_play_alert_tone) {
1410 alert_type = emcore_get_alert_type(account_tbl->options.vibrate_status);
1412 if (alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_MELODY)
1413 alert_tone_path = emcore_get_sound_file_path(account_tbl->options.default_ringtone_status, account_tbl->options.alert_ringtone_path);
1416 /* blocking mode : */
1417 #ifdef __FEATURE_BLOCKING_MODE__
1418 if (!emcore_get_blocking_mode_status()) {
1419 #endif /* __FEATURE_BLOCKING_MODE__ */
1420 if ((noti_err = notification_set_led_time_period(noti, 250, 2500)) != NOTIFICATION_ERROR_NONE) {
1421 EM_DEBUG_EXCEPTION("notification_set_led_time_period failed [%d]", noti_err);
1422 err = EMAIL_ERROR_SYSTEM_FAILURE;
1426 if ((noti_err = notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00)) != NOTIFICATION_ERROR_NONE) {
1427 EM_DEBUG_EXCEPTION("notification_set_led failed [%d]", noti_err);
1428 err = EMAIL_ERROR_SYSTEM_FAILURE;
1432 if ((alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_MELODY) && EM_SAFE_STRLEN(alert_tone_path)) {
1433 if (strcmp(alert_tone_path, "silent") == 0) {
1434 if ((noti_err = notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL)) != NOTIFICATION_ERROR_NONE) {
1435 EM_DEBUG_EXCEPTION("notification_set_sound failed [%d]", noti_err);
1436 err = EMAIL_ERROR_SYSTEM_FAILURE;
1440 if ((noti_err = notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_USER_DATA, alert_tone_path)) != NOTIFICATION_ERROR_NONE) {
1441 EM_DEBUG_EXCEPTION("notification_set_sound failed [%d]", noti_err);
1442 err = EMAIL_ERROR_SYSTEM_FAILURE;
1447 #ifdef __FEATURE_BLOCKING_MODE__
1449 #endif /* __FEATURE_BLOCKING_MODE__ */
1451 if (alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_VIB)
1452 noti_vibe_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1454 if ((noti_err = notification_set_vibration(noti, noti_vibe_type, NULL)) != NOTIFICATION_ERROR_NONE) {
1455 EM_DEBUG_EXCEPTION("notification_set_vibration failed [%d]", noti_err);
1456 err = EMAIL_ERROR_SYSTEM_FAILURE;
1460 if ((noti_err = notification_set_text_domain(noti, NATIVE_EMAIL_DOMAIN, tzplatform_mkpath(TZ_SYS_RO_APP,"org.tizen.email/res/locale"))) != NOTIFICATION_ERROR_NONE) {
1461 EM_DEBUG_EXCEPTION("notification_set_text_domain failed [%d]", noti_err);
1462 err = EMAIL_ERROR_SYSTEM_FAILURE;
1466 if (!emstorage_get_mailbox_name_by_mailbox_type(multi_user_name, account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_name, false, &err)) {
1467 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
1471 EM_DEBUG_LOG("unseen [%d] display_status [%d]", unseen, display_status);
1473 /* set execution option to launch email-viewer when single incoming mail*/
1474 app_control_create(&service);
1476 EM_DEBUG_EXCEPTION("service create failed");
1480 if (!emstorage_get_mail_by_id(multi_user_name, p_mail_id[0], &p_mail_data, false, &err)) {
1481 EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
1485 EM_DEBUG_LOG_SEC("single layout:account_name[%s], alias_sender[%s], time[%d], subject[%s]", account_tbl->account_name, p_mail_data->alias_sender, p_mail_data->date_time, p_mail_data->subject);
1486 if ((noti_err = emcore_layout_single_noti(noti, account_tbl->account_name, 0, p_mail_data->alias_sender, p_mail_data->date_time, p_mail_data->subject, display_status)) != NOTIFICATION_ERROR_NONE) {
1487 EM_DEBUG_EXCEPTION("notification_layout_single_noti failed [%d]", noti_err);
1488 err = EMAIL_ERROR_SYSTEM_FAILURE;
1492 snprintf(buf, sizeof(buf), "%d", 12);
1493 app_control_add_extra_data(service, "RUN_TYPE", buf);
1494 snprintf(buf, sizeof(buf), "%d", account_id);
1495 app_control_add_extra_data(service, "ACCOUNT_ID", buf);
1496 snprintf(buf, sizeof(buf), "%d", p_mail_data->mail_id);
1497 app_control_add_extra_data(service, "MAIL_ID", buf);
1498 snprintf(buf, sizeof(buf), "%d", p_mail_data->mailbox_id);
1499 app_control_add_extra_data(service, "MAILBOX_ID", buf);
1500 app_control_set_app_id(service, NATIVE_EMAIL_APPLICATION_PKG);
1502 app_control_to_bundle(service, &b);
1503 noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1504 if (noti_err != NOTIFICATION_ERROR_NONE) {
1505 EM_DEBUG_EXCEPTION("notification_set_execute_option failed [%d]", noti_err);
1506 err = EMAIL_ERROR_SYSTEM_FAILURE;
1509 } else if (unseen > 1) {
1510 EM_DEBUG_LOG_SEC("multi layout: unseen[%d], address[%s], account_name[%s]", unseen, account_tbl->user_email_address, account_tbl->account_name);
1511 if ((noti_err = emcore_layout_multi_noti(noti, unseen, account_tbl->user_email_address, account_tbl->account_name)) != NOTIFICATION_ERROR_NONE) {
1512 EM_DEBUG_EXCEPTION("notification_layout_multi_noti failed [%d]", noti_err);
1513 err = EMAIL_ERROR_SYSTEM_FAILURE;
1517 snprintf(buf, sizeof(buf), "%d", 13);
1518 app_control_add_extra_data(service, "RUN_TYPE", buf);
1519 snprintf(buf, sizeof(buf), "%d", account_id);
1520 app_control_add_extra_data(service, "ACCOUNT_ID", buf);
1522 if (unseen > EMAIL_NOTI_MAX_MAIL_ID)
1523 unseen = EMAIL_NOTI_MAX_MAIL_ID;
1524 value = (char **)em_malloc(unseen * sizeof(char *));
1525 if (value == NULL) {
1526 EM_DEBUG_EXCEPTION("em_mallocfailed");
1527 err = EMAIL_ERROR_OUT_OF_MEMORY;
1531 for (i = 0; i < unseen; i++) {
1532 memset(buf, 0x00, sizeof(buf));
1533 snprintf(buf, sizeof(buf), "%d", p_mail_id[i]);
1534 value[i] = EM_SAFE_STRDUP(buf);
1536 app_control_add_extra_data_array(service, "MAIL_ID", (const char **)value, unseen);
1537 app_control_set_app_id(service, NATIVE_EMAIL_APPLICATION_PKG);
1539 app_control_to_bundle(service, &b);
1540 noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, b);
1541 if (noti_err != NOTIFICATION_ERROR_NONE) {
1542 EM_DEBUG_EXCEPTION("notification_set_execute_option failed [%d]", noti_err);
1543 err = EMAIL_ERROR_SYSTEM_FAILURE;
1546 } else { /* if priority sender exists and no mail of priority sender, unseen will be 0*/
1547 EM_DEBUG_LOG("-unseen: [%d]", unseen);
1549 /* err = EMAIL_ERROR_PRIORITY_SENDER_MAIL_NOT_FOUND;*/ /*there is no mail for priority sender*/
1552 if ((noti_err = notification_set_display_applist(noti, display)) != NOTIFICATION_ERROR_NONE) {
1553 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1554 err = EMAIL_ERROR_SYSTEM_FAILURE;
1559 if ((noti_err = notification_insert(noti, &private_id)) != NOTIFICATION_ERROR_NONE) {
1560 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1561 err = EMAIL_ERROR_SYSTEM_FAILURE;
1565 EM_DEBUG_LOG("Private_id = [%d]", private_id);
1567 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1568 if (vconf_set_int(vconf_private_id, private_id) != 0) {
1569 EM_DEBUG_EXCEPTION("vconf_set_int failed");
1570 err = EMAIL_ERROR_SYSTEM_FAILURE;
1574 if ((noti_err = notification_update(noti)) != NOTIFICATION_ERROR_NONE) {
1575 EM_DEBUG_EXCEPTION("notification_update failed [%d]", noti_err);
1576 err = EMAIL_ERROR_SYSTEM_FAILURE;
1581 #ifdef __FEATURE_DRIVING_MODE__
1583 err = emcore_start_driving_mode(multi_user_name, p_mail_id[unseen - 1]);
1584 if (err != EMAIL_ERROR_NONE)
1585 EM_DEBUG_EXCEPTION("emcore_start_driving_mode failed : [%d]", err);
1587 #endif /* __FEATURE_DRIVING_MODE__ */
1592 app_control_destroy(service);
1595 notification_free(noti);
1598 emcore_unset_join_zone(join_zone);
1600 EM_SAFE_FREE(alert_tone_path);
1601 EM_SAFE_FREE(p_mail_id); /* prevent */
1604 emstorage_free_mail(&p_mail_data, 1, NULL);
1607 emstorage_free_account(&account_tbl, 1, NULL);
1609 for (i = 0; i < unseen; i++) {
1611 EM_SAFE_FREE(value[i]);
1613 EM_SAFE_FREE(value);
1615 EM_SAFE_FREE(mailbox_name);
1617 #endif /* __FEATURE_NOTIFICATION_ENABLE__ */
1619 EM_DEBUG_FUNC_END("ret [%d]", err);
1623 INTERNAL_FUNC int emcore_add_notification_for_send(char *multi_user_name, int account_id, int mail_id, email_action_t action, int sending_error, unsigned long display)
1625 EM_DEBUG_FUNC_BEGIN("account_id: %d, mail_id: %d, action:%d", account_id, mail_id, action);
1626 int err = EMAIL_ERROR_NONE;
1627 #ifdef __FEATURE_NOTIFICATION_ENABLE__
1629 void *join_zone = NULL;
1630 char *mailbox_name = NULL;
1631 char *dgettext_string = NULL;
1632 char vconf_private_id[MAX_PATH] = {0, };
1633 notification_h noti = NULL;
1634 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1635 emstorage_mail_tbl_t *p_mail_data = NULL;
1636 emstorage_account_tbl_t *account_tbl = NULL;
1638 /* For service bundle */
1639 char buf[256] = {0,};
1640 app_control_h service = NULL;
1643 /* get general noti status */
1644 if (!emstorage_get_account_by_id(multi_user_name, account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_tbl, true, &err)) {
1645 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err);
1649 if (!account_tbl->options.notification_status) {
1650 EM_DEBUG_LOG("notification disabled");
1654 if (!account_tbl->options.display_content_status) {
1655 EM_DEBUG_LOG("display content disabled");
1659 /* Delete the previous noti */
1660 emcore_delete_notification_by_account(multi_user_name, account_id, true);
1661 if (g_sending_noti_handle) {
1662 if ((noti_err = notification_free(g_sending_noti_handle)) != NOTIFICATION_ERROR_NONE)
1663 err = EMAIL_ERROR_NOTI;
1664 g_sending_noti_handle = NULL;
1667 if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
1668 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
1672 if (action == EMAIL_ACTION_SENDING_MAIL)
1673 noti = notification_create(NOTIFICATION_TYPE_ONGOING);
1675 noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
1678 EM_DEBUG_EXCEPTION("notification_new failed");
1679 err = EMAIL_ERROR_NOTI;
1683 if ((noti_err = notification_set_pkgname(noti, NATIVE_EMAIL_APPLICATION_PKG)) != NOTIFICATION_ERROR_NONE) {
1684 EM_DEBUG_EXCEPTION("notification_set_pkgname failed [%d]", noti_err);
1685 err = EMAIL_ERROR_NOTI;
1689 if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &p_mail_data, false, &err)) {
1690 EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
1694 /* Create service bundle */
1695 app_control_create(&service);
1697 EM_DEBUG_EXCEPTION("service create failed");
1700 snprintf(buf, sizeof(buf), "%d", 12);
1701 app_control_add_extra_data(service, "RUN_TYPE", buf);
1702 snprintf(buf, sizeof(buf), "%d", account_id);
1703 app_control_add_extra_data(service, "ACCOUNT_ID", buf);
1704 snprintf(buf, sizeof(buf), "%d", p_mail_data->mail_id);
1705 app_control_add_extra_data(service, "MAIL_ID", buf);
1706 snprintf(buf, sizeof(buf), "%d", p_mail_data->mailbox_id);
1707 app_control_add_extra_data(service, "MAILBOX_ID", buf);
1708 app_control_set_app_id(service, NATIVE_EMAIL_APPLICATION_PKG);
1710 app_control_to_bundle(service, &b);
1711 noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1712 if (noti_err != NOTIFICATION_ERROR_NONE) {
1713 EM_DEBUG_EXCEPTION("notification_set_execute_option failed [%d]", noti_err);
1714 err = EMAIL_ERROR_SYSTEM_FAILURE;
1719 case EMAIL_ACTION_SEND_MAIL:
1721 setlocale(LC_MESSAGES, vconf_get_str(VCONFKEY_LANGSET));
1722 bindtextdomain("sys_string", "/usr/share/locale");
1723 textdomain("sys_string");
1725 setlocale(LC_MESSAGES, vconf_get_str(VCONFKEY_LANGSET));
1726 bindtextdomain(NATIVE_EMAIL_DOMAIN, tzplatform_mkpath(TZ_SYS_RO_APP,"org.tizen.email/res/locale"));
1727 textdomain(NATIVE_EMAIL_DOMAIN);
1729 switch (sending_error) {
1730 case EMAIL_ERROR_NONE:
1731 dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_EMAIL_SENT");
1733 case EMAIL_ERROR_FLIGHT_MODE_ENABLE:
1734 dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_FAILED_TO_CONNECT_TO_NETWORK");
1736 case EMAIL_ERROR_NETWORK_NOT_AVAILABLE:
1737 case EMAIL_ERROR_NO_SIM_INSERTED:
1738 dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_NETWORK_NOT_AVAILABLE_EMAIL_WILL_BE_SENT_WHEN_CONNECTED_TO_NETWORK");
1740 case EMAIL_ERROR_SERVER_STORAGE_FULL:
1741 dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_SENDING_FAILED_SERVER_STORAGE_FULL_ABB");
1744 dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_SENDING_FAILED");
1748 if ((noti_err = notification_set_layout(noti,
1749 NOTIFICATION_LY_NOTI_EVENT_SINGLE)) != NOTIFICATION_ERROR_NONE) {
1750 EM_DEBUG_EXCEPTION("notification_set_layout failed [%d]", noti_err);
1751 err = EMAIL_ERROR_NOTI;
1755 if ((noti_err = notification_set_image(noti,
1756 NOTIFICATION_IMAGE_TYPE_ICON,
1757 EMAIL_NOTI_ICON_PATH)) != NOTIFICATION_ERROR_NONE) {
1758 EM_DEBUG_EXCEPTION("notification_set_image failed [%d]", noti_err);
1759 err = EMAIL_ERROR_NOTI;
1763 if ((noti_err = notification_set_text(noti,
1764 NOTIFICATION_TEXT_TYPE_TITLE,
1765 p_mail_data->alias_recipient,
1767 NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1768 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1769 err = EMAIL_ERROR_NOTI;
1773 switch (sending_error) {
1774 case EMAIL_ERROR_NONE:
1775 if ((noti_err = notification_set_text(noti,
1776 NOTIFICATION_TEXT_TYPE_CONTENT,
1779 NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1780 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1781 err = EMAIL_ERROR_NOTI;
1785 case EMAIL_ERROR_SERVER_STORAGE_FULL:
1786 if ((noti_err = notification_set_text(noti,
1787 NOTIFICATION_TEXT_TYPE_CONTENT,
1788 "Sending failed. Server storage full.",
1790 NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1791 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1792 err = EMAIL_ERROR_NOTI;
1797 if ((noti_err = notification_set_text(noti,
1798 NOTIFICATION_TEXT_TYPE_CONTENT,
1801 NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1802 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1803 err = EMAIL_ERROR_NOTI;
1809 if (sending_error == EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE) {
1810 if ((noti_err = notification_set_text(noti,
1811 NOTIFICATION_TEXT_TYPE_INFO_1,
1812 dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_POP_THE_EMAIL_IS_TOO_LARGE"),
1814 NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1815 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
1816 err = EMAIL_ERROR_NOTI;
1821 if ((noti_err = notification_set_display_applist(noti,
1822 NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER)) != NOTIFICATION_ERROR_NONE) {
1823 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1824 err = EMAIL_ERROR_NOTI;
1828 if ((noti_err = notification_insert(noti, &private_id)) != NOTIFICATION_ERROR_NONE) {
1829 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1830 err = EMAIL_ERROR_NOTI;
1834 EM_DEBUG_LOG("Private_id = [%d]", private_id);
1836 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1837 if (vconf_set_int(vconf_private_id, private_id) != 0) {
1838 EM_DEBUG_EXCEPTION("vconf_set_int failed");
1839 err = EMAIL_ERROR_GCONF_FAILURE;
1845 case EMAIL_ACTION_SENDING_MAIL:
1847 if ((noti_err = notification_set_text_domain(noti, NATIVE_EMAIL_DOMAIN, tzplatform_mkpath(TZ_SYS_RO_APP,"org.tizen.email/res/locale"))) != NOTIFICATION_ERROR_NONE) {
1848 EM_DEBUG_EXCEPTION("notification_set_text_domain failed [%d]", noti_err);
1849 err = EMAIL_ERROR_NOTI;
1853 if ((noti_err = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_PROGRESS)) != NOTIFICATION_ERROR_NONE) {
1854 EM_DEBUG_EXCEPTION("notification_set_layout failed [%d]", noti_err);
1855 err = EMAIL_ERROR_NOTI;
1859 if ((noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH)) != NOTIFICATION_ERROR_NONE) {
1860 EM_DEBUG_EXCEPTION("notification_set_image failed [%d]", noti_err);
1861 err = EMAIL_ERROR_NOTI;
1865 if ((noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Sending email...", dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_SENDING_EMAIL_ING"), NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1866 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1867 err = EMAIL_ERROR_NOTI;
1871 if ((noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, p_mail_data->subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1872 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1873 err = EMAIL_ERROR_NOTI;
1877 /*notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);*/
1879 if ((noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL)) != NOTIFICATION_ERROR_NONE) {
1880 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1881 err = EMAIL_ERROR_NOTI;
1885 if ((noti_err = notification_insert(noti, &private_id)) != NOTIFICATION_ERROR_NONE) {
1886 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1887 err = EMAIL_ERROR_NOTI;
1891 g_sending_noti_handle = noti;
1892 EM_DEBUG_LOG("Private_id = [%d]", private_id);
1894 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1895 if (vconf_set_int (vconf_private_id, private_id) != 0) {
1896 EM_DEBUG_EXCEPTION("vconf_set_int failed");
1897 err = EMAIL_ERROR_GCONF_FAILURE;
1905 if ((noti_err = notification_free(noti)) != NOTIFICATION_ERROR_NONE) {
1906 EM_DEBUG_EXCEPTION("notification_free error [%d]", noti_err);
1907 err = EMAIL_ERROR_NOTI;
1916 app_control_destroy(service);
1918 if ((action == EMAIL_ACTION_SEND_MAIL) && noti) {
1919 if ((noti_err = notification_free(noti)) != NOTIFICATION_ERROR_NONE) {
1920 err = EMAIL_ERROR_NOTI;
1924 if ((action != EMAIL_ACTION_SEND_MAIL) && (err != EMAIL_ERROR_NONE)) {
1926 notification_free(noti);
1927 g_sending_noti_handle = NULL;
1932 emcore_unset_join_zone(join_zone);
1935 emstorage_free_mail(&p_mail_data, 1, NULL);
1938 emstorage_free_account(&account_tbl, 1, NULL);
1940 EM_SAFE_FREE(mailbox_name);
1942 #endif /* __FEATURE_NOTIFICATION_ENABLE__ */
1944 EM_DEBUG_FUNC_END("ret [%d]", err);
1948 INTERNAL_FUNC void emcore_update_notification_for_send(int account_id, int mail_id, double progress)
1950 EM_DEBUG_FUNC_BEGIN("account_id: %d, mail_id: %d, progress: %f", account_id, mail_id, progress);
1953 char vconf_private_id[MAX_PATH] = {0, };
1954 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1956 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1957 if (vconf_get_int(vconf_private_id, &private_id) != 0) {
1958 EM_DEBUG_EXCEPTION("vconf_get_int failed");
1961 EM_DEBUG_LOG("Private_id = [%d]", private_id);
1962 noti_err = notification_update_progress(g_sending_noti_handle, private_id, progress);
1963 if (noti_err != NOTIFICATION_ERROR_NONE) {
1964 EM_DEBUG_LOG("notification_update_progress failed [0x%x]", noti_err);
1967 EM_DEBUG_FUNC_END();
1970 INTERNAL_FUNC int emcore_show_user_message(char *multi_user_name, int id, email_action_t action, int error)
1972 EM_DEBUG_FUNC_BEGIN("id[%d], action[%d], error[%d]", id, action, error);
1976 emstorage_mail_tbl_t *mail_table_data = NULL;
1978 if ((action == EMAIL_ACTION_SEND_MAIL || action == EMAIL_ACTION_SENDING_MAIL) && error != EMAIL_ERROR_CANCELLED) {
1979 /* In case email is cancelled using cancel button in Outbox there is no need to show Cancel/Retry Pop up */
1982 EM_DEBUG_LOG("Invalid mail_id");
1986 if (!emstorage_get_mail_by_id(multi_user_name, id, &mail_table_data, true, NULL)) {
1987 EM_DEBUG_LOG("Mail not found");
1991 EM_DEBUG_LOG("smtp_stream : sent_end");
1992 if (emcore_add_notification_for_send(multi_user_name, mail_table_data->account_id, id, action, error, display) != EMAIL_ERROR_NONE) {
1993 EM_DEBUG_EXCEPTION("emcore_notification_set error");
2001 if (mail_table_data && !emstorage_free_mail(&mail_table_data, 1, NULL))
2002 EM_DEBUG_EXCEPTION("emstorage_free_mail Failed");
2004 EM_DEBUG_FUNC_END("ret [%d]", ret);
2009 /* storage space handling - 210709 */
2010 int emcore_get_storage_status(void)
2012 EM_DEBUG_FUNC_BEGIN();
2013 int storage_status = 0, nError = 0;
2015 #if !GLIB_CHECK_VERSION(2, 36, 0)
2019 #ifdef STORAGE_STATUS
2020 nError = vconf_get_int(PS_KEY_SYSTEM_STORAGE_MOVI_STATUS,
2022 #endif /* STORAGE_STATUS */
2025 EM_DEBUG_EXCEPTION("vconf_get_int Failed");
2028 EM_DEBUG_FUNC_END();
2029 return storage_status;
2034 INTERNAL_FUNC int emcore_is_storage_full()
2036 EM_DEBUG_FUNC_BEGIN();
2037 int err = EMAIL_ERROR_NONE;
2038 int ret_from_storage_lib = 0;
2039 struct statvfs stat_result;
2041 ret_from_storage_lib = storage_get_internal_memory_size(&stat_result);
2042 if (ret_from_storage_lib < 0) {
2043 EM_DEBUG_EXCEPTION("ret_from_storage_lib [%d]", ret_from_storage_lib);
2044 err = EMAIL_ERROR_SYSTEM_FAILURE;
2047 unsigned long i_free = (stat_result.f_bsize*stat_result.f_bavail) / (1024 * 1024);
2048 if (i_free < EMAIL_LIMITATION_FREE_SPACE) {
2049 EM_DEBUG_EXCEPTION("total[%lf] avail[%lf]", (double)stat_result.f_frsize*stat_result.f_blocks, (double)stat_result.f_bsize*stat_result.f_bavail);
2050 EM_DEBUG_EXCEPTION("Not enough free space of storage [%ld] MB.", i_free);
2051 err = EMAIL_ERROR_MAIL_MEMORY_FULL;
2056 EM_DEBUG_FUNC_END("err[%d]", err);
2060 int emcore_calc_mail_size(char *multi_user_name, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, int *output_size)
2062 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);
2065 int mail_size = 0; /* size of the plain text body and attachments */
2066 int err = EMAIL_ERROR_NONE;
2068 char *prefix_path = NULL;
2069 char real_file_path[255] = {0};
2071 if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count && input_attachment_data_list) || !output_size) {
2072 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2073 err = EMAIL_ERROR_INVALID_PARAM;
2077 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
2078 err = emcore_get_container_path(multi_user_name, &prefix_path);
2079 if (err != EMAIL_ERROR_NONE) {
2080 EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
2084 prefix_path = strdup("");
2087 if (input_mail_data->file_path_plain != NULL) {
2088 memset(real_file_path, 0x00, sizeof(real_file_path));
2089 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_data->file_path_plain);
2091 if (stat(real_file_path, &st_buf) < 0) {
2092 EM_DEBUG_EXCEPTION_SEC("input_mail_data->file_path_plain : stat(\"%s\") failed...", input_mail_data->file_path_plain);
2093 err = EMAIL_ERROR_FILE_NOT_FOUND;
2097 mail_size += st_buf.st_size;
2101 if (input_mail_data->file_path_html != NULL) {
2102 memset(real_file_path, 0x00, sizeof(real_file_path));
2103 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_data->file_path_html);
2105 if (stat(real_file_path, &st_buf) < 0) {
2106 EM_DEBUG_EXCEPTION_SEC("input_mail_data->file_path_html : stat(\"%s\") failed...", input_mail_data->file_path_html);
2107 err = EMAIL_ERROR_FILE_NOT_FOUND;
2111 mail_size += st_buf.st_size;
2114 for (i = 0; i < input_attachment_count; i++) {
2115 memset(real_file_path, 0x00, sizeof(real_file_path));
2116 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_attachment_data_list[i].attachment_path);
2118 if (stat(real_file_path, &st_buf) < 0) {
2119 EM_DEBUG_EXCEPTION_SEC("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path);
2120 err = EMAIL_ERROR_FILE_NOT_FOUND;
2123 mail_size += st_buf.st_size;
2126 *output_size = mail_size;
2130 EM_SAFE_FREE(prefix_path);
2132 EM_DEBUG_FUNC_END("mail_size [%d]", mail_size);
2137 /* parse the Full mailbox Path and Get the Alias Name of the Mailbox */
2138 char *emcore_get_alias_of_mailbox(const char *mailbox_path)
2140 EM_DEBUG_FUNC_BEGIN();
2141 EM_IF_NULL_RETURN_VALUE(mailbox_path, NULL);
2144 gchar **token_list = NULL;
2145 gchar *mailbox = NULL, *name = NULL;
2146 char *converted_name;
2149 mailbox = g_strdup(mailbox_path);
2150 token_list = g_strsplit_set(mailbox, "/\\", -1);
2152 if (token_list == NULL) {
2153 EM_DEBUG_LOG("g_strsplit_set failed.");
2163 while (token_list[index] != NULL)
2166 name = g_strdup(token_list[index - 1]);
2171 g_strfreev(token_list);
2173 converted_name = emcore_convert_mutf7_to_utf8(name);
2174 EM_DEBUG_LOG_DEV("converted_name:%s", converted_name);
2176 if (!converted_name || EM_SAFE_STRLEN(converted_name) == 0) {
2177 EM_SAFE_FREE(converted_name);
2178 converted_name = g_strdup(name);
2184 EM_DEBUG_FUNC_END();
2185 return converted_name;
2189 INTERNAL_FUNC int emcore_get_first_address(const char *input_full_address, char **output_display_name, char **output_angle_addr)
2191 EM_DEBUG_FUNC_BEGIN("input_full_address[%p], output_display_name[%p], output_angle_addr[%p]", input_full_address, output_display_name, output_angle_addr);
2193 int err = EMAIL_ERROR_NONE;
2194 char *full_address = NULL;
2195 char angle_addr[MAX_EMAIL_ADDRESS_LENGTH] = { 0, };
2196 ADDRESS *address_list = NULL;
2198 if (input_full_address == NULL || output_display_name == NULL || output_angle_addr == NULL) {
2199 err = EMAIL_ERROR_INVALID_PARAM;
2200 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2204 /* full_address will be tainted by rfc822_parse_adrlist */
2205 /* So, input_full_address should be duplicated */
2206 full_address = EM_SAFE_STRDUP(input_full_address);
2208 if (full_address == NULL) {
2209 err = EMAIL_ERROR_OUT_OF_MEMORY;
2210 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
2214 rfc822_parse_adrlist(&address_list, (char*)full_address, NULL);
2217 if (address_list->host)
2218 SNPRINTF(angle_addr, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", address_list->mailbox, address_list->host);
2219 else /* For SMS of eas-engine : (example : 01012345678) */
2220 SNPRINTF(angle_addr, MAX_EMAIL_ADDRESS_LENGTH, "%s", address_list->mailbox);
2222 *output_display_name = EM_SAFE_STRDUP(address_list->personal);
2223 *output_angle_addr = EM_SAFE_STRDUP(angle_addr);
2225 mail_free_address(&address_list);
2229 EM_SAFE_FREE(full_address);
2231 EM_DEBUG_FUNC_END();
2235 void emcore_fill_address_information_of_mail_tbl(char *multi_user_name, emstorage_mail_tbl_t *mail_data)
2237 EM_DEBUG_FUNC_BEGIN("mail_data [%p]", mail_data);
2239 char *first_alias = NULL;
2240 char *first_address = NULL;
2241 char *recipient = NULL;
2246 char *recipient_self = NULL;
2248 email_account_t *ref_account = NULL;
2250 ref_account = emcore_get_account_reference(multi_user_name, mail_data->account_id, false);
2252 EM_DEBUG_LOG("emcore_get_account_reference failed [%d]", mail_data->account_id);
2255 EM_DEBUG_LOG_SEC("full_address_from [%s]", mail_data->full_address_from);
2257 /* sender alias & address */
2258 if (emcore_get_first_address(mail_data->full_address_from, &first_alias, &first_address) == true) {
2259 if (first_alias == NULL) {
2260 mail_data->alias_sender = EM_SAFE_STRDUP(first_address);
2262 mail_data->alias_sender = first_alias;
2265 mail_data->email_address_sender = first_address;
2266 first_address = NULL;
2269 EM_DEBUG_LOG_SEC("full_address_from [%s]", mail_data->full_address_from);
2271 /* recipient alias & address */
2272 if (mail_data->full_address_to != NULL)
2273 recipient = mail_data->full_address_to;
2274 else if (mail_data->full_address_cc != NULL)
2275 recipient = mail_data->full_address_cc;
2276 else if (mail_data->full_address_bcc != NULL)
2277 recipient = mail_data->full_address_bcc;
2279 /* if full_address_to contains account address, set account address to email_address_recipient */
2280 if (ref_account && mail_data->full_address_to &&
2281 g_strrstr(mail_data->full_address_to, ref_account->user_email_address)) {
2282 vector = g_strsplit_set(mail_data->full_address_to, ";", -1);
2283 vector_len = g_strv_length(vector);
2285 for (i = 0; i < vector_len; i++) {
2286 if (g_strrstr(vector[i], ref_account->user_email_address)) {
2287 recipient_self = EM_SAFE_STRDUP(vector[i]);
2293 if (recipient_self) {
2294 recipient = recipient_self;
2298 if (emcore_get_first_address(recipient, &first_alias, &first_address) == true) {
2299 if (first_alias == NULL)
2300 mail_data->alias_recipient = EM_SAFE_STRDUP(first_address);
2302 mail_data->alias_recipient = first_alias;
2304 mail_data->email_address_recipient = first_address;
2308 emcore_free_account(ref_account);
2309 EM_SAFE_FREE(ref_account);
2312 EM_SAFE_FREE(recipient_self);
2313 EM_DEBUG_FUNC_END();
2316 struct email_attribute_info {
2317 email_mail_attribute_type attribute_type;
2318 char *attribute_name;
2319 email_mail_attribute_value_type attribute_value_type;
2322 static struct email_attribute_info _mail_attribute_info_array[] = {
2323 {EMAIL_MAIL_ATTRIBUTE_MAIL_ID, "mail_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2324 {EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID, "account_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2325 {EMAIL_MAIL_ATTRIBUTE_MAILBOX_ID, "mailbox_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2326 {EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME, "mailbox_name", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2327 {EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE, "mailbox_type", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2328 {EMAIL_MAIL_ATTRIBUTE_SUBJECT, "subject", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2329 {EMAIL_MAIL_ATTRIBUTE_DATE_TIME, "date_time", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME},
2330 {EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_STATUS, "server_mail_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2331 {EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME, "server_mailbox_name", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2332 {EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID, "server_mail_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2333 {EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID, "message_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2334 {EMAIL_MAIL_ATTRIBUTE_REFERENCE_MAIL_ID, "reference_mail_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2335 {EMAIL_MAIL_ATTRIBUTE_FROM, "full_address_from", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2336 {EMAIL_MAIL_ATTRIBUTE_TO, "full_address_to", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2337 {EMAIL_MAIL_ATTRIBUTE_CC, "full_address_cc", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2338 {EMAIL_MAIL_ATTRIBUTE_BCC, "full_address_bcc", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2339 {EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS, "body_download_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2340 {EMAIL_MAIL_ATTRIBUTE_MAIL_SIZE, "mail_size", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2341 {EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN, "file_path_plain", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2342 {EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML, "file_path_html", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2343 {EMAIL_MAIL_ATTRIBUTE_FILE_SIZE, "file_size", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2344 {EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD, "flags_seen_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2345 {EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD, "flags_deleted_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER },
2346 {EMAIL_MAIL_ATTRIBUTE_FLAGS_FLAGGED_FIELD, "flags_flagged_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2347 {EMAIL_MAIL_ATTRIBUTE_FLAGS_ANSWERED_FIELD, "flags_answered_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2348 {EMAIL_MAIL_ATTRIBUTE_FLAGS_RECENT_FIELD, "flags_recent_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2349 {EMAIL_MAIL_ATTRIBUTE_FLAGS_DRAFT_FIELD, "flags_draft_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2350 {EMAIL_MAIL_ATTRIBUTE_FLAGS_FORWARDED_FIELD, "flags_forwarded_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2351 {EMAIL_MAIL_ATTRIBUTE_DRM_STATUS, "drm_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2352 {EMAIL_MAIL_ATTRIBUTE_PRIORITY, "priority", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2353 {EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS, "save_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2354 {EMAIL_MAIL_ATTRIBUTE_LOCK_STATUS, "lock_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2355 {EMAIL_MAIL_ATTRIBUTE_REPORT_STATUS, "report_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2356 {EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT, "attachment_count", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2357 {EMAIL_MAIL_ATTRIBUTE_INLINE_CONTENT_COUNT, "inline_content_count", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2358 {EMAIL_MAIL_ATTRIBUTE_THREAD_ID, "thread_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2359 {EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT, "thread_item_count", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2360 {EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT, "preview_text", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2361 {EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS, "meeting_request_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2362 {EMAIL_MAIL_ATTRIBUTE_MESSAGE_CLASS, "message_class", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2363 {EMAIL_MAIL_ATTRIBUTE_DIGEST_TYPE, "digest_type", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2364 {EMAIL_MAIL_ATTRIBUTE_SMIME_TYPE, "smime_type", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2365 {EMAIL_MAIL_ATTRIBUTE_SCHEDULED_SENDING_TIME, "scheduled_sending_time", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME},
2366 {EMAIL_MAIL_ATTRIBUTE_REMAINING_RESEND_TIMES, "remaining_resend_times", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2367 {EMAIL_MAIL_ATTRIBUTE_TAG_ID, "tag_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2368 {EMAIL_MAIL_ATTRIBUTE_REPLIED_TIME, "replied_time", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME},
2369 {EMAIL_MAIL_ATTRIBUTE_FORWARDED_TIME, "forwarded_time", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME},
2370 {EMAIL_MAIL_ATTRIBUTE_RECIPIENT_ADDRESS, "email_recipient_address", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2371 {EMAIL_MAIL_ATTRIBUTE_EAS_DATA_LENGTH_TYPE, "eas_data_length", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2372 {EMAIL_MAIL_ATTRIBUTE_EAS_DATA_TYPE, "eas_data", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_BINARY}
2375 INTERNAL_FUNC char* emcore_get_mail_field_name_by_attribute_type(email_mail_attribute_type input_attribute_type)
2377 EM_DEBUG_FUNC_BEGIN("input_attribute_type [%d]", input_attribute_type);
2379 if (input_attribute_type > EMAIL_MAIL_ATTRIBUTE_EAS_DATA_TYPE || input_attribute_type < 0) {
2380 EM_DEBUG_EXCEPTION("Invalid input_attribute_type [%d]", input_attribute_type);
2384 EM_DEBUG_LOG_DEV("return [%s]", _mail_attribute_info_array[input_attribute_type].attribute_name);
2385 return _mail_attribute_info_array[input_attribute_type].attribute_name;
2388 INTERNAL_FUNC int emcore_get_attribute_type_by_mail_field_name(char *input_mail_field_name, email_mail_attribute_type *output_mail_attribute_type)
2390 EM_DEBUG_FUNC_BEGIN("input_mail_field_name [%p], output_mail_attribute_type [%p]", input_mail_field_name, output_mail_attribute_type);
2392 int err = EMAIL_ERROR_DATA_NOT_FOUND;
2394 if (!input_mail_field_name || !output_mail_attribute_type) {
2395 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2396 return EMAIL_ERROR_INVALID_PARAM;
2399 for (i = 0; i < EMAIL_MAIL_ATTRIBUTE_END; i++) {
2400 if (EM_SAFE_STRCMP(input_mail_field_name, _mail_attribute_info_array[i].attribute_name) == 0) {
2401 *output_mail_attribute_type = i;
2402 err = EMAIL_ERROR_NONE;
2407 EM_DEBUG_FUNC_END("found mail attribute type [%d]", (int)*output_mail_attribute_type);
2411 INTERNAL_FUNC int emcore_get_mail_attribute_value_type(email_mail_attribute_type input_attribute_type, email_mail_attribute_value_type *output_value_type)
2413 EM_DEBUG_FUNC_BEGIN("input_attribute_type[%d] output_value_type[%p]", input_attribute_type, output_value_type);
2414 int err = EMAIL_ERROR_NONE;
2416 email_mail_attribute_value_type value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE;
2418 if (output_value_type == NULL) {
2419 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2420 err = EMAIL_ERROR_INVALID_PARAM;
2424 for (i = 0; i < EMAIL_MAIL_ATTRIBUTE_END; i++) {
2425 if (input_attribute_type == _mail_attribute_info_array[i].attribute_type) {
2426 value_type = _mail_attribute_info_array[i].attribute_value_type;
2431 *output_value_type = value_type;
2433 EM_DEBUG_LOG("value_type [%d]", value_type);
2436 EM_DEBUG_FUNC_END("err [%d]", err);
2440 #ifdef __FEATURE_BODY_SEARCH__
2441 int emcore_strip_mail_body_from_file(char *multi_user_name, emstorage_mail_tbl_t *mail, char **stripped_text, int *err_code)
2443 EM_DEBUG_FUNC_BEGIN("mail[%p]", mail);
2446 int err = EMAIL_ERROR_NONE;
2448 char *encoding_type = NULL;
2449 char *utf8_encoded_string = NULL;
2450 char *prefix_path = NULL;
2451 char real_html_path[255] = {0};
2452 char real_plain_path[255] = {0};
2453 gsize byte_read = 0;
2454 gsize byte_written = 0;
2455 GError *glib_error = NULL;
2456 FILE *fp_plain = NULL;
2460 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2461 err = EMAIL_ERROR_INVALID_PARAM;
2465 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
2466 err = emcore_get_container_path(multi_user_name, &prefix_path);
2467 if (err != EMAIL_ERROR_NONE) {
2468 EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
2472 prefix_path = strdup("");
2475 /* read file to buf & strip if html text */
2476 if (mail->file_path_html) {
2477 char result_buffer[MAX_PREVIEW_TEXT_LENGTH] = { 0, };
2479 if (mail->preview_text) {
2480 *stripped_text = EM_SAFE_STRDUP(mail->preview_text);
2485 SNPRINTF(real_html_path, sizeof(real_html_path), "%s%s", prefix_path, mail->file_path_html);
2487 if ((err = em_get_encoding_type_from_file_path(mail->file_path_plain, &encoding_type)) != EMAIL_ERROR_NONE) {
2488 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
2492 if ((err = emcore_strip_HTML_tag(real_html_path, encoding_type, result_buffer, MAX_PREVIEW_TEXT_LENGTH)) != EMAIL_ERROR_NONE) {
2493 EM_DEBUG_EXCEPTION("emcore_strip_HTML_tag failed");
2497 *stripped_text = EM_SAFE_STRDUP(result_buffer);
2500 if (!buf && mail->file_path_plain) {
2501 SNPRINTF(real_plain_path, sizeof(real_plain_path), "%s%s", prefix_path, mail->file_path_plain);
2503 if ((err = em_get_encoding_type_from_file_path(mail->file_path_plain, &encoding_type)) != EMAIL_ERROR_NONE) {
2504 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
2508 memset(&st_buf, 0, sizeof(struct stat));
2509 if (stat(real_plain_path, &st_buf) < 0) {
2510 EM_DEBUG_EXCEPTION_SEC("stat(\"%s\") failed...", real_plain_path);
2511 err = EMAIL_ERROR_INVALID_MAIL;
2515 err = em_fopen(real_plain_path, "r", &fp_plain);
2516 if (err != EMAIL_ERROR_NONE) {
2517 EM_DEBUG_EXCEPTION_SEC("em_fopen failed [%s]", real_plain_path);
2521 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
2522 EM_DEBUG_LOG("text_file is empty size");
2523 err = EMAIL_ERROR_EMPTY_FILE;
2527 if (!(buf = (char*)em_malloc(sizeof(char)*(st_buf.st_size + 1)))) {
2528 EM_DEBUG_EXCEPTION("em_mallocfailed");
2532 byte_read = fread(buf, sizeof(char), st_buf.st_size, fp_plain);
2534 if (byte_read <= 0) {
2536 err = EMAIL_ERROR_NULL_VALUE;
2537 if (ferror(fp_plain)) {
2538 EM_DEBUG_EXCEPTION_SEC("fread failed [%s]", real_plain_path);
2539 err = EMAIL_ERROR_SYSTEM_FAILURE;
2543 reg_replace(buf, CR_STRING, " ");
2544 reg_replace(buf, LF_STRING, " ");
2545 reg_replace(buf, TAB_STRING, " ");
2550 if (encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
2551 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
2553 if (strcasecmp(encoding_type, "ks_c_5601-1987") == 0 ||
2554 strcasecmp(encoding_type, "ksc5601") == 0 ||
2555 strcasecmp(encoding_type, "cp949") == 0) {
2556 EM_SAFE_FREE(encoding_type);
2557 encoding_type = EM_SAFE_STRDUP("EUC-KR");
2560 utf8_encoded_string = (char*)g_convert(buf, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
2562 if (utf8_encoded_string == NULL) {
2563 if (!g_error_matches(glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
2564 EM_SAFE_FREE(*stripped_text);
2565 *stripped_text = EM_SAFE_STRDUP(buf);
2568 EM_DEBUG_LOG("Extract the preview text, again");
2570 utf8_encoded_string = (char *)g_convert(buf, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
2571 if (utf8_encoded_string == NULL) {
2572 EM_SAFE_FREE(*stripped_text);
2573 *stripped_text = EM_SAFE_STRDUP(buf);
2579 EM_SAFE_FREE(*stripped_text);
2580 *stripped_text = EM_SAFE_STRDUP(utf8_encoded_string);
2582 EM_SAFE_FREE(*stripped_text);
2583 *stripped_text = EM_SAFE_STRDUP(buf);
2595 EM_SAFE_FREE(prefix_path);
2596 EM_SAFE_FREE(encoding_type);
2597 EM_SAFE_FREE(utf8_encoded_string);
2599 if (fp_plain != NULL)
2602 EM_DEBUG_FUNC_END("ret [%d]", ret);
2608 int emcore_get_preview_text_from_file(char *multi_user_name, const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer)
2610 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);
2612 int err = EMAIL_ERROR_NONE;
2613 gsize byte_read = 0;
2614 gsize byte_written = 0;
2615 int local_preview_buffer_length = 0;
2616 char *local_preview_text = NULL;
2617 char *encoding_type = NULL;
2618 char *utf8_encoded_string = NULL;
2619 FILE *fp_plain = NULL;
2620 GError *glib_error = NULL;
2622 char *prefix_path = NULL;
2623 char real_file_path[255] = {0};
2625 if (!output_preview_buffer) {
2626 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2627 err = EMAIL_ERROR_INVALID_PARAM;
2631 local_preview_buffer_length = input_preview_buffer_length * 2;
2633 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
2634 err = emcore_get_container_path(multi_user_name, &prefix_path);
2635 if (err != EMAIL_ERROR_NONE) {
2636 EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
2640 prefix_path = strdup("");
2643 if (input_html_path) { /*prevent 26249*/
2644 /* get preview text from html file */
2645 char result_buffer[MAX_PREVIEW_TEXT_LENGTH] = { 0, };
2647 memset(real_file_path, 0x00, sizeof(real_file_path));
2648 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_html_path);
2650 if ((err = em_get_encoding_type_from_file_path(input_html_path, &encoding_type)) != EMAIL_ERROR_NONE) {
2651 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
2655 if ((err = emcore_strip_HTML_tag(real_file_path, encoding_type, result_buffer, MAX_PREVIEW_TEXT_LENGTH)) != EMAIL_ERROR_NONE) {
2656 EM_DEBUG_EXCEPTION("emcore_strip_HTML_tag failed");
2659 local_preview_text = EM_SAFE_STRDUP(result_buffer);
2662 if (!local_preview_text && input_plain_path) { /*prevent 26249*/
2664 memset(real_file_path, 0x00, sizeof(real_file_path));
2665 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_plain_path);
2667 /* get preview text from plain text file */
2668 if ((err = em_get_encoding_type_from_file_path(input_plain_path, &encoding_type)) != EMAIL_ERROR_NONE) {
2669 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
2673 memset(&st_buf, 0, sizeof(struct stat));
2674 if (stat(real_file_path, &st_buf) < 0) {
2675 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_plain_path);
2676 err = EMAIL_ERROR_INVALID_MAIL;
2680 err = em_fopen(real_file_path, "r", &fp_plain);
2681 if (err != EMAIL_ERROR_NONE) {
2682 EM_DEBUG_EXCEPTION("em_fopen failed [%s]", input_plain_path);
2686 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
2687 EM_DEBUG_LOG("input_text_file is empty size");
2688 err = EMAIL_ERROR_EMPTY_FILE;
2692 if (!(local_preview_text = (char*)em_malloc(sizeof(char) * local_preview_buffer_length))) {
2693 EM_DEBUG_EXCEPTION("em_mallocfailed");
2697 byte_read = fread(local_preview_text, sizeof(char), local_preview_buffer_length - 1, fp_plain);
2699 if (byte_read <= 0) { /*prevent 26249*/
2700 EM_SAFE_FREE(local_preview_text);
2701 err = EMAIL_ERROR_NULL_VALUE;
2702 if (ferror(fp_plain)) {
2703 EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path);
2704 err = EMAIL_ERROR_SYSTEM_FAILURE;
2708 reg_replace(local_preview_text, CR_STRING, " ");
2709 reg_replace(local_preview_text, LF_STRING, " ");
2710 reg_replace(local_preview_text, TAB_STRING, " ");
2712 em_trim_left(local_preview_text);
2714 if (encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
2715 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
2717 if (strcasecmp(encoding_type, "ks_c_5601-1987") == 0 ||
2718 strcasecmp(encoding_type, "ksc5601") == 0 ||
2719 strcasecmp(encoding_type, "cp949") == 0) {
2720 EM_SAFE_FREE(encoding_type);
2721 encoding_type = EM_SAFE_STRDUP("EUC-KR");
2724 utf8_encoded_string = (char *)g_convert(local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
2726 if (utf8_encoded_string == NULL) {
2727 if (!g_error_matches(glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
2730 EM_DEBUG_LOG("Extract the preview text, again");
2732 utf8_encoded_string = (char *)g_convert(local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
2733 if (utf8_encoded_string == NULL) {
2734 EM_DEBUG_LOG("g_convert fail, again");
2738 EM_SAFE_FREE(local_preview_text);
2739 local_preview_text = utf8_encoded_string;
2745 if (local_preview_text != NULL)
2746 *output_preview_buffer = EM_SAFE_STRDUP(local_preview_text);
2748 if (local_preview_text != NULL) {
2749 EM_SAFE_FREE(*output_preview_buffer); /* valgrind */
2750 *output_preview_buffer = EM_SAFE_STRDUP(local_preview_text);
2753 EM_SAFE_FREE(local_preview_text);
2754 EM_SAFE_FREE(encoding_type);
2755 EM_SAFE_FREE(prefix_path);
2757 if (fp_plain != NULL)
2760 EM_DEBUG_FUNC_END("err [%d]", err);
2764 INTERNAL_FUNC int emcore_add_transaction_info(int mail_id, int handle , int *err_code)
2766 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%d]", mail_id, handle);
2769 int err = EMAIL_ERROR_NONE ;
2770 em_transaction_info_type_t *pTransinfo = NULL ;
2771 em_transaction_info_type_t *pTemp = NULL;
2773 EM_DEBUG_LOG("g_transaction_info_list[%p]", g_transaction_info_list);
2774 pTransinfo = g_transaction_info_list ;
2776 if (!(pTemp = em_malloc(sizeof(em_transaction_info_type_t)))) {
2777 EM_DEBUG_EXCEPTION("malloc failed...");
2778 err = EMAIL_ERROR_OUT_OF_MEMORY;
2781 pTemp->mail_id = mail_id ;
2782 pTemp->handle = handle;
2785 pTransinfo = pTemp ;
2786 g_transaction_info_list = pTransinfo ;
2788 while (pTransinfo->next)
2789 pTransinfo = pTransinfo->next;
2790 pTransinfo->next = pTemp;
2798 EM_DEBUG_FUNC_END("g_transaction_info_list[%p]", g_transaction_info_list);
2802 INTERNAL_FUNC int emcore_get_handle_by_mailId_from_transaction_info(int mail_id, int *pHandle)
2804 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p]", mail_id, pHandle);
2807 em_transaction_info_type_t *pTransinfo = NULL ;
2809 if (g_transaction_info_list == NULL) {
2810 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
2813 pTransinfo = g_transaction_info_list;
2816 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
2817 if (pTransinfo->mail_id == mail_id) {
2818 *pHandle = pTransinfo->handle;
2820 EM_DEBUG_LOG("*pHandle[%d]", *pHandle);
2823 pTransinfo = pTransinfo->next ;
2824 } while (pTransinfo);
2825 EM_DEBUG_FUNC_END();
2829 INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id)
2831 EM_DEBUG_FUNC_BEGIN("mail_id[%d]", mail_id);
2833 em_transaction_info_type_t *pTransinfo ;
2834 em_transaction_info_type_t *pTemp = NULL;
2836 if (g_transaction_info_list == NULL) {
2837 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
2840 pTransinfo = g_transaction_info_list;
2842 EM_DEBUG_LOG("pTransinfo[%p]", pTransinfo);
2845 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
2846 if (pTransinfo->mail_id == mail_id) {
2847 pTemp = pTransinfo->next ;
2849 EM_SAFE_FREE(pTransinfo) ;
2850 g_transaction_info_list = NULL;
2852 pTransinfo->mail_id = pTransinfo->next->mail_id;
2853 pTransinfo->handle = pTransinfo->next->handle;
2854 pTransinfo->next = pTransinfo->next->next;
2856 EM_SAFE_FREE(pTemp);
2860 pTransinfo = pTransinfo->next ;
2863 } while (pTransinfo);
2864 EM_DEBUG_FUNC_END();
2871 INTERNAL_FUNC int reg_replace(char *input_source_text, char *input_old_pattern_string, char *input_new_string)
2873 int error_code = EMAIL_ERROR_NONE;
2875 int so, n, nmatch, source_text_length, n_count = 1;
2876 regmatch_t *pmatch = NULL;
2877 regex_t reg_pattern;
2879 if (!input_source_text || !input_old_pattern_string || !input_new_string) {
2880 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2881 error_code = EMAIL_ERROR_INVALID_PARAM;
2885 source_text_length = EM_SAFE_STRLEN(input_source_text);
2887 if (regcomp(®_pattern, input_old_pattern_string, REG_EXTENDED | REG_ICASE) != 0) {
2888 EM_DEBUG_EXCEPTION("regcomp failed");
2892 nmatch = reg_pattern.re_nsub + 1;
2894 EM_DEBUG_LOG("nmatch [%d]", nmatch);
2897 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_DATA");
2898 error_code = EMAIL_ERROR_INVALID_DATA;
2902 pmatch = (regmatch_t *)em_malloc(sizeof(regmatch_t) * nmatch);
2904 if (pmatch == NULL) {
2905 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
2906 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
2910 for (pos = input_new_string; *pos ; pos++) {
2911 if (*pos == '\\' && *(pos + 1) > '0' && *(pos + 1) <= '9') {
2913 so = pmatch[*(pos + 1) - 48].rm_so;
2914 n = pmatch[*(pos + 1) - 48].rm_eo - so;
2916 EM_DEBUG_LOG("so [%d], n [%d]", so, n);
2918 if (so < 0 || EM_SAFE_STRLEN(input_new_string) + n - 1 > source_text_length)
2921 memmove(pos + n, pos + 2, EM_SAFE_STRLEN(pos) - 1);
2922 memmove(pos, input_source_text + so, n);
2927 for (pos = input_source_text; !regexec(®_pattern, pos, 1, pmatch, 0); ) {
2928 n = pmatch[0].rm_eo - pmatch[0].rm_so;
2929 pos += pmatch[0].rm_so;
2930 memmove(pos + EM_SAFE_STRLEN(input_new_string), pos + n, EM_SAFE_STRLEN(pos) - n + 1);
2931 memmove(pos, input_new_string, EM_SAFE_STRLEN(input_new_string));
2932 pos += EM_SAFE_STRLEN(input_new_string);
2938 EM_SAFE_FREE(pmatch);
2939 regfree(®_pattern);
2941 EM_DEBUG_FUNC_END("error_code [%d]", error_code);
2946 INTERNAL_FUNC char *reg_replace_new(char *input_source_text, char *input_old_pattern_string, char *input_new_string)
2948 char *replaced_str = NULL;
2949 GRegex *regex = NULL;
2950 GError *error = NULL;
2952 if (input_source_text == NULL) {
2953 EM_DEBUG_EXCEPTION("Invalid parameter");
2957 regex = g_regex_new(input_old_pattern_string, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, &error);
2959 EM_DEBUG_LOG("g_regex_new failed");
2963 replaced_str = g_regex_replace_literal(regex,
2965 strlen(input_source_text),
2970 if (replaced_str == NULL) {
2971 EM_DEBUG_EXCEPTION("g_regex_replace_literal failed : [%s][%d]", error->message, error->code);
2977 if (regex) g_regex_unref(regex);
2979 return replaced_str;
2983 #include <libxml/HTMLparser.h>
2985 static void emcore_get_content_string(xmlNode *input_node, char *input_result_buffer, int input_result_buffer_length, int *input_exit_flag)
2987 xmlNode *cur_node = NULL;
2988 char *temp_content_string = NULL;
2990 if (input_node == NULL || input_result_buffer == NULL || input_exit_flag == NULL) {
2991 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2995 for (cur_node = input_node; cur_node; cur_node = cur_node->next) {
2996 if (cur_node->name && (strcasecmp((const char *)cur_node->name, "head") == 0 || strcasecmp((const char *)cur_node->name, "title") == 0))
2999 if (cur_node->name && (strcasecmp((const char *)cur_node->name, "BR") == 0)) {
3000 if (EM_SAFE_STRLEN(input_result_buffer) + 1 >= input_result_buffer_length) {
3001 *input_exit_flag = 1;
3004 EM_SAFE_STRCAT(input_result_buffer, " ");
3009 if (cur_node->type == XML_TEXT_NODE && cur_node->content) {
3010 if ((EM_SAFE_STRLEN(cur_node->content) + EM_SAFE_STRLEN(input_result_buffer)) >= input_result_buffer_length) {
3011 int len1 = EM_SAFE_STRLEN(input_result_buffer);
3013 if (len1 >= 0 && len1 < input_result_buffer_length) {
3014 int remain_size = input_result_buffer_length - len1 - 2;
3015 EM_DEBUG_LOG("remain_size : [%d], len1 : [%d]", remain_size, len1);
3016 char *remain_str = NULL;
3018 if (remain_size > 0)
3019 remain_str = g_strndup((char *)(cur_node->content), remain_size);
3022 char *replaced_string = NULL;
3023 replaced_string = reg_replace_new(remain_str, "[ \t\r\n\v\f]+", " ");
3024 EM_SAFE_STRCAT(input_result_buffer, replaced_string);
3025 EM_SAFE_FREE(replaced_string);
3030 *input_exit_flag = 1;
3034 temp_content_string = EM_SAFE_STRDUP((const char *)cur_node->content);
3035 if (temp_content_string) {
3036 char *replaced_string = NULL;
3037 replaced_string = reg_replace_new(temp_content_string, "[ \t\r\n\v\f]+", " ");
3038 EM_SAFE_STRCAT(input_result_buffer, replaced_string);
3039 EM_SAFE_FREE(replaced_string);
3040 free(temp_content_string);
3044 if (cur_node->children)
3045 emcore_get_content_string(cur_node->children, input_result_buffer, input_result_buffer_length, input_exit_flag);
3047 if (*input_exit_flag == 1)
3056 static void emcore_default_xml_error_handler(void *ctx, const char *msg, ...)
3058 EM_DEBUG_EXCEPTION("htmlReadFile failed");
3061 int emcore_strip_HTML_tag(const char *input_html_file_path, char *input_encoding_type, char *output_result_buffer, int input_result_buffer_legnth)
3063 EM_DEBUG_FUNC_BEGIN("input_html_file_path[%p] input_encoding_type[%s] output_result_buffer[%p] input_result_buffer_legnth[%d]", input_html_file_path, input_encoding_type, output_result_buffer, input_result_buffer_legnth);
3064 int err = EMAIL_ERROR_NONE;
3066 char *result_string = NULL;
3067 xmlNode *root_element = NULL;
3068 htmlDocPtr result_html_document = NULL;
3069 char *encoding_type = NULL;
3070 char *utf_charset = "UTF-8";
3071 char *euc_kr_charset = "euc-kr";
3073 if (input_html_file_path == NULL || output_result_buffer == NULL || input_result_buffer_legnth == 0) {
3074 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
3075 err = EMAIL_ERROR_INVALID_PARAM;
3079 result_string = em_malloc(sizeof(char) * input_result_buffer_legnth);
3080 if (result_string == NULL) {
3081 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
3082 err = EMAIL_ERROR_OUT_OF_MEMORY;
3086 if (EM_SAFE_STRCMP(input_encoding_type, "unknown") == 0)
3087 encoding_type = utf_charset;
3088 else if (input_encoding_type && (strcasecmp(input_encoding_type, "ks_c_5601-1987") == 0 ||
3089 strcasecmp(input_encoding_type, "ksc5601") == 0 ||
3090 strcasecmp(input_encoding_type, "cp949") == 0))
3091 encoding_type = euc_kr_charset;
3093 encoding_type = input_encoding_type;
3095 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
3098 xmlSetGenericErrorFunc(NULL, emcore_default_xml_error_handler);
3099 result_html_document = htmlReadFile(input_html_file_path, encoding_type, HTML_PARSE_RECOVER | HTML_PARSE_NOWARNING | HTML_PARSE_NOERROR | HTML_PARSE_NONET | HTML_PARSE_NOBLANKS);
3100 if (result_html_document == NULL) {
3101 EM_DEBUG_EXCEPTION("htmlReadFile failed");
3102 err = EMAIL_ERROR_ON_PARSING;
3106 root_element = xmlDocGetRootElement(result_html_document);
3108 emcore_get_content_string(root_element, result_string, input_result_buffer_legnth, &exit_flag);
3109 char *replaced_string = reg_replace_new(result_string, "[ \t\r\n\v\f]+", " ");
3110 EM_SAFE_STRCPY(output_result_buffer, replaced_string);
3111 EM_SAFE_FREE(replaced_string);
3112 em_trim_left(output_result_buffer);
3115 if (result_html_document) {
3116 xmlFreeDoc(result_html_document);
3119 EM_SAFE_FREE(result_string);
3121 EM_DEBUG_FUNC_END("err [%d]", err);
3125 INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime)
3127 EM_DEBUG_FUNC_BEGIN_SEC("mailbox_name(%s) subject(%s), from(%s), uid(%s), datetime(%s)", mailbox_name, subject, from, uid, datetime);
3128 int error_code = EMAIL_ERROR_NONE;
3129 int param_length = 0;
3130 char *param_string = NULL;
3132 if (mailbox_name == NULL || subject == NULL || from == NULL || uid == NULL || datetime == NULL) {
3133 error_code = EMAIL_ERROR_INVALID_PARAM;
3134 EM_DEBUG_EXCEPTION("Invalid parameter, mailbox_name(%p), subject(%p), from(%p), uid(%p), datetime(%p)", mailbox_name, subject, from, uid, datetime);
3138 param_length = strlen(mailbox_name) + strlen(subject) + strlen(from) + strlen(uid) + strlen(datetime) + 5; /*prevent 34358*/
3140 param_string = em_malloc(param_length);
3141 if (param_string == NULL) {
3142 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
3143 EM_DEBUG_EXCEPTION("Memory allocation for 'param_string' is failed");
3147 memset(param_string, 0x00, param_length);
3149 SNPRINTF(param_string, param_length, "%s%c%s%c%s%c%s%c%s", mailbox_name, 0x01, subject, 0x01, from, 0x01, uid, 0x01, datetime);
3151 if (emcore_notify_network_event(NOTI_DOWNLOAD_NEW_MAIL, account_id, param_string, 0, 0) == 0) { /* failed */
3152 error_code = EMAIL_ERROR_UNKNOWN;
3153 EM_DEBUG_EXCEPTION("emcore_notify_network_eventis failed");
3159 EM_SAFE_FREE(param_string);
3160 EM_DEBUG_FUNC_END();
3164 #define MAX_TITLE_LENGTH 1024
3166 #ifdef __FEATURE_DRIVING_MODE__
3167 int convert_app_err_to_email_err(int app_error)
3169 int err = EMAIL_ERROR_NONE;
3171 switch (app_error) {
3172 case APP_CONTROL_ERROR_NONE:
3173 err = EMAIL_ERROR_NONE;
3175 case APP_CONTROL_ERROR_INVALID_PARAMETER:
3176 err = EMAIL_ERROR_INVALID_PARAM;
3178 case APP_CONTROL_ERROR_OUT_OF_MEMORY:
3179 err = EMAIL_ERROR_OUT_OF_MEMORY;
3182 err = EMAIL_ERROR_UNKNOWN;
3189 INTERNAL_FUNC int emcore_start_driving_mode(char *multi_user_name, int mail_id)
3191 EM_DEBUG_FUNC_BEGIN();
3192 int err = APP_CONTROL_ERROR_NONE;
3194 char string_mail[10] = { 0 };
3195 emstorage_mail_tbl_t *p_mail_data = NULL;
3196 app_control_h service = NULL;
3198 if (vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_DRIVINGMODE, &tts_enable) != 0) {
3199 EM_DEBUG_EXCEPTION("vconf_get_int failed");
3203 EM_DEBUG_LOG("Driving Mode : [%d]", tts_enable);
3209 if (vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_NEWEMAILS, &tts_enable) != 0) {
3210 EM_DEBUG_EXCEPTION("vconf_get_int failed");
3214 EM_DEBUG_LOG("New emails of driving Mode : [%d]", tts_enable);
3219 if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &p_mail_data, false, NULL)) {
3220 EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed");
3224 if (p_mail_data->tag_id >= 0)
3227 SNPRINTF(string_mail, sizeof(string_mail), "%d", mail_id);
3229 err = app_control_create(&service);
3230 if (err != APP_CONTROL_ERROR_NONE) {
3231 EM_DEBUG_EXCEPTION("app_control_create failed : [%d]", err);
3235 err = app_control_set_app_id(service, "org.tizen.email-tts-play");
3236 if (err != APP_CONTROL_ERROR_NONE) {
3237 EM_DEBUG_EXCEPTION("app_control_set_app_id failed : [%d]", err);
3241 err = app_control_add_extra_data(service, "tts_email_id", string_mail);
3242 if (err != APP_CONTROL_ERROR_NONE) {
3243 EM_DEBUG_EXCEPTION("app_control_add_extra_data failed : [%d]", err);
3247 err = app_control_send_launch_request(service, NULL, NULL);
3248 if (err != APP_CONTROL_ERROR_NONE) {
3249 EM_DEBUG_EXCEPTION("app_control_send_launch_request failed : [%d]", err);
3256 app_control_destroy(service);
3259 emstorage_free_mail(&p_mail_data, 1, NULL);
3261 EM_DEBUG_FUNC_END();
3262 return convert_app_err_to_email_err(err);
3264 #endif /* __FEATURE_DRIVING_MODE__ */
3266 INTERNAL_FUNC int emcore_clear_notifications(char *multi_user_name, int account_id)
3268 int account_count = 0, i;
3269 emstorage_account_tbl_t *account_list;
3270 int error_code = EMAIL_ERROR_NONE;
3272 if (account_id == ALL_ACCOUNT) {
3273 if (!emstorage_get_account_list(multi_user_name, &account_count, &account_list, true, false, &error_code)) {
3274 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed");
3278 for (i = 0; i < account_count; i++) {
3279 error_code = emcore_delete_notification_by_account(multi_user_name, account_list[i].account_id, true);
3280 if (error_code != EMAIL_ERROR_NONE)
3281 EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed");
3284 error_code = emcore_delete_notification_by_account(multi_user_name, account_id, true);
3285 if (error_code != EMAIL_ERROR_NONE)
3286 EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed");
3289 if (!emstorage_update_save_status(multi_user_name, account_id, &error_code)) {
3290 EM_DEBUG_EXCEPTION("emstorage_update_save_status failed : [%d]", error_code);
3296 if (account_count) {
3297 emstorage_free_account(&account_list, account_count, NULL);
3300 EM_DEBUG_FUNC_END("return[%d]", error_code);
3304 #define EAS_EXECUTABLE_PATH "/usr/bin/eas-engine"
3306 INTERNAL_FUNC int emcore_delete_notification_by_account(char *multi_user_name, int account_id, int with_noti_tray)
3308 EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
3309 int error_code = EMAIL_ERROR_NONE;
3311 char vconf_private_id[MAX_PATH] = {0, };
3313 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
3314 if (vconf_get_int(vconf_private_id, &private_id) != 0) {
3315 EM_DEBUG_EXCEPTION("vconf_get_int failed");
3317 #ifdef __FEATURE_NOTIFICATION_ENABLE__
3318 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
3320 if ((noti_err = notification_delete_by_priv_id(NATIVE_EMAIL_APPLICATION_PKG, NOTIFICATION_TYPE_NOTI, private_id)) != NOTIFICATION_ERROR_NONE) {
3321 EM_DEBUG_EXCEPTION("notification_delete_by_priv_id failed [%d]", noti_err);
3322 error_code = EMAIL_ERROR_NOTI;
3325 if (with_noti_tray) {
3326 if ((noti_err = notification_delete_by_priv_id(NATIVE_EMAIL_APPLICATION_PKG, NOTIFICATION_TYPE_ONGOING, private_id)) != NOTIFICATION_ERROR_NONE) {
3327 EM_DEBUG_EXCEPTION("notification_delete_by_priv_id failed [%d]", noti_err);
3328 error_code = EMAIL_ERROR_NOTI;
3331 #endif /* __FEATURE_NOTIFICATION_ENABLE__ */
3332 EM_DEBUG_FUNC_END();
3336 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
3339 * @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)
3340 * Prepare a linked list of uid ranges with each node having a uid_range and lowest and highest uid in it.
3342 *@author h.gahlaut@samsung.com
3343 * @param[in] id_set Specifies the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
3344 * @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
3345 * @param[in] range_len Specifies the maximum length of string of range allowed.
3346 * @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
3347 * @param[out] err_code Returns the error code.
3348 * @remarks An example of a uid_range formed is 2:6,8,10,14:15,89,
3349 * While using it the caller should remove the ending, (comma)
3350 * @return This function returns true on success or false on failure.
3353 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)
3355 EM_DEBUG_FUNC_BEGIN();
3358 int error = EMAIL_ERROR_NONE;
3360 if (NULL == id_set || id_set_count <= 0 || NULL == uid_range_set) {
3361 EM_DEBUG_EXCEPTION(" Invalid Parameter id_set[%p] id_set_count[%d] uid_range_set[%p]", id_set, id_set_count, uid_range_set);
3362 error = EMAIL_ERROR_INVALID_PARAM;
3367 unsigned long current_uid = 0;
3368 unsigned long first_uid = 0;
3369 unsigned long last_uid = 0;
3370 const int max_subset_string_size = MAX_SUBSET_STRING_SIZE;
3371 char subset_string[MAX_SUBSET_STRING_SIZE] = {0,};
3372 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*/
3374 if (range_len < (max_subset_string_size + 1)) /* 1 for ending NULL character */ {
3375 EM_DEBUG_EXCEPTION(" Invalid Parameter range_len[%d]", range_len);
3376 error = EMAIL_ERROR_INVALID_PARAM;
3380 EM_DEBUG_LOG("id set count[%d] range_len[%d]", id_set_count, range_len);
3383 first_uid = last_uid = current_uid = id_set[i].server_mail_id;
3384 /* Start subset string by putting first server mail id in it from id_set*/
3385 memset(subset_string, 0x00, max_subset_string_size);
3386 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
3389 /* Check if only one server mail id was left in id_set */
3390 if (i >= id_set_count) {
3391 /* No more server mail id left in id_set */
3392 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
3393 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
3398 /* 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 */
3400 current_uid = id_set[i].server_mail_id;
3401 if (current_uid == (last_uid + 1)) {
3402 last_uid = current_uid;
3405 memset(subset_string, 0x00, max_subset_string_size);
3406 if (first_uid != last_uid) /* Form subset string by first_uid:last_uid */
3407 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
3408 else /* Form subset string by first_uid */
3409 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
3411 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
3412 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
3415 /* To Start formation of new subset string break out of inner loop */
3419 } while (i < id_set_count);
3421 /* Flow comes here in two cases :
3422 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
3423 2. due to break statement */
3425 if (last_uid == current_uid) {
3427 memset(subset_string, 0x00, max_subset_string_size);
3428 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
3430 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
3431 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
3435 /* Case 2: Do Nothing */
3438 } while (i < id_set_count);
3443 if (NULL != err_code)
3445 EM_DEBUG_FUNC_END();
3451 * @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)
3452 * 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
3453 * and stores the subset_string in its uid_range. Also sets the lowest and highest uids for the corresponsing uid_range
3455 * @author h.gahlaut@samsung.com
3456 * @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.
3457 * @param[in] range_len Specifies the maximum length of range string allowed.
3458 * @param[in] luid Specifies the lowest uid in subset string
3459 * @param[in] huid Specifies the highest uid in subset string
3460 * @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
3461 * @param[out] err_code Returns the error code.
3463 * @return This function returns true on success or false on failure.
3466 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)
3468 EM_DEBUG_FUNC_BEGIN();
3469 email_uid_range_set *current_node = NULL;
3471 if (NULL == (*uid_range_set)) {
3472 /*This happens only once when list creation starts. Head Node is allocated */
3473 current_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
3474 if (NULL == current_node) {
3475 EM_DEBUG_EXCEPTION("em_mallocfailed");
3479 current_node->uid_range = (char *)em_malloc(range_len);
3481 if (NULL == current_node->uid_range) {
3482 EM_DEBUG_EXCEPTION("em_mallocfailed");
3483 EM_SAFE_FREE(current_node);
3487 SNPRINTF(current_node->uid_range, range_len, "%s,", subset_string);
3489 current_node->lowest_uid = luid;
3490 current_node->highest_uid = huid;
3491 (*uid_range_set) = current_node;
3493 (*current_node_adr) = current_node;
3496 /* Apart from first call to this function flow will always come here */
3497 current_node = (*current_node_adr);
3498 int len_sub_string = EM_SAFE_STRLEN(subset_string);
3499 int space_left_in_buffer = range_len - EM_SAFE_STRLEN(current_node->uid_range);
3501 if ((len_sub_string + 1 + 1) <= space_left_in_buffer) /* 1 for comma + 1 for ending null character */ {
3502 SNPRINTF(current_node->uid_range + EM_SAFE_STRLEN(current_node->uid_range), space_left_in_buffer, "%s,", subset_string);
3503 current_node->highest_uid = huid;
3505 /* No more space left in uid_range string.If continued on it, it will exceeded max size of range_len */
3506 /* Allocate new node in Uid Range set */
3507 email_uid_range_set *new_node = NULL;
3509 new_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
3511 if (NULL == new_node) {
3512 EM_DEBUG_EXCEPTION("em_mallocfailed");
3516 /* Allocate uid_range of new node */
3518 new_node->uid_range = (char *)em_malloc(range_len);
3520 if (NULL == new_node->uid_range) {
3521 EM_DEBUG_EXCEPTION("em_mallocfailed");
3522 EM_SAFE_FREE(new_node);
3526 SNPRINTF(new_node->uid_range, range_len, "%s, ", subset_string);
3528 new_node->lowest_uid = luid;
3529 new_node->highest_uid = huid;
3531 current_node->next = new_node;
3533 (*current_node_adr) = new_node;
3536 EM_DEBUG_FUNC_END();
3541 * void emcore_free_uid_range_set(email_uid_range_set **uid_range_head)
3542 * Frees the linked list of uid ranges
3544 * @author h.gahlaut@samsung.com
3545 * @param[in] uid_range_head Head pointer of linked list of uid ranges
3547 * @return This function does not return anything.
3551 void emcore_free_uid_range_set(email_uid_range_set **uid_range_set)
3553 EM_DEBUG_FUNC_BEGIN();
3555 email_uid_range_set *current_node = NULL;
3556 email_uid_range_set *uid_range_head = NULL;
3558 current_node = uid_range_head = (*uid_range_set); /* Make the current node and head ptr point to starting of uid_range_set */
3560 while (current_node) {
3561 uid_range_head = current_node->next; /* Move the head ptr to next node*/
3563 EM_SAFE_FREE(current_node->uid_range);
3564 EM_SAFE_FREE(current_node); /* Free the current node */
3566 current_node = uid_range_head; /* Make the current node point to head ptr */
3569 (*uid_range_set) = NULL;
3570 EM_DEBUG_FUNC_END();
3575 * @fn emcore_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char *** strings, int *string_count, int *err_code)
3576 * Forms comma separated strings of a give max_string_len from an array of numbers
3578 * @author h.gahlaut@samsung.com
3579 * @param[in] numbers Specifies the array of numbers to be converted into comma separated strings.
3580 * @param[in] num_count Specifies the count of numbers in numbers array.
3581 * @param[in] max_string_len Specifies the maximum length of comma separated strings that are to be formed.
3582 * @param[out] strings Returns the base address of a double dimension array which stores the strings.
3583 * @param[out] string_count Returns the number of strings formed.
3584 * @param[out] err_code Returns the error code.
3585 * @remarks If Input to the function is five numbers like 2755 2754 2748 2749 2750 and a given max_string_len is 20.
3586 * Then this function will form two comma separated strings as follows -
3587 * "2755, 2754, 2748"
3589 * @return This function returns true on success or false on failure.
3592 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)
3594 EM_DEBUG_FUNC_BEGIN();
3596 int error = EMAIL_ERROR_NONE;
3599 char **string_list = NULL;
3600 int num_of_strings = 0;
3603 char num[MAX_INTEGER_LENGTH + 1] = {0, };
3605 int space_in_buffer = 0;
3606 int len_of_string_formed = 0;
3608 if (NULL == numbers || num_count <= 0 ||
3609 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. */ {
3610 EM_DEBUG_EXCEPTION("Invalid Parameter numbers[%p] num_count [%d] max_string_len [%d] strings [%p] string_count[%p]",
3611 numbers, num_count, max_string_len, strings, string_count);
3612 error = EMAIL_ERROR_INVALID_PARAM;
3616 EM_DEBUG_LOG("num_count [%d] max_string_len [%d]", num_count, max_string_len);
3618 string_list = em_malloc(sizeof(char *));
3620 if (NULL == string_list) {
3621 EM_DEBUG_EXCEPTION("em_mallocfailed ");
3625 string_list[num_of_strings] = em_malloc(max_string_len);
3627 if (NULL == string_list[num_of_strings]) {
3628 EM_DEBUG_EXCEPTION("em_mallocfailed ");
3633 space_in_buffer = max_string_len;
3635 for (j = 0; j < num_count; ++j) {
3636 memset(num, 0x00, MAX_INTEGER_LENGTH + 1);
3637 SNPRINTF(num, MAX_INTEGER_LENGTH + 1, "%d", numbers[j]);
3639 num_len = EM_SAFE_STRLEN(num);
3641 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
3643 space_in_buffer = max_string_len - len_of_string_formed ;
3645 if (space_in_buffer >= (num_len+1+1)) /* 1 for comma and 1 for ending NULL */ {
3646 SNPRINTF(string_list[num_of_strings - 1] + len_of_string_formed, max_string_len, "%d,", numbers[j]);
3647 } else { /* Removing comma at end of string */
3648 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
3650 temp = (char **)realloc(string_list, sizeof(char *) * (num_of_strings + 1)); /* Allocate new buffer to store a pointer to a new string */
3653 EM_DEBUG_EXCEPTION("realloc failed");
3657 memset(temp + num_of_strings, 0X00, sizeof(char *));
3661 string_list[num_of_strings] = em_malloc(max_string_len);/* Allocate new buffer to store the string */
3663 if (NULL == string_list[num_of_strings]) {
3664 EM_DEBUG_EXCEPTION(" em_mallocfailed ");
3668 SNPRINTF(string_list[num_of_strings - 1] , max_string_len, "%d,", numbers[j]);/* Start making new string */
3672 /* Removing comma at end of string */
3673 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
3674 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
3680 emcore_free_comma_separated_strings(&string_list, &num_of_strings);
3683 for (i = 0; i < num_of_strings; ++i)
3684 EM_DEBUG_LOG("%s", string_list[i]);
3685 *strings = string_list;
3686 *string_count = num_of_strings;
3690 if (NULL != err_code)
3693 EM_DEBUG_FUNC_END("ret [%d]", ret);
3697 * @fn emcore_free_comma_separated_strings(char *** string_list, int *string_count)
3698 * Frees the double dimensional array of strings.
3700 * @author h.gahlaut@samsung.com
3701 * @param[in] uid_range_head Address of base address of double dimensional array of strings.
3702 * @param[in] string_count Address of variable holding the count of strings.
3704 * @return This function does not return anything.
3706 INTERNAL_FUNC void emcore_free_comma_separated_strings(char *** string_list, int *string_count)
3708 EM_DEBUG_FUNC_BEGIN();
3710 char **str_list = NULL;
3713 if (NULL != string_list) {
3714 str_list = *string_list;
3716 if (0 != *string_count) {
3717 count = *string_count;
3718 for (i = 0; i < count; ++i)
3719 EM_SAFE_FREE(str_list[i]);
3722 EM_SAFE_FREE(str_list);
3723 *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 */
3726 EM_DEBUG_FUNC_END();
3735 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)
3737 EM_DEBUG_FUNC_BEGIN_SEC("source_file_name[%s], sub_type[%s], result_file_name_buffer_length[%d] ", source_file_name, sub_type, result_file_name_buffer_length);
3738 int ret = false, err = EMAIL_ERROR_NONE;
3739 char *extcheck = NULL;
3740 char attachment_file_name[MAX_PATH + 1] = { 0, };
3742 if (!source_file_name || !result_file_name) {
3743 EM_DEBUG_EXCEPTION("Invalid Parameter");
3744 err = EMAIL_ERROR_INVALID_PARAM;
3748 strncpy(attachment_file_name, source_file_name, MAX_PATH);
3749 extcheck = strchr(attachment_file_name, '.');
3752 EM_DEBUG_LOG("Extension Exist in the Attachment [%s] ", extcheck);
3753 else { /* No extension attached, So add the Extension based on the subtype */
3755 if ((MAX_PATH + 1) < (strlen(sub_type) + 1)) {
3756 EM_DEBUG_EXCEPTION("Buffer overflow");
3757 err = EMAIL_ERROR_OUT_OF_MEMORY;
3761 EM_SAFE_STRNCAT(attachment_file_name, ".", MAX_PATH - EM_SAFE_STRLEN(attachment_file_name) - 1);
3762 EM_SAFE_STRNCAT(attachment_file_name, sub_type, MAX_PATH - EM_SAFE_STRLEN(attachment_file_name) - 1);
3763 EM_DEBUG_LOG_SEC("attachment_file_name with extension[%s] ", attachment_file_name);
3765 EM_DEBUG_LOG("UnKnown Extesnsion");
3768 memset(result_file_name, 0 , result_file_name_buffer_length);
3769 EM_SAFE_STRNCPY(result_file_name, attachment_file_name, result_file_name_buffer_length - 1);
3770 EM_DEBUG_LOG_SEC("*result_file_name[%s]", result_file_name);
3776 EM_DEBUG_FUNC_END();
3780 #ifdef __FEATURE_LOCAL_ACTIVITY__
3781 INTERNAL_FUNC int emcore_add_activity(emstorage_activity_tbl_t *new_activity, int *err_code)
3783 EM_DEBUG_FUNC_BEGIN();
3785 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", new_activity, err_code);
3787 /* default variable */
3789 int err = EMAIL_ERROR_NONE;
3791 if (!new_activity) {
3792 EM_DEBUG_LOG("\t new_activity[%p]\n", new_activity);
3793 err = EMAIL_ERROR_INVALID_PARAM;
3796 if (!emstorage_add_activity(new_activity, false, &err)) {
3797 EM_DEBUG_LOG("\t emstorage_add_activity falied - %d\n", err);
3810 INTERNAL_FUNC int emcore_delete_activity(emstorage_activity_tbl_t *activity, int *err_code)
3812 EM_DEBUG_FUNC_BEGIN();
3814 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", activity, err_code);
3816 /* default variable */
3818 int err = EMAIL_ERROR_NONE;
3820 EM_DEBUG_LOG("\t new_activity[%p]\n", activity);
3822 err = EMAIL_ERROR_INVALID_PARAM;
3825 if (!emstorage_delete_local_activity(activity, true, &err)) {
3826 EM_DEBUG_LOG("\t emstorage_delete_local_activity falied - %d\n", err);
3839 INTERNAL_FUNC int emcore_get_next_activity_id(int *activity_id, int *err_code)
3841 EM_DEBUG_FUNC_BEGIN();
3844 int err = EMAIL_ERROR_NONE;
3846 if (NULL == activity_id) {
3847 EM_DEBUG_EXCEPTION("\t activity_id[%p]", activity_id);
3848 err = EMAIL_ERROR_INVALID_PARAM;
3852 if (false == emstorage_get_next_activity_id(activity_id, &err)) {
3853 EM_DEBUG_LOG("\t emstorage_get_next_activity_id failed - %d\n", err);
3860 if (NULL != err_code) {
3868 #endif /* __FEATURE_LOCAL_ACTIVITY__ */
3871 INTERNAL_FUNC void emcore_free_rule(email_rule_t* rule)
3873 EM_DEBUG_FUNC_BEGIN();
3878 EM_SAFE_FREE(rule->filter_name);
3879 EM_SAFE_FREE(rule->value);
3880 EM_SAFE_FREE(rule->value2);
3882 EM_DEBUG_FUNC_END();
3885 INTERNAL_FUNC void emcore_free_body_sparep(void **p)
3887 EM_DEBUG_FUNC_BEGIN();
3889 EM_DEBUG_FUNC_END();
3892 INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_string, char *new_string, int *result)
3894 EM_DEBUG_FUNC_BEGIN_SEC("file_path : [%s], search_string : [%s]", file_path, search_string);
3895 int error = EMAIL_ERROR_NONE;
3897 int p_result = false;
3900 char *stripped = NULL;
3901 char *cid_string = NULL;
3902 char *modified_string = NULL;
3904 if (!search_string || !file_path || !result) {
3905 EM_DEBUG_EXCEPTION("Invalid parameter");
3906 error = EMAIL_ERROR_INVALID_PARAM;
3910 error = em_fopen(file_path, "r", &fp);
3911 if (error != EMAIL_ERROR_NONE || fp == NULL) {
3912 EM_DEBUG_EXCEPTION("em_fopen error [%d] [%s]", error, file_path);
3916 if (!emcore_get_file_size(file_path, &file_size, &error)) {
3917 EM_DEBUG_EXCEPTION("emcore_get_file_size error [%s]", file_path);
3921 buf = em_malloc(file_size + 1);
3923 EM_DEBUG_EXCEPTION("em_mallocfailed");
3924 error = EMAIL_ERROR_OUT_OF_MEMORY;
3928 if (fread(buf, sizeof(char), file_size, fp) != file_size) {
3929 EM_DEBUG_EXCEPTION("fread error [%d]", errno);
3930 error = EMAIL_ERROR_SYSTEM_FAILURE;
3935 stripped = em_replace_all_string(buf, CRLF_STRING, "");
3938 cid_string = em_malloc(strlen(search_string) + strlen("cid:") + 1);
3939 if (cid_string == NULL) {
3940 EM_DEBUG_EXCEPTION("em_mallocfailed");
3941 error = EMAIL_ERROR_OUT_OF_MEMORY;
3945 snprintf(cid_string, EM_SAFE_STRLEN(search_string) + EM_SAFE_STRLEN("cid:") + 1, "cid:%s", search_string);
3947 modified_string = em_replace_string(stripped, cid_string, new_string);
3948 if (modified_string) {
3952 error = em_fopen(file_path, "w", &fp);
3953 if (error != EMAIL_ERROR_NONE || fp == NULL) {
3954 EM_DEBUG_EXCEPTION("em_fopen failed");
3958 fprintf(fp, "%s", modified_string);
3964 if (strstr(stripped, search_string))
3971 EM_DEBUG_LOG("Search string[%s] not found", search_string);
3979 EM_SAFE_FREE(stripped); /*prevent 35586*/
3980 EM_SAFE_FREE(cid_string);
3981 EM_SAFE_FREE(modified_string);
3983 EM_DEBUG_FUNC_END("error:[%d]", error);
3987 INTERNAL_FUNC int emcore_load_query_from_file(char *file_path, char ***query_array, int *array_len)
3989 EM_DEBUG_FUNC_BEGIN_SEC("file_path : [%s], query_array : [%p]", file_path, *query_array);
3990 int error = EMAIL_ERROR_NONE;
3996 char **result_vector = NULL;
3999 EM_DEBUG_EXCEPTION("Invalid parameter");
4000 error = EMAIL_ERROR_INVALID_PARAM;
4004 error = em_fopen(file_path, "r", &fp);
4005 if (error != EMAIL_ERROR_NONE) {
4006 EM_DEBUG_EXCEPTION("em_fopen failed");
4010 if (!emcore_get_file_size(file_path, &file_size, &error)) {
4011 EM_DEBUG_EXCEPTION("emcore_get_file_size failed");
4015 buf = em_malloc(file_size + 1);
4017 EM_DEBUG_EXCEPTION("em_mallocfailed");
4018 error = EMAIL_ERROR_OUT_OF_MEMORY;
4022 if (fread(buf, sizeof(char), file_size, fp) != file_size) {
4023 EM_DEBUG_EXCEPTION("Get the data from file : failed");
4024 error = EMAIL_ERROR_SYSTEM_FAILURE;
4028 result_vector = g_strsplit(buf, ";", -1);
4029 if (!result_vector || g_strv_length(result_vector) <= 0) {
4030 EM_DEBUG_EXCEPTION("Parsing sql file failed");
4031 error = EMAIL_ERROR_SYSTEM_FAILURE;
4035 vector_len = g_strv_length(result_vector);
4036 if (vector_len <= 0) {
4037 EM_DEBUG_EXCEPTION("vector length : [%d]", vector_len);
4038 error = EMAIL_ERROR_SYSTEM_FAILURE;
4042 *query_array = (char **)calloc(vector_len, sizeof(char *));
4044 for (i = 0; i < vector_len; i++) {
4045 if (result_vector[i]) {
4046 char *str = g_strconcat(result_vector[i], ";", NULL);
4047 if (str) (*query_array)[i] = str;
4052 *array_len = vector_len;
4053 EM_DEBUG_LOG("SQL string array length : [%d]", vector_len);
4063 if (result_vector) {
4064 g_strfreev(result_vector);
4067 EM_DEBUG_FUNC_END("error:[%d]", error);
4072 static int emcore_get_next_peak_start_time(emstorage_account_tbl_t *input_account_ref, time_t input_current_time, time_t *output_time)
4074 EM_DEBUG_FUNC_BEGIN("input_account_ref [%p] input_time[%d] output_time[%p]", input_account_ref, input_current_time, output_time);
4075 int err = EMAIL_ERROR_NONE;
4081 struct tm *time_info;
4083 if (output_time == NULL) {
4084 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
4085 err = EMAIL_ERROR_INVALID_PARAM;
4089 time_info = localtime_r(&input_current_time, &time_buf);
4090 if (time_info == NULL) {
4091 EM_DEBUG_EXCEPTION("localtime failed");
4092 err = EMAIL_ERROR_SYSTEM_FAILURE;
4096 EM_DEBUG_LOG("input time and date: %s", asctime(time_info));
4098 wday = wday << time_info->tm_wday;
4100 EM_DEBUG_LOG("wday[%d] peak_days[%d]", wday, input_account_ref->peak_days);
4102 /* find next peak day */
4104 if (wday & input_account_ref->peak_days) {
4105 start_hour = input_account_ref->peak_start_time / 100;
4106 start_min = input_account_ref->peak_start_time % 100;
4107 if (start_hour < time_info->tm_hour || (start_hour == time_info->tm_hour && start_min < time_info->tm_min)) {
4108 if (wday == EMAIL_PEAK_DAYS_SATDAY)
4109 wday = EMAIL_PEAK_DAYS_SUNDAY;
4117 while (!(wday & input_account_ref->peak_days) && day_count < 7) {
4118 EM_DEBUG_LOG("wday[%d] day_count[%d]", wday, day_count);
4119 if (wday == EMAIL_PEAK_DAYS_SATDAY)
4120 wday = EMAIL_PEAK_DAYS_SUNDAY;
4126 EM_DEBUG_LOG("day_count[%d]", day_count);
4128 if (day_count < 7) {
4129 time_info->tm_mday += day_count; /* The other members of time_info will be interpreted or set by mktime */
4131 time_info->tm_hour = input_account_ref->peak_start_time / 100;
4132 time_info->tm_min = input_account_ref->peak_start_time % 100;
4133 time_info->tm_min = 0;
4135 *output_time = mktime(time_info);
4136 EM_DEBUG_LOG("result_time: %s", asctime(time_info));
4141 EM_DEBUG_FUNC_END("err[%d]", err);
4145 static int emcore_check_time_in_peak_schedule(emstorage_account_tbl_t *input_account_ref, time_t input_time, int *output_result)
4147 EM_DEBUG_FUNC_BEGIN("input_account_ref [%p] input_time[%d] output_result[%p]", input_account_ref, input_time, output_result);
4148 int err = EMAIL_ERROR_NONE;
4150 struct tm *time_info;
4158 if (input_account_ref == NULL || output_result == NULL) {
4159 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
4160 err = EMAIL_ERROR_INVALID_PARAM;
4164 time_info = localtime_r(&input_time, &time_buf);
4165 if (time_info == NULL) {
4166 EM_DEBUG_EXCEPTION("localtime failed");
4167 err = EMAIL_ERROR_SYSTEM_FAILURE;
4171 EM_DEBUG_LOG("input time and date: %s", asctime(time_info));
4173 wday = wday << time_info->tm_wday;
4175 EM_DEBUG_LOG("wday [%d]", wday);
4177 if (wday & input_account_ref->peak_days) {
4178 start_hour = input_account_ref->peak_start_time / 100;
4179 start_min = input_account_ref->peak_start_time % 100;
4181 end_hour = input_account_ref->peak_end_time / 100;
4182 end_min = input_account_ref->peak_end_time % 100;
4184 EM_DEBUG_LOG("start_hour[%d] start_min[%d] end_hour[%d] end_min[%d]", start_hour, start_min, end_hour, end_min);
4186 if (start_hour <= time_info->tm_hour && time_info->tm_hour <= end_hour) {
4187 if (time_info->tm_hour == end_hour) {
4188 if (time_info->tm_min < end_min)
4195 EM_DEBUG_LOG("result[%d]", result);
4196 *output_result = result;
4200 EM_DEBUG_FUNC_END("err[%d]", err);
4204 INTERNAL_FUNC int emcore_calc_next_time_to_sync(char *multi_user_name, int input_account_id, time_t input_current_time, time_t *output_time)
4206 EM_DEBUG_FUNC_BEGIN("input_account_id[%d] input_current_time[%d] output_time[%p]", input_account_id, input_current_time, output_time);
4207 int err = EMAIL_ERROR_NONE;
4208 emstorage_account_tbl_t *account = NULL;
4209 time_t next_time = 0;
4210 time_t next_peak_start_time = 0;
4211 time_t result_time = 0;
4212 int is_time_in_peak_schedule = 0;
4214 emstorage_get_account_by_id(multi_user_name, input_account_id, EMAIL_ACC_GET_OPT_DEFAULT, &account, true, &err);
4215 if (account == NULL) {
4216 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err);
4220 if (account->peak_days < 0) {
4221 /* peak schedule disabled */
4222 if (account->check_interval > 0)
4223 result_time = input_current_time + (account->check_interval * 60);
4224 } else if (account->peak_days > 0) {
4225 /* peak schedule enabled */
4227 /* if current time is in peak schedule */
4228 emcore_check_time_in_peak_schedule(account, input_current_time, &is_time_in_peak_schedule);
4229 EM_DEBUG_LOG("is_time_in_peak_schedule [%d]", is_time_in_peak_schedule);
4230 if (is_time_in_peak_schedule) {
4231 /* if next time to sync is in peak schedule? */
4232 next_time = input_current_time + (account->peak_interval * 60);
4234 emcore_check_time_in_peak_schedule(account, next_time, &is_time_in_peak_schedule);
4235 if (is_time_in_peak_schedule) {
4236 /* create an alarm to sync in peak schedule*/
4237 result_time = next_time;
4241 if (result_time == 0) {
4242 /* if current time is not in peak schedule */
4243 if (next_time == 0) {
4244 /* if normal sync schedule is set */
4245 if (account->check_interval) {
4246 next_time = input_current_time + (account->check_interval * 60);
4249 emcore_get_next_peak_start_time(account, input_current_time, &next_peak_start_time);
4251 EM_DEBUG_LOG("next_time : %s", ctime(&next_time));
4252 EM_DEBUG_LOG("next_peak_start_time : %s", ctime(&next_peak_start_time));
4254 /* if next time to sync is closer than next peak schedule start? */
4255 if (next_time && (next_time < next_peak_start_time)) {
4256 /* create an alarm to sync in check_interval */
4257 result_time = next_time;
4259 /* else check_interval is zero or next peak schedule start is close than next check_interval */
4261 result_time = next_peak_start_time;
4266 *output_time = result_time;
4267 EM_DEBUG_LOG("result_time : %s", ctime(&result_time));
4272 emstorage_free_account(&account, 1, NULL);
4275 EM_DEBUG_FUNC_END("err[%d]", err);
4279 static int convert_contact_err_to_email_err(int contact_err)
4281 int err = EMAIL_ERROR_NONE;
4283 switch (contact_err) {
4284 case CONTACTS_ERROR_NONE:
4285 err = EMAIL_ERROR_NONE;
4287 case CONTACTS_ERROR_OUT_OF_MEMORY:
4288 err = EMAIL_ERROR_OUT_OF_MEMORY;
4290 case CONTACTS_ERROR_INVALID_PARAMETER:
4291 err = EMAIL_ERROR_INVALID_PARAM;
4293 case CONTACTS_ERROR_NO_DATA:
4294 err = EMAIL_ERROR_DATA_NOT_FOUND;
4296 case CONTACTS_ERROR_DB:
4297 err = EMAIL_ERROR_DB_FAILURE;
4299 case CONTACTS_ERROR_IPC:
4300 err = EMAIL_ERROR_IPC_CONNECTION_FAILURE;
4302 case CONTACTS_ERROR_SYSTEM:
4303 err = EMAIL_ERROR_SYSTEM_FAILURE;
4305 case CONTACTS_ERROR_INTERNAL:
4307 err = EMAIL_ERROR_UNKNOWN;
4313 int emcore_get_mail_contact_info(char *multi_user_name, email_mail_contact_info_t *contact_info, char *full_address, int *err_code)
4315 EM_DEBUG_FUNC_BEGIN_SEC("contact_info[%p], full_address[%s], err_code[%p]", contact_info, full_address, err_code);
4318 int err = EMAIL_ERROR_NONE;
4320 if (!emcore_get_mail_contact_info_with_update(multi_user_name, contact_info, full_address, 0, &err))
4321 EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info_with_update failed [%d]", err);
4325 if (err_code != NULL)
4331 int emcore_search_contact_info(char *multi_user_name, const char *contact_uri, int address_property_id, char *address, int favorite_property_id, bool is_favorite, int limit, contacts_record_h *contacts_record)
4333 EM_DEBUG_FUNC_BEGIN();
4334 int contact_err = CONTACTS_ERROR_NONE;
4336 contacts_query_h query = NULL;
4337 contacts_filter_h filter = NULL;
4338 contacts_list_h list = NULL;
4340 void *join_zone = NULL;
4342 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
4343 if (emcore_set_join_zone(multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
4344 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
4349 if ((contact_err = contacts_query_create(contact_uri, &query)) != CONTACTS_ERROR_NONE) {
4350 EM_DEBUG_EXCEPTION("contacts_query_create failed");
4354 if ((contact_err = contacts_filter_create(contact_uri, &filter)) != CONTACTS_ERROR_NONE) {
4355 EM_DEBUG_EXCEPTION("contacts_filter_create failed");
4359 if ((contact_err = contacts_filter_add_str(filter, address_property_id, CONTACTS_MATCH_FULLSTRING, address)) != CONTACTS_ERROR_NONE) {
4360 EM_DEBUG_EXCEPTION("contacts_filter_add_str failed");
4364 if ((contact_err = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND)) != CONTACTS_ERROR_NONE) {
4365 EM_DEBUG_EXCEPTION("contacts_filter_add_operator failed");
4369 if ((contact_err = contacts_filter_add_bool(filter, favorite_property_id, is_favorite)) != CONTACTS_ERROR_NONE) {
4370 EM_DEBUG_EXCEPTION("contacts_filter_add_bool failed");
4374 if ((contact_err = contacts_query_set_filter(query, filter)) != CONTACTS_ERROR_NONE) {
4375 EM_DEBUG_EXCEPTION("contacts_query_set_filter failed");
4379 if ((contact_err = contacts_db_get_records_with_query(query, 0, limit, &list)) != CONTACTS_ERROR_NONE) {
4380 EM_DEBUG_EXCEPTION("contacts_db_get_record_with_query failed");
4384 if ((contact_err = contacts_list_get_current_record_p(list, contacts_record)) != CONTACTS_ERROR_NONE) {
4385 EM_DEBUG_EXCEPTION("contacts_list_get_current_record_p failed");
4392 contacts_query_destroy(query);
4395 contacts_filter_destroy(filter);
4398 contacts_list_destroy(list, false);
4401 emcore_unset_join_zone(join_zone);
4406 int emcore_search_contact_info_by_address(char *multi_user_name, const char *contact_uri, int property_id, char *address, int limit, contacts_record_h *contacts_record)
4408 EM_DEBUG_FUNC_BEGIN();
4409 int contact_err = CONTACTS_ERROR_NONE;
4411 contacts_query_h query = NULL;
4412 contacts_filter_h filter = NULL;
4413 contacts_list_h list = NULL;
4415 void *join_zone = NULL;
4417 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
4418 if (emcore_set_join_zone(multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
4419 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
4424 if ((contact_err = contacts_query_create(contact_uri, &query)) != CONTACTS_ERROR_NONE) {
4425 EM_DEBUG_EXCEPTION("contacts_query_create failed");
4429 if ((contact_err = contacts_filter_create(contact_uri, &filter)) != CONTACTS_ERROR_NONE) {
4430 EM_DEBUG_EXCEPTION("contacts_filter_create failed");
4434 if ((contact_err = contacts_filter_add_str(filter, property_id, CONTACTS_MATCH_FULLSTRING, address)) != CONTACTS_ERROR_NONE) {
4435 EM_DEBUG_EXCEPTION("contacts_filter_add_str failed");
4439 if ((contact_err = contacts_query_set_filter(query, filter)) != CONTACTS_ERROR_NONE) {
4440 EM_DEBUG_EXCEPTION("contacts_query_set_filter failed");
4444 if ((contact_err = contacts_db_get_records_with_query(query, 0, limit, &list)) != CONTACTS_ERROR_NONE) {
4445 EM_DEBUG_EXCEPTION("contacts_db_get_record_with_query failed");
4449 if ((contact_err = contacts_list_get_current_record_p(list, contacts_record)) != CONTACTS_ERROR_NONE) {
4450 if (contact_err != CONTACTS_ERROR_NO_DATA) /* no matching record found */
4451 EM_DEBUG_EXCEPTION("contacts_list_get_current_record_p failed [%d]", contact_err);
4458 contacts_query_destroy(query);
4461 contacts_filter_destroy(filter);
4464 contacts_list_destroy(list, false);
4467 emcore_unset_join_zone(join_zone);
4474 char *email_address;
4476 char *multi_user_name;
4478 email_action_t action;
4479 } set_contacts_log_internal_t;
4481 gboolean emcore_set_contacts_log_internal(void* arg)
4484 EM_DEBUG_EXCEPTION("no contact data to add");
4487 set_contacts_log_internal_t* tmp = (set_contacts_log_internal_t*) arg;
4488 int account_id = tmp->account_id;
4489 char *email_address = tmp->email_address;
4490 char *subject = tmp->subject;
4491 time_t date_time = tmp->date_time;
4492 email_action_t action = tmp->action;
4493 char *multi_user_name = tmp->multi_user_name;
4495 int contacts_error = CONTACTS_ERROR_NONE;
4497 int action_type = 0;
4499 contacts_record_h phone_record = NULL;
4500 contacts_record_h person_record = NULL;
4502 void *join_zone = NULL;
4504 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
4505 if (emcore_set_join_zone(multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
4506 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
4511 if ((contacts_error = contacts_record_create(_contacts_phone_log._uri, &phone_record)) != CONTACTS_ERROR_NONE) {
4512 EM_DEBUG_EXCEPTION("contacts_query_create failed [%d]", contacts_error);
4516 /* Set email address */
4517 if ((contacts_error = contacts_record_set_str(phone_record, _contacts_phone_log.address, email_address)) != CONTACTS_ERROR_NONE) {
4518 EM_DEBUG_EXCEPTION("contacts_record_set_str [address] failed [%d]", contacts_error);
4522 /* Search contact person info */
4523 if ((contacts_error = emcore_search_contact_info_by_address(multi_user_name, _contacts_person_email._uri, _contacts_person_email.email, email_address, 1, &person_record)) != CONTACTS_ERROR_NONE) {
4524 if (contacts_error != CONTACTS_ERROR_NO_DATA) /* no matching record found */
4525 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contacts_error);
4527 /* Get person_id in contacts_person_email record */
4528 if (person_record && (contacts_error = contacts_record_get_int(person_record, _contacts_person_email.person_id, &person_id)) != CONTACTS_ERROR_NONE) {
4529 EM_DEBUG_EXCEPTION("contacts_record_get_str failed [%d]", contacts_error);
4533 /* Set the person id */
4534 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.person_id, person_id)) != CONTACTS_ERROR_NONE) {
4535 EM_DEBUG_EXCEPTION("contacts_record_set_int [person id] failed [%d]", contacts_error);
4541 case EMAIL_ACTION_SEND_MAIL:
4542 action_type = CONTACTS_PLOG_TYPE_EMAIL_SENT;
4544 case EMAIL_ACTION_SYNC_HEADER:
4545 action_type = CONTACTS_PLOG_TYPE_EMAIL_RECEIVED;
4548 EM_DEBUG_EXCEPTION("Unknown action type");
4553 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.log_type, action_type)) != CONTACTS_ERROR_NONE) {
4554 EM_DEBUG_EXCEPTION("contacts_record_set_int [log_type] failed [%d]", contacts_error);
4559 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.log_time, (int)date_time)) != CONTACTS_ERROR_NONE) {
4560 EM_DEBUG_EXCEPTION("contacts_record_set_str [address] failed [%d]", contacts_error);
4565 if ((contacts_error = contacts_record_set_str(phone_record, _contacts_phone_log.extra_data2, subject)) != CONTACTS_ERROR_NONE) {
4566 EM_DEBUG_EXCEPTION("contacts_record_set_str [subject] failed [%d]", contacts_error);
4571 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.extra_data1, account_id)) != CONTACTS_ERROR_NONE) {
4572 EM_DEBUG_EXCEPTION("contacts_record_set_int [mail id] failed [%d]", contacts_error);
4576 /* Insert the record in DB */
4577 if ((contacts_error = contacts_db_insert_record(phone_record, NULL)) != CONTACTS_ERROR_NONE) {
4578 EM_DEBUG_EXCEPTION("contacts_db_insert_record failed [%d]", contacts_error);
4584 if (phone_record != NULL)
4585 contacts_record_destroy(phone_record, false);
4587 if (person_record != NULL)
4588 contacts_record_destroy(person_record, false);
4591 emcore_unset_join_zone(join_zone);
4593 EM_SAFE_FREE(email_address);
4594 EM_SAFE_FREE(subject);
4597 EM_DEBUG_FUNC_END("contact err [%d]", convert_contact_err_to_email_err(contacts_error));
4601 int emcore_set_contacts_log(char *multi_user_name,
4603 char *email_address,
4606 email_action_t action)
4608 /* arg shall be destroyed in emcore_set_contacts_log_internal */
4609 set_contacts_log_internal_t *arg = em_malloc(sizeof(set_contacts_log_internal_t));
4611 EM_DEBUG_EXCEPTION("em_mallocerror");
4612 return EMAIL_ERROR_OUT_OF_MEMORY;
4616 arg->account_id = account_id;
4617 arg->email_address = EM_SAFE_STRDUP(email_address);
4618 arg->subject = EM_SAFE_STRDUP(subject);
4619 arg->date_time = date_time;
4620 arg->action = action;
4621 arg->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
4623 g_main_context_invoke(NULL, emcore_set_contacts_log_internal, arg);
4625 return EMAIL_ERROR_NONE;
4628 INTERNAL_FUNC int emcore_set_sent_contacts_log(char *multi_user_name, emstorage_mail_tbl_t *input_mail_data)
4630 EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
4633 int err = EMAIL_ERROR_NONE;
4634 char email_address[MAX_EMAIL_ADDRESS_LENGTH];
4635 char *address_array[3] = {input_mail_data->full_address_to, input_mail_data->full_address_cc, input_mail_data->full_address_bcc};
4636 ADDRESS *addr = NULL;
4637 ADDRESS *p_addr = NULL;
4639 for (i = 0; i < 3; i++) {
4640 if (address_array[i] && address_array[i][0] != 0) {
4641 rfc822_parse_adrlist(&addr, address_array[i], NULL);
4642 for (p_addr = addr; p_addr; p_addr = p_addr->next) {
4643 SNPRINTF(email_address, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", addr->mailbox, addr->host);
4644 if ((err = emcore_set_contacts_log(multi_user_name,
4645 input_mail_data->account_id,
4647 input_mail_data->subject,
4648 input_mail_data->date_time,
4649 EMAIL_ACTION_SEND_MAIL)) != EMAIL_ERROR_NONE) {
4650 EM_DEBUG_EXCEPTION("emcore_set_contacts_log failed : [%d]", err);
4656 mail_free_address(&addr);
4665 mail_free_address(&addr);
4667 EM_DEBUG_FUNC_END("err [%d]", err);
4672 INTERNAL_FUNC int emcore_set_received_contacts_log(char *multi_user_name, emstorage_mail_tbl_t *input_mail_data)
4674 EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
4675 int err = EMAIL_ERROR_NONE;
4677 if ((err = emcore_set_contacts_log(multi_user_name,
4678 input_mail_data->account_id,
4679 input_mail_data->email_address_sender,
4680 input_mail_data->subject,
4681 input_mail_data->date_time,
4682 EMAIL_ACTION_SYNC_HEADER)) != EMAIL_ERROR_NONE) {
4683 EM_DEBUG_EXCEPTION("emcore_set_contacts_log failed [%d]", err);
4686 EM_DEBUG_FUNC_END("err [%d]", err);
4690 typedef struct _contacts_delete_data {
4692 char *multi_user_name;
4693 } contacts_delete_data;
4695 gboolean emcore_delete_contacts_log_internal(void* arg)
4697 EM_DEBUG_FUNC_BEGIN();
4699 contacts_delete_data *data = (contacts_delete_data *)arg;
4700 int contacts_error = CONTACTS_ERROR_NONE;
4702 void *join_zone = NULL;
4704 if (EM_SAFE_STRLEN(data->multi_user_name) > 0) {
4705 if (emcore_set_join_zone(data->multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
4706 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
4711 /* Delete record of the account id */
4712 if ((contacts_error = contacts_phone_log_delete(CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1, data->account_id)) != CONTACTS_ERROR_NONE) {
4713 EM_DEBUG_EXCEPTION("contacts_phone_log_delete failed [%d]", contacts_error);
4715 /* err = convert_contact_err_to_email_err(contacts_error); */
4718 emcore_unset_join_zone(join_zone);
4720 EM_SAFE_FREE(data->multi_user_name);
4723 EM_DEBUG_FUNC_END();
4727 INTERNAL_FUNC int emcore_delete_contacts_log(char *multi_user_name, int account_id)
4729 contacts_delete_data *data = NULL;
4731 data = (contacts_delete_data *)em_malloc(sizeof(contacts_delete_data));
4733 EM_DEBUG_EXCEPTION("em_mallocfailed");
4734 return EMAIL_ERROR_OUT_OF_MEMORY;
4737 data->account_id = account_id;
4738 data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
4740 g_main_context_invoke(NULL, emcore_delete_contacts_log_internal, (void*) data);
4742 return EMAIL_ERROR_NONE;
4745 INTERNAL_FUNC int emcore_get_mail_display_name(char *multi_user_name, char *email_address, char **contact_display_name)
4747 if (!email_address || !contact_display_name) {
4748 EM_DEBUG_EXCEPTION("NULL_PARAM email_address[%p] contact_display_name[%p]",
4749 email_address, contact_display_name);
4750 return EMAIL_ERROR_INVALID_PARAM;
4753 GError *gerror = NULL;
4754 GVariant *result = NULL;
4755 int ret = EMAIL_ERROR_NONE;
4757 #if !GLIB_CHECK_VERSION(2, 36, 0)
4761 GDBusProxy* bproxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
4762 G_DBUS_PROXY_FLAGS_NONE,
4770 EM_DEBUG_EXCEPTION("g_dbus_proxy_new_for_bus_sync error [%s]",
4772 ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
4776 result = g_dbus_proxy_call_sync(bproxy,
4778 g_variant_new("(ss)", email_address, multi_user_name),
4779 G_DBUS_CALL_FLAGS_NONE,
4786 EM_DEBUG_EXCEPTION("g_dbus_proxy_call_sync 'GetDisplayName' error [%s]",
4788 ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
4792 g_variant_get(result, "(si)", contact_display_name, &ret);
4794 /* replace "" to NULL */
4795 if (!g_strcmp0(*contact_display_name, ""))
4796 EM_SAFE_FREE(*contact_display_name);
4798 g_variant_unref(result);
4801 EM_DEBUG_LOG("ret [%d]\n", ret);
4803 g_object_unref(bproxy);
4806 g_error_free(gerror);
4812 INTERNAL_FUNC int emcore_get_mail_display_name_internal(char *multi_user_name,
4813 char *email_address,
4814 char **contact_display_name)
4816 EM_DEBUG_FUNC_BEGIN_SEC("contact_name_value[%s], contact_display_name[%p]", email_address, contact_display_name);
4818 int contact_err = 0;
4819 int err = EMAIL_ERROR_NONE;
4821 char *display = NULL;
4822 /* Contact variable */
4823 contacts_record_h record = NULL;
4826 if ((contact_err = contacts_connect_on_thread()) != CONTACTS_ERROR_NONE) {
4827 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contact_err);
4831 if ((contact_err = emcore_search_contact_info_by_address(multi_user_name, _contacts_contact_email._uri, _contacts_contact_email.email, email_address, 1, &record)) != CONTACTS_ERROR_NONE) {
4832 if (contact_err != CONTACTS_ERROR_NO_DATA) /* no matching record found */
4833 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contact_err);
4837 if ((contact_err = contacts_list_get_count(list, &list_count)) != CONTACTS_ERROR_NONE) {
4838 EM_DEBUG_EXCEPTION("contacts_list_get_count failed");
4842 if (list_count > 1) {
4843 EM_DEBUG_EXCEPTION("Duplicated contacts info");
4844 contact_err = CONTACTS_ERROR_INTERNAL;
4846 } else if (list_count == 0) {
4847 EM_DEBUG_EXCEPTION("Not found contact info");
4848 contact_err = CONTACTS_ERROR_NO_DATA;
4853 if (contacts_record_get_str(record, _contacts_contact_email.display_name, &display) != CONTACTS_ERROR_NONE) {
4854 EM_DEBUG_EXCEPTION("contacts_record_get_str failed");
4862 /* contacts_disconnect_on_thread(); */
4865 contacts_record_destroy(record, false);
4868 *contact_display_name = display;
4870 *contact_display_name = NULL;
4871 EM_SAFE_FREE(display);
4874 err = convert_contact_err_to_email_err(contact_err);
4879 INTERNAL_FUNC int emcore_connect_contacts_service(char *multi_user_name)
4881 EM_DEBUG_FUNC_BEGIN();
4882 int contact_err = 0;
4883 int err = EMAIL_ERROR_NONE;
4885 void *join_zone = NULL;
4887 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
4888 if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
4889 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
4894 if ((contact_err = contacts_connect()) != CONTACTS_ERROR_NONE) {
4895 EM_DEBUG_EXCEPTION("contacts_connect failed : [%d]", contact_err);
4898 err = convert_contact_err_to_email_err(contact_err);
4901 emcore_unset_join_zone(join_zone);
4903 EM_DEBUG_FUNC_END();
4907 INTERNAL_FUNC int emcore_disconnect_contacts_service(char *multi_user_name)
4909 EM_DEBUG_FUNC_BEGIN();
4910 int contact_err = 0;
4911 int err = EMAIL_ERROR_NONE;
4913 void *join_zone = NULL;
4915 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
4916 if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
4917 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
4922 if ((contact_err = contacts_disconnect()) != CONTACTS_ERROR_NONE) {
4923 EM_DEBUG_EXCEPTION("contacts_disconnect failed : [%d]", contact_err);
4926 err = convert_contact_err_to_email_err(contact_err);
4929 emcore_unset_join_zone(join_zone);
4931 EM_DEBUG_FUNC_END();
4935 #ifdef __FEATURE_BLOCKING_MODE__
4937 #define ALLOWED_CONTACT_TYPE_NONE 0
4938 #define ALLOWED_CONTACT_TYPE_ALL 1
4939 #define ALLOWED_CONTACT_TYPE_FAVORITES 2
4940 #define ALLOWED_CONTACT_TYPE_CUSTOM 3
4942 static int blocking_mode_status = false;
4943 INTERNAL_FUNC int blocking_mode_of_setting = false;
4945 INTERNAL_FUNC void emcore_set_blocking_mode_of_setting(int input_blocking_mode_of_setting)
4947 blocking_mode_of_setting = input_blocking_mode_of_setting;
4950 INTERNAL_FUNC int emcore_get_blocking_mode_status()
4952 EM_DEBUG_FUNC_BEGIN("blocking_mode_status : [%d]", blocking_mode_status);
4953 EM_DEBUG_FUNC_END();
4955 return blocking_mode_status;
4958 INTERNAL_FUNC void emcore_set_blocking_mode_status(int blocking_mode)
4960 blocking_mode_status = blocking_mode;
4963 INTERNAL_FUNC int emcore_check_blocking_mode(char *multi_user_name, char *sender_address, int *blocking_status)
4965 if (!sender_address || !blocking_status) {
4966 EM_DEBUG_EXCEPTION("NULL_PARAM sender_address[%p] blocking_status[%p]",
4967 sender_address, blocking_status);
4968 return EMAIL_ERROR_INVALID_PARAM;
4972 GError *gerror = NULL;
4973 GVariant *result = NULL;
4974 int ret = EMAIL_ERROR_NONE;
4976 #if !GLIB_CHECK_VERSION(2, 36, 0)
4980 GDBusProxy* bproxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
4981 G_DBUS_PROXY_FLAGS_NONE,
4989 EM_DEBUG_EXCEPTION("g_dbus_proxy_new_for_bus_sync error [%s]",
4991 ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
4995 result = g_dbus_proxy_call_sync(bproxy,
4996 "CheckBlockingMode",
4997 g_variant_new("(ss)", sender_address, multi_user_name),
4998 G_DBUS_CALL_FLAGS_NONE,
5005 EM_DEBUG_EXCEPTION("g_dbus_proxy_call_sync 'CheckBlockingMode' error [%s]",
5007 ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
5011 g_variant_get(result, "(ii)", blocking_status, &ret);
5012 g_variant_unref(result);
5017 g_object_unref(bproxy);
5020 g_error_free(gerror);
5025 INTERNAL_FUNC int emcore_check_blocking_mode_internal(char *multi_user_name, char *sender_address, int *blocking_status)
5027 EM_DEBUG_FUNC_BEGIN();
5028 int err = EMAIL_ERROR_NONE;
5029 int contact_error = 0;
5031 int allowed_contact_type = 0; /* 0 : NONE, 1 : All contacts, 2 : Favorites, 3 : Custom */
5032 char *person_id_string = NULL;
5035 contacts_record_h record = NULL;
5037 if (!blocking_mode_of_setting) {
5041 if (vconf_get_int(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_TYPE, &allowed_contact_type) != 0) {
5042 EM_DEBUG_EXCEPTION("vconf_get_int failed");
5043 err = EMAIL_ERROR_SYSTEM_FAILURE;
5048 if ((contact_error = contacts_connect_on_thread()) != CONTACTS_ERROR_NONE) {
5049 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contact_error);
5053 switch (allowed_contact_type) {
5054 case ALLOWED_CONTACT_TYPE_NONE:
5055 EM_DEBUG_LOG("allowed_contact_type is none : bloacking all(notification)");
5056 *blocking_status = true;
5059 case ALLOWED_CONTACT_TYPE_ALL:
5060 EM_DEBUG_LOG("allowed_contact_type is ALL");
5061 /* Search the allowed contact type in contact DB */
5062 if ((contact_error = emcore_search_contact_info_by_address(multi_user_name, _contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) {
5063 if (contact_error != CONTACTS_ERROR_NO_DATA) /* no matching record found */
5064 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contact_error);
5068 if (record == NULL) {
5069 EM_DEBUG_LOG("No search contact info");
5073 *blocking_status = false;
5076 case ALLOWED_CONTACT_TYPE_FAVORITES:
5077 if ((contact_error = emcore_search_contact_info(multi_user_name, _contacts_person_email._uri, _contacts_person_email.email, sender_address, _contacts_person_email.is_favorite, true, 1, &record)) != CONTACTS_ERROR_NONE) {
5078 EM_DEBUG_EXCEPTION("emcore_search_contact_info failed : [%d]", contact_error);
5082 if (record == NULL) {
5083 EM_DEBUG_LOG("No search contact info");
5087 *blocking_status = false;
5090 case ALLOWED_CONTACT_TYPE_CUSTOM:
5091 person_id_string = vconf_get_str(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_LIST);
5092 if (person_id_string == NULL) {
5093 EM_DEBUG_LOG("Custom allowed contact type is NULL");
5097 if ((contact_error = emcore_search_contact_info_by_address(multi_user_name, _contacts_person_email._uri, _contacts_person_email.email, sender_address, 1, &record)) != CONTACTS_ERROR_NONE) {
5098 if (contact_error != CONTACTS_ERROR_NO_DATA) /* no matching record found */
5099 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contact_error);
5103 if (record == NULL) {
5104 EM_DEBUG_LOG("No search contact info");
5108 if (contacts_record_get_int(record, _contacts_contact_email.person_id, &person_id) != CONTACTS_ERROR_NONE) {
5109 EM_DEBUG_EXCEPTION("contacts_record_get_int failed");
5113 token = strtok_r(person_id_string, ",", &str);
5115 if (person_id == atoi(token)) {
5116 *blocking_status = false;
5119 } while ((token = strtok_r(NULL, ",", &str)));
5124 EM_DEBUG_EXCEPTION("Invalid parameter : [%d]", allowed_contact_type);
5125 *blocking_status = true;
5126 err = EMAIL_ERROR_INVALID_PARAM;
5132 contacts_disconnect_on_thread();
5134 err = convert_contact_err_to_email_err(contact_error);
5136 EM_SAFE_FREE(person_id_string);
5138 EM_DEBUG_FUNC_END();
5142 #endif /* __FEATURE_BLOCKING_MODE__ */
5144 INTERNAL_FUNC char *emcore_set_mime_entity(char *mime_path)
5146 EM_DEBUG_FUNC_BEGIN("mime_path : [%s]", mime_path);
5147 FILE *fp_read = NULL;
5148 FILE *fp_write = NULL;
5149 char *mime_entity = NULL;
5150 char *mime_entity_path = NULL;
5151 char temp_buffer[255] = {0,};
5152 int err = EMAIL_ERROR_NONE;
5155 if (!emcore_get_temp_file_name(&mime_entity_path, &err)) {
5156 EM_DEBUG_EXCEPTION(" em_core_get_temp_file_name failed[%d]", err);
5160 /* get mime entity */
5161 if (mime_path != NULL) {
5162 err = em_fopen(mime_path, "r", &fp_read);
5163 if (err != EMAIL_ERROR_NONE) {
5164 EM_DEBUG_EXCEPTION_SEC("File em_fopen(read) is failed : filename [%s]", mime_path);
5168 err = em_fopen(mime_entity_path, "w", &fp_write);
5169 if (err != EMAIL_ERROR_NONE) {
5170 EM_DEBUG_EXCEPTION_SEC("File em_fopen(write) is failed : filename [%s]", mime_entity_path);
5174 fseek(fp_read, 0, SEEK_SET);
5175 fseek(fp_write, 0, SEEK_SET);
5177 while (fgets(temp_buffer, 255, fp_read) != NULL) {
5178 mime_entity = strcasestr(temp_buffer, "content-type");
5179 if (mime_entity != NULL && !searched)
5183 fprintf(fp_write, "%s", temp_buffer);
5195 EM_SAFE_FREE(mime_entity);
5197 EM_DEBUG_FUNC_END();
5198 return mime_entity_path;
5201 INTERNAL_FUNC int emcore_get_content_from_file(char *filename, char **contents, int *length)
5203 EM_DEBUG_FUNC_BEGIN("filename[%s], contents[%p], length[%p]", filename, contents, length);
5205 struct stat stat_buf;
5210 int err = EMAIL_ERROR_NONE;
5212 char errno_buf[ERRNO_BUF_SIZE] = {0};
5214 if (filename == NULL || contents == NULL || length == NULL) {
5215 err = EMAIL_ERROR_INVALID_PARAM;
5216 EM_DEBUG_EXCEPTION("Invalid parameter");
5220 err = em_open(filename, O_RDONLY, 0, &fd);
5221 if (err != EMAIL_ERROR_NONE) {
5222 EM_DEBUG_EXCEPTION("em_open error [%s][%d]", filename, err);
5226 if (fstat(fd, &stat_buf) < 0) {
5227 EM_DEBUG_EXCEPTION("fstat failed for fd [%d]", fd);
5228 err = EMAIL_ERROR_SYSTEM_FAILURE;
5232 if (stat_buf.st_size > 0 && S_ISREG(stat_buf.st_mode)) {
5233 size = stat_buf.st_size;
5234 alloc_size = size + 1;
5235 buf = em_malloc(alloc_size);
5237 EM_DEBUG_EXCEPTION("malloc failed...");
5238 err = EMAIL_ERROR_OUT_OF_MEMORY;
5245 while (bytes_read < size) {
5246 ssize_t rd_size = 0;
5247 rd_size = read(fd, buf + bytes_read, size - bytes_read);
5250 if (errno != EINTR) {
5251 EM_DEBUG_EXCEPTION("read failed: %s", EM_STRERROR(errno_buf));
5252 err = EMAIL_ERROR_SYSTEM_FAILURE;
5255 } else if (rd_size == 0)
5258 bytes_read += rd_size;
5261 buf[bytes_read] = '\0';
5264 *length = bytes_read;
5268 EM_SAFE_CLOSE(fd); /* prevent 39093 */
5270 EM_DEBUG_FUNC_END();
5276 EM_SAFE_CLOSE(fd); /* prevent 39093 */
5277 EM_DEBUG_FUNC_END();
5282 INTERNAL_FUNC int emcore_set_content_to_file(const char *contents, char *dest_path, int length)
5284 EM_DEBUG_FUNC_BEGIN("contents[%p], dest_path[%s], length[%d]", contents, dest_path, length);
5286 int err = EMAIL_ERROR_NONE;
5287 char *tmp_path = NULL;
5288 char errno_buf[ERRNO_BUF_SIZE] = {0};
5289 int byte_written = 0; /* 39063 */
5291 if (contents == NULL || dest_path == NULL || length <= 0) {
5292 err = EMAIL_ERROR_INVALID_PARAM;
5293 EM_DEBUG_EXCEPTION("Invalid parameter");
5297 tmp_path = emcore_mime_get_save_file_name(&err);
5298 if (!tmp_path) { /* prevent 39114 */
5299 EM_DEBUG_EXCEPTION("tmp_path NULL");
5303 err = em_open(tmp_path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, &fd);
5304 if (err != EMAIL_ERROR_NONE) {
5305 EM_DEBUG_EXCEPTION("em_open error [%s][%d]", tmp_path, err);
5310 while (length > 0 && contents && errno == 0) {
5311 byte_written = write(fd, (void *)contents, length);
5312 if (byte_written < 0) {
5313 /* interrupted by a signal */
5314 if (errno == EINTR) {
5318 EM_DEBUG_EXCEPTION("write failed: %s", EM_STRERROR(errno_buf));
5319 err = EMAIL_ERROR_SYSTEM_FAILURE;
5323 EM_DEBUG_LOG("NWRITTEN [%d]", byte_written);
5324 length -= byte_written;
5325 contents += byte_written;
5329 if (fsync(fd) != 0) {
5330 EM_DEBUG_EXCEPTION("fsync failed: %s", EM_STRERROR(errno_buf));
5331 err = EMAIL_ERROR_SYSTEM_FAILURE;
5335 if (tmp_path && dest_path && rename(tmp_path, dest_path) != 0) {
5336 EM_DEBUG_EXCEPTION("rename failed: %s", EM_STRERROR(errno_buf));
5337 err = EMAIL_ERROR_SYSTEM_FAILURE;
5343 EM_SAFE_FREE(tmp_path);
5344 EM_SAFE_CLOSE(fd); /* prevent 39114, 39136*/
5345 EM_DEBUG_FUNC_END();
5349 #ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__
5351 INTERNAL_FUNC int emcore_update_db_table_schema(char *multi_user_name)
5353 EM_DEBUG_FUNC_BEGIN();
5354 int err = EMAIL_ERROR_NONE;
5356 err = emstorage_update_db_table_schema(multi_user_name);
5358 EM_DEBUG_FUNC_END("err[%d]", err);
5362 #endif /* __FEATURE_UPDATE_DB_TABLE_SCHEMA__ */
5364 INTERNAL_FUNC int emcore_unescape_from_url(char *input_url, char **output_url)
5366 EM_DEBUG_FUNC_BEGIN("input_url[%p] output_url[%p]", input_url, output_url);
5367 int err = EMAIL_ERROR_NONE;
5368 int input_length = 0;
5369 int output_length = 0;
5370 char *result_string = NULL;
5373 if (input_url == NULL || output_url == NULL) {
5374 err = EMAIL_ERROR_INVALID_PARAM;
5375 EM_DEBUG_EXCEPTION("Invalid parameter");
5380 curl = curl_easy_init();
5382 input_length = EM_SAFE_STRLEN(input_url);
5384 result_string = curl_easy_unescape(curl, input_url, input_length, &output_length);
5387 *output_url = EM_SAFE_STRDUP(result_string);
5391 curl_free(result_string);
5394 curl_easy_cleanup(curl);
5396 EM_DEBUG_FUNC_END("err[%d]", err);
5400 INTERNAL_FUNC char *__em_get_month_in_string(int month)
5402 EM_DEBUG_FUNC_BEGIN("month [%d]", month);
5408 mon = strdup("jan");
5411 mon = strdup("feb");
5414 mon = strdup("mar");
5417 mon = strdup("apr");
5420 mon = strdup("may");
5423 mon = strdup("jun");
5426 mon = strdup("jul");
5429 mon = strdup("aug");
5432 mon = strdup("sep");
5435 mon = strdup("oct");
5438 mon = strdup("nov");
5441 mon = strdup("dec");
5447 INTERNAL_FUNC int emcore_make_date_string_for_search(time_t input_time, char **output_date_string)
5449 EM_DEBUG_FUNC_BEGIN("input_time[%p] output_date_string[%p]", input_time, output_date_string);
5450 int err = EMAIL_ERROR_NONE;
5452 struct tm *timeinfo;
5454 char *temp_date_string = NULL;
5456 EM_DEBUG_LOG("RawTime Info [%lu]", input_time);
5458 timeinfo = localtime_r(&input_time, &time_buf);
5459 if (timeinfo == NULL) {
5460 EM_DEBUG_EXCEPTION("localtime failed");
5461 err = EMAIL_ERROR_SYSTEM_FAILURE;
5465 EM_DEBUG_LOG(">>>>>Time %d %d %d %d %d %d", 1900+timeinfo->tm_year, timeinfo->tm_mon+1, timeinfo->tm_mday);
5467 mon = __em_get_month_in_string(timeinfo->tm_mon);
5469 temp_date_string = g_strdup_printf("%d-%s-%04d", timeinfo->tm_mday, mon, 1900 + timeinfo->tm_year);
5470 EM_DEBUG_LOG("DATE IS [ %s ] ", temp_date_string);
5474 if (output_date_string)
5475 *output_date_string = temp_date_string;
5477 EM_SAFE_FREE(temp_date_string);
5479 EM_DEBUG_FUNC_END("err [%d]", err);
5483 INTERNAL_FUNC int emcore_make_uid_range_string(emcore_uid_list *uid_list, int total, char **output_uid_range_string)
5485 EM_DEBUG_FUNC_BEGIN("uid_list[%p] total[%d] output_uid_range_string[%p]", uid_list, total, output_uid_range_string);
5486 int err = EMAIL_ERROR_NONE;
5487 emcore_uid_list *uid_list_prev = NULL;
5488 emcore_uid_list *uid_list_fast = uid_list;
5490 int msg_count = total;
5491 int uid_range_size = msg_count * 8 + 1000;
5492 char *uid_range = NULL;
5494 if (uid_list == NULL || total == 0 || output_uid_range_string == NULL) {
5495 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
5496 err = EMAIL_ERROR_INVALID_PARAM;
5500 EM_DEBUG_LOG("memory allocation for uid_range [%d, %d]", msg_count, uid_range_size);
5501 uid_range = malloc(sizeof(char) * uid_range_size);
5502 if (uid_range == NULL) {
5503 EM_DEBUG_EXCEPTION("memory allocation for uid_range failed");
5504 err = EMAIL_ERROR_OUT_OF_MEMORY;
5508 uid_list_prev = uid_list_fast;
5510 if (uid_list_fast->next == NULL) {
5511 /* Single list entry */
5512 snprintf(uid_range, uid_range_size, "%d", atoi(uid_list_fast->uid));
5513 EM_DEBUG_LOG("uid_range [%d]", uid_range);
5515 /* forming range of uids to be passed */
5516 while (uid_list_fast != NULL) {
5517 /* uid_list_fast = uid_list_fast->next; */
5519 if ((uid_list_fast->next != NULL) && (((atoi(uid_list_prev->uid)) - (atoi(uid_list_fast->next->uid))) == 1)) {
5520 index += snprintf(uid_range+index, uid_range_size, "%d", atoi(uid_list_prev->uid));
5522 uid_list_fast = uid_list_fast->next;
5523 uid_list_prev = uid_list_fast;
5525 /* to make UID range string "abc, XX : YY" */
5526 while (uid_list_fast != NULL) {
5527 if (uid_list_fast->next == NULL)
5529 if (((atoi(uid_list_prev->uid)) - (atoi(uid_list_fast->next->uid))) == 1) {
5530 uid_list_fast = uid_list_fast->next;
5531 uid_list_prev = uid_list_fast;
5535 if ((uid_list_fast != NULL) && (uid_list_fast->next != NULL))
5536 index += snprintf(uid_range+index, uid_range_size, ":%d,", atoi(uid_list_prev->uid));
5538 index += snprintf(uid_range+index, uid_range_size, ":%d", atoi(uid_list_prev->uid));
5540 uid_list_fast = uid_list_fast->next;
5541 uid_list_prev = uid_list_fast;
5543 if (uid_list_fast->next != NULL)
5544 index += snprintf(uid_range+index, uid_range_size, "%d,", atoi(uid_list_prev->uid));
5546 index += snprintf(uid_range+index, uid_range_size, "%d", atoi(uid_list_prev->uid));
5547 uid_list_fast = uid_list_fast->next;
5548 uid_list_prev = uid_list_fast;
5552 EM_DEBUG_LOG("index [%d]", index);
5554 *output_uid_range_string = uid_range;
5558 EM_DEBUG_FUNC_END("err [%d]", err);