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__ */
63 #include <curl/curl.h>
65 #include <contacts_internal.h>
67 #include "email-types.h"
68 #include "email-core-global.h"
69 #include "email-core-utils.h"
70 #include "email-debug-log.h"
71 #include "email-core-mail.h"
72 #include "email-core-event.h"
73 #include "email-core-mailbox.h"
74 #include "email-core-account.h"
75 #include "email-core-mailbox-sync.h"
76 #include "email-core-mime.h"
77 #include "email-core-gmime.h"
78 #include "email-core-signal.h"
79 #include "email-daemon.h"
80 #include "email-utilities.h"
81 #include "email-convert.h"
82 #include "email-internal-types.h"
83 #include "email-device.h"
84 #include "email-core-container.h"
87 #include "email-dbus-activation.h"
90 #include <app_control.h>
91 #include <app_control_internal.h>
93 #define LED_TIMEOUT_SECS 12
94 #define G_DISPLAY_LENGTH 256
96 #define DIR_SEPERATOR_CH '/'
97 #define EMAIL_CH_QUOT '"'
98 #define EMAIL_CH_BRACKET_S '<'
99 #define EMAIL_CH_BRACKET_E '>'
100 #define EMAIL_CH_COMMA ','
101 #define EMAIL_CH_SEMICOLON ';'
102 #define EMAIL_CH_ROUND_BRACKET_S '('
103 #define EMAIL_CH_ROUND_BRACKET_E ')'
104 #define EMAIL_CH_SQUARE_BRACKET_S '['
105 #define EMAIL_CH_SQUARE_BRACKET_E ']'
106 #define EMAIL_CH_SPACE ' '
107 #define EMAIL_NOTI_ICON_PATH "/usr/apps/org.tizen.quickpanel/shared/res/noti_icons/noti_email.png"
108 #define EMAIL_NOTI_INDICATOR_ICON_PATH "/usr/apps/org.tizen.indicator/res/icons/Event/B03_Event_email.png"
109 #define EMAIL_NOTI_MAX_MAIL_ID 100
112 typedef struct _em_transaction_info_type_t {
115 struct _em_transaction_info_type_t *next;
117 } em_transaction_info_type_t;
119 em_transaction_info_type_t *g_transaction_info_list;
121 __thread email_session_t g_session = {0};
122 static notification_h g_sending_noti_handle = NULL;
123 typedef struct emcore_account_list_t emcore_account_list_t;
124 struct emcore_account_list_t {
125 email_account_t *account;
126 emcore_account_list_t *next;
129 #include <gmime/gmime.h>
131 INTERNAL_FUNC char *emcore_convert_mutf7_to_utf8(char *mailbox_name)
133 EM_DEBUG_FUNC_BEGIN("mailbox_name[%p]", mailbox_name);
136 char *result_mailbox_name = NULL;
137 char *mutf7_text = NULL;
141 if (mailbox_name == NULL) {
142 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
146 EM_DEBUG_LOG_SEC("mailbox_name[%s]", mailbox_name);
148 cursor = mutf7_text = EM_SAFE_STRDUP(mailbox_name);
150 if (mutf7_text == NULL) {
151 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
155 for (; *cursor; ++cursor)
158 if (!is_base64) *cursor = '&';
176 cd = g_mime_iconv_open("UTF-8", "UTF-7");
179 result_mailbox_name = g_mime_iconv_strdup(cd, mutf7_text);
181 EM_DEBUG_LOG_SEC("result_mailbox_name[%s]", result_mailbox_name);
183 if (result_mailbox_name) {
184 cursor = result_mailbox_name;
185 for (; *cursor; ++cursor) {
198 result_mailbox_name = (char *)utf8_from_mutf7((unsigned char *)mailbox_name);
199 EM_DEBUG_LOG_SEC("result_mailbox_name[%s]", result_mailbox_name);
200 if (result_mailbox_name == NULL)
201 result_mailbox_name = EM_SAFE_STRDUP(mutf7_text);
204 EM_DEBUG_LOG_SEC("result_mailbox_name[%s]", result_mailbox_name);
207 g_mime_iconv_close(cd);
209 EM_SAFE_FREE(mutf7_text);
211 EM_DEBUG_FUNC_END("result_mailbox_name[%p]", result_mailbox_name);
212 return result_mailbox_name;
215 /* in smtp case, path argument must be ENCODED_PATH_SMTP */
216 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)
218 EM_PROFILE_BEGIN(emCorelongEncodedpath);
219 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);
222 int error = EMAIL_ERROR_NONE;
224 email_authentication_method_t authentication_method = 0;
226 size_t long_enc_path_len = 0;
228 if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) { /* imap or pop3 */
229 EM_DEBUG_LOG_SEC("account->incoming_server_address[%p]", account->incoming_server_address);
230 EM_DEBUG_LOG_SEC("account->incoming_server_address[%s]", account->incoming_server_address);
232 if (!account->incoming_server_address) {
233 EM_DEBUG_EXCEPTION("account->incoming_server_address is null");
234 error = EMAIL_ERROR_INVALID_ACCOUNT;
238 long_enc_path_len = EM_SAFE_STRLEN(account->incoming_server_address) + EM_SAFE_STRLEN(path) + 256; /*prevent 34357*/
240 *long_enc_path = em_malloc(long_enc_path_len);
241 if (!*long_enc_path) {
242 EM_DEBUG_EXCEPTION("malloc failed...");
243 error = EMAIL_ERROR_OUT_OF_MEMORY;
249 /* ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}my-mailbox" */
251 if (multi_user_name) {
252 SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d%s%s",
253 account->incoming_server_address,
254 account->incoming_server_port_number,
255 account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap",
257 TOKEN_FOR_MULTI_USER,
260 SNPRINTF(p, long_enc_path_len, "{%s:%d/%s/user=%d",
261 account->incoming_server_address,
262 account->incoming_server_port_number,
263 account->incoming_server_type == EMAIL_SERVER_TYPE_POP3 ? "pop3" : "imap",
264 account->account_id);
267 if (account->incoming_server_secure_connection & 0x01) {
268 strncat(p, "/ssl", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
269 /* strcat(p, "/tryssl"); */
270 } else if (account->incoming_server_secure_connection & 0x02) {
271 strncat(p, "/tls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
274 authentication_method = account->incoming_server_authentication_method;
276 if (account->incoming_server_requires_apop) {
277 strncat(p, "/apop", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
281 long_enc_path_len = EM_SAFE_STRLEN(account->outgoing_server_address) + 64;
283 *long_enc_path = em_malloc(EM_SAFE_STRLEN(account->outgoing_server_address) + 64);
284 if (!*long_enc_path) {
285 EM_DEBUG_EXCEPTION("\t malloc failed...\n");
287 error = EMAIL_ERROR_OUT_OF_MEMORY;
293 /* ex:"mail.test.com:25/smtp" */
295 SNPRINTF(p, long_enc_path_len, "%s:%d/%s",
296 account->outgoing_server_address,
297 account->outgoing_server_port_number,
300 if (account->outgoing_server_need_authentication > 0) {
301 if (multi_user_name) {
302 SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d%s%s",
304 TOKEN_FOR_MULTI_USER,
307 SNPRINTF(p + EM_SAFE_STRLEN(p), long_enc_path_len-(EM_SAFE_STRLEN(p)), "/user=%d",
308 account->account_id);
311 if (account->outgoing_server_need_authentication == EMAIL_AUTHENTICATION_METHOD_XOAUTH2) {
312 strncat(p, "/xoauth2", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
316 if (account->outgoing_server_secure_connection & 0x01) {
317 strncat(p, "/ssl/force_tls_v1_0", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
318 /* strcat(p, "/tryssl"); */
320 else if (account->outgoing_server_secure_connection & 0x02)
321 strncat(p, "/tls/force_tls_v1_0", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
323 strncat(p, "/notls", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
325 authentication_method = account->outgoing_server_need_authentication;
328 #ifdef FEATURE_CORE_DEBUG
329 strncat(p, "/debug", long_enc_path_len-(strlen("/debug")+1));
332 /* Authentication method */
333 switch(authentication_method) {
334 case EMAIL_AUTHENTICATION_METHOD_DEFAULT:
335 strncat(p, "/needauth", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
337 case EMAIL_AUTHENTICATION_METHOD_XOAUTH2:
338 strncat(p, "/xoauth2", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
340 case EMAIL_AUTHENTICATION_METHOD_NO_AUTH:
345 if (path == NULL || (path && strncmp(path, ENCODED_PATH_SMTP, EM_SAFE_STRLEN(ENCODED_PATH_SMTP)) != 0)) {
346 strncat(p, "}", long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
349 strncat(p, path, long_enc_path_len-(EM_SAFE_STRLEN(p)+1));
354 EM_DEBUG_LOG_SEC("long_enc_path [%s]", *long_enc_path);
362 if (err_code != NULL)
364 EM_PROFILE_END(emCorelongEncodedpath);
368 int emcore_get_long_encoded_path(char *multi_user_name, int account_id, char *path, int delimiter, char **long_enc_path, int *err_code)
370 EM_PROFILE_BEGIN(emCorelongEncodedpath);
371 EM_DEBUG_FUNC_BEGIN("account_id[%d], delimiter[%d], long_enc_path[%p], err_code[%p]", account_id, delimiter, long_enc_path, err_code);
374 int error = EMAIL_ERROR_NONE;
375 email_account_t *ref_account = NULL;
377 ref_account = emcore_get_account_reference(multi_user_name, account_id, false);
379 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", account_id);
380 error = EMAIL_ERROR_INVALID_ACCOUNT;
384 if (emcore_get_long_encoded_path_with_account_info(multi_user_name, ref_account, path, delimiter, long_enc_path, &error) == false) {
385 EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path_with_account_info failed [%d]", error);
394 emcore_free_account(ref_account);
395 EM_SAFE_FREE(ref_account);
398 if (err_code != NULL)
400 EM_PROFILE_END(emCorelongEncodedpath);
404 int emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code)
406 EM_DEBUG_FUNC_BEGIN_SEC("name[%s], enc_name[%p], err_code[%p]", name, enc_name, err_code);
408 if (!name || !enc_name) {
409 if (err_code != NULL)
410 *err_code = EMAIL_ERROR_INVALID_PARAM;
415 /* encoding mailbox name (Charset->UTF8->UTF7) */
416 char *last_slash = NULL;
417 char *last_word = NULL;
418 char *last_enc_word = NULL;
419 char *ret_enc_name = NULL;
420 int err = EMAIL_ERROR_NONE;
423 last_slash = rindex(name, '/');
424 last_word = (last_slash)? last_slash+1 : name;
426 EM_DEBUG_EXCEPTION("Wrong mailbox [%s]", name);
427 err = EMAIL_ERROR_INVALID_PARAM;
432 /* convert the last mailbox folder to utf7 char */
433 last_enc_word = (char*)utf8_to_mutf7 ((unsigned char*)last_word);
434 if (!last_enc_word) {
435 EM_DEBUG_EXCEPTION("utf8_to_mutf7 failed");
436 err = EMAIL_ERROR_INVALID_PARAM;
441 /* if last word of mailbox name is ASCII, use input */
442 if (!strcmp(last_enc_word, last_word)) {
443 EM_DEBUG_LOG_SEC("NOT UTF-8 [%s]", last_word);
444 ret_enc_name = strdup(name);
448 EM_DEBUG_LOG_SEC("UTF-7 [%s](%d)->[%s](%d)",last_word, strlen(last_word), last_enc_word, strlen(last_enc_word));
450 /* if last word of mailbox name is UTF-8, replace it */
451 /* it is not a subfolder */
453 ret_enc_name = strdup(last_enc_word);
455 else { /* it is a subfolder */
456 /*temprarily NULL assigned*/
458 int len = strlen(name) + 1 + strlen(last_enc_word); /* including '/' */
459 ret_enc_name = em_malloc(len + 1); /* NULL */
461 EM_DEBUG_EXCEPTION("malloc failed...");
462 err = EMAIL_ERROR_OUT_OF_MEMORY;
467 snprintf(ret_enc_name, len+1, "%s/%s", name, last_enc_word);
471 EM_DEBUG_LOG_SEC("utf-7 encoding complete!! name[%s], enc_name[%s]", name, ret_enc_name);
474 EM_SAFE_FREE(last_enc_word);
475 *enc_name = ret_enc_name;
476 if (err_code != NULL)
479 EM_DEBUG_FUNC_END("result [%s]", *enc_name);
483 int emcore_get_temp_file_name(char **filename, int *err_code)
485 EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code);
488 int error = EMAIL_ERROR_NONE;
490 if (filename == NULL) {
491 EM_DEBUG_EXCEPTION("\t filename[%p]\n", filename);
492 error = EMAIL_ERROR_INVALID_PARAM;
496 char tempname[512] = {0x00, };
500 gettimeofday(&tv, NULL);
503 /* Create Directory If deleted by user*/
504 emstorage_create_dir_if_delete();
506 SNPRINTF(tempname, sizeof(tempname), "%s%c%d", MAILTEMP, DIR_SEPERATOR_CH, rand());
508 char *p = EM_SAFE_STRDUP(tempname);
510 EM_DEBUG_EXCEPTION("\t strdup failed...\n");
511 error = EMAIL_ERROR_OUT_OF_MEMORY;
520 if (err_code != NULL)
526 int emcore_get_file_name(char *path, char **filename, int *err_code)
528 EM_DEBUG_FUNC_BEGIN_SEC("path[%s], filename[%p], err_code[%p]", path, filename, err_code);
531 int error = EMAIL_ERROR_NONE;
533 if (!path || !filename) {
534 EM_DEBUG_EXCEPTION("path[%p], filename[%p]", path, filename);
536 error = EMAIL_ERROR_INVALID_PARAM;
540 int i = (int)EM_SAFE_STRLEN(path);
544 if (path[i] == DIR_SEPERATOR_CH)
547 *filename = path + i + 1;
552 if (err_code != NULL)
558 INTERNAL_FUNC int emcore_get_file_size(char *path, int *size, int *err_code)
560 EM_DEBUG_FUNC_BEGIN("path[%s], size[%p], err_code[%p]", path, size, err_code);
563 int error = EMAIL_ERROR_NONE;
565 if ((path == NULL) || (size == NULL)) {
566 EM_DEBUG_EXCEPTION("\t path[%p], size[%p]\n", path, size);
568 error = EMAIL_ERROR_INVALID_PARAM;
574 if (stat(path, &st_buf) < 0) {
575 EM_DEBUG_EXCEPTION("\t stat failed - %s\n", path);
577 error = EMAIL_ERROR_SYSTEM_FAILURE;
581 *size = st_buf.st_size;
586 if (err_code != NULL)
592 INTERNAL_FUNC int emcore_check_drm_file(char *path, int *err_code)
594 EM_DEBUG_FUNC_BEGIN("path[%s], err_code[%p]", path, err_code);
597 int error = EMAIL_ERROR_NONE;
600 EM_DEBUG_EXCEPTION("path[%p]", path);
601 error = EMAIL_ERROR_INVALID_PARAM;
605 #ifdef __FEATURE_USE_DRM_API__
607 drm_bool_type_e isdrm;
608 drm_ret = drm_is_drm_file(path, &isdrm);
609 if (drm_ret != DRM_RETURN_SUCCESS || isdrm != DRM_TRUE) {
610 EM_DEBUG_LOG("file is not drm file");
611 error = EMAIL_ERROR_SYSTEM_FAILURE;
616 #endif /* __FEATURE_USE_DRM_API__ */
620 if (err_code != NULL)
627 INTERNAL_FUNC int emcore_check_drm_is_ringtone(char *ringtone_path, int *err_code)
629 EM_DEBUG_FUNC_BEGIN("ringtone_path[%s], err_code[%p]", ringtone_path, err_code);
632 int error = EMAIL_ERROR_NONE;
634 if (ringtone_path == NULL) {
635 EM_DEBUG_EXCEPTION("path[%p]", ringtone_path);
636 error = EMAIL_ERROR_INVALID_PARAM;
640 #ifdef __FEATURE_USE_DRM_API__
642 drm_bool_type_e allowed = DRM_UNKNOWN;
643 drm_action_allowed_data_s data;
644 memset(&data, 0x00, sizeof(drm_action_allowed_data_s));
645 strncpy(data.file_path, ringtone_path, strlen(ringtone_path));
646 data.data = (int)DRM_SETAS_RINGTONE;
648 drm_ret = drm_is_action_allowed(DRM_HAS_VALID_SETAS_STATUS, &data, &allowed);
650 if (drm_ret != DRM_RETURN_SUCCESS || allowed != DRM_TRUE) {
651 EM_DEBUG_LOG("fail to drm_is_action_allowed [0x%x]", drm_ret);
652 error = EMAIL_ERROR_SYSTEM_FAILURE;
656 EM_DEBUG_LOG("allowed [DRM_TRUE]");
658 #endif /* __FEATURE_USE_DRM_API__ */
662 if (err_code != NULL)
669 static int _emcore_check_host(char *host)
673 return strncmp(host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."));
678 int emcore_get_address_count(char *addr_str, int *count, int *err_code)
680 EM_DEBUG_FUNC_BEGIN("addr_str[%s], count[%p], err_code[%p]", addr_str, count, err_code);
683 int error = EMAIL_ERROR_NONE;
685 ADDRESS *addr = NULL;
686 ADDRESS *p_addr = NULL;
692 EM_DEBUG_EXCEPTION("addr_str[%s], count[%p]", addr_str, count);
693 error = EMAIL_ERROR_INVALID_PARAM;
697 if (addr_str != NULL) {
698 em_skip_whitespace(addr_str, &p);
699 EM_DEBUG_LOG("em_skip_whitespace[p][%s]", p);
702 for (i = 0, j = EM_SAFE_STRLEN(p); i < j; i++)
703 if (p[i] == ';') p[i] = ',';
704 rfc822_parse_adrlist(&addr, p, NULL);
708 for (p_addr = addr, i = 0; p_addr; p_addr = p_addr->next, i++) {
709 if (p_addr->mailbox && p_addr->host) {
710 if (!strncmp(p_addr->mailbox, "UNEXPECTED_DATA_AFTER_ADDRESS", strlen("UNEXPECTED_DATA_AFTER_ADDRESS"))
711 || !strncmp(p_addr->mailbox, "INVALID_ADDRESS", strlen("INVALID_ADDRESS"))
712 || !strncmp(p_addr->host, ".SYNTAX-ERROR.", strlen(".SYNTAX-ERROR."))) { /*prevent 34356*/
713 EM_DEBUG_LOG("Invalid address ");
717 if ((!p_addr->mailbox) || (_emcore_check_host(p_addr->host) == 0)) {
718 EM_DEBUG_EXCEPTION_SEC("\t invalid address : mailbox[%s], host[%s]\n", p_addr->mailbox, p_addr->host);
720 error = EMAIL_ERROR_INVALID_ADDRESS;
721 /* goto FINISH_OFF; */
727 if (error != EMAIL_ERROR_INVALID_ADDRESS)
732 mail_free_address(&addr);
734 if (err_code != NULL)
740 INTERNAL_FUNC int emcore_set_network_error(int err_code)
742 email_session_t *session = NULL;
744 EM_DEBUG_FUNC_BEGIN();
746 emcore_get_current_session(&session);
751 session->network = err_code;
756 INTERNAL_FUNC int emcore_get_empty_session(email_session_t **session)
758 EM_DEBUG_FUNC_BEGIN("session[%p]", session);
760 *session = &g_session;
766 INTERNAL_FUNC int emcore_clear_session(email_session_t *session)
768 EM_DEBUG_FUNC_BEGIN();
771 memset (session, 0x00, sizeof(email_session_t));
777 INTERNAL_FUNC int emcore_get_current_session(email_session_t **session)
779 EM_DEBUG_FUNC_BEGIN("session[%p]", session);
781 *session = &g_session;
787 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)
789 EM_DEBUG_FUNC_BEGIN("account_id : [%d], mailbox_type : [%d], priority_sender : [%d]", account_id, mailbox_type, priority_sender);
792 int err = EMAIL_ERROR_NONE;
794 int type = EMAIL_PRIORITY_SENDER;
795 int unread_count = 0;
797 char *conditional_clause_string = NULL;
800 int is_completed = 0;
801 emstorage_rule_tbl_t *rule = NULL;
803 int filter_count = 0;
804 email_list_filter_t *filter_list = NULL;
807 if (priority_sender) {
808 if (!emstorage_get_rule(multi_user_name, ALL_ACCOUNT, type, 0, &rule_count, &is_completed, &rule, true, &err)) {
809 EM_DEBUG_EXCEPTION("emstorage_get_rule failed");
812 if (err == EMAIL_ERROR_FILTER_NOT_FOUND) {
813 EM_DEBUG_LOG("no rule found");
814 ret = true; /*it is not an error*/
819 EM_DEBUG_LOG_DEV ("rule count [%d]", rule_count);
821 /* Make query for searching unread mail */
822 filter_count = 3; /* unseen field requires one filter, "flags_seen_field = 0"
823 and "deleted_flag = 0" */
826 filter_count += (rule_count * 2) + 2; /* one rule requires two filters,"A" "OR", plus two more operator "(" and ")" */
829 if (account_id != ALL_ACCOUNT) {
830 filter_count += 2; /* two filters, "AND" "account_id = x" */
834 filter_count += 2; /* two filters, "AND" "mailbox_type = x" */
836 filter_list = em_malloc(sizeof(email_list_filter_t) * filter_count);
837 if (filter_list == NULL) {
838 EM_DEBUG_EXCEPTION("em_malloc failed");
839 err = EMAIL_ERROR_OUT_OF_MEMORY;
845 /* priority sender only, convert one rule to two filters which is composed of from_address and or/and */
846 /* example: ( from_A OR from_B ) AND ... */
847 if (rule_count > 0) {
848 /* first, add left parenthesis to from address clause, "(" */
849 filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
850 filter_list[0].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_LEFT_PARENTHESIS;
852 for (i = 0; i < rule_count; i++) {
853 /*array at odd index(1, 3, 5,..) has rule values, "from_A" */
855 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
856 filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
857 filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FROM;
858 filter_list[k].list_filter_item.rule.key_value.string_type_value = EM_SAFE_STRDUP(rule[i].value2);
860 /*array at even index(2, 4, 6,..) has either AND ,or OR*/
861 if (i != (rule_count - 1)) { /*if it is not the last rule, "OR" */
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_OR;
865 } else { /* ")" "AND" */
866 filter_list[++k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
867 filter_list[k].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_RIGHT_PARENTHESIS;
869 filter_list[++k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
870 filter_list[k].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
876 /*rule value, unseen +1*/
877 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
878 filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
879 filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD;
880 filter_list[k++].list_filter_item.rule.key_value.integer_type_value = 0;
882 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
883 filter_list[k++].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
885 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
886 filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_NOT_EQUAL;
887 filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS;
888 filter_list[k++].list_filter_item.rule.key_value.integer_type_value = EMAIL_MAIL_STATUS_SAVED_OFFLINE;
890 /*account_id requires two filters*/
891 if (account_id != ALL_ACCOUNT) {
892 /* odd index, logical operator */
893 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
894 filter_list[k++].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
896 /* even index, rule value */
897 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
898 filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
899 filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID;
900 filter_list[k++].list_filter_item.rule.key_value.integer_type_value = account_id;
903 /*mailbox_type requires two filters*/
905 /* odd index, logical operator */
906 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
907 filter_list[k++].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
909 /* even index, rule value */
910 filter_list[k].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
911 filter_list[k].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
912 filter_list[k].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE;
913 filter_list[k++].list_filter_item.rule.key_value.integer_type_value = mailbox_type;
916 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) {
917 EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
921 EM_DEBUG_LOG_DEV ("conditional_clause_string[%s]", conditional_clause_string);
923 /* Search the mail of priority sender in DB */
924 if ((err = emstorage_query_mail_count(multi_user_name, conditional_clause_string, true, &total_count, &unread_count)) != EMAIL_ERROR_NONE) {
925 EM_DEBUG_EXCEPTION("emstorage_query_mail_count failed:[%d]", err);
934 emstorage_free_rule(&rule, rule_count, NULL);
937 emstorage_free_list_filter(&filter_list, filter_count);
939 EM_SAFE_FREE(conditional_clause_string);
942 *total_mail = total_count;
945 *unread_mail = unread_count;
953 INTERNAL_FUNC int emcore_display_badge_count(char *multi_user_name, int count)
955 EM_DEBUG_FUNC_BEGIN();
957 int err = EMAIL_ERROR_NONE;
958 badge_error_e badge_err = BADGE_ERROR_NONE;
960 void *join_zone = NULL;
962 if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
963 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
967 if((badge_err = badge_is_existing("org.tizen.email", &exist)) != BADGE_ERROR_NONE) {
968 EM_DEBUG_EXCEPTION("badge_is_existing failed [%d]", badge_err);
969 err = EMAIL_ERROR_BADGE_API_FAILED;
975 if((badge_err = badge_create("org.tizen.email", "/usr/bin/email-service")) != BADGE_ERROR_NONE) {
976 EM_DEBUG_EXCEPTION("badge_create failed [%d]", badge_err);
977 err = EMAIL_ERROR_BADGE_API_FAILED;
982 if((badge_err = badge_set_count("org.tizen.email", count)) != BADGE_ERROR_NONE) {
983 EM_DEBUG_EXCEPTION("badge_set_count failed [%d]", badge_err);
984 if (badge_err != BADGE_ERROR_SERVICE_NOT_READY) {
985 err = EMAIL_ERROR_BADGE_API_FAILED;
989 /* Badge callback function : When the badge service ready, call the callback function */
990 badge_err = badge_add_deferred_task(emcore_display_unread_in_badge, NULL);
991 if (badge_err != BADGE_ERROR_NONE) {
992 EM_DEBUG_EXCEPTION("badge_add_deferred_task failed : [%d]", badge_err);
993 err = EMAIL_ERROR_BADGE_API_FAILED;
1001 emcore_unset_join_zone(join_zone);
1003 EM_DEBUG_FUNC_END();
1007 void emcore_display_unread_in_badge(void *data)
1009 EM_DEBUG_FUNC_BEGIN();
1011 int err = EMAIL_ERROR_NONE;
1012 int total_unread_count = 0;
1013 int total_mail_count = 0;
1016 if (!emcore_get_mail_count_by_query((char *)data, ALL_ACCOUNT,
1017 EMAIL_MAILBOX_TYPE_INBOX, 0,
1018 &total_mail_count, &total_unread_count,
1020 EM_DEBUG_EXCEPTION("emcore_get_mail_count_by_query failed");
1024 unseen = total_unread_count;
1029 if ((err = emcore_display_badge_count((char *)data, 0)) != EMAIL_ERROR_NONE) {
1030 EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err);
1033 if ((err = emcore_display_badge_count((char *)data, unseen)) != EMAIL_ERROR_NONE) {
1034 EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err);
1038 EM_DEBUG_FUNC_END();
1041 static int emcore_layout_multi_noti(notification_h noti, int unread_mail, char *email_address, char *account_name)
1043 EM_DEBUG_FUNC_BEGIN("unread_count %d", unread_mail);
1044 char temp_buffer[512] = {0};
1045 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1047 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
1048 if (noti_err != NOTIFICATION_ERROR_NONE) {
1049 EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_MULTIPLE failed [%d]", noti_err);
1053 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);
1054 if (noti_err != NOTIFICATION_ERROR_NONE) {
1055 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
1059 SNPRINTF(temp_buffer, sizeof(temp_buffer), "%d", unread_mail);
1060 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, temp_buffer, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1061 if (noti_err != NOTIFICATION_ERROR_NONE) {
1062 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_EVENT_COUNT failed");
1067 SNPRINTF(temp_buffer, sizeof(temp_buffer), "%s, %s", email_address, account_name);
1069 SNPRINTF(temp_buffer, sizeof(temp_buffer), "%s", email_address);
1071 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, temp_buffer, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1072 if (noti_err != NOTIFICATION_ERROR_NONE) {
1073 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
1077 noti_err = notification_set_time(noti, time(NULL));
1078 if (noti_err != NOTIFICATION_ERROR_NONE) {
1079 EM_DEBUG_EXCEPTION("notification_set_time failed");
1083 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH);
1084 if (noti_err != NOTIFICATION_ERROR_NONE) {
1085 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1089 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, EMAIL_NOTI_INDICATOR_ICON_PATH);
1090 if (noti_err != NOTIFICATION_ERROR_NONE) {
1091 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1095 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, EMAIL_NOTI_ICON_PATH);
1096 if (noti_err != NOTIFICATION_ERROR_NONE) {
1097 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1103 EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err);
1107 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)
1109 EM_DEBUG_FUNC_BEGIN();
1110 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1112 noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
1113 if (noti_err != NOTIFICATION_ERROR_NONE) {
1114 EM_DEBUG_EXCEPTION("notification_set_layout NOTI_EVENT_SINGLE failed [%d]", noti_err);
1119 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Email", dgettext(NATIVE_EMAIL_DOMAIN,"IDS_ST_HEADER_EMAIL"), NOTIFICATION_VARIABLE_TYPE_NONE);
1121 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, display_sender, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1123 if (noti_err != NOTIFICATION_ERROR_NONE) {
1124 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_TITLE failed");
1128 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, account_name, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1129 if (noti_err != NOTIFICATION_ERROR_NONE) {
1130 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
1135 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, NULL, display_sender, NOTIFICATION_VARIABLE_TYPE_NONE);
1137 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, display_sender, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1139 if (noti_err != NOTIFICATION_ERROR_NONE) {
1140 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_CONTENT failed");
1145 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
1147 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);
1149 if (noti_err != NOTIFICATION_ERROR_NONE) {
1150 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
1154 noti_err = notification_set_time(noti, time);
1155 if (noti_err != NOTIFICATION_ERROR_NONE) {
1156 EM_DEBUG_EXCEPTION("notification_set_time failed");
1160 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH);
1161 if (noti_err != NOTIFICATION_ERROR_NONE) {
1162 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1166 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, EMAIL_NOTI_INDICATOR_ICON_PATH);
1167 if (noti_err != NOTIFICATION_ERROR_NONE) {
1168 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1172 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, EMAIL_NOTI_ICON_PATH);
1173 if (noti_err != NOTIFICATION_ERROR_NONE) {
1174 EM_DEBUG_EXCEPTION("notification_set_image TYPE_ICON failed");
1179 EM_DEBUG_FUNC_END("noti_err : [%d]", noti_err);
1183 static int emcore_get_alert_type(int vibrate_status)
1185 EM_DEBUG_FUNC_BEGIN();
1186 int global_sound_status = 0;
1187 int global_vibe_status = 0;
1188 int email_vibe_status = 0;
1190 int alert_type = EMAIL_ALERT_TYPE_MUTE;
1191 #ifdef __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__
1192 int voicerecoder_state = 0;
1193 #endif /* __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__ */
1195 if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &global_sound_status) != 0) {
1196 EM_DEBUG_LOG("vconf_get_bool for VCONFKEY_SETAPPL_SOUND_STATUS_BOOL failed");
1200 if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &global_vibe_status) != 0) {
1201 EM_DEBUG_LOG("vconf_get_bool for VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOLfailed");
1205 EM_DEBUG_LOG("global_sound_status [%d] global_vibe_status [%d]", global_sound_status, global_vibe_status);
1207 if (global_sound_status || global_vibe_status) {
1208 #ifdef __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__
1209 if (vconf_get_int(VCONFKEY_VOICERECORDER_STATE, &voicerecoder_state) != 0) {
1210 EM_DEBUG_LOG("vconf_get_int for VCONFKEY_VOICERECORDER_STATE failed");
1212 EM_DEBUG_LOG("voicerecoder_state [%d]", voicerecoder_state);
1213 #endif /* __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__ */
1215 if (vconf_get_int(VCONFKEY_CALL_STATE, &call_state) != 0) {
1216 EM_DEBUG_LOG("vconf_get_int for VCONFKEY_CALL_STATE failed");
1218 EM_DEBUG_LOG("call_state [%d] ", call_state);
1220 email_vibe_status = vibrate_status;
1222 EM_DEBUG_LOG("email_vibe_status [%d] ", email_vibe_status);
1223 #ifdef __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__
1224 if (voicerecoder_state == VCONFKEY_VOICERECORDER_RECORDING) {
1225 alert_type = EMAIL_ALERT_TYPE_VIB;
1226 EM_DEBUG_LOG("voice recorder is on recording...");
1228 /* else if (call_state > VCONFKEY_CALL_OFF && call_state < VCONFKEY_CALL_STATE_MAX) { */
1229 #endif /* __FEATURE_VOICERECORDER_STATUS_FOR_NOTI__ */
1231 if (call_state > VCONFKEY_CALL_OFF && call_state < VCONFKEY_CALL_STATE_MAX) {
1232 EM_DEBUG_LOG("Calling");
1233 if (global_sound_status)
1234 alert_type = EMAIL_ALERT_TYPE_MELODY;
1236 alert_type = EMAIL_ALERT_TYPE_NONE;
1238 else if (global_sound_status && email_vibe_status) {
1239 alert_type = EMAIL_ALERT_TYPE_MELODY_AND_VIB;
1241 else if (global_sound_status) {
1242 alert_type = EMAIL_ALERT_TYPE_MELODY;
1244 else if (global_vibe_status) {
1245 alert_type = EMAIL_ALERT_TYPE_VIB;
1251 EM_DEBUG_FUNC_END("alert_type [%d]", alert_type);
1255 static char *emcore_get_sound_file_path(int default_ringtone_status, char *alert_ringtone_path)
1257 EM_DEBUG_FUNC_BEGIN();
1259 int use_default_ring_tone = 0;
1261 use_default_ring_tone = default_ringtone_status;
1263 EM_DEBUG_LOG("use_default_ring_tone [%d]", use_default_ring_tone);
1265 if (use_default_ring_tone)
1266 ret = vconf_get_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
1268 ret = EM_SAFE_STRDUP(alert_ringtone_path);
1270 if ((emcore_check_drm_file(ret, NULL)) && (!emcore_check_drm_is_ringtone(ret, NULL))) {
1271 EM_DEBUG_LOG_DEV("The ringtone is not allowed DRM. : [%s]", ret);
1273 ret = EM_SAFE_STRDUP(vconf_get_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR));
1276 EM_DEBUG_FUNC_END("ret [%s]", ret);
1280 #if 0 //using notification_status_message_post instead of calling email-app toast - change date: 30/9/2014
1281 INTERNAL_FUNC int emcore_show_toast_popup(char *input_popup_string)
1283 int err = EMAIL_ERROR_NONE;
1284 int ret = APP_CONTROL_ERROR_NONE;
1285 app_control_h svc_handle = NULL;
1287 ret = app_control_create(&svc_handle);
1289 if (ret != APP_CONTROL_ERROR_NONE || !svc_handle) {
1290 EM_DEBUG_LOG("app_control_create() failed! ret:[%d]", ret);
1291 err = EMAIL_ERROR_SYSTEM_FAILURE;
1295 ret = app_control_set_app_id(svc_handle, "org.tizen.email-tts-play");
1296 if (ret != APP_CONTROL_ERROR_NONE) {
1297 EM_DEBUG_LOG("app_control_set_app_id() failed! ret:[%d]", ret);
1298 err = EMAIL_ERROR_SYSTEM_FAILURE;
1302 ret = app_control_add_extra_data(svc_handle, "email_misc_work_type", "1003");
1303 if (ret != APP_CONTROL_ERROR_NONE) {
1304 EM_DEBUG_LOG("app_control_add_extra_data() failed! ret:[%d]", ret);
1305 err = EMAIL_ERROR_SYSTEM_FAILURE;
1309 ret = app_control_add_extra_data(svc_handle, "popup_string", input_popup_string);
1310 if (ret != APP_CONTROL_ERROR_NONE) {
1311 EM_DEBUG_LOG("app_control_add_extra_data() failed! ret:[%d]", ret);
1312 err = EMAIL_ERROR_SYSTEM_FAILURE;
1316 ret = app_control_send_launch_request(svc_handle, NULL, NULL);
1317 if (ret != APP_CONTROL_ERROR_NONE) {
1318 EM_DEBUG_LOG("app_control_send_launch_request() failed! ret:[%d]", ret);
1319 err = EMAIL_ERROR_SYSTEM_FAILURE;
1326 ret = app_control_destroy(svc_handle);
1327 if (ret != APP_CONTROL_ERROR_NONE) {
1328 EM_DEBUG_LOG("app_control_destroy() failed! ret:[%d]", ret);
1329 err = EMAIL_ERROR_SYSTEM_FAILURE;
1338 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)
1340 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 );
1341 int err = EMAIL_ERROR_NONE;
1342 #ifdef __FEATURE_NOTIFICATION_ENABLE__
1348 int unread_mail_count_t = 0;
1349 char *mailbox_name = NULL;
1350 char vconf_private_id[MAX_PATH] = {0, };
1351 notification_h noti = NULL;
1352 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1353 notification_vibration_type_e noti_vibe_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1354 emstorage_account_tbl_t *account_tbl = NULL;
1355 emstorage_mail_tbl_t *p_mail_data = NULL;
1356 int display_status = false;
1357 EMAIL_ALERT_TYPE alert_type = EMAIL_ALERT_TYPE_NONE;
1358 char *alert_tone_path = NULL;
1359 void *join_zone = NULL;
1361 /* For service bundle */
1362 char buf[256] = {0,};
1363 char **value = NULL;
1364 app_control_h service = NULL;
1367 if (!emstorage_get_account_by_id(multi_user_name, account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_tbl, true, &err)) {
1368 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err);
1372 if (!account_tbl->options.notification_status) {
1373 EM_DEBUG_LOG("Notification disabled");
1377 /* Get the unread mail id */
1378 if (!emstorage_get_unread_mailid(multi_user_name, account_id, 0, &p_mail_id, &unread_mail_count_t, &err)) {
1379 EM_DEBUG_EXCEPTION("emstorage_get_unread_mailid failed [%d]", err);
1383 unseen = unread_mail_count_t;
1384 display_status = account_tbl->options.display_content_status;
1386 /* Load the previous noti */
1387 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1388 if (vconf_get_int(vconf_private_id, &private_id) != 0) {
1389 EM_DEBUG_EXCEPTION("vconf_get_int failed");
1392 /* Turn display on to blink LED */
1393 // emdevice_change_display_state(DISPLAY_STATE_ON);
1395 if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
1396 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
1400 noti = notification_load(NULL, private_id);
1402 EM_DEBUG_EXCEPTION("notification_load failed");
1403 noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
1405 EM_DEBUG_EXCEPTION("notification_new failed");
1406 err = EMAIL_ERROR_SYSTEM_FAILURE;
1410 if ((noti_err = notification_set_pkgname(noti, NATIVE_EMAIL_APPLICATION_PKG)) != NOTIFICATION_ERROR_NONE) {
1411 EM_DEBUG_EXCEPTION("notification_set_pkgname failed [%d]", noti_err);
1412 err = EMAIL_ERROR_SYSTEM_FAILURE;
1419 if (input_play_alert_tone) {
1420 alert_type = emcore_get_alert_type(account_tbl->options.vibrate_status);
1422 if (alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_MELODY)
1423 alert_tone_path = emcore_get_sound_file_path(account_tbl->options.default_ringtone_status, account_tbl->options.alert_ringtone_path);
1426 /* blocking mode : */
1427 #ifdef __FEATURE_BLOCKING_MODE__
1428 if (!emcore_get_blocking_mode_status()) {
1429 #endif /* __FEATURE_BLOCKING_MODE__ */
1430 if ((noti_err = notification_set_led_time_period(noti, 250, 2500)) != NOTIFICATION_ERROR_NONE) {
1431 EM_DEBUG_EXCEPTION("notification_set_led_time_period failed [%d]", noti_err);
1432 err = EMAIL_ERROR_SYSTEM_FAILURE;
1436 if ((noti_err = notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00)) != NOTIFICATION_ERROR_NONE) {
1437 EM_DEBUG_EXCEPTION("notification_set_led failed [%d]", noti_err);
1438 err = EMAIL_ERROR_SYSTEM_FAILURE;
1442 if ((alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_MELODY) && EM_SAFE_STRLEN(alert_tone_path)) {
1443 if(strcmp(alert_tone_path, "silent") == 0) {
1444 if ((noti_err = notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL)) != NOTIFICATION_ERROR_NONE) {
1445 EM_DEBUG_EXCEPTION("notification_set_sound failed [%d]", noti_err);
1446 err = EMAIL_ERROR_SYSTEM_FAILURE;
1450 if ((noti_err = notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_USER_DATA, alert_tone_path)) != NOTIFICATION_ERROR_NONE) {
1451 EM_DEBUG_EXCEPTION("notification_set_sound failed [%d]", noti_err);
1452 err = EMAIL_ERROR_SYSTEM_FAILURE;
1457 #ifdef __FEATURE_BLOCKING_MODE__
1459 #endif /* __FEATURE_BLOCKING_MODE__ */
1461 if (alert_type == EMAIL_ALERT_TYPE_MELODY_AND_VIB || alert_type == EMAIL_ALERT_TYPE_VIB)
1462 noti_vibe_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1464 if ((noti_err = notification_set_vibration(noti, noti_vibe_type, NULL)) != NOTIFICATION_ERROR_NONE) {
1465 EM_DEBUG_EXCEPTION("notification_set_vibration failed [%d]", noti_err);
1466 err = EMAIL_ERROR_SYSTEM_FAILURE;
1470 if ((noti_err = notification_set_text_domain(noti, NATIVE_EMAIL_DOMAIN, "/usr/apps/org.tizen.email/res/locale")) != NOTIFICATION_ERROR_NONE) {
1471 EM_DEBUG_EXCEPTION("notification_set_text_domain failed [%d]", noti_err);
1472 err = EMAIL_ERROR_SYSTEM_FAILURE;
1476 if (!emstorage_get_mailbox_name_by_mailbox_type(multi_user_name, account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_name, false, &err)) {
1477 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
1481 EM_DEBUG_LOG("unseen [%d] display_status [%d]", unseen, display_status);
1483 /* set execution option to launch email-viewer when single incoming mail*/
1484 app_control_create(&service);
1486 EM_DEBUG_EXCEPTION("service create failed");
1490 if (!emstorage_get_mail_by_id(multi_user_name, p_mail_id[0], &p_mail_data, false, &err)) {
1491 EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
1495 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);
1496 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) {
1497 EM_DEBUG_EXCEPTION("notification_layout_single_noti failed [%d]", noti_err);
1498 err = EMAIL_ERROR_SYSTEM_FAILURE;
1502 snprintf(buf, sizeof(buf), "%d", 12);
1503 app_control_add_extra_data(service, "RUN_TYPE", buf);
1504 snprintf(buf, sizeof(buf), "%d", account_id);
1505 app_control_add_extra_data(service, "ACCOUNT_ID", buf);
1506 snprintf(buf, sizeof(buf), "%d", p_mail_data->mail_id);
1507 app_control_add_extra_data(service, "MAIL_ID", buf);
1508 snprintf(buf, sizeof(buf), "%d", p_mail_data->mailbox_id);
1509 app_control_add_extra_data(service, "MAILBOX_ID", buf);
1510 app_control_set_app_id(service, NATIVE_EMAIL_APPLICATION_PKG);
1512 app_control_to_bundle(service, &b);
1513 noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1514 if (noti_err != NOTIFICATION_ERROR_NONE) {
1515 EM_DEBUG_EXCEPTION("notification_set_execute_option failed [%d]", noti_err);
1516 err = EMAIL_ERROR_SYSTEM_FAILURE;
1519 } else if (unseen > 1) {
1520 EM_DEBUG_LOG_SEC("multi layout: unseen[%d], address[%s], account_name[%s]", unseen, account_tbl->user_email_address, account_tbl->account_name);
1521 if ((noti_err = emcore_layout_multi_noti(noti, unseen, account_tbl->user_email_address, account_tbl->account_name)) != NOTIFICATION_ERROR_NONE) {
1522 EM_DEBUG_EXCEPTION("notification_layout_multi_noti failed [%d]", noti_err);
1523 err = EMAIL_ERROR_SYSTEM_FAILURE;
1527 snprintf(buf, sizeof(buf), "%d", 13);
1528 app_control_add_extra_data(service, "RUN_TYPE", buf);
1529 snprintf(buf, sizeof(buf), "%d", account_id);
1530 app_control_add_extra_data(service, "ACCOUNT_ID", buf);
1532 if (unseen > EMAIL_NOTI_MAX_MAIL_ID)
1533 unseen = EMAIL_NOTI_MAX_MAIL_ID;
1534 value = (char **)em_malloc(unseen * sizeof(char *));
1535 if (value == NULL) {
1536 EM_DEBUG_EXCEPTION("em_malloc failed");
1537 err = EMAIL_ERROR_OUT_OF_MEMORY;
1541 for (i = 0; i < unseen; i++) {
1542 memset(buf, 0x00, sizeof(buf));
1543 snprintf(buf, sizeof(buf), "%d", p_mail_id[i]);
1544 value[i] = EM_SAFE_STRDUP(buf);
1546 app_control_add_extra_data_array(service, "MAIL_ID", (const char **)value, unseen);
1547 app_control_set_app_id(service, NATIVE_EMAIL_APPLICATION_PKG);
1549 app_control_to_bundle(service, &b);
1550 noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, b);
1551 if (noti_err != NOTIFICATION_ERROR_NONE) {
1552 EM_DEBUG_EXCEPTION("notification_set_execute_option failed [%d]", noti_err);
1553 err = EMAIL_ERROR_SYSTEM_FAILURE;
1556 } else { /* if priority sender exists and no mail of priority sender, unseen will be 0*/
1557 EM_DEBUG_LOG("-unseen: [%d]", unseen);
1559 /* err = EMAIL_ERROR_PRIORITY_SENDER_MAIL_NOT_FOUND;*/ /*there is no mail for priority sender*/
1562 if ((noti_err = notification_set_display_applist(noti, display)) != NOTIFICATION_ERROR_NONE) {
1563 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1564 err = EMAIL_ERROR_SYSTEM_FAILURE;
1569 if ((noti_err = notification_insert(noti, &private_id)) != NOTIFICATION_ERROR_NONE) {
1570 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1571 err = EMAIL_ERROR_SYSTEM_FAILURE;
1575 EM_DEBUG_LOG("Private_id = [%d]", private_id);
1577 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1578 if (vconf_set_int(vconf_private_id, private_id) != 0) {
1579 EM_DEBUG_EXCEPTION("vconf_set_int failed");
1580 err = EMAIL_ERROR_SYSTEM_FAILURE;
1584 if ((noti_err = notification_update(noti)) != NOTIFICATION_ERROR_NONE) {
1585 EM_DEBUG_EXCEPTION("notification_update failed [%d]", noti_err);
1586 err = EMAIL_ERROR_SYSTEM_FAILURE;
1591 #ifdef __FEATURE_DRIVING_MODE__
1593 err = emcore_start_driving_mode(multi_user_name, p_mail_id[unseen - 1]);
1594 if (err != EMAIL_ERROR_NONE)
1595 EM_DEBUG_EXCEPTION("emcore_start_driving_mode failed : [%d]", err);
1597 #endif /* __FEATURE_DRIVING_MODE__ */
1602 app_control_destroy(service);
1605 notification_free(noti);
1608 emcore_unset_join_zone(join_zone);
1610 EM_SAFE_FREE(alert_tone_path);
1611 EM_SAFE_FREE(p_mail_id); /* prevent */
1614 emstorage_free_mail(&p_mail_data, 1, NULL);
1617 emstorage_free_account(&account_tbl, 1, NULL);
1619 for (i = 0; i < unseen; i++) {
1621 EM_SAFE_FREE(value[i]);
1623 EM_SAFE_FREE(value);
1625 EM_SAFE_FREE(mailbox_name);
1627 #endif /* __FEATURE_NOTIFICATION_ENABLE__ */
1629 EM_DEBUG_FUNC_END("ret [%d]", err);
1633 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)
1635 EM_DEBUG_FUNC_BEGIN("account_id: %d, mail_id: %d, action:%d", account_id, mail_id, action );
1636 int err = EMAIL_ERROR_NONE;
1637 #ifdef __FEATURE_NOTIFICATION_ENABLE__
1639 void *join_zone = NULL;
1640 char *mailbox_name = NULL;
1641 char *dgettext_string = NULL;
1642 char vconf_private_id[MAX_PATH] = {0, };
1643 notification_h noti = NULL;
1644 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1645 emstorage_mail_tbl_t *p_mail_data = NULL;
1646 emstorage_account_tbl_t *account_tbl = NULL;
1648 /* For service bundle */
1649 char buf[256] = {0,};
1650 app_control_h service = NULL;
1653 /* get general noti status */
1654 if (!emstorage_get_account_by_id(multi_user_name, account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_tbl, true, &err)) {
1655 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]", err);
1659 if (!account_tbl->options.notification_status) {
1660 EM_DEBUG_LOG("notification disabled");
1664 if (!account_tbl->options.display_content_status) {
1665 EM_DEBUG_LOG("display content disabled");
1669 /* Delete the previous noti */
1670 emcore_delete_notification_by_account(multi_user_name, account_id, true);
1671 if (g_sending_noti_handle) {
1672 if((noti_err = notification_free(g_sending_noti_handle)) != NOTIFICATION_ERROR_NONE)
1673 err = EMAIL_ERROR_NOTI;
1674 g_sending_noti_handle = NULL;
1677 if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
1678 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
1682 if (action == EMAIL_ACTION_SENDING_MAIL)
1683 noti = notification_create(NOTIFICATION_TYPE_ONGOING);
1685 noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
1688 EM_DEBUG_EXCEPTION("notification_new failed");
1689 err = EMAIL_ERROR_NOTI;
1693 if ((noti_err = notification_set_pkgname(noti, NATIVE_EMAIL_APPLICATION_PKG)) != NOTIFICATION_ERROR_NONE) {
1694 EM_DEBUG_EXCEPTION("notification_set_pkgname failed [%d]", noti_err);
1695 err = EMAIL_ERROR_NOTI;
1699 if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &p_mail_data, false, &err)) {
1700 EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err);
1704 /* Create service bundle */
1705 app_control_create(&service);
1707 EM_DEBUG_EXCEPTION("service create failed");
1710 snprintf(buf, sizeof(buf), "%d", 12);
1711 app_control_add_extra_data(service, "RUN_TYPE", buf);
1712 snprintf(buf, sizeof(buf), "%d", account_id);
1713 app_control_add_extra_data(service, "ACCOUNT_ID", buf);
1714 snprintf(buf, sizeof(buf), "%d", p_mail_data->mail_id);
1715 app_control_add_extra_data(service, "MAIL_ID", buf);
1716 snprintf(buf, sizeof(buf), "%d", p_mail_data->mailbox_id);
1717 app_control_add_extra_data(service, "MAILBOX_ID", buf);
1718 app_control_set_app_id(service, NATIVE_EMAIL_APPLICATION_PKG);
1720 app_control_to_bundle(service, &b);
1721 noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1722 if (noti_err != NOTIFICATION_ERROR_NONE) {
1723 EM_DEBUG_EXCEPTION("notification_set_execute_option failed [%d]", noti_err);
1724 err = EMAIL_ERROR_SYSTEM_FAILURE;
1729 case EMAIL_ACTION_SEND_MAIL :
1731 setlocale(LC_MESSAGES, vconf_get_str(VCONFKEY_LANGSET));
1732 bindtextdomain("sys_string", "/usr/share/locale");
1733 textdomain("sys_string");
1735 setlocale(LC_MESSAGES, vconf_get_str(VCONFKEY_LANGSET));
1736 bindtextdomain(NATIVE_EMAIL_DOMAIN, "/usr/apps/org.tizen.email/res/locale");
1737 textdomain(NATIVE_EMAIL_DOMAIN);
1739 switch(sending_error) {
1740 case EMAIL_ERROR_NONE:
1741 dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_EMAIL_SENT");
1743 case EMAIL_ERROR_FLIGHT_MODE_ENABLE:
1744 dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_FAILED_TO_CONNECT_TO_NETWORK");
1746 case EMAIL_ERROR_NETWORK_NOT_AVAILABLE:
1747 case EMAIL_ERROR_NO_SIM_INSERTED:
1748 dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_NETWORK_NOT_AVAILABLE_EMAIL_WILL_BE_SENT_WHEN_CONNECTED_TO_NETWORK");
1750 case EMAIL_ERROR_SERVER_STORAGE_FULL:
1751 dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_SENDING_FAILED_SERVER_STORAGE_FULL_ABB");
1754 dgettext_string = dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_TPOP_SENDING_FAILED");
1758 if ((noti_err = notification_set_layout(noti,
1759 NOTIFICATION_LY_NOTI_EVENT_SINGLE)) != NOTIFICATION_ERROR_NONE) {
1760 EM_DEBUG_EXCEPTION("notification_set_layout failed [%d]", noti_err);
1761 err = EMAIL_ERROR_NOTI;
1765 if ((noti_err = notification_set_image(noti,
1766 NOTIFICATION_IMAGE_TYPE_ICON,
1767 EMAIL_NOTI_ICON_PATH)) != NOTIFICATION_ERROR_NONE) {
1768 EM_DEBUG_EXCEPTION("notification_set_image failed [%d]", noti_err);
1769 err = EMAIL_ERROR_NOTI;
1773 if ((noti_err = notification_set_text(noti,
1774 NOTIFICATION_TEXT_TYPE_TITLE,
1775 p_mail_data->alias_recipient,
1777 NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1778 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1779 err = EMAIL_ERROR_NOTI;
1783 switch (sending_error) {
1784 case EMAIL_ERROR_NONE:
1785 if ((noti_err = notification_set_text(noti,
1786 NOTIFICATION_TEXT_TYPE_CONTENT,
1789 NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1790 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1791 err = EMAIL_ERROR_NOTI;
1795 case EMAIL_ERROR_SERVER_STORAGE_FULL:
1796 if ((noti_err = notification_set_text(noti,
1797 NOTIFICATION_TEXT_TYPE_CONTENT,
1798 "Sending failed. Server storage full.",
1800 NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1801 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1802 err = EMAIL_ERROR_NOTI;
1807 if ((noti_err = notification_set_text(noti,
1808 NOTIFICATION_TEXT_TYPE_CONTENT,
1811 NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1812 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1813 err = EMAIL_ERROR_NOTI;
1819 if (sending_error == EMAIL_ERROR_SMTP_SEND_FAILURE_BY_OVERSIZE) {
1820 if ((noti_err = notification_set_text(noti,
1821 NOTIFICATION_TEXT_TYPE_INFO_1,
1822 dgettext(NATIVE_EMAIL_DOMAIN, "IDS_EMAIL_POP_THE_EMAIL_IS_TOO_LARGE"),
1824 NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1825 EM_DEBUG_EXCEPTION("notification_set_text TEXT_TYPE_INFO_1 failed");
1826 err = EMAIL_ERROR_NOTI;
1831 if ((noti_err = notification_set_display_applist(noti,
1832 NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER)) != NOTIFICATION_ERROR_NONE) {
1833 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1834 err = EMAIL_ERROR_NOTI;
1838 if ((noti_err = notification_insert(noti, &private_id)) != NOTIFICATION_ERROR_NONE) {
1839 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1840 err = EMAIL_ERROR_NOTI;
1844 EM_DEBUG_LOG("Private_id = [%d]", private_id);
1846 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1847 if (vconf_set_int(vconf_private_id, private_id) != 0) {
1848 EM_DEBUG_EXCEPTION("vconf_set_int failed");
1849 err = EMAIL_ERROR_GCONF_FAILURE;
1855 case EMAIL_ACTION_SENDING_MAIL :
1857 if ((noti_err = notification_set_text_domain(noti, NATIVE_EMAIL_DOMAIN, "/usr/apps/org.tizen.email/res/locale")) != NOTIFICATION_ERROR_NONE) {
1858 EM_DEBUG_EXCEPTION("notification_set_text_domain failed [%d]", noti_err);
1859 err = EMAIL_ERROR_NOTI;
1863 if ((noti_err = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_PROGRESS)) != NOTIFICATION_ERROR_NONE) {
1864 EM_DEBUG_EXCEPTION("notification_set_layout failed [%d]", noti_err);
1865 err = EMAIL_ERROR_NOTI;
1869 if ((noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, EMAIL_NOTI_ICON_PATH)) != NOTIFICATION_ERROR_NONE) {
1870 EM_DEBUG_EXCEPTION("notification_set_image failed [%d]", noti_err);
1871 err = EMAIL_ERROR_NOTI;
1875 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) {
1876 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1877 err = EMAIL_ERROR_NOTI;
1881 if ((noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, p_mail_data->subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE)) != NOTIFICATION_ERROR_NONE) {
1882 EM_DEBUG_EXCEPTION("notification_set_text failed [%d]", noti_err);
1883 err = EMAIL_ERROR_NOTI;
1887 /*notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);*/
1889 if ((noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL)) != NOTIFICATION_ERROR_NONE) {
1890 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1891 err = EMAIL_ERROR_NOTI;
1895 if ((noti_err = notification_insert(noti, &private_id)) != NOTIFICATION_ERROR_NONE) {
1896 EM_DEBUG_EXCEPTION("notification_insert failed [%d]", noti_err);
1897 err = EMAIL_ERROR_NOTI;
1901 g_sending_noti_handle = noti;
1902 EM_DEBUG_LOG("Private_id = [%d]", private_id);
1904 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1905 if (vconf_set_int (vconf_private_id, private_id) != 0) {
1906 EM_DEBUG_EXCEPTION("vconf_set_int failed");
1907 err = EMAIL_ERROR_GCONF_FAILURE;
1914 if ((noti_err = notification_free (noti)) != NOTIFICATION_ERROR_NONE) {
1915 EM_DEBUG_EXCEPTION ("notification_free error [%d]", noti_err);
1916 err = EMAIL_ERROR_NOTI;
1925 app_control_destroy(service);
1927 if ((action == EMAIL_ACTION_SEND_MAIL) && noti) {
1928 if ((noti_err = notification_free(noti)) != NOTIFICATION_ERROR_NONE) {
1929 err = EMAIL_ERROR_NOTI;
1933 if ((action != EMAIL_ACTION_SEND_MAIL) && (err != EMAIL_ERROR_NONE)) {
1935 notification_free(noti);
1936 g_sending_noti_handle = NULL;
1941 emcore_unset_join_zone(join_zone);
1944 emstorage_free_mail(&p_mail_data, 1, NULL);
1947 emstorage_free_account(&account_tbl, 1, NULL);
1949 EM_SAFE_FREE(mailbox_name);
1951 #endif /* __FEATURE_NOTIFICATION_ENABLE__ */
1953 EM_DEBUG_FUNC_END("ret [%d]", err);
1957 INTERNAL_FUNC void emcore_update_notification_for_send(int account_id, int mail_id, double progress)
1959 EM_DEBUG_FUNC_BEGIN("account_id: %d, mail_id: %d, progress: %f", account_id, mail_id, progress);
1962 char vconf_private_id[MAX_PATH] = {0, };
1963 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1965 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
1966 if (vconf_get_int(vconf_private_id, &private_id) != 0) {
1967 EM_DEBUG_EXCEPTION("vconf_get_int failed");
1970 EM_DEBUG_LOG("Private_id = [%d]", private_id);
1971 noti_err = notification_update_progress(g_sending_noti_handle, private_id, progress);
1972 if (noti_err != NOTIFICATION_ERROR_NONE) {
1973 EM_DEBUG_LOG("notification_update_progress failed [0x%x]", noti_err);
1976 EM_DEBUG_FUNC_END();
1979 INTERNAL_FUNC int emcore_show_user_message(char *multi_user_name, int id, email_action_t action, int error)
1981 EM_DEBUG_FUNC_BEGIN("id[%d], action[%d], error[%d]", id, action, error);
1985 emstorage_mail_tbl_t *mail_table_data = NULL;
1987 if ((action == EMAIL_ACTION_SEND_MAIL || action == EMAIL_ACTION_SENDING_MAIL) && error != EMAIL_ERROR_CANCELLED) {
1988 /* In case email is cancelled using cancel button in Outbox there is no need to show Cancel/Retry Pop up */
1991 EM_DEBUG_LOG("Invalid mail_id");
1995 if (!emstorage_get_mail_by_id(multi_user_name, id, &mail_table_data, true, NULL)) {
1996 EM_DEBUG_LOG("Mail not found");
2000 EM_DEBUG_LOG ("smtp_stream : sent_end");
2001 if (emcore_add_notification_for_send(multi_user_name, mail_table_data->account_id, id, action, error, display) != EMAIL_ERROR_NONE) {
2002 EM_DEBUG_EXCEPTION("emcore_notification_set error");
2010 if (mail_table_data && !emstorage_free_mail(&mail_table_data, 1, NULL))
2011 EM_DEBUG_EXCEPTION("emstorage_free_mail Failed");
2013 EM_DEBUG_FUNC_END("ret [%d]", ret);
2018 /* storage space handling - 210709 */
2019 int emcore_get_storage_status(void)
2021 EM_DEBUG_FUNC_BEGIN();
2022 int storage_status = 0, nError = 0;
2024 #if !GLIB_CHECK_VERSION(2, 36, 0)
2028 #ifdef STORAGE_STATUS
2029 nError = vconf_get_int(PS_KEY_SYSTEM_STORAGE_MOVI_STATUS,
2031 #endif /* STORAGE_STATUS */
2034 EM_DEBUG_EXCEPTION("vconf_get_int Failed");
2037 EM_DEBUG_FUNC_END();
2038 return storage_status;
2043 INTERNAL_FUNC int emcore_is_storage_full()
2045 EM_DEBUG_FUNC_BEGIN();
2046 int err = EMAIL_ERROR_NONE;
2047 int ret_from_storage_lib = 0;
2048 struct statvfs stat_result;
2050 ret_from_storage_lib = storage_get_internal_memory_size(&stat_result);
2051 if (ret_from_storage_lib < 0) {
2052 EM_DEBUG_EXCEPTION("ret_from_storage_lib [%d]", ret_from_storage_lib);
2053 err = EMAIL_ERROR_SYSTEM_FAILURE;
2057 unsigned long i_free = (stat_result.f_bsize*stat_result.f_bavail) / (1024 * 1024);
2058 if (i_free < EMAIL_LIMITATION_FREE_SPACE) {
2059 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);
2060 EM_DEBUG_EXCEPTION("Not enough free space of storage [%ld] MB.", i_free);
2061 err = EMAIL_ERROR_MAIL_MEMORY_FULL;
2066 EM_DEBUG_FUNC_END("err[%d]", err);
2070 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)
2072 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);
2075 int mail_size = 0; /* size of the plain text body and attachments */
2076 int err = EMAIL_ERROR_NONE;
2078 char *prefix_path = NULL;
2079 char real_file_path[255] = {0};
2081 if (!input_mail_data || (input_attachment_count && !input_attachment_data_list) || (!input_attachment_count &&input_attachment_data_list) || !output_size) {
2082 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2083 err = EMAIL_ERROR_INVALID_PARAM;
2087 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
2088 err = emcore_get_container_path(multi_user_name, &prefix_path);
2089 if (err != EMAIL_ERROR_NONE) {
2090 EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
2094 prefix_path = strdup("");
2097 if (input_mail_data->file_path_plain != NULL) {
2098 memset(real_file_path, 0x00, sizeof(real_file_path));
2099 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_data->file_path_plain);
2101 if (stat(real_file_path, &st_buf) < 0) {
2102 EM_DEBUG_EXCEPTION_SEC("input_mail_data->file_path_plain : stat(\"%s\") failed...", input_mail_data->file_path_plain);
2103 err = EMAIL_ERROR_FILE_NOT_FOUND;
2107 mail_size += st_buf.st_size;
2111 if (input_mail_data->file_path_html != NULL) {
2112 memset(real_file_path, 0x00, sizeof(real_file_path));
2113 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_data->file_path_html);
2115 if (stat(real_file_path, &st_buf) < 0) {
2116 EM_DEBUG_EXCEPTION_SEC("input_mail_data->file_path_html : stat(\"%s\") failed...", input_mail_data->file_path_html);
2117 err = EMAIL_ERROR_FILE_NOT_FOUND;
2121 mail_size += st_buf.st_size;
2124 for(i = 0; i < input_attachment_count; i++) {
2125 memset(real_file_path, 0x00, sizeof(real_file_path));
2126 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_attachment_data_list[i].attachment_path);
2128 if (stat(real_file_path, &st_buf) < 0) {
2129 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_attachment_data_list[i].attachment_path);
2130 err = EMAIL_ERROR_FILE_NOT_FOUND;
2133 mail_size += st_buf.st_size;
2136 *output_size = mail_size;
2140 EM_SAFE_FREE(prefix_path);
2142 EM_DEBUG_FUNC_END("mail_size [%d]", mail_size);
2147 /* parse the Full mailbox Path and Get the Alias Name of the Mailbox */
2148 char *emcore_get_alias_of_mailbox(const char *mailbox_path)
2150 EM_DEBUG_FUNC_BEGIN();
2151 EM_IF_NULL_RETURN_VALUE(mailbox_path, NULL);
2154 gchar **token_list = NULL;
2155 gchar *mailbox = NULL, *name = NULL;
2156 char *converted_name;
2159 mailbox = g_strdup(mailbox_path);
2160 token_list = g_strsplit_set(mailbox, "/", -1);
2162 if(token_list == NULL) {
2163 EM_DEBUG_LOG("g_strsplit_set failed.");
2173 while (token_list[index] != NULL)
2176 name = g_strdup(token_list[index - 1]);
2177 if (!name) /* prevent 27459 */ {
2184 g_strfreev(token_list);
2186 converted_name = emcore_convert_mutf7_to_utf8(name);
2187 EM_DEBUG_LOG_DEV("converted_name:%s", converted_name);
2189 if (!converted_name || EM_SAFE_STRLEN(converted_name) == 0) {
2190 EM_SAFE_FREE(converted_name);
2191 converted_name = g_strdup(name);
2197 EM_DEBUG_FUNC_END();
2198 return converted_name;
2202 INTERNAL_FUNC int emcore_get_first_address(const char *input_full_address, char **output_display_name, char **output_angle_addr)
2204 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);
2206 int err = EMAIL_ERROR_NONE;
2207 char *full_address = NULL;
2208 char angle_addr[MAX_EMAIL_ADDRESS_LENGTH] = { 0, };
2209 ADDRESS *address_list = NULL;
2211 if (input_full_address == NULL || output_display_name == NULL || output_angle_addr == NULL) {
2212 err = EMAIL_ERROR_INVALID_PARAM;
2213 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2217 /* full_address will be tainted by rfc822_parse_adrlist */
2218 /* So, input_full_address should be duplicated */
2219 full_address = EM_SAFE_STRDUP(input_full_address);
2221 if (full_address == NULL) {
2222 err = EMAIL_ERROR_OUT_OF_MEMORY;
2223 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
2227 rfc822_parse_adrlist(&address_list, (char*)full_address, NULL);
2230 if (address_list->host)
2231 SNPRINTF(angle_addr, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", address_list->mailbox, address_list->host);
2232 else /* For SMS of eas-engine : (example : 01012345678) */
2233 SNPRINTF(angle_addr, MAX_EMAIL_ADDRESS_LENGTH, "%s", address_list->mailbox);
2235 *output_display_name = EM_SAFE_STRDUP(address_list->personal);
2236 *output_angle_addr = EM_SAFE_STRDUP(angle_addr);
2238 mail_free_address(&address_list);
2242 EM_SAFE_FREE(full_address);
2244 EM_DEBUG_FUNC_END();
2248 void emcore_fill_address_information_of_mail_tbl(char *multi_user_name, emstorage_mail_tbl_t *mail_data)
2250 EM_DEBUG_FUNC_BEGIN("mail_data [%p]", mail_data);
2252 char *first_alias = NULL;
2253 char *first_address = NULL;
2254 char *recipient = NULL;
2259 char *recipient_self = NULL;
2261 email_account_t *ref_account = NULL;
2263 ref_account = emcore_get_account_reference(multi_user_name, mail_data->account_id, false);
2265 EM_DEBUG_LOG("emcore_get_account_reference failed [%d]", mail_data->account_id);
2268 EM_DEBUG_LOG_SEC("full_address_from [%s]", mail_data->full_address_from);
2270 /* sender alias & address */
2271 if (emcore_get_first_address(mail_data->full_address_from, &first_alias, &first_address) == true) {
2272 if (first_alias == NULL) {
2273 mail_data->alias_sender = EM_SAFE_STRDUP(first_address);
2276 mail_data->alias_sender = first_alias;
2279 mail_data->email_address_sender = first_address;
2280 first_address = NULL;
2283 EM_DEBUG_LOG_SEC("full_address_from [%s]", mail_data->full_address_from);
2285 /* recipient alias & address */
2286 if (mail_data->full_address_to != NULL)
2287 recipient = mail_data->full_address_to;
2288 else if (mail_data->full_address_cc != NULL)
2289 recipient = mail_data->full_address_cc;
2290 else if (mail_data->full_address_bcc != NULL)
2291 recipient = mail_data->full_address_bcc;
2293 /* if full_address_to contains account address, set account address to email_address_recipient */
2294 if (ref_account && mail_data->full_address_to &&
2295 g_strrstr(mail_data->full_address_to, ref_account->user_email_address)) {
2296 vector = g_strsplit_set(mail_data->full_address_to, ";", -1);
2297 vector_len = g_strv_length(vector);
2299 for (i = 0; i < vector_len; i++) {
2300 if (g_strrstr(vector[i], ref_account->user_email_address)) {
2301 recipient_self = EM_SAFE_STRDUP(vector[i]);
2307 if (recipient_self) {
2308 recipient = recipient_self;
2312 if (emcore_get_first_address(recipient, &first_alias, &first_address) == true) {
2313 if (first_alias == NULL)
2314 mail_data->alias_recipient = EM_SAFE_STRDUP(first_address);
2316 mail_data->alias_recipient = first_alias;
2318 mail_data->email_address_recipient = first_address;
2322 emcore_free_account(ref_account);
2323 EM_SAFE_FREE(ref_account);
2326 EM_SAFE_FREE(recipient_self);
2327 EM_DEBUG_FUNC_END();
2330 struct email_attribute_info {
2331 email_mail_attribute_type attribute_type;
2332 char *attribute_name;
2333 email_mail_attribute_value_type attribute_value_type;
2336 static struct email_attribute_info _mail_attribute_info_array[] = {
2337 {EMAIL_MAIL_ATTRIBUTE_MAIL_ID, "mail_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2338 {EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID, "account_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2339 {EMAIL_MAIL_ATTRIBUTE_MAILBOX_ID, "mailbox_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2340 {EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME, "mailbox_name", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2341 {EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE, "mailbox_type", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2342 {EMAIL_MAIL_ATTRIBUTE_SUBJECT, "subject", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2343 {EMAIL_MAIL_ATTRIBUTE_DATE_TIME, "date_time",EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME},
2344 {EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_STATUS, "server_mail_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2345 {EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME, "server_mailbox_name", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2346 {EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID, "server_mail_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2347 {EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID, "message_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2348 {EMAIL_MAIL_ATTRIBUTE_REFERENCE_MAIL_ID, "reference_mail_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2349 {EMAIL_MAIL_ATTRIBUTE_FROM, "full_address_from", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2350 {EMAIL_MAIL_ATTRIBUTE_TO, "full_address_to", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2351 {EMAIL_MAIL_ATTRIBUTE_CC, "full_address_cc", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2352 {EMAIL_MAIL_ATTRIBUTE_BCC, "full_address_bcc", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2353 {EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS, "body_download_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2354 {EMAIL_MAIL_ATTRIBUTE_MAIL_SIZE, "mail_size", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2355 {EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN, "file_path_plain",EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2356 {EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML,"file_path_html", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2357 {EMAIL_MAIL_ATTRIBUTE_FILE_SIZE,"file_size", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2358 {EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD,"flags_seen_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2359 {EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD,"flags_deleted_field",EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER },
2360 {EMAIL_MAIL_ATTRIBUTE_FLAGS_FLAGGED_FIELD,"flags_flagged_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2361 {EMAIL_MAIL_ATTRIBUTE_FLAGS_ANSWERED_FIELD,"flags_answered_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2362 {EMAIL_MAIL_ATTRIBUTE_FLAGS_RECENT_FIELD,"flags_recent_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2363 {EMAIL_MAIL_ATTRIBUTE_FLAGS_DRAFT_FIELD,"flags_draft_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2364 {EMAIL_MAIL_ATTRIBUTE_FLAGS_FORWARDED_FIELD,"flags_forwarded_field", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2365 {EMAIL_MAIL_ATTRIBUTE_DRM_STATUS,"drm_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2366 {EMAIL_MAIL_ATTRIBUTE_PRIORITY,"priority", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2367 {EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS,"save_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2368 {EMAIL_MAIL_ATTRIBUTE_LOCK_STATUS,"lock_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2369 {EMAIL_MAIL_ATTRIBUTE_REPORT_STATUS,"report_status", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2370 {EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT,"attachment_count", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2371 {EMAIL_MAIL_ATTRIBUTE_INLINE_CONTENT_COUNT,"inline_content_count", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2372 {EMAIL_MAIL_ATTRIBUTE_THREAD_ID,"thread_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2373 {EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT,"thread_item_count", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2374 {EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT,"preview_text", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2375 {EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS,"meeting_request_status", },
2376 {EMAIL_MAIL_ATTRIBUTE_MESSAGE_CLASS,"message_class", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2377 {EMAIL_MAIL_ATTRIBUTE_DIGEST_TYPE,"digest_type", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2378 {EMAIL_MAIL_ATTRIBUTE_SMIME_TYPE,"smime_type", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2379 {EMAIL_MAIL_ATTRIBUTE_SCHEDULED_SENDING_TIME,"scheduled_sending_time", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME},
2380 {EMAIL_MAIL_ATTRIBUTE_REMAINING_RESEND_TIMES,"remaining_resend_times", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2381 {EMAIL_MAIL_ATTRIBUTE_TAG_ID,"tag_id", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2382 {EMAIL_MAIL_ATTRIBUTE_REPLIED_TIME,"replied_time", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME},
2383 {EMAIL_MAIL_ATTRIBUTE_FORWARDED_TIME,"forwarded_time", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME},
2384 {EMAIL_MAIL_ATTRIBUTE_RECIPIENT_ADDRESS,"email_recipient_address", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING},
2385 {EMAIL_MAIL_ATTRIBUTE_EAS_DATA_LENGTH_TYPE,"eas_data_length", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER},
2386 {EMAIL_MAIL_ATTRIBUTE_EAS_DATA_TYPE,"eas_data", EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_BINARY}
2389 INTERNAL_FUNC char* emcore_get_mail_field_name_by_attribute_type(email_mail_attribute_type input_attribute_type)
2391 EM_DEBUG_FUNC_BEGIN("input_attribute_type [%d]", input_attribute_type);
2393 if(input_attribute_type > EMAIL_MAIL_ATTRIBUTE_EAS_DATA_TYPE || input_attribute_type < 0) {
2394 EM_DEBUG_EXCEPTION("Invalid input_attribute_type [%d]", input_attribute_type);
2398 EM_DEBUG_LOG_DEV("return [%s]", _mail_attribute_info_array[input_attribute_type].attribute_name);
2399 return _mail_attribute_info_array[input_attribute_type].attribute_name;
2402 INTERNAL_FUNC int emcore_get_attribute_type_by_mail_field_name(char *input_mail_field_name, email_mail_attribute_type *output_mail_attribute_type)
2404 EM_DEBUG_FUNC_BEGIN("input_mail_field_name [%p], output_mail_attribute_type [%p]", input_mail_field_name, output_mail_attribute_type);
2406 int err = EMAIL_ERROR_DATA_NOT_FOUND;
2408 if(!input_mail_field_name || !output_mail_attribute_type) {
2409 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2410 return EMAIL_ERROR_INVALID_PARAM;
2413 for (i = 0; i < EMAIL_MAIL_ATTRIBUTE_END; i++) {
2414 if (EM_SAFE_STRCMP(input_mail_field_name, _mail_attribute_info_array[i].attribute_name) == 0) {
2415 *output_mail_attribute_type = i;
2416 err = EMAIL_ERROR_NONE;
2421 EM_DEBUG_FUNC_END("found mail attribute type [%d]", (int)*output_mail_attribute_type);
2425 INTERNAL_FUNC int emcore_get_mail_attribute_value_type(email_mail_attribute_type input_attribute_type, email_mail_attribute_value_type *output_value_type)
2427 EM_DEBUG_FUNC_BEGIN("input_attribute_type[%d] output_value_type[%p]", input_attribute_type, output_value_type);
2428 int err = EMAIL_ERROR_NONE;
2430 email_mail_attribute_value_type value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE;
2432 if (output_value_type == NULL) {
2433 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2434 err = EMAIL_ERROR_INVALID_PARAM;
2438 for(i = 0; i < EMAIL_MAIL_ATTRIBUTE_END; i++) {
2439 if(input_attribute_type == _mail_attribute_info_array[i].attribute_type) {
2440 value_type = _mail_attribute_info_array[i].attribute_value_type;
2445 *output_value_type = value_type;
2447 EM_DEBUG_LOG("value_type [%d]", value_type);
2450 EM_DEBUG_FUNC_END("err [%d]", err);
2454 #ifdef __FEATURE_BODY_SEARCH__
2455 int emcore_strip_mail_body_from_file(char *multi_user_name, emstorage_mail_tbl_t *mail, char **stripped_text, int *err_code)
2457 EM_DEBUG_FUNC_BEGIN("mail[%p]", mail);
2460 int err = EMAIL_ERROR_NONE;
2462 char *encoding_type = NULL;
2463 char *utf8_encoded_string = NULL;
2464 char *prefix_path = NULL;
2465 char real_html_path[255] = {0};
2466 char real_plain_path[255] = {0};
2467 gsize byte_read = 0;
2468 gsize byte_written = 0;
2469 GError *glib_error = NULL;
2470 FILE *fp_plain = NULL;
2474 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2475 err = EMAIL_ERROR_INVALID_PARAM;
2479 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
2480 err = emcore_get_container_path(multi_user_name, &prefix_path);
2481 if (err != EMAIL_ERROR_NONE) {
2482 EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
2486 prefix_path = strdup("");
2489 /* read file to buf & strip if html text */
2490 if (mail->file_path_html) {
2491 char result_buffer[MAX_PREVIEW_TEXT_LENGTH] = { 0, };
2493 if (mail->preview_text) {
2494 *stripped_text = EM_SAFE_STRDUP(mail->preview_text);
2499 SNPRINTF(real_html_path, sizeof(real_html_path), "%s%s", prefix_path, mail->file_path_html);
2501 if ((err = em_get_encoding_type_from_file_path(mail->file_path_plain, &encoding_type)) != EMAIL_ERROR_NONE) {
2502 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
2506 if ((err = emcore_strip_HTML_tag(real_html_path, encoding_type, result_buffer, MAX_PREVIEW_TEXT_LENGTH)) != EMAIL_ERROR_NONE) {
2507 EM_DEBUG_EXCEPTION("emcore_strip_HTML_tag failed");
2511 *stripped_text = EM_SAFE_STRDUP(result_buffer);
2514 if (!buf && mail->file_path_plain) {
2515 SNPRINTF(real_plain_path, sizeof(real_plain_path), "%s%s", prefix_path, mail->file_path_plain);
2517 if ((err = em_get_encoding_type_from_file_path(mail->file_path_plain, &encoding_type)) != EMAIL_ERROR_NONE) {
2518 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
2522 memset(&st_buf, 0, sizeof(struct stat));
2523 if (stat(real_plain_path, &st_buf) < 0) {
2524 EM_DEBUG_EXCEPTION_SEC("stat(\"%s\") failed...", real_plain_path);
2525 err = EMAIL_ERROR_INVALID_MAIL;
2529 err = em_fopen(real_plain_path, "r", &fp_plain);
2530 if (err != EMAIL_ERROR_NONE) {
2531 EM_DEBUG_EXCEPTION_SEC("em_fopen failed [%s]", real_plain_path);
2535 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
2536 EM_DEBUG_LOG("text_file is empty size");
2537 err = EMAIL_ERROR_EMPTY_FILE;
2541 if (!(buf = (char*)em_malloc(sizeof(char)*(st_buf.st_size + 1)))) {
2542 EM_DEBUG_EXCEPTION("em_malloc failed");
2546 byte_read = fread(buf, sizeof(char), st_buf.st_size, fp_plain);
2548 if (byte_read <= 0) {
2550 err = EMAIL_ERROR_NULL_VALUE;
2551 if (ferror(fp_plain)) {
2552 EM_DEBUG_EXCEPTION_SEC("fread failed [%s]", real_plain_path);
2553 err = EMAIL_ERROR_SYSTEM_FAILURE;
2557 reg_replace(buf, CR_STRING, " ");
2558 reg_replace(buf, LF_STRING, " ");
2559 reg_replace(buf, TAB_STRING, " ");
2564 if(encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
2565 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
2567 if (strcasecmp(encoding_type, "ks_c_5601-1987") == 0 ||
2568 strcasecmp(encoding_type, "ksc5601") == 0 ||
2569 strcasecmp(encoding_type, "cp949") == 0) {
2570 EM_SAFE_FREE(encoding_type);
2571 encoding_type = EM_SAFE_STRDUP("EUC-KR");
2574 utf8_encoded_string = (char*)g_convert(buf, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
2576 if(utf8_encoded_string == NULL) {
2577 if (!g_error_matches(glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
2578 EM_SAFE_FREE(*stripped_text);
2579 *stripped_text = EM_SAFE_STRDUP(buf);
2582 EM_DEBUG_LOG("Extract the preview text, again");
2584 utf8_encoded_string = (char *)g_convert(buf, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
2585 if (utf8_encoded_string == NULL) {
2586 EM_SAFE_FREE(*stripped_text);
2587 *stripped_text = EM_SAFE_STRDUP(buf);
2593 EM_SAFE_FREE(*stripped_text);
2594 *stripped_text = EM_SAFE_STRDUP(utf8_encoded_string);
2596 EM_SAFE_FREE(*stripped_text);
2597 *stripped_text = EM_SAFE_STRDUP(buf);
2609 EM_SAFE_FREE(prefix_path);
2610 EM_SAFE_FREE(encoding_type);
2611 EM_SAFE_FREE(utf8_encoded_string);
2613 if (fp_plain != NULL)
2616 EM_DEBUG_FUNC_END("ret [%d]", ret);
2622 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)
2624 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);
2626 int err = EMAIL_ERROR_NONE;
2627 gsize byte_read = 0;
2628 gsize byte_written = 0;
2629 int local_preview_buffer_length = 0;
2630 char *local_preview_text = NULL;
2631 char *encoding_type = NULL;
2632 char *utf8_encoded_string = NULL;
2633 FILE *fp_plain = NULL;
2634 GError *glib_error = NULL;
2636 char *prefix_path = NULL;
2637 char real_file_path[255] = {0};
2639 if (!output_preview_buffer) {
2640 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2641 err = EMAIL_ERROR_INVALID_PARAM;
2645 local_preview_buffer_length = input_preview_buffer_length * 2;
2647 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
2648 err = emcore_get_container_path(multi_user_name, &prefix_path);
2649 if (err != EMAIL_ERROR_NONE) {
2650 EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
2654 prefix_path = strdup("");
2657 if (input_html_path) { /*prevent 26249*/
2658 /* get preview text from html file */
2659 char result_buffer[MAX_PREVIEW_TEXT_LENGTH] = { 0, };
2661 memset(real_file_path, 0x00, sizeof(real_file_path));
2662 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_html_path);
2664 if( (err = em_get_encoding_type_from_file_path(input_html_path, &encoding_type)) != EMAIL_ERROR_NONE) {
2665 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
2669 if ((err = emcore_strip_HTML_tag(real_file_path, encoding_type, result_buffer, MAX_PREVIEW_TEXT_LENGTH)) != EMAIL_ERROR_NONE) {
2670 EM_DEBUG_EXCEPTION("emcore_strip_HTML_tag failed");
2673 local_preview_text = EM_SAFE_STRDUP(result_buffer);
2676 if (!local_preview_text && input_plain_path) { /*prevent 26249*/
2678 memset(real_file_path, 0x00, sizeof(real_file_path));
2679 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_plain_path);
2681 /* get preview text from plain text file */
2682 if( (err = em_get_encoding_type_from_file_path(input_plain_path, &encoding_type)) != EMAIL_ERROR_NONE) {
2683 EM_DEBUG_EXCEPTION("em_get_encoding_type_from_file_path failed [%d]", err);
2687 memset(&st_buf, 0, sizeof(struct stat));
2688 if (stat(real_file_path, &st_buf) < 0) {
2689 EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", input_plain_path);
2690 err = EMAIL_ERROR_INVALID_MAIL;
2694 err = em_fopen(real_file_path, "r", &fp_plain);
2695 if (err != EMAIL_ERROR_NONE) {
2696 EM_DEBUG_EXCEPTION("em_fopen failed [%s]", input_plain_path);
2700 if (S_ISREG(st_buf.st_mode) && st_buf.st_size == 0) {
2701 EM_DEBUG_LOG("input_text_file is empty size");
2702 err = EMAIL_ERROR_EMPTY_FILE;
2706 if (!(local_preview_text = (char*)em_malloc(sizeof(char) * local_preview_buffer_length))) {
2707 EM_DEBUG_EXCEPTION("em_malloc failed");
2711 byte_read = fread(local_preview_text, sizeof(char), local_preview_buffer_length - 1, fp_plain);
2713 if(byte_read <=0) { /*prevent 26249*/
2714 EM_SAFE_FREE(local_preview_text);
2715 err = EMAIL_ERROR_NULL_VALUE;
2716 if (ferror(fp_plain)) {
2717 EM_DEBUG_EXCEPTION("fread failed [%s]", input_plain_path);
2718 err = EMAIL_ERROR_SYSTEM_FAILURE;
2722 reg_replace(local_preview_text, CR_STRING, " ");
2723 reg_replace(local_preview_text, LF_STRING, " ");
2724 reg_replace(local_preview_text, TAB_STRING, " ");
2726 em_trim_left(local_preview_text);
2728 if(encoding_type && strcasecmp(encoding_type, "UTF-8") != 0) {
2729 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
2731 if (strcasecmp(encoding_type, "ks_c_5601-1987") == 0 ||
2732 strcasecmp(encoding_type, "ksc5601") == 0 ||
2733 strcasecmp(encoding_type, "cp949") == 0) {
2734 EM_SAFE_FREE(encoding_type);
2735 encoding_type = EM_SAFE_STRDUP("EUC-KR");
2738 utf8_encoded_string = (char *)g_convert(local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
2740 if(utf8_encoded_string == NULL) {
2741 if (!g_error_matches (glib_error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) {
2744 EM_DEBUG_LOG("Extract the preview text, again");
2746 utf8_encoded_string = (char *)g_convert(local_preview_text, -1, "UTF-8", encoding_type, &byte_read, &byte_written, &glib_error);
2747 if (utf8_encoded_string == NULL) {
2748 EM_DEBUG_LOG("g_convert fail, again");
2752 EM_SAFE_FREE(local_preview_text);
2753 local_preview_text = utf8_encoded_string;
2759 if (local_preview_text != NULL)
2760 *output_preview_buffer = EM_SAFE_STRDUP(local_preview_text);
2762 if (local_preview_text != NULL) {
2763 EM_SAFE_FREE(*output_preview_buffer); /* valgrind */
2764 *output_preview_buffer = EM_SAFE_STRDUP(local_preview_text);
2767 EM_SAFE_FREE(local_preview_text);
2768 EM_SAFE_FREE(encoding_type);
2769 EM_SAFE_FREE(prefix_path);
2771 if (fp_plain != NULL)
2774 EM_DEBUG_FUNC_END("err [%d]", err);
2778 INTERNAL_FUNC int emcore_add_transaction_info(int mail_id, int handle , int *err_code)
2780 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%d]", mail_id, handle);
2783 int err = EMAIL_ERROR_NONE ;
2784 em_transaction_info_type_t *pTransinfo = NULL ;
2785 em_transaction_info_type_t *pTemp = NULL;
2787 EM_DEBUG_LOG("g_transaction_info_list[%p]", g_transaction_info_list);
2788 pTransinfo = g_transaction_info_list ;
2790 if (!(pTemp = em_malloc(sizeof(em_transaction_info_type_t)))) {
2791 EM_DEBUG_EXCEPTION("malloc failed...");
2792 err = EMAIL_ERROR_OUT_OF_MEMORY;
2795 pTemp->mail_id = mail_id ;
2796 pTemp->handle = handle;
2799 pTransinfo = pTemp ;
2800 g_transaction_info_list = pTransinfo ;
2803 while (pTransinfo->next)
2804 pTransinfo = pTransinfo->next;
2805 pTransinfo->next = pTemp;
2813 EM_DEBUG_FUNC_END("g_transaction_info_list[%p]", g_transaction_info_list);
2817 INTERNAL_FUNC int emcore_get_handle_by_mailId_from_transaction_info(int mail_id, int *pHandle)
2819 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p]", mail_id, pHandle);
2822 em_transaction_info_type_t *pTransinfo = NULL ;
2824 if (g_transaction_info_list == NULL) {
2825 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
2828 pTransinfo = g_transaction_info_list;
2831 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
2832 if (pTransinfo->mail_id == mail_id) {
2833 *pHandle = pTransinfo->handle;
2835 EM_DEBUG_LOG("*pHandle[%d]", *pHandle);
2839 pTransinfo = pTransinfo->next ;
2840 }while (pTransinfo);
2841 EM_DEBUG_FUNC_END();
2845 INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id )
2847 EM_DEBUG_FUNC_BEGIN("mail_id[%d]", mail_id);
2849 em_transaction_info_type_t *pTransinfo ;
2850 em_transaction_info_type_t *pTemp = NULL;
2852 if (g_transaction_info_list == NULL) {
2853 EM_DEBUG_EXCEPTION("g_transaction_info_list NULL");
2856 pTransinfo = g_transaction_info_list;
2858 EM_DEBUG_LOG("pTransinfo[%p]", pTransinfo);
2861 EM_DEBUG_LOG("pTransinfo->mail_id[%d]", pTransinfo->mail_id);
2862 if (pTransinfo->mail_id == mail_id) {
2863 pTemp = pTransinfo->next ;
2865 EM_SAFE_FREE(pTransinfo) ;
2866 g_transaction_info_list = NULL;
2869 pTransinfo->mail_id = pTransinfo->next->mail_id;
2870 pTransinfo->handle = pTransinfo->next->handle ;
2871 pTransinfo->next = pTransinfo->next->next;
2873 EM_SAFE_FREE(pTemp);
2878 pTransinfo = pTransinfo->next ;
2881 }while (pTransinfo);
2882 EM_DEBUG_FUNC_END();
2889 INTERNAL_FUNC int reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string)
2891 int error_code = EMAIL_ERROR_NONE;
2893 int so, n, nmatch, source_text_length, n_count = 1;
2894 regmatch_t *pmatch = NULL;
2895 regex_t reg_pattern;
2897 if(!input_source_text || !input_old_pattern_string || !input_new_string) {
2898 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
2899 error_code = EMAIL_ERROR_INVALID_PARAM;
2903 source_text_length = EM_SAFE_STRLEN(input_source_text);
2905 if (regcomp(®_pattern, input_old_pattern_string, REG_EXTENDED | REG_ICASE) != 0) {
2906 EM_DEBUG_EXCEPTION("regcomp failed");
2910 nmatch = reg_pattern.re_nsub + 1;
2912 EM_DEBUG_LOG("nmatch [%d]", nmatch);
2915 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_DATA");
2916 error_code = EMAIL_ERROR_INVALID_DATA;
2920 pmatch = (regmatch_t*)em_malloc(sizeof(regmatch_t) * nmatch);
2922 if(pmatch == NULL) {
2923 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
2924 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
2928 for (pos = input_new_string; *pos ; pos++) {
2929 if (*pos == '\\' && *(pos + 1) > '0' && *(pos + 1) <= '9') {
2931 so = pmatch[*(pos + 1) - 48].rm_so;
2932 n = pmatch[*(pos + 1) - 48].rm_eo - so;
2934 EM_DEBUG_LOG("so [%d], n [%d]", so, n);
2936 if (so < 0 || EM_SAFE_STRLEN (input_new_string) + n - 1 > source_text_length)
2939 memmove (pos + n, pos + 2, EM_SAFE_STRLEN (pos) - 1);
2940 memmove (pos, input_source_text + so, n);
2945 for (pos = input_source_text; !regexec (®_pattern, pos, 1, pmatch, 0);) {
2946 n = pmatch[0].rm_eo - pmatch[0].rm_so;
2947 pos += pmatch[0].rm_so;
2949 memmove (pos + EM_SAFE_STRLEN (input_new_string), pos + n, EM_SAFE_STRLEN (pos) - n + 1);
2950 memmove (pos, input_new_string, EM_SAFE_STRLEN (input_new_string));
2951 pos += EM_SAFE_STRLEN (input_new_string);
2957 EM_SAFE_FREE(pmatch);
2958 regfree (®_pattern);
2960 EM_DEBUG_FUNC_END("error_code [%d]", error_code);
2965 INTERNAL_FUNC char *reg_replace_new(char *input_source_text, char *input_old_pattern_string, char *input_new_string)
2967 char *replaced_str = NULL;
2968 GRegex *regex = NULL;
2969 GError *error = NULL;
2971 if (input_source_text == NULL) {
2972 EM_DEBUG_EXCEPTION("Invalid parameter");
2976 regex = g_regex_new(input_old_pattern_string, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, &error);
2978 EM_DEBUG_LOG("g_regex_new failed");
2982 replaced_str = g_regex_replace_literal(regex,
2984 strlen(input_source_text),
2989 if (replaced_str == NULL) {
2990 EM_DEBUG_EXCEPTION("g_regex_replace_literal failed : [%s][%d]", error->message, error->code);
2996 if (regex) g_regex_unref(regex);
2998 return replaced_str;
3002 #include <libxml/HTMLparser.h>
3004 static void emcore_get_content_string(xmlNode *input_node, char *input_result_buffer, int input_result_buffer_length, int *input_exit_flag)
3006 xmlNode *cur_node = NULL;
3007 char *temp_content_string = NULL;
3009 if (input_node == NULL || input_result_buffer == NULL || input_exit_flag == NULL) {
3010 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
3014 for (cur_node = input_node; cur_node; cur_node = cur_node->next) {
3015 if (cur_node->name && (strcasecmp((const char *)cur_node->name, "head") == 0 || strcasecmp((const char *)cur_node->name, "title") == 0))
3018 if (cur_node->name && (strcasecmp((const char *)cur_node->name, "BR") == 0)) {
3019 if (EM_SAFE_STRLEN(input_result_buffer) + 1 >= input_result_buffer_length) {
3020 *input_exit_flag = 1;
3023 EM_SAFE_STRCAT(input_result_buffer, " ");
3028 if (cur_node->type == XML_TEXT_NODE && cur_node->content) {
3029 if ((EM_SAFE_STRLEN(cur_node->content) + EM_SAFE_STRLEN(input_result_buffer)) >= input_result_buffer_length) {
3030 int len1 = EM_SAFE_STRLEN(input_result_buffer);
3032 if (len1 >= 0 && len1 < input_result_buffer_length) {
3033 int remain_size = input_result_buffer_length - len1 - 2;
3034 EM_DEBUG_LOG("remain_size : [%d], len1 : [%d]", remain_size, len1);
3035 char *remain_str = NULL;
3037 if (remain_size > 0)
3038 remain_str = g_strndup((char *)(cur_node->content), remain_size);
3041 char *replaced_string = NULL;
3042 replaced_string = reg_replace_new(remain_str, "[ \t\r\n\v\f]+", " ");
3043 EM_SAFE_STRCAT(input_result_buffer, replaced_string);
3044 EM_SAFE_FREE(replaced_string);
3049 *input_exit_flag = 1;
3053 temp_content_string = EM_SAFE_STRDUP((const char *)cur_node->content);
3054 if (temp_content_string) {
3055 char *replaced_string = NULL;
3056 replaced_string = reg_replace_new(temp_content_string, "[ \t\r\n\v\f]+", " ");
3057 EM_SAFE_STRCAT(input_result_buffer, replaced_string);
3058 EM_SAFE_FREE(replaced_string);
3059 free(temp_content_string);
3063 if (cur_node->children)
3064 emcore_get_content_string(cur_node->children, input_result_buffer, input_result_buffer_length, input_exit_flag);
3066 if (*input_exit_flag == 1)
3075 static void emcore_default_xml_error_handler(void *ctx, const char *msg, ...) {
3076 EM_DEBUG_EXCEPTION("htmlReadFile failed");
3079 int emcore_strip_HTML_tag(const char *input_html_file_path, char *input_encoding_type, char *output_result_buffer, int input_result_buffer_legnth)
3081 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);
3082 int err = EMAIL_ERROR_NONE;
3084 char *result_string = NULL;
3085 xmlNode *root_element = NULL;
3086 htmlDocPtr result_html_document = NULL;
3087 char *encoding_type = NULL;
3088 char *utf_charset = "UTF-8";
3089 char *euc_kr_charset = "euc-kr";
3091 if (input_html_file_path == NULL || output_result_buffer == NULL || input_result_buffer_legnth == 0) {
3092 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
3093 err = EMAIL_ERROR_INVALID_PARAM;
3097 result_string = em_malloc(sizeof(char) * input_result_buffer_legnth);
3098 if (result_string == NULL) {
3099 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
3100 err = EMAIL_ERROR_OUT_OF_MEMORY;
3104 if (EM_SAFE_STRCMP(input_encoding_type, "unknown") == 0)
3105 encoding_type = utf_charset;
3106 else if (input_encoding_type && (strcasecmp(input_encoding_type, "ks_c_5601-1987") == 0 ||
3107 strcasecmp(input_encoding_type, "ksc5601") == 0 ||
3108 strcasecmp(input_encoding_type, "cp949") == 0))
3109 encoding_type = euc_kr_charset;
3111 encoding_type = input_encoding_type;
3113 EM_DEBUG_LOG("encoding_type [%s]", encoding_type);
3116 xmlSetGenericErrorFunc(NULL, emcore_default_xml_error_handler);
3117 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);
3118 if (result_html_document == NULL) {
3119 EM_DEBUG_EXCEPTION("htmlReadFile failed");
3120 err = EMAIL_ERROR_ON_PARSING;
3124 root_element = xmlDocGetRootElement(result_html_document);
3126 emcore_get_content_string(root_element, result_string, input_result_buffer_legnth, &exit_flag);
3127 char *replaced_string = reg_replace_new(result_string, "[ \t\r\n\v\f]+", " ");
3128 EM_SAFE_STRCPY(output_result_buffer, replaced_string);
3129 EM_SAFE_FREE(replaced_string);
3130 em_trim_left(output_result_buffer);
3133 if (result_html_document) {
3134 xmlFreeDoc(result_html_document);
3137 EM_SAFE_FREE(result_string);
3139 EM_DEBUG_FUNC_END("err [%d]", err);
3143 INTERNAL_FUNC int emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime)
3145 EM_DEBUG_FUNC_BEGIN_SEC("mailbox_name(%s) subject(%s), from(%s), uid(%s), datetime(%s)", mailbox_name, subject, from, uid, datetime);
3146 int error_code = EMAIL_ERROR_NONE;
3147 int param_length = 0;
3148 char *param_string = NULL;
3150 if (mailbox_name == NULL || subject == NULL || from == NULL || uid == NULL || datetime == NULL) {
3151 error_code = EMAIL_ERROR_INVALID_PARAM;
3152 EM_DEBUG_EXCEPTION("Invalid parameter, mailbox_name(%p), subject(%p), from(%p), uid(%p), datetime(%p)", mailbox_name, subject, from, uid, datetime);
3156 param_length = strlen(mailbox_name) + strlen(subject) + strlen(from) + strlen(uid) + strlen(datetime) + 5; /*prevent 34358*/
3158 param_string = em_malloc(param_length);
3159 if (param_string == NULL) {
3160 error_code = EMAIL_ERROR_OUT_OF_MEMORY;
3161 EM_DEBUG_EXCEPTION("Memory allocation for 'param_string' is failed");
3165 memset(param_string, 0x00, param_length);
3167 SNPRINTF(param_string, param_length, "%s%c%s%c%s%c%s%c%s", mailbox_name, 0x01, subject, 0x01, from, 0x01, uid, 0x01, datetime);
3169 if (emcore_notify_network_event(NOTI_DOWNLOAD_NEW_MAIL, account_id, param_string, 0, 0) == 0) { /* failed */
3170 error_code = EMAIL_ERROR_UNKNOWN;
3171 EM_DEBUG_EXCEPTION("emcore_notify_network_event is failed");
3177 EM_SAFE_FREE(param_string);
3178 EM_DEBUG_FUNC_END();
3182 #define MAX_TITLE_LENGTH 1024
3184 #ifdef __FEATURE_DRIVING_MODE__
3185 int convert_app_err_to_email_err(int app_error)
3187 int err = EMAIL_ERROR_NONE;
3190 case APP_CONTROL_ERROR_NONE :
3191 err = EMAIL_ERROR_NONE;
3193 case APP_CONTROL_ERROR_INVALID_PARAMETER :
3194 err = EMAIL_ERROR_INVALID_PARAM;
3196 case APP_CONTROL_ERROR_OUT_OF_MEMORY :
3197 err = EMAIL_ERROR_OUT_OF_MEMORY;
3200 err = EMAIL_ERROR_UNKNOWN;
3207 INTERNAL_FUNC int emcore_start_driving_mode(char *multi_user_name, int mail_id)
3209 EM_DEBUG_FUNC_BEGIN();
3210 int err = APP_CONTROL_ERROR_NONE;
3212 char string_mail[10] = { 0 };
3213 emstorage_mail_tbl_t *p_mail_data = NULL;
3214 app_control_h service = NULL;
3216 if (vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_DRIVINGMODE, &tts_enable) != 0) {
3217 EM_DEBUG_EXCEPTION("vconf_get_int failed");
3221 EM_DEBUG_LOG("Driving Mode : [%d]", tts_enable);
3227 if (vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_NEWEMAILS, &tts_enable) != 0) {
3228 EM_DEBUG_EXCEPTION("vconf_get_int failed");
3232 EM_DEBUG_LOG("New emails of driving Mode : [%d]", tts_enable);
3237 if (!emstorage_get_mail_by_id(multi_user_name, mail_id, &p_mail_data, false, NULL)) {
3238 EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed");
3242 if (p_mail_data->tag_id >= 0)
3245 SNPRINTF(string_mail, sizeof(string_mail), "%d", mail_id);
3247 err = app_control_create(&service);
3248 if (err != APP_CONTROL_ERROR_NONE) {
3249 EM_DEBUG_EXCEPTION("app_control_create failed : [%d]", err);
3253 err = app_control_set_app_id(service, "org.tizen.email-tts-play");
3254 if (err != APP_CONTROL_ERROR_NONE) {
3255 EM_DEBUG_EXCEPTION("app_control_set_app_id failed : [%d]", err);
3259 err = app_control_add_extra_data(service, "tts_email_id", string_mail);
3260 if (err != APP_CONTROL_ERROR_NONE) {
3261 EM_DEBUG_EXCEPTION("app_control_add_extra_data failed : [%d]", err);
3265 err = app_control_send_launch_request(service, NULL, NULL);
3266 if (err != APP_CONTROL_ERROR_NONE) {
3267 EM_DEBUG_EXCEPTION("app_control_send_launch_request failed : [%d]", err);
3274 app_control_destroy(service);
3277 emstorage_free_mail(&p_mail_data, 1, NULL);
3279 EM_DEBUG_FUNC_END();
3280 return convert_app_err_to_email_err(err);
3282 #endif /* __FEATURE_DRIVING_MODE__ */
3284 INTERNAL_FUNC int emcore_clear_notifications(char *multi_user_name, int account_id)
3286 int account_count = 0, i;
3287 emstorage_account_tbl_t *account_list;
3288 int error_code = EMAIL_ERROR_NONE;
3290 if (account_id == ALL_ACCOUNT) {
3291 if(!emstorage_get_account_list(multi_user_name, &account_count, &account_list, true, false, &error_code)) {
3292 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed");
3296 for(i = 0; i < account_count; i++) {
3297 error_code = emcore_delete_notification_by_account(multi_user_name, account_list[i].account_id, true);
3298 if (error_code != EMAIL_ERROR_NONE)
3299 EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed");
3302 error_code = emcore_delete_notification_by_account(multi_user_name, account_id, true);
3303 if (error_code != EMAIL_ERROR_NONE)
3304 EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed");
3307 if (!emstorage_update_save_status(multi_user_name, account_id, &error_code)) {
3308 EM_DEBUG_EXCEPTION("emstorage_update_save_status failed : [%d]", error_code);
3315 emstorage_free_account(&account_list, account_count, NULL);
3318 EM_DEBUG_FUNC_END("return[%d]", error_code);
3322 #define EAS_EXECUTABLE_PATH "/usr/bin/eas-engine"
3324 INTERNAL_FUNC int emcore_delete_notification_by_account(char *multi_user_name, int account_id, int with_noti_tray)
3326 EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
3327 int error_code = EMAIL_ERROR_NONE;
3329 char vconf_private_id[MAX_PATH] = {0, };
3331 SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
3332 if (vconf_get_int(vconf_private_id, &private_id) != 0) {
3333 EM_DEBUG_EXCEPTION("vconf_get_int failed");
3335 #ifdef __FEATURE_NOTIFICATION_ENABLE__
3336 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
3338 if ((noti_err = notification_delete_by_priv_id(NATIVE_EMAIL_APPLICATION_PKG, NOTIFICATION_TYPE_NOTI, private_id)) != NOTIFICATION_ERROR_NONE) {
3339 EM_DEBUG_EXCEPTION("notification_delete_by_priv_id failed [%d]", noti_err);
3340 error_code = EMAIL_ERROR_NOTI;
3343 if (with_noti_tray) {
3344 if ((noti_err = notification_delete_by_priv_id(NATIVE_EMAIL_APPLICATION_PKG, NOTIFICATION_TYPE_ONGOING, private_id)) != NOTIFICATION_ERROR_NONE) {
3345 EM_DEBUG_EXCEPTION("notification_delete_by_priv_id failed [%d]", noti_err);
3346 error_code = EMAIL_ERROR_NOTI;
3349 #endif /* __FEATURE_NOTIFICATION_ENABLE__ */
3350 EM_DEBUG_FUNC_END();
3354 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
3357 * @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)
3358 * Prepare a linked list of uid ranges with each node having a uid_range and lowest and highest uid in it.
3360 *@author h.gahlaut@samsung.com
3361 * @param[in] id_set Specifies the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
3362 * @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
3363 * @param[in] range_len Specifies the maximum length of string of range allowed.
3364 * @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
3365 * @param[out] err_code Returns the error code.
3366 * @remarks An example of a uid_range formed is 2:6,8,10,14:15,89,
3367 * While using it the caller should remove the ending, (comma)
3368 * @return This function returns true on success or false on failure.
3371 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)
3373 EM_DEBUG_FUNC_BEGIN();
3376 int error = EMAIL_ERROR_NONE;
3378 if (NULL == id_set || id_set_count <= 0 || NULL == uid_range_set) {
3379 EM_DEBUG_EXCEPTION(" Invalid Parameter id_set[%p] id_set_count[%d] uid_range_set[%p]", id_set, id_set_count, uid_range_set);
3380 error = EMAIL_ERROR_INVALID_PARAM;
3385 unsigned long current_uid = 0;
3386 unsigned long first_uid = 0;
3387 unsigned long last_uid = 0;
3388 const int max_subset_string_size = MAX_SUBSET_STRING_SIZE;
3389 char subset_string[MAX_SUBSET_STRING_SIZE] = {0,};
3390 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*/
3392 if (range_len < (max_subset_string_size + 1)) /* 1 for ending NULL character */ {
3393 EM_DEBUG_EXCEPTION(" Invalid Parameter range_len[%d]", range_len);
3394 error = EMAIL_ERROR_INVALID_PARAM;
3398 EM_DEBUG_LOG("id set count[%d] range_len[%d]", id_set_count, range_len);
3401 first_uid = last_uid = current_uid = id_set[i].server_mail_id;
3402 /* Start subset string by putting first server mail id in it from id_set*/
3403 memset(subset_string, 0x00, max_subset_string_size);
3404 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
3407 /* Check if only one server mail id was left in id_set */
3408 if (i >= id_set_count) {
3409 /* No more server mail id left in id_set */
3410 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
3411 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
3417 /* 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 */
3419 current_uid = id_set[i].server_mail_id;
3420 if (current_uid == (last_uid + 1)) {
3421 last_uid = current_uid;
3425 memset(subset_string, 0x00, max_subset_string_size);
3426 if (first_uid != last_uid) /* Form subset string by first_uid:last_uid */
3427 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
3428 else /* Form subset string by first_uid */
3429 SNPRINTF(subset_string, max_subset_string_size, "%lu", first_uid);
3431 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
3432 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
3435 /* To Start formation of new subset string break out of inner loop */
3439 } while (i < id_set_count);
3441 /* Flow comes here in two cases :
3442 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
3443 2. due to break statement */
3445 if (last_uid == current_uid) {
3448 memset(subset_string, 0x00, max_subset_string_size);
3449 SNPRINTF(subset_string, max_subset_string_size, "%lu:%lu", first_uid, last_uid);
3451 if (false == emcore_append_subset_string_to_uid_range(subset_string, ¤t_node, uid_range_set, range_len, first_uid, last_uid)) {
3452 EM_DEBUG_EXCEPTION("emcore_append_subset_string_to_uid_range failed");
3457 /* Case 2: Do Nothing */
3461 } while (i < id_set_count);
3466 if (NULL != err_code)
3468 EM_DEBUG_FUNC_END();
3474 * @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)
3475 * 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
3476 * and stores the subset_string in its uid_range. Also sets the lowest and highest uids for the corresponsing uid_range
3478 * @author h.gahlaut@samsung.com
3479 * @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.
3480 * @param[in] range_len Specifies the maximum length of range string allowed.
3481 * @param[in] luid Specifies the lowest uid in subset string
3482 * @param[in] huid Specifies the highest uid in subset string
3483 * @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
3484 * @param[out] err_code Returns the error code.
3486 * @return This function returns true on success or false on failure.
3489 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)
3491 EM_DEBUG_FUNC_BEGIN();
3492 email_uid_range_set *current_node = NULL;
3494 if (NULL == (*uid_range_set)) {
3495 /*This happens only once when list creation starts. Head Node is allocated */
3496 current_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
3497 if (NULL == current_node) {
3498 EM_DEBUG_EXCEPTION("em_malloc failed");
3502 current_node->uid_range = (char *)em_malloc(range_len);
3504 if (NULL == current_node->uid_range) {
3505 EM_DEBUG_EXCEPTION("em_malloc failed");
3506 EM_SAFE_FREE(current_node);
3510 SNPRINTF(current_node->uid_range, range_len, "%s,", subset_string);
3512 current_node->lowest_uid = luid;
3513 current_node->highest_uid = huid;
3514 (*uid_range_set) = current_node;
3516 (*current_node_adr) = current_node;
3520 /* Apart from first call to this function flow will always come here */
3521 current_node = (*current_node_adr);
3522 int len_sub_string = EM_SAFE_STRLEN(subset_string);
3523 int space_left_in_buffer = range_len - EM_SAFE_STRLEN(current_node->uid_range);
3525 if ((len_sub_string + 1 + 1) <= space_left_in_buffer) /* 1 for comma + 1 for ending null character */ {
3526 SNPRINTF(current_node->uid_range + EM_SAFE_STRLEN(current_node->uid_range), space_left_in_buffer, "%s,", subset_string);
3527 current_node->highest_uid = huid;
3530 /* No more space left in uid_range string.If continued on it, it will exceeded max size of range_len */
3531 /* Allocate new node in Uid Range set */
3532 email_uid_range_set *new_node = NULL;
3534 new_node = (email_uid_range_set *)em_malloc(sizeof(email_uid_range_set));
3536 if (NULL == new_node) {
3537 EM_DEBUG_EXCEPTION("em_malloc failed");
3541 /* Allocate uid_range of new node */
3543 new_node->uid_range = (char *)em_malloc(range_len);
3545 if (NULL == new_node->uid_range) {
3546 EM_DEBUG_EXCEPTION("em_malloc failed");
3547 EM_SAFE_FREE(new_node);
3551 SNPRINTF(new_node->uid_range, range_len, "%s, ", subset_string);
3553 new_node->lowest_uid = luid;
3554 new_node->highest_uid = huid;
3556 current_node->next = new_node;
3558 (*current_node_adr) = new_node;
3561 EM_DEBUG_FUNC_END();
3566 * void emcore_free_uid_range_set(email_uid_range_set **uid_range_head)
3567 * Frees the linked list of uid ranges
3569 * @author h.gahlaut@samsung.com
3570 * @param[in] uid_range_head Head pointer of linked list of uid ranges
3572 * @return This function does not return anything.
3576 void emcore_free_uid_range_set(email_uid_range_set **uid_range_set)
3578 EM_DEBUG_FUNC_BEGIN();
3580 email_uid_range_set *current_node = NULL;
3581 email_uid_range_set *uid_range_head = NULL;
3583 current_node = uid_range_head = (*uid_range_set); /* Make the current node and head ptr point to starting of uid_range_set */
3585 while (current_node) {
3586 uid_range_head = current_node->next; /* Move the head ptr to next node*/
3588 EM_SAFE_FREE(current_node->uid_range);
3589 EM_SAFE_FREE(current_node); /* Free the current node */
3591 current_node = uid_range_head; /* Make the current node point to head ptr */
3594 (*uid_range_set) = NULL;
3595 EM_DEBUG_FUNC_END();
3600 * @fn emcore_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char *** strings, int *string_count, int *err_code)
3601 * Forms comma separated strings of a give max_string_len from an array of numbers
3603 * @author h.gahlaut@samsung.com
3604 * @param[in] numbers Specifies the array of numbers to be converted into comma separated strings.
3605 * @param[in] num_count Specifies the count of numbers in numbers array.
3606 * @param[in] max_string_len Specifies the maximum length of comma separated strings that are to be formed.
3607 * @param[out] strings Returns the base address of a double dimension array which stores the strings.
3608 * @param[out] string_count Returns the number of strings formed.
3609 * @param[out] err_code Returns the error code.
3610 * @remarks If Input to the function is five numbers like 2755 2754 2748 2749 2750 and a given max_string_len is 20.
3611 * Then this function will form two comma separated strings as follows -
3612 * "2755, 2754, 2748"
3614 * @return This function returns true on success or false on failure.
3617 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)
3619 EM_DEBUG_FUNC_BEGIN();
3621 int error = EMAIL_ERROR_NONE;
3624 char **string_list = NULL;
3625 int num_of_strings = 0;
3628 char num[MAX_INTEGER_LENGTH + 1] = {0, };
3630 int space_in_buffer = 0;
3631 int len_of_string_formed = 0;
3633 if (NULL == numbers || num_count <= 0 || \
3634 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. */ {
3635 EM_DEBUG_EXCEPTION("Invalid Parameter numbers[%p] num_count [%d] max_string_len [%d] strings [%p] string_count[%p]", \
3636 numbers, num_count, max_string_len, strings, string_count);
3637 error = EMAIL_ERROR_INVALID_PARAM;
3641 EM_DEBUG_LOG("num_count [%d] max_string_len [%d]", num_count, max_string_len);
3643 string_list = em_malloc(sizeof(char *));
3645 if (NULL == string_list) {
3646 EM_DEBUG_EXCEPTION("em_malloc failed ");
3650 string_list[num_of_strings] = em_malloc(max_string_len);
3652 if (NULL == string_list[num_of_strings]) {
3653 EM_DEBUG_EXCEPTION("em_malloc failed ");
3658 space_in_buffer = max_string_len;
3660 for (j = 0; j < num_count;++j) {
3661 memset(num, 0x00, MAX_INTEGER_LENGTH + 1);
3662 SNPRINTF(num, MAX_INTEGER_LENGTH + 1, "%d", numbers[j]);
3664 num_len = EM_SAFE_STRLEN(num);
3666 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
3668 space_in_buffer = max_string_len - len_of_string_formed ;
3670 if (space_in_buffer >= (num_len+1+1)) /* 1 for comma and 1 for ending NULL */ {
3671 SNPRINTF(string_list[num_of_strings - 1] + len_of_string_formed, max_string_len, "%d,", numbers[j]);
3673 else { /* Removing comma at end of string */
3674 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
3676 temp = (char **)realloc(string_list, sizeof(char *) * (num_of_strings + 1)); /* Allocate new buffer to store a pointer to a new string */
3679 EM_DEBUG_EXCEPTION("realloc failed");
3683 memset(temp + num_of_strings, 0X00, sizeof(char *));
3687 string_list[num_of_strings] = em_malloc(max_string_len);/* Allocate new buffer to store the string */
3689 if (NULL == string_list[num_of_strings]) {
3690 EM_DEBUG_EXCEPTION(" em_malloc failed ");
3694 SNPRINTF(string_list[num_of_strings - 1] , max_string_len, "%d,", numbers[j]);/* Start making new string */
3698 /* Removing comma at end of string */
3699 len_of_string_formed = EM_SAFE_STRLEN(string_list[num_of_strings - 1]);
3700 string_list[num_of_strings - 1][len_of_string_formed-1] = '\0';
3706 emcore_free_comma_separated_strings(&string_list, &num_of_strings);
3709 for (i = 0; i < num_of_strings;++i)
3710 EM_DEBUG_LOG("%s", string_list[i]);
3711 *strings = string_list;
3712 *string_count = num_of_strings;
3716 if (NULL != err_code)
3719 EM_DEBUG_FUNC_END("ret [%d]", ret);
3723 * @fn emcore_free_comma_separated_strings(char *** string_list, int *string_count)
3724 * Frees the double dimensional array of strings.
3726 * @author h.gahlaut@samsung.com
3727 * @param[in] uid_range_head Address of base address of double dimensional array of strings.
3728 * @param[in] string_count Address of variable holding the count of strings.
3730 * @return This function does not return anything.
3732 INTERNAL_FUNC void emcore_free_comma_separated_strings(char *** string_list, int *string_count)
3734 EM_DEBUG_FUNC_BEGIN();
3736 char **str_list = NULL;
3739 if (NULL != string_list) {
3740 str_list = *string_list;
3742 if (0 != *string_count) {
3743 count = *string_count;
3744 for (i = 0; i < count; ++i)
3745 EM_SAFE_FREE(str_list[i]);
3748 EM_SAFE_FREE(str_list);
3749 *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 */
3752 EM_DEBUG_FUNC_END();
3761 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)
3763 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);
3764 int ret = false, err = EMAIL_ERROR_NONE;
3765 char *extcheck = NULL;
3766 char attachment_file_name[MAX_PATH + 1] = { 0, };
3768 if (!source_file_name || !result_file_name) {
3769 EM_DEBUG_EXCEPTION("Invalid Parameter");
3770 err = EMAIL_ERROR_INVALID_PARAM;
3774 strncpy(attachment_file_name, source_file_name, MAX_PATH);
3775 extcheck = strchr(attachment_file_name, '.');
3778 EM_DEBUG_LOG("Extension Exist in the Attachment [%s] ", extcheck);
3779 else { /* No extension attached, So add the Extension based on the subtype */
3781 if ((MAX_PATH + 1) < (strlen(sub_type) + 1)) {
3782 EM_DEBUG_EXCEPTION("Buffer overflow");
3783 err = EMAIL_ERROR_OUT_OF_MEMORY;
3787 strcat(attachment_file_name, ".");
3788 strcat(attachment_file_name, sub_type);
3789 EM_DEBUG_LOG_SEC("attachment_file_name with extension[%s] ", attachment_file_name);
3792 EM_DEBUG_LOG("UnKnown Extesnsion");
3795 memset(result_file_name, 0 , result_file_name_buffer_length);
3796 EM_SAFE_STRNCPY(result_file_name, attachment_file_name, result_file_name_buffer_length - 1);
3797 EM_DEBUG_LOG_SEC("*result_file_name[%s]", result_file_name);
3803 EM_DEBUG_FUNC_END();
3807 #ifdef __FEATURE_LOCAL_ACTIVITY__
3808 INTERNAL_FUNC int emcore_add_activity(emstorage_activity_tbl_t *new_activity, int *err_code)
3810 EM_DEBUG_FUNC_BEGIN();
3812 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", new_activity, err_code);
3814 /* default variable */
3816 int err = EMAIL_ERROR_NONE;
3818 if (!new_activity) {
3819 EM_DEBUG_LOG("\t new_activity[%p]\n", new_activity);
3820 err = EMAIL_ERROR_INVALID_PARAM;
3823 if (!emstorage_add_activity(new_activity, false, &err)) {
3824 EM_DEBUG_LOG("\t emstorage_add_activity falied - %d\n", err);
3837 INTERNAL_FUNC int emcore_delete_activity(emstorage_activity_tbl_t *activity, int *err_code)
3839 EM_DEBUG_FUNC_BEGIN();
3841 EM_DEBUG_LOG("\t new_activity[%p], err_code[%p]", activity, err_code);
3843 /* default variable */
3845 int err = EMAIL_ERROR_NONE;
3847 EM_DEBUG_LOG("\t new_activity[%p]\n", activity);
3849 err = EMAIL_ERROR_INVALID_PARAM;
3852 if (!emstorage_delete_local_activity(activity, true, &err)) {
3853 EM_DEBUG_LOG("\t emstorage_delete_local_activity falied - %d\n", err);
3866 INTERNAL_FUNC int emcore_get_next_activity_id(int *activity_id, int *err_code)
3868 EM_DEBUG_FUNC_BEGIN();
3871 int err = EMAIL_ERROR_NONE;
3873 if (NULL == activity_id)
3875 EM_DEBUG_EXCEPTION("\t activity_id[%p]", activity_id);
3877 err = EMAIL_ERROR_INVALID_PARAM;
3881 if (false == emstorage_get_next_activity_id(activity_id, &err)) {
3882 EM_DEBUG_LOG("\t emstorage_get_next_activity_id failed - %d\n", err);
3889 if (NULL != err_code) {
3897 #endif /* __FEATURE_LOCAL_ACTIVITY__ */
3900 INTERNAL_FUNC void emcore_free_rule(email_rule_t* rule)
3902 EM_DEBUG_FUNC_BEGIN();
3907 EM_SAFE_FREE(rule->filter_name);
3908 EM_SAFE_FREE(rule->value);
3909 EM_SAFE_FREE(rule->value2);
3911 EM_DEBUG_FUNC_END();
3914 INTERNAL_FUNC void emcore_free_body_sparep(void **p)
3916 EM_DEBUG_FUNC_BEGIN();
3918 EM_DEBUG_FUNC_END();
3921 INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_string, char *new_string, int *result)
3923 EM_DEBUG_FUNC_BEGIN_SEC("file_path : [%s], search_string : [%s]", file_path, search_string);
3924 int error = EMAIL_ERROR_NONE;
3926 int p_result = false;
3929 char *stripped = NULL;
3930 char *cid_string = NULL;
3931 char *modified_string = NULL;
3933 if (!search_string || !file_path || !result) {
3934 EM_DEBUG_EXCEPTION("Invalid parameter");
3935 error = EMAIL_ERROR_INVALID_PARAM;
3939 error = em_fopen(file_path, "r", &fp);
3940 if (error != EMAIL_ERROR_NONE || fp == NULL) {
3941 EM_DEBUG_EXCEPTION("em_fopen error [%d] [%s]", error, file_path);
3945 if (!emcore_get_file_size(file_path, &file_size, &error)) {
3946 EM_DEBUG_EXCEPTION("emcore_get_file_size error [%s]", file_path);
3950 buf = em_malloc(file_size + 1);
3952 EM_DEBUG_EXCEPTION("em_malloc failed");
3953 error = EMAIL_ERROR_OUT_OF_MEMORY;
3957 if (fread(buf, sizeof(char), file_size, fp) != file_size) {
3958 EM_DEBUG_EXCEPTION("fread error [%d]", errno);
3959 error = EMAIL_ERROR_SYSTEM_FAILURE;
3964 stripped = em_replace_all_string(buf, CRLF_STRING, "");
3967 cid_string = em_malloc(strlen(search_string) + strlen("cid:") + 1);
3968 if (cid_string == NULL) {
3969 EM_DEBUG_EXCEPTION("em_malloc failed");
3970 error = EMAIL_ERROR_OUT_OF_MEMORY;
3974 sprintf(cid_string, "cid:%s", search_string);
3976 modified_string = em_replace_string(stripped, cid_string, new_string);
3977 if (modified_string) {
3981 error = em_fopen(file_path, "w", &fp);
3982 if (error != EMAIL_ERROR_NONE || fp == NULL) {
3983 EM_DEBUG_EXCEPTION("em_fopen failed");
3987 fprintf(fp, "%s", modified_string);
3993 if (strstr(stripped, search_string))
4000 EM_DEBUG_LOG("Search string[%s] not found",search_string);
4008 EM_SAFE_FREE(stripped); /*prevent 35586*/
4009 EM_SAFE_FREE(cid_string);
4010 EM_SAFE_FREE(modified_string);
4012 EM_DEBUG_FUNC_END("error:[%d]", error);
4016 INTERNAL_FUNC int emcore_load_query_from_file(char *file_path, char ***query_array, int *array_len)
4018 EM_DEBUG_FUNC_BEGIN_SEC("file_path : [%s], query_array : [%p]", file_path, *query_array);
4019 int error = EMAIL_ERROR_NONE;
4025 char **result_vector = NULL;
4028 EM_DEBUG_EXCEPTION("Invalid parameter");
4029 error = EMAIL_ERROR_INVALID_PARAM;
4033 error = em_fopen(file_path, "r", &fp);
4034 if (error != EMAIL_ERROR_NONE) {
4035 EM_DEBUG_EXCEPTION("em_fopen failed");
4039 if (!emcore_get_file_size(file_path, &file_size, &error)) {
4040 EM_DEBUG_EXCEPTION("emcore_get_file_size failed");
4044 buf = em_malloc(file_size + 1);
4046 EM_DEBUG_EXCEPTION("em_malloc failed");
4047 error = EMAIL_ERROR_OUT_OF_MEMORY;
4051 if (fread(buf, sizeof(char), file_size, fp) != file_size) {
4052 EM_DEBUG_EXCEPTION("Get the data from file : failed");
4053 error = EMAIL_ERROR_SYSTEM_FAILURE;
4057 result_vector = g_strsplit(buf, ";", -1);
4058 if (!result_vector || g_strv_length(result_vector) <= 0) {
4059 EM_DEBUG_EXCEPTION("Parsing sql file failed");
4060 error = EMAIL_ERROR_SYSTEM_FAILURE;
4064 vector_len = g_strv_length(result_vector);
4065 if (vector_len <= 0) {
4066 EM_DEBUG_EXCEPTION("vector length : [%d]", vector_len);
4067 error = EMAIL_ERROR_SYSTEM_FAILURE;
4071 *query_array = (char **)calloc(vector_len, sizeof(char *));
4073 for (i = 0; i < vector_len; i++) {
4074 if (result_vector[i]) {
4075 char *str = g_strconcat(result_vector[i], ";", NULL);
4076 if (str) (*query_array)[i] = str;
4081 *array_len = vector_len;
4082 EM_DEBUG_LOG("SQL string array length : [%d]", vector_len);
4092 if (result_vector) {
4093 g_strfreev(result_vector);
4096 EM_DEBUG_FUNC_END("error:[%d]", error);
4101 static int emcore_get_next_peak_start_time(emstorage_account_tbl_t *input_account_ref, time_t input_current_time, time_t *output_time)
4103 EM_DEBUG_FUNC_BEGIN("input_account_ref [%p] input_time[%d] output_time[%p]", input_account_ref, input_current_time, output_time);
4104 int err = EMAIL_ERROR_NONE;
4109 struct tm *time_info;
4111 if(output_time == NULL) {
4112 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
4113 err = EMAIL_ERROR_INVALID_PARAM;
4117 time_info = localtime (&input_current_time);
4118 if (time_info == NULL) {
4119 EM_DEBUG_EXCEPTION("localtime failed");
4120 err = EMAIL_ERROR_SYSTEM_FAILURE;
4124 EM_DEBUG_LOG("input time and date: %s", asctime(time_info));
4126 wday = wday << time_info->tm_wday;
4128 EM_DEBUG_LOG("wday[%d] peak_days[%d]", wday, input_account_ref->peak_days);
4130 /* find next peak day */
4132 if (wday & input_account_ref->peak_days) {
4133 start_hour = input_account_ref->peak_start_time / 100;
4134 start_min = input_account_ref->peak_start_time % 100;
4135 if (start_hour < time_info->tm_hour || (start_hour == time_info->tm_hour && start_min < time_info->tm_min)) {
4136 if(wday == EMAIL_PEAK_DAYS_SATDAY)
4137 wday = EMAIL_PEAK_DAYS_SUNDAY;
4145 while (!(wday & input_account_ref->peak_days) && day_count < 7){
4146 EM_DEBUG_LOG("wday[%d] day_count[%d]", wday, day_count);
4147 if(wday == EMAIL_PEAK_DAYS_SATDAY)
4148 wday = EMAIL_PEAK_DAYS_SUNDAY;
4154 EM_DEBUG_LOG("day_count[%d]", day_count);
4156 if (day_count < 7) {
4157 time_info->tm_mday += day_count; /* The other members of time_info will be interpreted or set by mktime */
4159 time_info->tm_hour = input_account_ref->peak_start_time / 100;
4160 time_info->tm_min = input_account_ref->peak_start_time % 100;
4161 time_info->tm_min = 0;
4163 *output_time = mktime(time_info);
4164 EM_DEBUG_LOG("result_time: %s", asctime(time_info));
4169 EM_DEBUG_FUNC_END("err[%d]", err);
4173 static int emcore_check_time_in_peak_schedule(emstorage_account_tbl_t *input_account_ref, time_t input_time, int *output_result)
4175 EM_DEBUG_FUNC_BEGIN("input_account_ref [%p] input_time[%d] output_result[%p]", input_account_ref, input_time, output_result);
4176 int err = EMAIL_ERROR_NONE;
4177 struct tm *time_info;
4185 if(input_account_ref == NULL || output_result == NULL) {
4186 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
4187 err = EMAIL_ERROR_INVALID_PARAM;
4191 time_info = localtime(&input_time);
4192 if (time_info == NULL) {
4193 EM_DEBUG_EXCEPTION("localtime failed");
4194 err = EMAIL_ERROR_SYSTEM_FAILURE;
4198 EM_DEBUG_LOG("input time and date: %s", asctime(time_info));
4200 wday = wday << time_info->tm_wday;
4202 EM_DEBUG_LOG("wday [%d]", wday);
4204 if(wday & input_account_ref->peak_days) {
4205 start_hour = input_account_ref->peak_start_time / 100;
4206 start_min = input_account_ref->peak_start_time % 100;
4208 end_hour = input_account_ref->peak_end_time / 100;
4209 end_min = input_account_ref->peak_end_time % 100;
4211 EM_DEBUG_LOG("start_hour[%d] start_min[%d] end_hour[%d] end_min[%d]", start_hour, start_min, end_hour, end_min);
4213 if(start_hour <= time_info->tm_hour && time_info->tm_hour <= end_hour) {
4214 if(time_info->tm_hour == end_hour) {
4215 if(time_info->tm_min < end_min)
4223 EM_DEBUG_LOG("result[%d]", result);
4224 *output_result = result;
4228 EM_DEBUG_FUNC_END("err[%d]", err);
4232 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)
4234 EM_DEBUG_FUNC_BEGIN("input_account_id[%d] input_current_time[%d] output_time[%p]", input_account_id, input_current_time, output_time);
4235 int err = EMAIL_ERROR_NONE;
4236 emstorage_account_tbl_t *account = NULL;
4237 time_t next_time = 0;
4238 time_t next_peak_start_time = 0;
4239 time_t result_time = 0;
4240 int is_time_in_peak_schedule = 0;
4242 emstorage_get_account_by_id(multi_user_name, input_account_id, EMAIL_ACC_GET_OPT_DEFAULT, &account, true, &err);
4243 if (account == NULL) {
4244 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed [%d]",err);
4248 if (account->peak_days < 0) {
4249 /* peak schedule disabled */
4250 if (account->check_interval > 0)
4251 result_time = input_current_time + (account->check_interval * 60);
4253 else if(account->peak_days > 0) {
4254 /* peak schedule enabled */
4256 /* if current time is in peak schedule */
4257 emcore_check_time_in_peak_schedule(account, input_current_time, &is_time_in_peak_schedule);
4258 EM_DEBUG_LOG("is_time_in_peak_schedule [%d]", is_time_in_peak_schedule);
4259 if(is_time_in_peak_schedule) {
4260 /* if next time to sync is in peak schedule? */
4261 next_time = input_current_time + (account->peak_interval * 60);
4263 emcore_check_time_in_peak_schedule(account, next_time, &is_time_in_peak_schedule);
4264 if(is_time_in_peak_schedule) {
4265 /* create an alarm to sync in peak schedule*/
4266 result_time = next_time;
4270 if(result_time == 0) {
4271 /* if current time is not in peak schedule */
4272 if(next_time == 0) {
4273 /* if normal sync schedule is set */
4274 if(account->check_interval) {
4275 next_time = input_current_time + (account->check_interval * 60);
4278 emcore_get_next_peak_start_time(account, input_current_time, &next_peak_start_time);
4280 EM_DEBUG_LOG("next_time : %s", ctime(&next_time));
4281 EM_DEBUG_LOG("next_peak_start_time : %s", ctime(&next_peak_start_time));
4283 /* if next time to sync is closer than next peak schedule start? */
4284 if(next_time && (next_time < next_peak_start_time)) {
4285 /* create an alarm to sync in check_interval */
4286 result_time = next_time;
4288 /* else check_interval is zero or next peak schedule start is close than next check_interval */
4290 result_time = next_peak_start_time;
4295 *output_time = result_time;
4296 EM_DEBUG_LOG("result_time : %s", ctime(&result_time));
4301 emstorage_free_account(&account, 1, NULL);
4304 EM_DEBUG_FUNC_END("err[%d]", err);
4308 static int convert_contact_err_to_email_err(int contact_err)
4310 int err = EMAIL_ERROR_NONE;
4312 switch (contact_err) {
4313 case CONTACTS_ERROR_NONE :
4314 err = EMAIL_ERROR_NONE;
4316 case CONTACTS_ERROR_OUT_OF_MEMORY :
4317 err = EMAIL_ERROR_OUT_OF_MEMORY;
4319 case CONTACTS_ERROR_INVALID_PARAMETER :
4320 err = EMAIL_ERROR_INVALID_PARAM;
4322 case CONTACTS_ERROR_NO_DATA :
4323 err = EMAIL_ERROR_DATA_NOT_FOUND;
4325 case CONTACTS_ERROR_DB :
4326 err = EMAIL_ERROR_DB_FAILURE;
4328 case CONTACTS_ERROR_IPC :
4329 err = EMAIL_ERROR_IPC_CONNECTION_FAILURE;
4331 case CONTACTS_ERROR_SYSTEM:
4332 err = EMAIL_ERROR_SYSTEM_FAILURE;
4334 case CONTACTS_ERROR_INTERNAL:
4336 err = EMAIL_ERROR_UNKNOWN;
4342 int emcore_get_mail_contact_info(char *multi_user_name, email_mail_contact_info_t *contact_info, char *full_address, int *err_code)
4344 EM_DEBUG_FUNC_BEGIN_SEC("contact_info[%p], full_address[%s], err_code[%p]", contact_info, full_address, err_code);
4347 int err = EMAIL_ERROR_NONE;
4349 if (!emcore_get_mail_contact_info_with_update(multi_user_name, contact_info, full_address, 0, &err))
4350 EM_DEBUG_EXCEPTION("emcore_get_mail_contact_info_with_update failed [%d]", err);
4354 if (err_code != NULL)
4360 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)
4362 EM_DEBUG_FUNC_BEGIN();
4363 int contact_err = CONTACTS_ERROR_NONE;
4365 contacts_query_h query = NULL;
4366 contacts_filter_h filter = NULL;
4367 contacts_list_h list = NULL;
4369 void *join_zone = NULL;
4371 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
4372 if (emcore_set_join_zone(multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
4373 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
4378 if ((contact_err = contacts_query_create(contact_uri, &query)) != CONTACTS_ERROR_NONE) {
4379 EM_DEBUG_EXCEPTION("contacts_query_create failed");
4383 if ((contact_err = contacts_filter_create(contact_uri, &filter)) != CONTACTS_ERROR_NONE) {
4384 EM_DEBUG_EXCEPTION("contacts_filter_create failed");
4388 if ((contact_err = contacts_filter_add_str(filter, address_property_id, CONTACTS_MATCH_FULLSTRING, address)) != CONTACTS_ERROR_NONE) {
4389 EM_DEBUG_EXCEPTION("contacts_filter_add_str failed");
4393 if ((contact_err = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND)) != CONTACTS_ERROR_NONE) {
4394 EM_DEBUG_EXCEPTION("contacts_filter_add_operator failed");
4398 if ((contact_err = contacts_filter_add_bool(filter, favorite_property_id, is_favorite)) != CONTACTS_ERROR_NONE) {
4399 EM_DEBUG_EXCEPTION("contacts_filter_add_bool failed");
4403 if ((contact_err = contacts_query_set_filter(query, filter)) != CONTACTS_ERROR_NONE) {
4404 EM_DEBUG_EXCEPTION("contacts_query_set_filter failed");
4408 if ((contact_err = contacts_db_get_records_with_query(query, 0, limit, &list)) != CONTACTS_ERROR_NONE) {
4409 EM_DEBUG_EXCEPTION("contacts_db_get_record_with_query failed");
4413 if ((contact_err = contacts_list_get_current_record_p(list, contacts_record)) != CONTACTS_ERROR_NONE) {
4414 EM_DEBUG_EXCEPTION("contacts_list_get_current_record_p failed");
4421 contacts_query_destroy(query);
4424 contacts_filter_destroy(filter);
4427 contacts_list_destroy(list, false);
4430 emcore_unset_join_zone(join_zone);
4435 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)
4437 EM_DEBUG_FUNC_BEGIN();
4438 int contact_err = CONTACTS_ERROR_NONE;
4440 contacts_query_h query = NULL;
4441 contacts_filter_h filter = NULL;
4442 contacts_list_h list = NULL;
4444 void *join_zone = NULL;
4446 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
4447 if (emcore_set_join_zone(multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
4448 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
4453 if ((contact_err = contacts_query_create(contact_uri, &query)) != CONTACTS_ERROR_NONE) {
4454 EM_DEBUG_EXCEPTION("contacts_query_create failed");
4458 if ((contact_err = contacts_filter_create(contact_uri, &filter)) != CONTACTS_ERROR_NONE) {
4459 EM_DEBUG_EXCEPTION("contacts_filter_create failed");
4463 if ((contact_err = contacts_filter_add_str(filter, property_id, CONTACTS_MATCH_FULLSTRING, address)) != CONTACTS_ERROR_NONE) {
4464 EM_DEBUG_EXCEPTION("contacts_filter_add_str failed");
4468 if ((contact_err = contacts_query_set_filter(query, filter)) != CONTACTS_ERROR_NONE) {
4469 EM_DEBUG_EXCEPTION("contacts_query_set_filter failed");
4473 if ((contact_err = contacts_db_get_records_with_query(query, 0, limit, &list)) != CONTACTS_ERROR_NONE) {
4474 EM_DEBUG_EXCEPTION("contacts_db_get_record_with_query failed");
4478 if ((contact_err = contacts_list_get_current_record_p(list, contacts_record)) != CONTACTS_ERROR_NONE) {
4479 if (contact_err != CONTACTS_ERROR_NO_DATA) /* no matching record found */
4480 EM_DEBUG_EXCEPTION ("contacts_list_get_current_record_p failed [%d]", contact_err);
4487 contacts_query_destroy(query);
4490 contacts_filter_destroy(filter);
4493 contacts_list_destroy(list, false);
4496 emcore_unset_join_zone(join_zone);
4503 char *email_address;
4505 char *multi_user_name;
4507 email_action_t action;
4508 } set_contacts_log_internal_t;
4510 gboolean emcore_set_contacts_log_internal (void* arg)
4513 EM_DEBUG_EXCEPTION ("no contact data to add");
4516 set_contacts_log_internal_t* tmp = (set_contacts_log_internal_t*) arg;
4517 int account_id = tmp->account_id;
4518 char *email_address = tmp->email_address;
4519 char *subject = tmp->subject;
4520 time_t date_time = tmp->date_time;
4521 email_action_t action = tmp->action;
4522 char *multi_user_name = tmp->multi_user_name;
4524 int contacts_error = CONTACTS_ERROR_NONE;
4526 int action_type = 0;
4528 contacts_record_h phone_record = NULL;
4529 contacts_record_h person_record = NULL;
4531 void *join_zone = NULL;
4533 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
4534 if (emcore_set_join_zone(multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
4535 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
4540 if ((contacts_error = contacts_record_create(_contacts_phone_log._uri, &phone_record)) != CONTACTS_ERROR_NONE) {
4541 EM_DEBUG_EXCEPTION("contacts_query_create failed [%d]", contacts_error);
4545 /* Set email address */
4546 if ((contacts_error = contacts_record_set_str(phone_record, _contacts_phone_log.address, email_address)) != CONTACTS_ERROR_NONE) {
4547 EM_DEBUG_EXCEPTION("contacts_record_set_str [address] failed [%d]", contacts_error);
4551 /* Search contact person info */
4552 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) {
4553 if (contacts_error != CONTACTS_ERROR_NO_DATA) /* no matching record found */
4554 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contacts_error);
4556 /* Get person_id in contacts_person_email record */
4557 if (person_record && (contacts_error = contacts_record_get_int(person_record, _contacts_person_email.person_id, &person_id)) != CONTACTS_ERROR_NONE) {
4558 EM_DEBUG_EXCEPTION("contacts_record_get_str failed [%d]", contacts_error);
4562 /* Set the person id */
4563 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.person_id, person_id)) != CONTACTS_ERROR_NONE) {
4564 EM_DEBUG_EXCEPTION("contacts_record_set_int [person id] failed [%d]", contacts_error);
4570 case EMAIL_ACTION_SEND_MAIL :
4571 action_type = CONTACTS_PLOG_TYPE_EMAIL_SENT;
4573 case EMAIL_ACTION_SYNC_HEADER :
4574 action_type = CONTACTS_PLOG_TYPE_EMAIL_RECEIVED;
4577 EM_DEBUG_EXCEPTION("Unknown action type");
4582 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.log_type, action_type)) != CONTACTS_ERROR_NONE) {
4583 EM_DEBUG_EXCEPTION("contacts_record_set_int [log_type] failed [%d]", contacts_error);
4588 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.log_time, (int)date_time)) != CONTACTS_ERROR_NONE) {
4589 EM_DEBUG_EXCEPTION("contacts_record_set_str [address] failed [%d]", contacts_error);
4594 if ((contacts_error = contacts_record_set_str(phone_record, _contacts_phone_log.extra_data2, subject)) != CONTACTS_ERROR_NONE) {
4595 EM_DEBUG_EXCEPTION("contacts_record_set_str [subject] failed [%d]", contacts_error);
4600 if ((contacts_error = contacts_record_set_int(phone_record, _contacts_phone_log.extra_data1, account_id)) != CONTACTS_ERROR_NONE) {
4601 EM_DEBUG_EXCEPTION("contacts_record_set_int [mail id] failed [%d]", contacts_error);
4605 /* Insert the record in DB */
4606 if ((contacts_error = contacts_db_insert_record(phone_record, NULL)) != CONTACTS_ERROR_NONE) {
4607 EM_DEBUG_EXCEPTION("contacts_db_insert_record failed [%d]",contacts_error );
4613 if (phone_record != NULL)
4614 contacts_record_destroy(phone_record, false);
4616 if (person_record != NULL)
4617 contacts_record_destroy(person_record, false);
4620 emcore_unset_join_zone(join_zone);
4622 EM_SAFE_FREE (email_address);
4623 EM_SAFE_FREE (subject);
4626 EM_DEBUG_FUNC_END("contact err [%d]", convert_contact_err_to_email_err(contacts_error));
4630 int emcore_set_contacts_log (char *multi_user_name,
4632 char *email_address,
4635 email_action_t action)
4637 /* arg shall be destroyed in emcore_set_contacts_log_internal */
4638 set_contacts_log_internal_t *arg = em_malloc (sizeof(set_contacts_log_internal_t));
4640 EM_DEBUG_EXCEPTION ("em_malloc error");
4641 return EMAIL_ERROR_OUT_OF_MEMORY;
4645 arg->account_id = account_id;
4646 arg->email_address = EM_SAFE_STRDUP (email_address);
4647 arg->subject = EM_SAFE_STRDUP (subject);
4648 arg->date_time = date_time;
4649 arg->action = action;
4650 arg->multi_user_name = EM_SAFE_STRDUP (multi_user_name);
4652 g_main_context_invoke (NULL, emcore_set_contacts_log_internal, arg);
4654 return EMAIL_ERROR_NONE;
4657 INTERNAL_FUNC int emcore_set_sent_contacts_log(char *multi_user_name, emstorage_mail_tbl_t *input_mail_data)
4659 EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
4662 int err = EMAIL_ERROR_NONE;
4663 char email_address[MAX_EMAIL_ADDRESS_LENGTH];
4664 char *address_array[3] = {input_mail_data->full_address_to, input_mail_data->full_address_cc, input_mail_data->full_address_bcc};
4665 ADDRESS *addr = NULL;
4666 ADDRESS *p_addr = NULL;
4668 for (i = 0; i < 3; i++) {
4669 if (address_array[i] && address_array[i][0] != 0) {
4670 rfc822_parse_adrlist(&addr, address_array[i], NULL);
4671 for (p_addr = addr ; p_addr ;p_addr = p_addr->next) {
4672 SNPRINTF(email_address, MAX_EMAIL_ADDRESS_LENGTH, "%s@%s", addr->mailbox, addr->host);
4673 if ((err = emcore_set_contacts_log(multi_user_name,
4674 input_mail_data->account_id,
4676 input_mail_data->subject,
4677 input_mail_data->date_time,
4678 EMAIL_ACTION_SEND_MAIL)) != EMAIL_ERROR_NONE) {
4679 EM_DEBUG_EXCEPTION("emcore_set_contacts_log failed : [%d]", err);
4685 mail_free_address(&addr);
4694 mail_free_address(&addr);
4696 EM_DEBUG_FUNC_END("err [%d]", err);
4701 INTERNAL_FUNC int emcore_set_received_contacts_log(char *multi_user_name, emstorage_mail_tbl_t *input_mail_data)
4703 EM_DEBUG_FUNC_BEGIN("input_mail_data : [%p]", input_mail_data);
4704 int err = EMAIL_ERROR_NONE;
4706 if ((err = emcore_set_contacts_log(multi_user_name,
4707 input_mail_data->account_id,
4708 input_mail_data->email_address_sender,
4709 input_mail_data->subject,
4710 input_mail_data->date_time,
4711 EMAIL_ACTION_SYNC_HEADER)) != EMAIL_ERROR_NONE) {
4712 EM_DEBUG_EXCEPTION("emcore_set_contacts_log failed [%d]", err);
4715 EM_DEBUG_FUNC_END("err [%d]", err);
4719 typedef struct _contacts_delete_data
4722 char *multi_user_name;
4723 } contacts_delete_data;
4725 gboolean emcore_delete_contacts_log_internal(void* arg)
4727 EM_DEBUG_FUNC_BEGIN();
4729 contacts_delete_data *data = (contacts_delete_data *)arg;
4730 int contacts_error = CONTACTS_ERROR_NONE;
4732 void *join_zone = NULL;
4734 if (EM_SAFE_STRLEN(data->multi_user_name) > 0) {
4735 if (emcore_set_join_zone(data->multi_user_name, &join_zone) != EMAIL_ERROR_NONE) {
4736 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed");
4741 /* Delete record of the account id */
4742 if ((contacts_error = contacts_phone_log_delete(CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1, data->account_id)) != CONTACTS_ERROR_NONE) {
4743 EM_DEBUG_EXCEPTION("contacts_phone_log_delete failed [%d]", contacts_error);
4745 /* err = convert_contact_err_to_email_err(contacts_error); */
4748 emcore_unset_join_zone(join_zone);
4750 EM_SAFE_FREE(data->multi_user_name);
4753 EM_DEBUG_FUNC_END();
4757 INTERNAL_FUNC int emcore_delete_contacts_log(char *multi_user_name, int account_id)
4759 contacts_delete_data *data = NULL;
4761 data = (contacts_delete_data *)em_malloc(sizeof(contacts_delete_data));
4763 EM_DEBUG_EXCEPTION("em_malloc failed");
4764 return EMAIL_ERROR_OUT_OF_MEMORY;
4767 data->account_id = account_id;
4768 data->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
4770 g_main_context_invoke (NULL, emcore_delete_contacts_log_internal, (void*) data);
4772 return EMAIL_ERROR_NONE;
4775 INTERNAL_FUNC int emcore_get_mail_display_name (char *multi_user_name, char *email_address, char **contact_display_name)
4777 if (!email_address || !contact_display_name) {
4778 EM_DEBUG_EXCEPTION ("NULL_PARAM email_address[%p] contact_display_name[%p]",
4779 email_address, contact_display_name);
4780 return EMAIL_ERROR_INVALID_PARAM;
4783 GError *gerror = NULL;
4784 GVariant *result = NULL;
4785 int ret = EMAIL_ERROR_NONE;
4787 #if !GLIB_CHECK_VERSION(2, 36, 0)
4791 GDBusProxy* bproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
4792 G_DBUS_PROXY_FLAGS_NONE,
4800 EM_DEBUG_EXCEPTION ("g_dbus_proxy_new_for_bus_sync error [%s]",
4802 ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
4806 result = g_dbus_proxy_call_sync (bproxy,
4808 g_variant_new ("(ss)", email_address, multi_user_name),
4809 G_DBUS_CALL_FLAGS_NONE,
4816 EM_DEBUG_EXCEPTION ("g_dbus_proxy_call_sync 'GetDisplayName' error [%s]",
4818 ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
4822 g_variant_get (result, "(si)", contact_display_name, &ret);
4824 /* replace "" to NULL */
4825 if (!g_strcmp0 (*contact_display_name, ""))
4826 EM_SAFE_FREE (*contact_display_name);
4828 g_variant_unref (result);
4831 EM_DEBUG_LOG ("ret [%d]\n", ret);
4833 g_object_unref (bproxy);
4835 g_error_free (gerror);
4841 INTERNAL_FUNC int emcore_get_mail_display_name_internal (char *multi_user_name,
4842 char *email_address,
4843 char **contact_display_name)
4845 EM_DEBUG_FUNC_BEGIN_SEC("contact_name_value[%s], contact_display_name[%p]", email_address, contact_display_name);
4847 int contact_err = 0;
4848 int err = EMAIL_ERROR_NONE;
4850 char *display = NULL;
4851 /* Contact variable */
4852 contacts_record_h record = NULL;
4855 if ((contact_err = contacts_connect_on_thread()) != CONTACTS_ERROR_NONE) {
4856 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contact_err);
4860 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) {
4861 if (contact_err != CONTACTS_ERROR_NO_DATA) /* no matching record found */
4862 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contact_err);
4866 if ((contact_err = contacts_list_get_count(list, &list_count)) != CONTACTS_ERROR_NONE) {
4867 EM_DEBUG_EXCEPTION("contacts_list_get_count failed");
4871 if (list_count > 1) {
4872 EM_DEBUG_EXCEPTION("Duplicated contacts info");
4873 contact_err = CONTACTS_ERROR_INTERNAL;
4875 } else if (list_count == 0) {
4876 EM_DEBUG_EXCEPTION("Not found contact info");
4877 contact_err = CONTACTS_ERROR_NO_DATA;
4882 if (contacts_record_get_str(record, _contacts_contact_email.display_name, &display) != CONTACTS_ERROR_NONE) {
4883 EM_DEBUG_EXCEPTION("contacts_record_get_str failed");
4891 /* contacts_disconnect_on_thread(); */
4894 contacts_record_destroy(record, false);
4897 *contact_display_name = display;
4899 *contact_display_name = NULL;
4900 EM_SAFE_FREE(display);
4903 err = convert_contact_err_to_email_err(contact_err);
4908 INTERNAL_FUNC int emcore_connect_contacts_service(char *multi_user_name)
4910 EM_DEBUG_FUNC_BEGIN();
4911 int contact_err = 0;
4912 int err = EMAIL_ERROR_NONE;
4914 void *join_zone = NULL;
4916 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
4917 if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
4918 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
4923 if ((contact_err = contacts_connect()) != CONTACTS_ERROR_NONE) {
4924 EM_DEBUG_EXCEPTION("contacts_connect failed : [%d]", contact_err);
4927 err = convert_contact_err_to_email_err(contact_err);
4930 emcore_unset_join_zone(join_zone);
4932 EM_DEBUG_FUNC_END();
4936 INTERNAL_FUNC int emcore_disconnect_contacts_service(char *multi_user_name)
4938 EM_DEBUG_FUNC_BEGIN();
4939 int contact_err = 0;
4940 int err = EMAIL_ERROR_NONE;
4942 void *join_zone = NULL;
4944 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
4945 if ((err = emcore_set_join_zone(multi_user_name, &join_zone)) != EMAIL_ERROR_NONE) {
4946 EM_DEBUG_EXCEPTION("emcore_set_join_zone failed : [%d]", err);
4951 if ((contact_err = contacts_disconnect()) != CONTACTS_ERROR_NONE) {
4952 EM_DEBUG_EXCEPTION("contacts_disconnect failed : [%d]", contact_err);
4955 err = convert_contact_err_to_email_err(contact_err);
4958 emcore_unset_join_zone(join_zone);
4960 EM_DEBUG_FUNC_END();
4964 #ifdef __FEATURE_BLOCKING_MODE__
4966 #define ALLOWED_CONTACT_TYPE_NONE 0
4967 #define ALLOWED_CONTACT_TYPE_ALL 1
4968 #define ALLOWED_CONTACT_TYPE_FAVORITES 2
4969 #define ALLOWED_CONTACT_TYPE_CUSTOM 3
4971 static int blocking_mode_status = false;
4972 INTERNAL_FUNC int blocking_mode_of_setting = false;
4974 INTERNAL_FUNC void emcore_set_blocking_mode_of_setting(int input_blocking_mode_of_setting)
4976 blocking_mode_of_setting = input_blocking_mode_of_setting;
4979 INTERNAL_FUNC int emcore_get_blocking_mode_status()
4981 EM_DEBUG_FUNC_BEGIN("blocking_mode_status : [%d]", blocking_mode_status);
4982 EM_DEBUG_FUNC_END();
4984 return blocking_mode_status;
4987 INTERNAL_FUNC void emcore_set_blocking_mode_status(int blocking_mode)
4989 blocking_mode_status = blocking_mode;
4992 INTERNAL_FUNC int emcore_check_blocking_mode (char *multi_user_name, char *sender_address, int *blocking_status)
4994 if ( !sender_address || !blocking_status ) {
4995 EM_DEBUG_EXCEPTION ("NULL_PARAM sender_address[%p] blocking_status[%p]",
4996 sender_address, blocking_status);
4997 return EMAIL_ERROR_INVALID_PARAM;
5001 GError *gerror = NULL;
5002 GVariant *result = NULL;
5003 int ret = EMAIL_ERROR_NONE;
5005 #if !GLIB_CHECK_VERSION(2, 36, 0)
5009 GDBusProxy* bproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
5010 G_DBUS_PROXY_FLAGS_NONE,
5018 EM_DEBUG_EXCEPTION ("g_dbus_proxy_new_for_bus_sync error [%s]",
5020 ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
5024 result = g_dbus_proxy_call_sync (bproxy,
5025 "CheckBlockingMode",
5026 g_variant_new ("(ss)", sender_address, multi_user_name),
5027 G_DBUS_CALL_FLAGS_NONE,
5034 EM_DEBUG_EXCEPTION ("g_dbus_proxy_call_sync 'CheckBlockingMode' error [%s]",
5036 ret = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
5040 g_variant_get (result, "(ii)", blocking_status, &ret);
5041 g_variant_unref (result);
5046 g_object_unref (bproxy);
5048 g_error_free (gerror);
5053 INTERNAL_FUNC int emcore_check_blocking_mode_internal (char *multi_user_name, char *sender_address, int *blocking_status)
5055 EM_DEBUG_FUNC_BEGIN();
5056 int err = EMAIL_ERROR_NONE;
5057 int contact_error = 0;
5059 int allowed_contact_type = 0; /* 0 : NONE, 1 : All contacts, 2 : Favorites, 3 : Custom */
5060 char *person_id_string = NULL;
5063 contacts_record_h record = NULL;
5065 if (!blocking_mode_of_setting) {
5069 if (vconf_get_int(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_TYPE, &allowed_contact_type) != 0) {
5070 EM_DEBUG_EXCEPTION("vconf_get_int failed");
5071 err = EMAIL_ERROR_SYSTEM_FAILURE;
5076 if ((contact_error = contacts_connect_on_thread()) != CONTACTS_ERROR_NONE) {
5077 EM_DEBUG_EXCEPTION("Open connect service failed [%d]", contact_error);
5081 switch (allowed_contact_type) {
5082 case ALLOWED_CONTACT_TYPE_NONE :
5083 EM_DEBUG_LOG("allowed_contact_type is none : bloacking all(notification)");
5084 *blocking_status = true;
5086 case ALLOWED_CONTACT_TYPE_ALL :
5087 EM_DEBUG_LOG("allowed_contact_type is ALL");
5088 /* Search the allowed contact type in contact DB */
5089 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) {
5090 if (contact_error != CONTACTS_ERROR_NO_DATA) /* no matching record found */
5091 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contact_error);
5095 if (record == NULL) {
5096 EM_DEBUG_LOG("No search contact info");
5100 *blocking_status = false;
5103 case ALLOWED_CONTACT_TYPE_FAVORITES :
5104 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) {
5105 EM_DEBUG_EXCEPTION("emcore_search_contact_info failed : [%d]", contact_error);
5109 if (record == NULL) {
5110 EM_DEBUG_LOG("No search contact info");
5114 *blocking_status = false;
5117 case ALLOWED_CONTACT_TYPE_CUSTOM :
5118 person_id_string = vconf_get_str(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_LIST);
5119 if (person_id_string == NULL) {
5120 EM_DEBUG_LOG("Custom allowed contact type is NULL");
5124 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) {
5125 if (contact_error != CONTACTS_ERROR_NO_DATA) /* no matching record found */
5126 EM_DEBUG_EXCEPTION("emcore_search_contact_info_by_address failed [%d]", contact_error);
5130 if (record == NULL) {
5131 EM_DEBUG_LOG("No search contact info");
5135 if (contacts_record_get_int(record, _contacts_contact_email.person_id, &person_id) != CONTACTS_ERROR_NONE) {
5136 EM_DEBUG_EXCEPTION("contacts_record_get_int failed");
5140 token = strtok_r(person_id_string, ",", &str);
5142 if (person_id == atoi(token)) {
5143 *blocking_status = false;
5146 } while ((token = strtok_r(NULL, ",", &str)));
5151 EM_DEBUG_EXCEPTION("Invalid parameter : [%d]", allowed_contact_type);
5152 *blocking_status = true;
5153 err = EMAIL_ERROR_INVALID_PARAM;
5159 contacts_disconnect_on_thread();
5161 err = convert_contact_err_to_email_err(contact_error);
5163 EM_SAFE_FREE(person_id_string);
5165 EM_DEBUG_FUNC_END();
5169 #endif /* __FEATURE_BLOCKING_MODE__ */
5171 INTERNAL_FUNC char *emcore_set_mime_entity(char *mime_path)
5173 EM_DEBUG_FUNC_BEGIN("mime_path : [%s]", mime_path);
5174 FILE *fp_read = NULL;
5175 FILE *fp_write = NULL;
5176 char *mime_entity = NULL;
5177 char *mime_entity_path = NULL;
5178 char temp_buffer[255] = {0,};
5179 int err = EMAIL_ERROR_NONE;
5182 if (!emcore_get_temp_file_name(&mime_entity_path, &err)) {
5183 EM_DEBUG_EXCEPTION(" em_core_get_temp_file_name failed[%d]", err);
5187 /* get mime entity */
5188 if (mime_path != NULL) {
5189 err = em_fopen(mime_path, "r", &fp_read);
5190 if (err != EMAIL_ERROR_NONE) {
5191 EM_DEBUG_EXCEPTION_SEC("File em_fopen(read) is failed : filename [%s]", mime_path);
5195 err = em_fopen(mime_entity_path, "w", &fp_write);
5196 if (err != EMAIL_ERROR_NONE) {
5197 EM_DEBUG_EXCEPTION_SEC("File em_fopen(write) is failed : filename [%s]", mime_entity_path);
5201 fseek(fp_read, 0, SEEK_SET);
5202 fseek(fp_write, 0, SEEK_SET);
5204 while (fgets(temp_buffer, 255, fp_read) != NULL) {
5205 mime_entity = strcasestr(temp_buffer, "content-type");
5206 if (mime_entity != NULL && !searched)
5210 fprintf(fp_write, "%s", temp_buffer);
5222 EM_SAFE_FREE(mime_entity);
5224 EM_DEBUG_FUNC_END();
5225 return mime_entity_path;
5228 INTERNAL_FUNC int emcore_get_content_from_file(char *filename, char **contents, int *length)
5230 EM_DEBUG_FUNC_BEGIN("filename[%s], contents[%p], length[%p]", filename, contents, length);
5232 struct stat stat_buf;
5237 int err = EMAIL_ERROR_NONE;
5239 char errno_buf[ERRNO_BUF_SIZE] = {0};
5241 if (filename == NULL || contents == NULL || length == NULL) {
5242 err = EMAIL_ERROR_INVALID_PARAM;
5243 EM_DEBUG_EXCEPTION("Invalid parameter");
5247 err = em_open(filename, O_RDONLY, 0 ,&fd);
5248 if (err != EMAIL_ERROR_NONE) {
5249 EM_DEBUG_EXCEPTION("em_open error [%s][%d]", filename, err);
5253 if (fstat (fd, &stat_buf) < 0) {
5254 EM_DEBUG_EXCEPTION("fstat failed for fd [%d]", fd);
5255 err = EMAIL_ERROR_SYSTEM_FAILURE;
5259 if (stat_buf.st_size > 0 && S_ISREG(stat_buf.st_mode)) {
5260 size = stat_buf.st_size;
5261 alloc_size = size + 1;
5262 buf = em_malloc(alloc_size);
5264 EM_DEBUG_EXCEPTION("malloc failed...");
5265 err = EMAIL_ERROR_OUT_OF_MEMORY;
5272 while (bytes_read < size) {
5273 ssize_t rd_size = 0;
5274 rd_size = read (fd, buf + bytes_read, size - bytes_read);
5277 if (errno != EINTR) {
5278 EM_DEBUG_EXCEPTION("read failed: %s", EM_STRERROR(errno_buf));
5279 err = EMAIL_ERROR_SYSTEM_FAILURE;
5283 else if (rd_size == 0)
5286 bytes_read += rd_size;
5289 buf[bytes_read] = '\0';
5292 *length = bytes_read;
5296 EM_SAFE_CLOSE (fd); /* prevent 39093 */
5298 EM_DEBUG_FUNC_END();
5304 EM_SAFE_CLOSE (fd); /* prevent 39093 */
5305 EM_DEBUG_FUNC_END ();
5310 INTERNAL_FUNC int emcore_set_content_to_file(const char *contents, char *dest_path, int length)
5312 EM_DEBUG_FUNC_BEGIN("contents[%p], dest_path[%s], length[%d]", contents, dest_path, length);
5314 int err = EMAIL_ERROR_NONE;
5315 char *tmp_path = NULL;
5316 char errno_buf[ERRNO_BUF_SIZE] = {0};
5317 int byte_written = 0; /* 39063 */
5319 if (contents == NULL || dest_path == NULL || length <= 0) {
5320 err = EMAIL_ERROR_INVALID_PARAM;
5321 EM_DEBUG_EXCEPTION("Invalid parameter");
5325 tmp_path = emcore_mime_get_save_file_name(&err);
5326 if (!tmp_path) { /* prevent 39114 */
5327 EM_DEBUG_EXCEPTION ("tmp_path NULL");
5331 err = em_open(tmp_path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, &fd);
5332 if (err != EMAIL_ERROR_NONE) {
5333 EM_DEBUG_EXCEPTION("em_open error [%s][%d]", tmp_path, err);
5338 while(length > 0 && contents && errno == 0) {
5339 byte_written = write(fd, (void *)contents, length);
5340 if (byte_written < 0) {
5341 /* interrupted by a signal */
5342 if (errno == EINTR) {
5346 EM_DEBUG_EXCEPTION("write failed: %s", EM_STRERROR(errno_buf));
5347 err = EMAIL_ERROR_SYSTEM_FAILURE;
5351 EM_DEBUG_LOG("NWRITTEN [%d]", byte_written);
5352 length -= byte_written;
5353 contents += byte_written;
5357 if (fsync(fd) != 0){
5358 EM_DEBUG_EXCEPTION("fsync failed: %s", EM_STRERROR(errno_buf));
5359 err = EMAIL_ERROR_SYSTEM_FAILURE;
5363 if (tmp_path && dest_path && rename(tmp_path, dest_path) != 0) {
5364 EM_DEBUG_EXCEPTION("rename failed: %s", EM_STRERROR(errno_buf));
5365 err = EMAIL_ERROR_SYSTEM_FAILURE;
5371 EM_SAFE_FREE(tmp_path);
5372 EM_SAFE_CLOSE (fd); /* prevent 39114, 39136*/
5373 EM_DEBUG_FUNC_END();
5377 #ifdef __FEATURE_UPDATE_DB_TABLE_SCHEMA__
5379 INTERNAL_FUNC int emcore_update_db_table_schema(char *multi_user_name)
5381 EM_DEBUG_FUNC_BEGIN();
5382 int err = EMAIL_ERROR_NONE;
5384 err = emstorage_update_db_table_schema(multi_user_name);
5386 EM_DEBUG_FUNC_END("err[%d]", err);
5390 #endif /* __FEATURE_UPDATE_DB_TABLE_SCHEMA__ */
5392 INTERNAL_FUNC int emcore_unescape_from_url(char *input_url, char **output_url)
5394 EM_DEBUG_FUNC_BEGIN("input_url[%p] output_url[%p]", input_url, output_url);
5395 int err = EMAIL_ERROR_NONE;
5396 int input_length = 0;
5397 int output_length = 0;
5398 char *result_string = NULL;
5401 if (input_url == NULL|| output_url == NULL) {
5402 err = EMAIL_ERROR_INVALID_PARAM;
5403 EM_DEBUG_EXCEPTION("Invalid parameter");
5408 curl = curl_easy_init();
5410 input_length = EM_SAFE_STRLEN(input_url);
5412 result_string = curl_easy_unescape(curl, input_url, input_length, &output_length);
5415 *output_url = EM_SAFE_STRDUP(result_string);
5419 curl_free(result_string);
5422 curl_easy_cleanup(curl);
5424 EM_DEBUG_FUNC_END("err[%d]", err);
5428 INTERNAL_FUNC char *__em_get_month_in_string(int month)
5430 EM_DEBUG_FUNC_BEGIN("month [%d]", month);
5436 mon = strdup("jan");
5439 mon = strdup("feb");
5442 mon = strdup("mar");
5445 mon = strdup("apr");
5448 mon = strdup("may");
5451 mon = strdup("jun");
5454 mon = strdup("jul");
5457 mon = strdup("aug");
5460 mon = strdup("sep");
5463 mon = strdup("oct");
5466 mon = strdup("nov");
5469 mon = strdup("dec");
5475 INTERNAL_FUNC int emcore_make_date_string_for_search(time_t input_time, char *output_date_string)
5477 EM_DEBUG_FUNC_BEGIN("input_time[%p] output_date_string[%p]", input_time, output_date_string);
5478 int err = EMAIL_ERROR_NONE;
5479 struct tm *timeinfo = NULL;
5482 EM_DEBUG_LOG("RawTime Info [%lu]", input_time);
5484 timeinfo = localtime(&input_time);
5485 if (timeinfo == NULL) {
5486 EM_DEBUG_EXCEPTION("localtime failed");
5487 err = EMAIL_ERROR_SYSTEM_FAILURE;
5491 EM_DEBUG_LOG(">>>>>Time %d %d %d %d %d %d", 1900+timeinfo->tm_year, timeinfo->tm_mon+1, timeinfo->tm_mday);
5493 memset(output_date_string, 0x00, 20);
5495 mon = __em_get_month_in_string(timeinfo->tm_mon);
5497 snprintf(output_date_string, 16, "%d-%s-%04d", timeinfo->tm_mday, mon, 1900 + timeinfo->tm_year);
5498 EM_DEBUG_LOG("DATE IS [ %s ] ", output_date_string);
5502 EM_DEBUG_FUNC_END("err [%d]", err);
5506 INTERNAL_FUNC int emcore_make_uid_range_string(emcore_uid_list *uid_list, int total, char **output_uid_range_string)
5508 EM_DEBUG_FUNC_BEGIN("uid_list[%p] total[%d] output_uid_range_string[%p]", uid_list, total, output_uid_range_string);
5509 int err = EMAIL_ERROR_NONE;
5510 emcore_uid_list *uid_list_prev = NULL;
5511 emcore_uid_list *uid_list_fast = uid_list;
5513 int msg_count = total;
5514 int uid_range_size = msg_count * 8 + 1000;
5515 char *uid_range = NULL;
5517 if (uid_list == NULL || total == 0 || output_uid_range_string == NULL) {
5518 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
5519 err = EMAIL_ERROR_INVALID_PARAM;
5523 EM_DEBUG_LOG("memory allocation for uid_range [%d, %d]", msg_count, uid_range_size);
5524 uid_range = malloc(sizeof(char) * uid_range_size);
5526 if (uid_range == NULL){
5527 EM_DEBUG_EXCEPTION("memory allocation for uid_range failed");
5528 err = EMAIL_ERROR_OUT_OF_MEMORY;
5532 uid_list_prev = uid_list_fast;
5534 if (uid_list_fast->next == NULL){
5535 /* Single list entry */
5536 snprintf(uid_range, uid_range_size, "%d", atoi(uid_list_fast->uid));
5537 EM_DEBUG_LOG("uid_range [%d]", uid_range);
5540 /* forming range of uids to be passed */
5541 while (uid_list_fast != NULL){
5542 /* uid_list_fast = uid_list_fast->next; */
5544 if ((uid_list_fast->next != NULL) && (((atoi(uid_list_prev->uid)) - (atoi(uid_list_fast->next->uid))) == 1)){
5545 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;
5550 /* to make UID range string "abc, XX : YY" */
5551 while (uid_list_fast != NULL){
5552 if (uid_list_fast->next == NULL)
5554 if (((atoi(uid_list_prev->uid)) - (atoi(uid_list_fast->next->uid))) == 1){
5555 uid_list_fast = uid_list_fast->next;
5556 uid_list_prev = uid_list_fast;
5561 if ((uid_list_fast != NULL) && (uid_list_fast->next != NULL))
5562 index += snprintf(uid_range+index, uid_range_size, ":%d,", atoi(uid_list_prev->uid));
5564 index += snprintf(uid_range+index, uid_range_size, ":%d", atoi(uid_list_prev->uid));
5566 uid_list_fast = uid_list_fast->next;
5567 uid_list_prev = uid_list_fast;
5570 if (uid_list_fast->next != NULL)
5571 index += snprintf(uid_range+index, uid_range_size, "%d,", atoi(uid_list_prev->uid));
5573 index += snprintf(uid_range+index, uid_range_size, "%d", atoi(uid_list_prev->uid));
5574 uid_list_fast = uid_list_fast->next;
5575 uid_list_prev = uid_list_fast;
5579 EM_DEBUG_LOG("index [%d]", index);
5581 *output_uid_range_string = uid_range;
5585 EM_DEBUG_FUNC_END("err [%d]", err);