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.
24 /******************************************************************************
25 * File: email-daemon-init.c
26 * Desc: email-daemon Initialization
31 * 2006.08.16 : created
32 *****************************************************************************/
37 #include <glib-object.h>
39 #include <vconf-internal-account-keys.h>
40 #include <dbus/dbus.h>
41 #include <dlfcn.h> /* added for Disabling the Pthread flag log */
42 #include <net_connection.h>
44 #include "email-daemon.h"
45 #include "email-storage.h"
46 #include "email-debug-log.h"
47 #include "email-daemon-init.h"
48 #include "email-daemon-account.h"
49 #include "email-daemon-auto-poll.h"
50 #include "email-daemon-event.h"
51 #include "email-core-utils.h"
52 #include "email-core-mail.h"
53 #include "email-core-event.h"
54 #include "email-core-account.h"
55 #include "email-core-mailbox.h"
56 #include "email-core-smtp.h"
57 #include "email-core-global.h"
58 #include "email-core-imap-idle.h"
59 #include "email-storage.h"
60 #include "email-core-task-manager.h"
61 #include "email-core-alarm.h"
62 #ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
63 #include "email-core-auto-download.h"
65 #include "email-daemon-emn.h"
66 #include "email-network.h"
67 #include "email-device.h"
68 #include "email-core-cynara.h"
70 #include "email-core-smime.h"
71 #include "email-core-container.h"
73 connection_h conn = NULL;
76 pop3_parameters(long function, void *value);
78 imap_parameters(long function, void *value);
80 INTERNAL_FUNC int g_client_count = 0;
81 extern int blocking_mode_of_setting;
82 extern GList *alarm_data_list;
84 #ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
85 extern pthread_cond_t _auto_downalod_available_signal;
88 static int default_alarm_callback(int input_timer_id, void *user_parameter);
90 /* static functions */
91 static int _emdaemon_load_email_core()
93 EM_DEBUG_FUNC_BEGIN();
95 int err = EMAIL_ERROR_NONE;
97 /* initialize mail core */
98 if (!emdaemon_core_init(&err))
101 #ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__
102 emdaemon_setup_handler_for_open_ssl_multithread();
103 #endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */
105 if (emdaemon_start_event_loop(&err) < 0)
108 if (emdaemon_start_event_loop_for_sending_mails(&err) < 0)
111 emcore_init_task_handler_array();
113 /* Disabled task manager
114 if ((err = emcore_start_task_manager_loop()) != EMAIL_ERROR_NONE) {
115 EM_DEBUG_EXCEPTION("emcore_start_task_manager_loop failed [%d]",err);
120 #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
121 if (emdaemon_start_thread_for_downloading_partial_body(&err) < 0) {
122 EM_DEBUG_EXCEPTION("emcore_start_thread_for_downloading_partial_body failed [%d]",err);
127 #ifdef __FEATURE_BLOCKING_MODE__
128 emdaemon_init_blocking_mode_status();
129 #endif /* __FEATURE_BLOCKING_MODE__ */
131 #ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
132 if (!emcore_start_auto_download_loop(&err))
138 EM_DEBUG_FUNC_END("err [%d]", err);
142 static int _emdaemon_unload_email_core()
144 EM_DEBUG_FUNC_BEGIN();
145 int err = EMAIL_ERROR_NONE;
147 /* finish event loop */
148 emcore_stop_event_loop(&err);
149 emcore_stop_task_manager_loop();
151 /* Destroy container for daemon */
152 emcore_destroy_container();
154 #ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
155 emcore_stop_auto_download_loop(&err);
158 #ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__
159 emdaemon_cleanup_handler_for_open_ssl_multithread();
160 #endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */
162 EM_DEBUG_FUNC_END("err [%d]", err);
166 #ifdef __FEATURE_SYNC_STATUS__
167 static void callback_for_SYNC_ALL_STATUS_from_account_svc(keynode_t *input_node, void *input_user_data)
169 EM_DEBUG_FUNC_BEGIN("input_node [%p], input_user_data [%p]", input_node, input_user_data);
172 int err = EMAIL_ERROR_NONE;
173 int account_count = 0;
174 int sync_start_toggle = 0;
175 email_account_t *account_list = NULL;
176 emstorage_mailbox_tbl_t *mailbox_tbl_data = NULL;
178 if (!emdaemon_get_account_list(NULL, &account_list, &account_count, &err)) {
179 EM_DEBUG_EXCEPTION("emdaemon_get_account_list failed [%d]", err);
184 sync_start_toggle = vconf_keynode_get_int(input_node);
186 for(i = 0; i < account_count; i++) {
187 if(sync_start_toggle == 1) {
188 if(!emstorage_get_mailbox_by_mailbox_type(NULL, account_list[i].account_id, EMAIL_MAILBOX_TYPE_INBOX, &mailbox_tbl_data, true, &err)) {
189 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type for [%d] failed [%d]", account_list[i].account_id, err);
193 if(!emdaemon_sync_header(NULL, account_list[i].account_id, mailbox_tbl_data->mailbox_id, &handle, &err)) {
194 EM_DEBUG_EXCEPTION("emdaemon_sync_header for [%d] failed [%d]", account_list[i].account_id, err);
197 emstorage_free_mailbox(&mailbox_tbl_data, 1, NULL); /* prevent 27459: remove unnecessary if clause */
198 mailbox_tbl_data = NULL;
201 emcore_cancel_all_threads_of_an_account(NULL, account_list[i].account_id);
207 emdaemon_free_account(&account_list, account_count, NULL);
209 emstorage_free_mailbox(&mailbox_tbl_data, 1, NULL);
214 static void callback_for_AUTO_SYNC_STATUS_from_account_svc(keynode_t *input_node, void *input_user_data)
216 EM_DEBUG_FUNC_BEGIN("input_node [%p], input_user_data [%p]", input_node, input_user_data);
217 int err = EMAIL_ERROR_NONE;
219 int auto_sync_toggle = 0;
220 int account_count = 0;
221 email_account_t *account_list = NULL;
222 email_account_t *account_info = NULL;
224 if (!emdaemon_get_account_list(NULL, &account_list, &account_count, &err)) {
225 EM_DEBUG_EXCEPTION("emdaemon_get_account_list failed [%d]", err);
230 auto_sync_toggle = vconf_keynode_get_int(input_node);
232 for(i = 0; i < account_count; i++) {
233 account_info = account_list + i;
235 if(auto_sync_toggle == 1) { /* on */
237 if(account_info->check_interval < 0)
238 account_info->check_interval = ~account_info->check_interval + 1;
242 if(account_info->check_interval > 0)
243 account_info->check_interval = ~account_info->check_interval + 1;
246 if(!emdaemon_update_account(NULL, account_info->account_id, account_info, &err)) {
247 EM_DEBUG_EXCEPTION("emdaemon_update_account failed [%d]", err);
254 emdaemon_free_account(&account_list, account_count, NULL);
258 #endif /* __FEATURE_SYNC_STATUS__ */
260 static void callback_for_NETWORK_STATUS(connection_type_e new_conn_type, void *input_user_data)
262 EM_DEBUG_FUNC_BEGIN("new_conn_type [%p], input_user_data [%p]", new_conn_type, input_user_data);
263 int err = EMAIL_ERROR_NONE;
267 int account_count = 0;
270 int send_saved_handle = 0;
271 char *multi_user_name = NULL;
272 email_event_t *event_data = NULL;
273 email_account_t *account_list = NULL;
274 email_account_t *account_info = NULL;
275 emstorage_mailbox_tbl_t *local_mailbox = NULL;
277 conn_type = emnetwork_get_network_status();
279 switch (new_conn_type) {
280 case CONNECTION_TYPE_WIFI:
281 case CONNECTION_TYPE_CELLULAR:
282 if(conn_type != new_conn_type) {
283 EM_DEBUG_LOG("Network type changed from [%d] to [%d]", conn_type, new_conn_type);
284 emnetwork_set_network_status(new_conn_type);
288 case CONNECTION_TYPE_DISCONNECTED:
289 EM_DEBUG_LOG("Network is disconnected. [%d]", new_conn_type);
290 emnetwork_set_network_status(new_conn_type);
294 EM_DEBUG_LOG("Unexpected value came. Set disconnectted network. [%d]", new_conn_type);
295 emnetwork_set_network_status(CONNECTION_TYPE_DISCONNECTED);
299 emcore_get_sync_fail_event_data(&event_data);
301 if (event_data != NULL) {
302 if (!emcore_insert_event(event_data, &handle, &err)) {
303 EM_DEBUG_LOG("emcore_insert_event failed : %d", err);
307 if (false == emcore_is_partial_body_thd_que_empty())
308 emcore_pb_thd_set_local_activity_continue(true);
310 if (!emdaemon_get_account_list(NULL, &account_list, &account_count, &err)) {
311 EM_DEBUG_EXCEPTION("emdaemon_get_account_list failed [%d]", err);
315 for (i = 0; i < account_count ; i++) {
316 account_info = account_list + i;
317 /* check if inbox folder sync is finished */
318 if (!emstorage_get_mailbox_by_mailbox_type (multi_user_name, account_info->account_id, EMAIL_MAILBOX_TYPE_INBOX, &local_mailbox, false, &err)) {
319 if (err == EMAIL_ERROR_MAILBOX_NOT_FOUND) {
321 emdaemon_get_imap_mailbox_list(multi_user_name, account_info->account_id, "", &handle, &err);
322 if (err != EMAIL_ERROR_NONE) {
323 EM_DEBUG_EXCEPTION("emdaemon_get_imap_mailbox_list error [%d]", err);
328 if (!emstorage_free_mailbox(&local_mailbox, 1, &err)) {
329 EM_DEBUG_EXCEPTION("emstorage_free_mailbox error [%d]", err);
332 /* send mails in outbox */
333 if (!emcore_get_mail_count_by_query(NULL, account_info->account_id, EMAIL_MAILBOX_TYPE_OUTBOX, 0, &total, &unseen, &err)) {
334 EM_DEBUG_EXCEPTION("emstorage_get_mail_count_by_query failed [%d]", err);
340 if (!emdaemon_send_mail_saved(multi_user_name, account_info->account_id, &send_saved_handle, &err)) {
341 EM_DEBUG_EXCEPTION("emdaemon_send_mail_saved failed : [%d]", err);
348 emstorage_free_mailbox(&local_mailbox, 1, NULL);
351 emdaemon_free_account(&account_list, account_count, NULL);
353 EM_DEBUG_FUNC_END("Error : [%d]", err);
356 #ifdef __FEATURE_BLOCKING_MODE__
357 INTERNAL_FUNC void callback_for_BLOCKING_MODE_STATUS(keynode_t *input_node, void *input_user_data)
359 EM_DEBUG_FUNC_BEGIN();
360 int blocking_mode_of_setting = 0;
363 EM_DEBUG_EXCEPTION("Invalid param");
367 blocking_mode_of_setting = vconf_keynode_get_bool(input_node);
369 emcore_set_blocking_mode_of_setting(blocking_mode_of_setting);
373 #endif /* __FEATURE_BLOCKING_MODE__ */
375 #ifdef __FEATURE_OMA_EMN__
376 static void callback_for_VCONFKEY_MSG_SERVER_READY(keynode_t *input_node, void *input_user_data)
378 EM_DEBUG_FUNC_BEGIN();
379 int msg_server_ready = 0;
382 EM_DEBUG_EXCEPTION("Invalid param");
386 msg_server_ready = vconf_keynode_get_bool(input_node);
388 if(msg_server_ready) {
389 if(emdaemon_initialize_emn() != EMAIL_ERROR_NONE) {
390 EM_DEBUG_EXCEPTION("emdaemon_initialize_emn failed");
396 #endif /* __FEATURE_OMA_EMN__ */
398 static void callback_for_VCONFKEY_GLOBAL_BADGE_STATUS(keynode_t *input_node, void *input_user_data)
400 EM_DEBUG_FUNC_BEGIN();
402 int err = EMAIL_ERROR_NONE;
403 int badge_ticker = 0;
406 EM_DEBUG_EXCEPTION("Invalid param");
410 noti_status = vconf_keynode_get_bool(input_node);
413 emcore_display_unread_in_badge((char *)input_user_data);
415 if (vconf_get_bool(VCONF_VIP_NOTI_BADGE_TICKER, &badge_ticker) != 0) {
416 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
417 err = EMAIL_ERROR_GCONF_FAILURE;
420 /* if priority sender is on, show the priority sender unread */
422 emcore_display_unread_in_badge((char *)input_user_data);
427 if ((err = emcore_display_badge_count((char *)input_user_data, 0)) != EMAIL_ERROR_NONE)
428 EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err);
436 static void callback_for_VCONFKEY_PRIORITY_BADGE_STATUS(keynode_t *input_node, void *input_user_data)
438 EM_DEBUG_FUNC_BEGIN();
440 int err = EMAIL_ERROR_NONE;
441 int badge_ticker = 0;
444 EM_DEBUG_EXCEPTION("Invalid param");
448 noti_status = vconf_keynode_get_bool(input_node);
451 emcore_display_unread_in_badge((char *)input_user_data);
454 if (vconf_get_bool(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, &badge_ticker) != 0) {
455 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
456 err = EMAIL_ERROR_GCONF_FAILURE;
460 /*if global badge is on, show the global unread*/
462 emcore_display_unread_in_badge((char *)input_user_data);
465 /* if all badges are off, reset badge count */
466 if ((err = emcore_display_badge_count((char *)input_user_data, 0)) != EMAIL_ERROR_NONE)
467 EM_DEBUG_EXCEPTION("emcore_display_badge_count failed : [%d]", err);
474 #ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
475 static void callback_for_VCONFKEY_WIFI_STATE(keynode_t *input_node, void *input_user_data)
477 EM_DEBUG_FUNC_BEGIN();
481 EM_DEBUG_EXCEPTION("Invalid param");
485 wifi_status = vconf_keynode_get_int(input_node);
487 EM_DEBUG_LOG("wifi_status [%d]", wifi_status);
489 if (wifi_status > 1) {
490 if (!emcore_get_pbd_thd_state() &&
491 emcore_is_event_queue_empty() &&
492 emcore_is_send_event_queue_empty()) {
493 WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal);
501 INTERNAL_FUNC int emdaemon_initialize(char *multi_user_name, int* err_code)
503 EM_DEBUG_FUNC_BEGIN();
505 /* default variable */
507 int err = EMAIL_ERROR_NONE;
508 connection_type_e net_state = CONNECTION_TYPE_DISCONNECTED;
510 if (!g_client_count) {
511 EM_DEBUG_LOG("Initialization was already done. increased counter=[%d]", g_client_count);
513 EM_DEBUG_LOG("************* start email service build time [%s %s] ************* ", __DATE__, __TIME__);
515 dbus_threads_init_default();
517 #if !GLIB_CHECK_VERSION(2, 36, 0)
520 if ((err = _emdaemon_load_email_core()) != EMAIL_ERROR_NONE) {
521 EM_DEBUG_EXCEPTION("_emdaemon_load_email_core failed [%d]", err);
525 err = emcore_init_cynara();
526 if (err != EMAIL_ERROR_NONE) {
527 EM_DEBUG_EXCEPTION("emcore_init_cynara failed : [%d]", err);
531 #ifdef __FEATURE_OMA_EMN__
532 if(emdaemon_initialize_emn() != EMAIL_ERROR_NONE) {
533 vconf_notify_key_changed(VCONFKEY_MSG_SERVER_READY, callback_for_VCONFKEY_MSG_SERVER_READY, NULL);
539 if (!emstorage_open(multi_user_name, &err)) {
540 EM_DEBUG_EXCEPTION("emstorage_open failed [%d]", err);
544 if ((err = emstorage_update_db_table_schema(multi_user_name)) != EMAIL_ERROR_NONE)
545 EM_DEBUG_EXCEPTION("emstorage_update_db_table_schema failed [%d]", err);
547 if (!emstorage_clean_save_status(multi_user_name, EMAIL_MAIL_STATUS_SAVED, &err))
548 EM_DEBUG_EXCEPTION("emstorage_check_mail_status Failed [%d]", err );
550 #ifdef __FEATURE_AUTO_RETRY_SEND__
551 if ((err = emcore_create_alarm_for_auto_resend (multi_user_name, AUTO_RESEND_INTERVAL)) != EMAIL_ERROR_NONE) {
552 if (err == EMAIL_ERROR_MAIL_NOT_FOUND)
553 EM_DEBUG_LOG ("no mail found");
555 EM_DEBUG_EXCEPTION("emcore_create_alarm_for_auto_resend failed [%d]", err);
557 #endif /* __FEATURE_AUTO_RETRY_SEND__ */
560 /* Start auto polling */
561 #ifdef __FEATURE_AUTO_POLLING__
562 emdaemon_start_auto_polling(multi_user_name, &err);
565 #ifdef __FEATURE_IMAP_IDLE__
567 emcore_create_imap_idle_thread();
568 #endif /* __FEATURE_IMAP_IDLE__ */
570 /* Subscribe Events */
571 #ifdef __FEATURE_SYNC_STATUS__
572 vconf_notify_key_changed(VCONFKEY_ACCOUNT_SYNC_ALL_STATUS_INT, callback_for_SYNC_ALL_STATUS_from_account_svc, NULL);
573 vconf_notify_key_changed(VCONFKEY_ACCOUNT_AUTO_SYNC_STATUS_INT, callback_for_AUTO_SYNC_STATUS_from_account_svc, NULL);
574 #endif /* __FEATURE_SYNC_STATUS__ */
576 int error_from_connection = 0;
578 if ((error_from_connection = connection_create(&conn)) == CONNECTION_ERROR_NONE) {
579 if (connection_get_type(conn, &net_state) != CONNECTION_ERROR_NONE) {
580 EM_DEBUG_EXCEPTION("connection_get_type failed");
582 emnetwork_set_network_status(net_state);
585 if (connection_set_type_changed_cb(conn, callback_for_NETWORK_STATUS, NULL) != CONNECTION_ERROR_NONE)
586 EM_DEBUG_EXCEPTION("connection_set_type_changed_cb failed");
589 EM_DEBUG_EXCEPTION("connection_create failed[%d]", error_from_connection);
592 #ifdef __FEATURE_BLOCKING_MODE__
593 vconf_notify_key_changed(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, callback_for_BLOCKING_MODE_STATUS, NULL);
595 vconf_notify_key_changed(VCONFKEY_TICKER_NOTI_BADGE_EMAIL, callback_for_VCONFKEY_GLOBAL_BADGE_STATUS, multi_user_name);
596 vconf_notify_key_changed(VCONF_VIP_NOTI_BADGE_TICKER, callback_for_VCONFKEY_PRIORITY_BADGE_STATUS, multi_user_name);
597 vconf_notify_key_changed(VCONFKEY_SETAPPL_STATE_TICKER_NOTI_EMAIL_BOOL, callback_for_VCONFKEY_GLOBAL_BADGE_STATUS, multi_user_name);
598 vconf_notify_key_changed(VCONF_VIP_NOTI_NOTIFICATION_TICKER, callback_for_VCONFKEY_PRIORITY_BADGE_STATUS, multi_user_name);
599 #ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__
600 vconf_notify_key_changed(VCONFKEY_WIFI_STATE, callback_for_VCONFKEY_WIFI_STATE, NULL);
603 emcore_display_unread_in_badge(multi_user_name);
613 EM_DEBUG_FUNC_END("ret [%d], g_client_count [%d]", ret, g_client_count);
617 INTERNAL_FUNC int emdaemon_finalize(int* err_code)
619 EM_DEBUG_FUNC_BEGIN();
621 /* default variable */
623 int err = EMAIL_ERROR_NONE;
625 if ( (err = _emdaemon_unload_email_core()) != EMAIL_ERROR_NONE) {
626 EM_DEBUG_EXCEPTION("_emdaemon_unload_email_core failed [%d]", err);
630 connection_destroy(conn);
633 emcore_finish_cynara();
636 if (!emstorage_close(&err)) {
637 EM_DEBUG_EXCEPTION("emstorage_close failed [%d]", err);
641 /* Openssl clean up */
642 emcore_clean_openssl_library();
653 #ifdef __FEATURE_AUTO_POLLING__
654 INTERNAL_FUNC int emdaemon_start_auto_polling(char *multi_user_name, int* err_code)
656 EM_DEBUG_FUNC_BEGIN();
658 /* default variable */
659 int ret = false, count = 0, i= 0;
660 int err = EMAIL_ERROR_NONE;
661 emstorage_account_tbl_t* account_list = NULL;
663 /* get account list */
664 if (!emstorage_get_account_list(multi_user_name, &count, &account_list, false, false, &err)) {
665 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
669 for (i = 0; i < count; i++) {
670 /* start auto polling, if check_interval not zero */
671 if(account_list[i].check_interval > 0 || ((account_list[i].peak_days > 0) && account_list[i].peak_interval > 0)) {
672 if(!emdaemon_add_polling_alarm(multi_user_name, account_list[i].account_id))
673 EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm failed");
680 emstorage_free_account(&account_list, count, NULL);
682 if (err_code != NULL)
685 EM_DEBUG_FUNC_END("ret[%d]", ret);
688 #endif /* __FEATURE_AUTO_POLLING__ */
690 /* initialize mail core */
691 INTERNAL_FUNC int emdaemon_core_init(int *err_code)
693 EM_DEBUG_FUNC_BEGIN();
695 if (err_code != NULL) {
696 *err_code = EMAIL_ERROR_NONE;
699 mail_link(&imapdriver); /* link in the imap driver */
700 mail_link(&pop3driver); /* link in the pop3 driver */
702 mail_link(&unixdriver); /* link in the unix driver */
703 mail_link(&dummydriver); /* link in the dummy driver */
707 auth_link(&auth_xoauth2); /* link in the xoauth2 authenticator */
708 auth_link(&auth_md5); /* link in the md5 authenticator */
709 auth_link(&auth_pla); /* link in the pla authenticator */
710 auth_link(&auth_log); /* link in the log authenticator */
712 /* Disabled to authenticate with plain text */
713 mail_parameters(NIL, SET_DISABLEPLAINTEXT, (void *) 2);
715 /* Set max trials for login */
716 imap_parameters(SET_MAXLOGINTRIALS, (void *)2); /* 3-> 2*/
717 pop3_parameters(SET_MAXLOGINTRIALS, (void *)2); /* 3-> 2*/
718 smtp_parameters(SET_MAXLOGINTRIALS, (void *)1); /* 3-> 2*/
720 mail_parameters(NIL, SET_SSLCERTIFICATEQUERY, (void *)emnetwork_callback_ssl_cert_query);
721 mail_parameters(NIL, SET_SSLCAPATH, (void *)SSL_CERT_DIRECTORY);
723 /* Set time out in second */
724 mail_parameters(NIL, SET_OPENTIMEOUT , (void *)50);
725 mail_parameters(NIL, SET_READTIMEOUT , (void *)60); /* 180 -> 15 */
726 mail_parameters(NIL, SET_WRITETIMEOUT , (void *)20); /* 180 -> 15 */
727 mail_parameters(NIL, SET_CLOSETIMEOUT , (void *)20); /* 30 -> 15 */
729 emdaemon_init_alarm_data_list();
731 /* Openssl library init */
732 emcore_init_openssl_library();
735 *err_code = EMAIL_ERROR_NONE;
740 INTERNAL_FUNC bool emdaemon_init_blocking_mode_status()
742 EM_DEBUG_FUNC_BEGIN("blocking_mode_of_setting : [%d]", blocking_mode_of_setting);
744 #ifdef __FEATURE_BLOCKING_MODE__
745 if (vconf_get_bool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &blocking_mode_of_setting) != 0) {
746 EM_DEBUG_EXCEPTION("vconf_get_bool failed");
749 #endif /* __FEATURE_BLOCKING_MODE__ */
755 INTERNAL_FUNC int emdaemon_init_alarm_data_list()
757 EM_DEBUG_FUNC_BEGIN();
758 int ret = ALARMMGR_RESULT_SUCCESS;
759 int err = EMAIL_ERROR_NONE;
760 alarm_data_list = NULL;
762 if ((ret = alarmmgr_init(EMAIL_ALARM_DESTINATION)) != ALARMMGR_RESULT_SUCCESS) {
763 EM_DEBUG_EXCEPTION("alarmmgr_init failed [%d]",ret);
764 err = EMAIL_ERROR_SYSTEM_FAILURE;
768 if ((ret = alarmmgr_set_cb(default_alarm_callback, NULL)) != ALARMMGR_RESULT_SUCCESS) {
769 EM_DEBUG_EXCEPTION("alarmmgr_set_cb() failed [%d]", ret);
770 err = EMAIL_ERROR_SYSTEM_FAILURE;
776 EM_DEBUG_FUNC_END("err [%d]", err);
780 static int default_alarm_callback(int input_timer_id, void *user_parameter)
782 EM_DEBUG_FUNC_BEGIN("input_timer_id [%d] user_parameter [%p]", input_timer_id, user_parameter);
783 int err = EMAIL_ERROR_NONE;
784 email_alarm_data_t *alarm_data = NULL;
786 EM_DEBUG_ALARM_LOG("default_alarm_callback input_timer_id[%d]", input_timer_id);
788 emdevice_set_sleep_on_off(STAY_AWAKE_FLAG_FOR_ALARM_CALLBACK, false, NULL);
790 if ((err = emcore_get_alarm_data_by_alarm_id(input_timer_id, &alarm_data)) != EMAIL_ERROR_NONE || alarm_data == NULL) {
791 EM_DEBUG_EXCEPTION("emcore_get_alarm_data_by_alarm_id failed [%d]", err);
795 emcore_delete_alram_data_from_alarm_data_list(alarm_data);
797 if ((err = alarm_data->alarm_callback(alarm_data, user_parameter)) != EMAIL_ERROR_NONE) {
798 EM_DEBUG_EXCEPTION("alarm_callback failed [%d]", err);
805 EM_SAFE_FREE(alarm_data->user_data);
806 EM_SAFE_FREE(alarm_data);
809 emdevice_set_sleep_on_off(STAY_AWAKE_FLAG_FOR_ALARM_CALLBACK, true, NULL);
812 EM_DEBUG_FUNC_END("err [%d]", err);