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 /* Email service Main .c */
29 #include <glib-object.h>
31 #include <sys/types.h>
36 #include "email-daemon.h"
37 #include "email-ipc.h"
38 #include "email-ipc-api-info.h"
39 #include "email-utilities.h"
40 #include "email-debug-log.h"
41 #include "email-daemon-auto-poll.h"
42 #include "email-daemon-account.h"
43 #include "email-convert.h"
44 #include "email-internal-types.h"
45 #include "email-types.h"
46 #include "email-core-account.h"
47 #include "email-core-mail.h"
48 #include "email-core-smtp.h"
49 #include "email-core-event.h"
50 #include "email-core-global.h"
51 #include "email-core-mailbox.h"
52 #include "email-core-utils.h"
53 #include "email-core-smime.h"
54 #include "email-core-pgp.h"
55 #include "email-core-cert.h"
56 #include "email-core-task-manager.h"
57 #include "email-core-signal.h"
58 #include "email-core-imap-idle.h"
59 #include "email-core-gmime.h"
60 #include "email-storage.h"
61 #include "email-dbus-activation.h"
62 #include "email-core-container.h"
63 #include "email-core-cynara.h"
65 void stb_create_account(HIPC_API a_hAPI)
67 EM_DEBUG_FUNC_BEGIN();
70 char* local_account_stream = NULL;
71 email_account_t account;
72 int err = EMAIL_ERROR_NONE;
74 int nAPPID = emipc_get_app_id(a_hAPI);
75 char *multi_user_name = NULL;
77 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
78 EM_DEBUG_EXCEPTION("emcore_get_user_name failed : [%d]", err);
79 multi_user_name = NULL;
81 /* Initialize the email_account_t */
82 memset(&account, 0x00, sizeof(email_account_t));
84 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 0);
85 EM_DEBUG_LOG("size [%d]", buffer_size);
86 if(buffer_size <= 0) {
87 err = EMAIL_ERROR_INVALID_PARAM;
90 local_account_stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0);
91 /* Convert account stream to structure */
92 em_convert_byte_stream_to_account(local_account_stream, buffer_size, &account);
93 account.user_name = EM_SAFE_STRDUP(multi_user_name);
95 EM_DEBUG_LOG_SEC("Account name - %s", account.account_name);
96 EM_DEBUG_LOG_SEC("Email Address - %s", account.user_email_address);
97 EM_DEBUG_LOG("Multi user name - %s", account.user_name);
99 if(!emdaemon_create_account(multi_user_name, &account, &err)) {
100 EM_DEBUG_EXCEPTION("emdaemon_create_account fail ");
105 #ifdef __FEATURE_AUTO_POLLING__
106 /* start auto polling, if check_interval not zero */
107 if(account.check_interval > 0 || (account.peak_days > 0 && account.peak_interval > 0)) {
108 if(!emdaemon_add_polling_alarm(multi_user_name, account.account_id))
109 EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm[NOTI_ACCOUNT_ADD] : start auto poll failed >>> ");
111 #ifdef __FEATURE_IMAP_IDLE__
112 else if(account.check_interval == 0 || (account.peak_days > 0 && account.peak_interval == 0))
113 emcore_refresh_imap_idle_thread();
114 #endif /* __FEATURE_IMAP_IDLE__ */
119 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
120 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
122 EM_DEBUG_LOG("[3] APPID[%d], APIID [%d]", emipc_get_app_id(a_hAPI), emipc_get_api_id(a_hAPI));
123 EM_DEBUG_LOG("account id[%d]", account.account_id);
125 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &(account.account_id), sizeof(int)))
126 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
130 if ( local_result == 0 ) {
131 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
132 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : local_result ");
133 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
134 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : err");
136 if (!emipc_execute_stub_api(a_hAPI))
137 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
139 emcore_free_account(&account); /* valgrind */
141 //emcore_init_account_reference();
143 if (local_result == 1) {
144 if (!emcore_notify_storage_event (NOTI_ACCOUNT_ADD_FINISH, account.account_id, 0, NULL, 0))
145 EM_DEBUG_EXCEPTION("emcore_notify_storage_event[NOTI_ACCOUNT_ADD] : Notification failed");
147 if (!emcore_notify_storage_event (NOTI_ACCOUNT_ADD_FAIL, account.account_id, 0, NULL, 0))
148 EM_DEBUG_EXCEPTION("emcore_notify_storage_event[NOTI_ACCOUNT_ADD] : Notification failed");
151 EM_SAFE_FREE(multi_user_name);
155 void stb_delete_account(HIPC_API a_hAPI)
157 EM_DEBUG_FUNC_BEGIN();
159 int local_result = 0;
160 int *ret_nth_value = NULL;
161 int err = EMAIL_ERROR_NONE;
162 int nAPPID = emipc_get_app_id(a_hAPI);
163 char *multi_user_name = NULL;
165 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
166 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
167 multi_user_name = NULL;
171 if ((ret_nth_value = (int *)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0)))
172 account_id = *ret_nth_value;
174 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
178 if(!emdaemon_delete_account(multi_user_name, account_id, &err)) {
179 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
180 EM_DEBUG_LOG("emipc_add_parameter failed ");
182 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
183 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
185 if (!emipc_execute_stub_api(a_hAPI))
186 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
190 #ifdef __FEATURE_AUTO_POLLING__
191 /* stop auto polling for this acount */
192 if(emdaemon_check_auto_polling_started(account_id)) {
193 if(!emdaemon_remove_polling_alarm(account_id))
194 EM_DEBUG_EXCEPTION("emdaemon_remove_polling_alarm[ NOTI_ACCOUNT_DELETE] : remove auto poll failed >>> ");
199 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
200 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
202 if (!emipc_execute_stub_api(a_hAPI))
203 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
205 /* if file is not deleted, main thread kills the thread */
206 emcore_send_signal_for_del_account (EMAIL_SIGNAL_DB_DELETED);
207 EM_DEBUG_LOG ("publish db of account deleted");
211 EM_SAFE_FREE(multi_user_name);
215 void stb_update_account(HIPC_API a_hAPI)
217 EM_DEBUG_FUNC_BEGIN();
218 int account_id = 0, buffer_size = 0, with_validation = 0;
219 int *ret_nth_value = NULL;
220 char* local_account_stream = NULL;
221 email_account_t new_account_info = {0};
222 int err = EMAIL_ERROR_NONE;
224 int nAPPID = emipc_get_app_id(a_hAPI);
225 char *multi_user_name = NULL;
227 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
228 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
229 multi_user_name = NULL;
232 if ((ret_nth_value = (int *)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0)))
233 account_id = *ret_nth_value;
235 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
239 /* get account structure from stream */
240 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 1);
241 EM_DEBUG_LOG("size [%d]", buffer_size);
242 local_account_stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 1);
243 em_convert_byte_stream_to_account(local_account_stream, buffer_size, &new_account_info);
245 /*get validation flag */
246 if ((ret_nth_value = (int *)emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 2))) {
247 with_validation = *ret_nth_value;
249 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
253 if(with_validation) {
254 if(!emdaemon_validate_account_and_update(multi_user_name, account_id, &new_account_info, &handle, &err)){
255 EM_DEBUG_EXCEPTION("emdaemon_validate_account_and_update failed [%d]", err);
260 if(!emdaemon_update_account(multi_user_name, account_id, &new_account_info, &err)) {
261 EM_DEBUG_EXCEPTION("emdaemon_update_account failed [%d]", err);
269 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
270 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
272 if (!emipc_execute_stub_api(a_hAPI))
273 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
275 emcore_free_account(&new_account_info);
277 EM_SAFE_FREE(multi_user_name);
281 void stb_validate_account(HIPC_API a_hAPI)
283 EM_DEBUG_FUNC_BEGIN();
286 int local_result = 0;
289 int nAPPID = emipc_get_app_id(a_hAPI);
290 char *multi_user_name = NULL;
292 if ((err_code = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
293 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err_code);
294 multi_user_name = NULL;
298 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
299 local_result = emdaemon_validate_account(multi_user_name, account_id, &handle, &err_code);
301 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
302 EM_DEBUG_LOG("emipc_add_parameter failed ");
304 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
305 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
307 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
308 EM_DEBUG_EXCEPTION("emipc_add_parameter result failed ");
310 if (!emipc_execute_stub_api(a_hAPI))
311 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
313 EM_SAFE_FREE(multi_user_name);
318 void stb_get_account_list(HIPC_API a_hAPI)
320 EM_DEBUG_FUNC_BEGIN();
322 int local_result = 0;
324 char* local_stream = NULL;
325 email_account_t* account_list;
328 int err = EMAIL_ERROR_NONE;
329 int nAPPID = emipc_get_app_id(a_hAPI);
330 char *multi_user_name = NULL;
332 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
333 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
334 multi_user_name = NULL;
337 if(emdaemon_get_account_list(multi_user_name, &account_list, &count, &err)) {
338 EM_DEBUG_LOG("emdaemon_get_account_list success");
340 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
341 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
343 EM_DEBUG_LOG("Count [%d]", count);
344 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &count, sizeof(int)))
345 EM_DEBUG_EXCEPTION("emipc_add_parameter count failed ");
347 for(i=0; i<count; i++) {
348 EM_DEBUG_LOG_SEC("Name - %s", account_list[i].account_name);
350 local_stream = em_convert_account_to_byte_stream(account_list+i, &size);
353 EM_DEBUG_EXCEPTION ("INVALID PARAM: local_stream NULL ");
354 emcore_free_account_list(&account_list, count, NULL);
358 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, local_stream, size))
359 EM_DEBUG_EXCEPTION("Add Param mailbox failed ");
362 EM_SAFE_FREE(local_stream);
365 emcore_free_account_list(&account_list, count, NULL);
366 if (!emipc_execute_stub_api(a_hAPI))
367 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
371 EM_DEBUG_LOG("emdaemon_get_account_list failed");
372 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
373 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
374 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
375 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : err");
376 if (!emipc_execute_stub_api(a_hAPI))
377 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
380 EM_SAFE_FREE(local_stream);
381 EM_SAFE_FREE(multi_user_name);
385 /* sowmya.kr, 10-May-2010, changes for API improvement */
386 void stb_sync_header(HIPC_API a_hAPI)
388 EM_DEBUG_FUNC_BEGIN();
389 int err = EMAIL_ERROR_NONE;
391 int account_id = 0, maibox_id = 0;
392 int nAPPID = emipc_get_app_id(a_hAPI);
393 char *multi_user_name = NULL;
395 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
396 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
397 multi_user_name = NULL;
401 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
403 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &maibox_id);
404 EM_DEBUG_LOG("account_id [%d] maibox_id [%d]", account_id, maibox_id);
406 if(!emdaemon_sync_header(multi_user_name, account_id, maibox_id, &handle, &err)) {
407 EM_DEBUG_EXCEPTION ("emdaemon_sync_header failed [%d]", err);
410 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
411 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
412 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
413 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
414 if (!emipc_execute_stub_api(a_hAPI))
415 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
417 EM_SAFE_FREE(multi_user_name);
421 void stb_download_body(HIPC_API a_hAPI)
423 EM_DEBUG_FUNC_BEGIN();
424 int err = EMAIL_ERROR_NONE;
426 int attachment_count = 0;
429 int nAPPID = emipc_get_app_id(a_hAPI);
430 char *multi_user_name = NULL;
432 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
433 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
434 multi_user_name = NULL;
438 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
441 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mail_id);
444 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &attachment_count);
447 if (!emdaemon_download_body(multi_user_name, account_id, mail_id, 1, attachment_count, &handle, &err)) {
448 EM_DEBUG_EXCEPTION("emdaemon_download_body - failed");
452 err = EMAIL_ERROR_NONE;
456 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
457 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
459 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
460 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
462 if (!emipc_execute_stub_api(a_hAPI))
463 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
465 EM_SAFE_FREE(multi_user_name);
471 void stb_create_mailbox(HIPC_API a_hAPI)
473 EM_DEBUG_FUNC_BEGIN();
475 int err = EMAIL_ERROR_NONE;
476 int *ret_nth_value = NULL;
477 char *local_stream = NULL;
479 email_mailbox_t mailbox = { 0 };
480 int handle = 0; /* Added for cancelling mailbox creating */
481 int nAPPID = emipc_get_app_id(a_hAPI);
482 char *multi_user_name = NULL;
484 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
485 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
486 multi_user_name = NULL;
489 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 0);
490 EM_DEBUG_LOG("size [%d]", buffer_size);
492 if(buffer_size <= 0) {
493 EM_DEBUG_EXCEPTION("buffer_size(%d) should be greater than 0", buffer_size);
494 err = EMAIL_ERROR_INVALID_PARAM;
498 local_stream = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0);
499 em_convert_byte_stream_to_mailbox(local_stream, buffer_size, &mailbox);
500 EM_DEBUG_LOG_SEC("Mailbox name - %s", mailbox.mailbox_name);
502 if ((ret_nth_value = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 1)))
503 on_server = *ret_nth_value;
505 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
507 emdaemon_add_mailbox(multi_user_name, &mailbox, on_server, &handle, &err);
511 emcore_free_mailbox(&mailbox);
512 EM_SAFE_FREE(multi_user_name);
514 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
515 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1");
516 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
517 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 2");
518 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &mailbox.mailbox_id, sizeof(int)))
519 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 3");
521 if (!emipc_execute_stub_api(a_hAPI)) {
522 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
530 void stb_delete_mailbox(HIPC_API a_hAPI)
532 EM_DEBUG_FUNC_BEGIN();
533 int err = EMAIL_ERROR_NONE;
535 int handle = 0; /* Added for cancelling mailbox deleting */
536 int input_mailbox_id = 0;
537 int nAPPID = emipc_get_app_id(a_hAPI);
538 char *multi_user_name = NULL;
540 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
541 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
542 multi_user_name = NULL;
546 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &input_mailbox_id);
547 EM_DEBUG_LOG("input_mailbox_id [%d]", input_mailbox_id);
549 if (input_mailbox_id > 0)
550 EM_DEBUG_LOG("input_mailbox_id [%d]", input_mailbox_id);
552 EM_DEBUG_LOG("input_mailbox_id == 0");
554 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &on_server);
556 if(emdaemon_delete_mailbox(multi_user_name, input_mailbox_id, on_server, &handle, &err))
557 err = EMAIL_ERROR_NONE;
559 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
560 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
561 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
562 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
564 if (!emipc_execute_stub_api(a_hAPI))
565 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
567 EM_SAFE_FREE(multi_user_name);
571 void stb_set_mailbox_type(HIPC_API a_hAPI)
573 EM_DEBUG_FUNC_BEGIN();
574 int err = EMAIL_ERROR_NONE;
576 int mailbox_type = 0;
577 int nAPPID = emipc_get_app_id(a_hAPI);
578 char *multi_user_name = NULL;
580 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
581 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
582 multi_user_name = NULL;
585 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mailbox_id);
586 EM_DEBUG_LOG("mailbox_id[%d]", mailbox_id);
588 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mailbox_type);
589 EM_DEBUG_LOG("mailbox_type[%d]", mailbox_type);
591 if( (err = emdaemon_set_mailbox_type(multi_user_name, mailbox_id, mailbox_type)) != EMAIL_ERROR_NONE)
592 err = EMAIL_ERROR_NONE;
594 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
595 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1");
597 if (!emipc_execute_stub_api(a_hAPI))
598 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
600 EM_SAFE_FREE(multi_user_name);
604 void stb_set_local_mailbox(HIPC_API a_hAPI)
606 EM_DEBUG_FUNC_BEGIN();
607 int err = EMAIL_ERROR_NONE;
609 int is_local_mailbox = 0;
610 int nAPPID = emipc_get_app_id(a_hAPI);
611 char *multi_user_name = NULL;
613 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
614 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
615 multi_user_name = NULL;
618 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mailbox_id);
619 EM_DEBUG_LOG("mailbox_id[%d]", mailbox_id);
621 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &is_local_mailbox);
622 EM_DEBUG_LOG("is_local_mailbox[%d]", is_local_mailbox);
624 if( (err = emdaemon_set_local_mailbox(multi_user_name, mailbox_id, is_local_mailbox)) != EMAIL_ERROR_NONE)
625 err = EMAIL_ERROR_NONE;
627 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
628 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1");
630 if (!emipc_execute_stub_api(a_hAPI))
631 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
633 EM_SAFE_FREE(multi_user_name);
637 void stb_stamp_sync_time_of_mailbox(HIPC_API a_hAPI)
639 EM_DEBUG_FUNC_BEGIN();
640 int err = EMAIL_ERROR_NONE;
642 int nAPPID = emipc_get_app_id(a_hAPI);
643 char *multi_user_name = NULL;
645 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
646 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
647 multi_user_name = NULL;
650 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mailbox_id);
651 EM_DEBUG_LOG("mailbox_id[%d]", mailbox_id);
653 err = emstorage_stamp_last_sync_time_of_mailbox(multi_user_name, mailbox_id, 1);
655 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
656 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1");
658 if (!emipc_execute_stub_api(a_hAPI))
659 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
661 EM_SAFE_FREE(multi_user_name);
665 void stb_set_mail_slot_size_of_mailbox(HIPC_API a_hAPI)
667 EM_DEBUG_FUNC_BEGIN();
668 int err = EMAIL_ERROR_NONE;
672 int mail_slot_size = 0;
673 int nAPPID = emipc_get_app_id(a_hAPI);
674 char *multi_user_name = NULL;
676 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
677 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
678 multi_user_name = NULL;
681 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
682 EM_DEBUG_LOG("account_id[%d]", account_id);
684 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mailbox_id);
685 EM_DEBUG_LOG("mailbox_id[%d]", mailbox_id);
687 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &mail_slot_size);
688 EM_DEBUG_LOG("mail_slot_size[%d]", mail_slot_size);
690 if(emdaemon_set_mail_slot_size_of_mailbox(multi_user_name, account_id, mailbox_id, mail_slot_size, &handle, &err))
691 err = EMAIL_ERROR_NONE;
692 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
693 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1");
695 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
696 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 2");
698 if (!emipc_execute_stub_api(a_hAPI))
699 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
701 EM_SAFE_FREE(multi_user_name);
705 void stb_rename_mailbox(HIPC_API a_hAPI)
707 EM_DEBUG_FUNC_BEGIN();
709 int err = EMAIL_ERROR_NONE;
713 char *mailbox_path = NULL;
714 char *mailbox_alias = NULL;
715 int nAPPID = emipc_get_app_id(a_hAPI);
716 char *multi_user_name = NULL;
718 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
719 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
720 multi_user_name = NULL;
723 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mailbox_id);
724 EM_DEBUG_LOG("mailbox_id[%d]", mailbox_id);
726 buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
727 EM_DEBUG_LOG("mailbox_path string size[%d]", buffer_size);
728 if(buffer_size > 0) {
729 mailbox_path = (char*)em_malloc(buffer_size);
730 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, mailbox_path);
731 EM_DEBUG_LOG_SEC("mailbox_path [%s]", mailbox_path);
734 buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 2);
735 EM_DEBUG_LOG("mailbox_alias string size[%d]", buffer_size);
736 if(buffer_size > 0) {
737 mailbox_alias = (char*)em_malloc(buffer_size);
738 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, buffer_size, mailbox_alias);
739 EM_DEBUG_LOG_SEC("mailbox_alias [%s]", mailbox_alias);
742 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &on_server);
743 EM_DEBUG_LOG("on_server[%d]", on_server);
745 if ((err = emdaemon_rename_mailbox(multi_user_name, mailbox_id, mailbox_path, mailbox_alias, NULL, 0, on_server, &handle)) != EMAIL_ERROR_NONE) {
746 EM_DEBUG_EXCEPTION("emdaemon_rename_mailbox failed [%d]", err);
749 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
750 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1");
752 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
753 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 2");
755 if (!emipc_execute_stub_api(a_hAPI))
756 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
758 EM_SAFE_FREE(mailbox_alias);
759 EM_SAFE_FREE(mailbox_path);
761 EM_SAFE_FREE(multi_user_name);
765 void stb_rename_mailbox_ex(HIPC_API a_hAPI)
767 EM_DEBUG_FUNC_BEGIN();
769 int err = EMAIL_ERROR_NONE;
773 int eas_data_length = 0;
774 char *mailbox_path = NULL;
775 char *mailbox_alias = NULL;
776 void *eas_data = NULL;
777 int nAPPID = emipc_get_app_id(a_hAPI);
778 char *multi_user_name = NULL;
780 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
781 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
782 multi_user_name = NULL;
785 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mailbox_id);
786 EM_DEBUG_LOG("mailbox_id[%d]", mailbox_id);
788 buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
789 EM_DEBUG_LOG("mailbox_path string size[%d]", buffer_size);
790 if(buffer_size > 0) {
791 mailbox_path = (char*)em_malloc(buffer_size);
792 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, mailbox_path);
793 EM_DEBUG_LOG_SEC("mailbox_path [%s]", mailbox_path);
796 buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 2);
797 EM_DEBUG_LOG("mailbox_alias string size[%d]", buffer_size);
798 if(buffer_size > 0) {
799 mailbox_alias = (char*)em_malloc(buffer_size);
800 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, buffer_size, mailbox_alias);
801 EM_DEBUG_LOG_SEC("mailbox_alias [%s]", mailbox_alias);
804 eas_data_length = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 3);
805 EM_DEBUG_LOG("eas_data_length size[%d]", eas_data_length);
806 if(eas_data_length > 0) {
807 eas_data = (char*)em_malloc(eas_data_length);
808 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, eas_data_length, eas_data);
811 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 4, sizeof(int), &on_server);
812 EM_DEBUG_LOG("on_server[%d]", on_server);
814 if ((err = emdaemon_rename_mailbox(multi_user_name, mailbox_id, mailbox_path, mailbox_alias, eas_data, eas_data_length, on_server, &handle)) != EMAIL_ERROR_NONE) {
815 EM_DEBUG_EXCEPTION("emdaemon_rename_mailbox failed [%d]", err);
818 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
819 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 1");
821 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
822 EM_DEBUG_EXCEPTION("emipc_add_parameter failed 2");
824 if (!emipc_execute_stub_api(a_hAPI))
825 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
827 EM_SAFE_FREE(mailbox_alias);
828 EM_SAFE_FREE(mailbox_path);
829 EM_SAFE_FREE(eas_data);
831 EM_SAFE_FREE(multi_user_name);
835 void stb_send_mail(HIPC_API a_hAPI)
837 EM_DEBUG_FUNC_BEGIN();
838 char* local_stream = NULL;
841 int err = EMAIL_ERROR_NONE;
842 int nAPPID = emipc_get_app_id(a_hAPI);
843 char *multi_user_name = NULL;
845 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
846 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
847 multi_user_name = NULL;
851 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
852 EM_DEBUG_LOG("mail_id [%d]", mail_id);
854 if(emdaemon_send_mail(multi_user_name, mail_id, &handle, &err)) {
855 err = EMAIL_ERROR_NONE;
856 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
857 EM_DEBUG_EXCEPTION("emipc_add_parameter result failed ");
858 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
859 EM_DEBUG_EXCEPTION("emipc_add_parameter result failed ");
860 if (!emipc_execute_stub_api(a_hAPI))
861 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
864 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
865 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
866 if (!emipc_execute_stub_api(a_hAPI))
867 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
870 EM_SAFE_FREE(local_stream);
872 EM_SAFE_FREE(multi_user_name);
876 void stb_query_smtp_mail_size_limit(HIPC_API a_hAPI)
878 EM_DEBUG_FUNC_BEGIN();
882 int err = EMAIL_ERROR_NONE;
883 int nAPPID = emipc_get_app_id(a_hAPI);
884 char *multi_user_name = NULL;
886 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
887 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
888 multi_user_name = NULL;
892 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
893 EM_DEBUG_LOG("account_id [%d]", account_id);
895 if(emdaemon_query_smtp_mail_size_limit(multi_user_name, account_id, &handle, &err)) {
896 err = EMAIL_ERROR_NONE;
897 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
898 EM_DEBUG_EXCEPTION("emipc_add_parameter result failed ");
899 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
900 EM_DEBUG_EXCEPTION("emipc_add_parameter result failed ");
901 if (!emipc_execute_stub_api(a_hAPI))
902 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
904 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
905 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
906 if (!emipc_execute_stub_api(a_hAPI))
907 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
910 EM_SAFE_FREE(multi_user_name);
914 /* obsolete - there is no api calling this function */
915 void stb_get_mailbox_list(HIPC_API a_hAPI)
917 EM_DEBUG_FUNC_BEGIN();
918 int err = EMAIL_ERROR_NONE;
920 char* local_stream = NULL;
922 email_mailbox_t* mailbox_list = NULL;
925 int nAPPID = emipc_get_app_id(a_hAPI);
926 char *multi_user_name = NULL;
928 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
929 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
930 multi_user_name = NULL;
933 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
935 if(emdaemon_get_mailbox_list(multi_user_name, account_id, &mailbox_list, &count, &err))
936 EM_DEBUG_LOG("emdaemon_get_mailbox_list - success");
938 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
939 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
941 if(EMAIL_ERROR_NONE == err) {
942 EM_DEBUG_LOG("Count [%d]", count);
943 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &count, sizeof(int)))
944 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
946 for(counter=0; counter<count; counter++) {
947 EM_DEBUG_LOG_SEC("Name - %s", mailbox_list[counter].mailbox_name);
949 local_stream = em_convert_mailbox_to_byte_stream(mailbox_list+counter, &size);
952 EM_DEBUG_EXCEPTION ("INVALID PARAM: local_stream NULL ");
953 emcore_free_mailbox_list(&mailbox_list, count);
957 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, local_stream, size))
958 EM_DEBUG_EXCEPTION("Add Param mailbox failed ");
960 EM_SAFE_FREE(local_stream);
965 if (!emipc_execute_stub_api(a_hAPI))
966 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
968 emcore_free_mailbox_list(&mailbox_list, count);
970 EM_SAFE_FREE(multi_user_name);
974 void stb_delete_all_mails(HIPC_API a_hAPI)
976 EM_DEBUG_FUNC_BEGIN();
979 int err = EMAIL_ERROR_NONE;
980 int nAPPID = emipc_get_app_id(a_hAPI);
981 char *multi_user_name = NULL;
983 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
984 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
985 multi_user_name = NULL;
989 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mailbox_id);
992 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &from_server);
994 emdaemon_delete_mail_all(multi_user_name, mailbox_id, from_server, NULL, &err);
996 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
997 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
998 if (!emipc_execute_stub_api(a_hAPI))
999 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
1001 EM_SAFE_FREE(multi_user_name);
1002 EM_DEBUG_FUNC_END();
1005 void stb_delete_mail(HIPC_API a_hAPI)
1007 EM_DEBUG_FUNC_BEGIN();
1008 int err = EMAIL_ERROR_NONE;
1010 int from_server = 0;
1013 int *mail_ids = NULL;
1014 int nAPPID = emipc_get_app_id(a_hAPI);
1015 char *multi_user_name = NULL;
1017 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1018 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1019 multi_user_name = NULL;
1023 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mailbox_id);
1025 EM_DEBUG_LOG("mailbox_id [%d]", mailbox_id);
1027 /* Number of mail_ids */
1028 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &num);
1029 EM_DEBUG_LOG("number of mails [%d]", num);
1032 mail_ids = em_malloc(sizeof(int) * num);
1034 EM_DEBUG_EXCEPTION("em_malloc failed");
1035 err = EMAIL_ERROR_OUT_OF_MEMORY;
1040 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, num * sizeof(int), mail_ids);
1042 for(counter = 0; counter < num; counter++)
1043 EM_DEBUG_LOG("mail_ids [%d]", mail_ids[counter]);
1046 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &from_server);
1047 EM_DEBUG_LOG("from_server [%d]", from_server);
1049 emdaemon_delete_mail(multi_user_name, mailbox_id, mail_ids, num, from_server, NULL, &err);
1052 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1053 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1055 if (!emipc_execute_stub_api(a_hAPI))
1056 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1058 EM_SAFE_FREE(mail_ids);
1060 EM_SAFE_FREE(multi_user_name);
1061 EM_DEBUG_FUNC_END();
1064 void stb_clear_mail_data (HIPC_API a_hAPI)
1066 EM_DEBUG_FUNC_BEGIN();
1067 int err = EMAIL_ERROR_NONE;
1069 int nAPPID = emipc_get_app_id(a_hAPI);
1070 char *multi_user_name = NULL;
1072 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1073 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1074 multi_user_name = NULL;
1077 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1078 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : err");
1079 if (!emipc_execute_stub_api(a_hAPI))
1080 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
1082 if(emdaemon_clear_all_mail_data(multi_user_name, &err)) {
1083 EM_DEBUG_LOG(">>> stb_clear_mail_data Success [ %d] >> ", err);
1086 EM_SAFE_FREE(multi_user_name);
1087 EM_DEBUG_FUNC_END();
1090 void stb_add_rule(HIPC_API a_hAPI)
1092 EM_DEBUG_FUNC_BEGIN();
1093 int buffer_size = 0;
1094 int err = EMAIL_ERROR_NONE;
1095 char* local_rule_stream = NULL;
1096 email_rule_t rule = { 0 };
1097 int nAPPID = emipc_get_app_id(a_hAPI);
1098 char *multi_user_name = NULL;
1100 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1101 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1102 multi_user_name = NULL;
1105 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 0);
1106 if(buffer_size <= 0) {
1107 err = EMAIL_ERROR_INVALID_PARAM;
1111 local_rule_stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0);
1112 if(!local_rule_stream) {
1113 err = EMAIL_ERROR_INVALID_PARAM;
1116 em_convert_byte_stream_to_rule(local_rule_stream, buffer_size, &rule);
1117 EM_DEBUG_LOG("account ID [%d]", rule.account_id);
1119 /* call add_filter handler */
1120 err = emdaemon_add_filter(multi_user_name, &rule);
1124 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1125 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1126 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &rule.filter_id, sizeof(int)))
1127 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1128 if (!emipc_execute_stub_api(a_hAPI))
1129 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
1131 emcore_free_rule(&rule);
1133 EM_SAFE_FREE(multi_user_name);
1134 EM_DEBUG_FUNC_END();
1138 /* obsolete - there is no api calling this function */
1139 void stb_get_rule(HIPC_API a_hAPI)
1141 EM_DEBUG_FUNC_BEGIN();
1142 int err = EMAIL_ERROR_NONE;
1144 email_rule_t* rule = NULL;
1146 char* local_rule_stream = NULL;
1147 int nAPPID = emipc_get_app_id(a_hAPI);
1148 char *multi_user_name = NULL;
1150 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1151 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1152 multi_user_name = NULL;
1155 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &filter_id);
1156 EM_DEBUG_LOG("Filter ID : [%d]", filter_id);
1158 if (!emdaemon_get_filter(multi_user_name, filter_id, &rule, &err)) {
1159 EM_DEBUG_EXCEPTION("emdaemon_get_filter failed : [%d]", err);
1163 /* insert a rule if there exists a rule */
1165 local_rule_stream = em_convert_rule_to_byte_stream(rule, &size);
1166 if (!local_rule_stream) { /*prevent 26265*/
1167 EM_DEBUG_EXCEPTION("em_convert_rule_to_byte_stream failed");
1168 err = EMAIL_ERROR_SYSTEM_FAILURE;
1176 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1177 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1179 if (err == EMAIL_ERROR_NONE) {
1180 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, local_rule_stream, size))
1181 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1184 if (!emipc_execute_stub_api(a_hAPI)) {
1185 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1189 emcore_free_rule(rule);
1191 EM_SAFE_FREE(local_rule_stream);
1192 EM_SAFE_FREE(multi_user_name);
1194 EM_DEBUG_FUNC_END();
1197 /* obsolete - there is no api calling this function */
1198 void stb_get_rule_list(HIPC_API a_hAPI)
1200 EM_DEBUG_FUNC_BEGIN();
1201 int err = EMAIL_ERROR_NONE;
1203 char* local_stream = NULL;
1206 email_rule_t* filtering_list = NULL;
1207 int nAPPID = emipc_get_app_id(a_hAPI);
1208 char *multi_user_name = NULL;
1210 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1211 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1212 multi_user_name = NULL;
1215 emdaemon_get_filter_list(multi_user_name, &filtering_list, &count, &err);
1217 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1218 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1220 /* insert rules if there exist rules*/
1222 EM_DEBUG_LOG("num of rules [%d]", count);
1223 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &count, sizeof(int)))
1224 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1226 for(i=0; i<count; i++) {
1227 EM_DEBUG_LOG("Value - %s", filtering_list[i].value);
1229 local_stream = em_convert_rule_to_byte_stream(filtering_list+i, &size);
1231 if(!local_stream) break;
1233 if(!emipc_add_dynamic_parameter(a_hAPI, ePARAMETER_OUT, local_stream, size))
1234 EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed ");
1240 if (!emipc_execute_stub_api(a_hAPI)) {
1241 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
1244 EM_SAFE_FREE(multi_user_name);
1245 EM_DEBUG_FUNC_END();
1248 /* obsolete - there is no api calling this function */
1249 void stb_find_rule(HIPC_API a_hAPI)
1251 EM_DEBUG_FUNC_BEGIN();
1252 int buffer_size = 0;
1253 int err = EMAIL_ERROR_NONE;
1254 char* local_rule_stream = NULL;
1255 email_rule_t rule = { 0 };
1256 int nAPPID = emipc_get_app_id(a_hAPI);
1257 char *multi_user_name = NULL;
1259 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1260 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1261 multi_user_name = NULL;
1264 buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
1265 if(buffer_size > 0) {
1266 local_rule_stream = (char*)em_malloc(buffer_size);
1267 if (local_rule_stream == NULL) {
1268 EM_DEBUG_EXCEPTION("Out of memory");
1269 err = EMAIL_ERROR_OUT_OF_MEMORY;
1273 if (local_rule_stream) {
1274 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, buffer_size, local_rule_stream);
1275 em_convert_byte_stream_to_rule(local_rule_stream, buffer_size, &rule);
1276 EM_SAFE_FREE(local_rule_stream);
1277 EM_DEBUG_LOG("account ID [%d]", rule.account_id);
1279 if (!emdaemon_find_filter(multi_user_name, &rule, &err)) {
1280 EM_DEBUG_EXCEPTION("emdaemon_find_filter failed : [%d]", err);
1287 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1288 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1290 if (!emipc_execute_stub_api(a_hAPI))
1291 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
1293 EM_SAFE_FREE(multi_user_name);
1294 EM_DEBUG_FUNC_END();
1297 void stb_update_rule(HIPC_API a_hAPI)
1299 EM_DEBUG_FUNC_BEGIN();
1302 int buffer_size = 0;
1303 int err = EMAIL_ERROR_NONE;
1304 int *ret_nth_value = NULL;
1305 char* rule_stream = NULL;
1306 email_rule_t rule = {0};
1307 int nAPPID = emipc_get_app_id(a_hAPI);
1308 char *multi_user_name = NULL;
1310 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1311 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1312 multi_user_name = NULL;
1316 if ((ret_nth_value = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0))) {
1317 filter_id = *ret_nth_value;
1319 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1324 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 1);
1325 EM_DEBUG_LOG("size [%d]", buffer_size);
1326 if(buffer_size <= 0) {
1327 err = EMAIL_ERROR_INVALID_PARAM;
1330 rule_stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 1);
1332 err = EMAIL_ERROR_INVALID_PARAM;
1335 em_convert_byte_stream_to_rule(rule_stream, buffer_size, &rule);
1337 /* call update handler */
1338 emdaemon_update_filter(multi_user_name, filter_id, &rule, &err);
1341 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1342 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1344 if (!emipc_execute_stub_api(a_hAPI))
1345 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1347 emcore_free_rule(&rule);
1349 EM_SAFE_FREE(multi_user_name);
1350 EM_DEBUG_FUNC_END();
1353 void stb_move_all_mails(HIPC_API a_hAPI)
1355 EM_DEBUG_FUNC_BEGIN();
1356 int err = EMAIL_ERROR_NONE;
1357 int src_mailbox_id = 0, dst_mailbox_id = 0;
1358 int nAPPID = emipc_get_app_id(a_hAPI);
1359 char *multi_user_name = NULL;
1361 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1362 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1363 multi_user_name = NULL;
1366 /* src_mailbox_id */
1367 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &src_mailbox_id);
1368 EM_DEBUG_LOG("src_mailbox_id [%d]", src_mailbox_id);
1370 if (src_mailbox_id > 0)
1371 EM_DEBUG_LOG("src_mailbox_id [%d]", src_mailbox_id);
1373 EM_DEBUG_LOG("src_mailbox_id == 0");
1375 /* dst_mailbox_id */
1376 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &dst_mailbox_id);
1377 EM_DEBUG_LOG("dst_mailbox_id [%d]", dst_mailbox_id);
1379 if (dst_mailbox_id > 0)
1380 EM_DEBUG_LOG("dst_mailbox_id [%d]", dst_mailbox_id);
1382 EM_DEBUG_LOG("dst_mailbox_id == 0");
1384 if(emdaemon_move_mail_all_mails(multi_user_name, src_mailbox_id, dst_mailbox_id, &err))
1385 EM_DEBUG_LOG("emdaemon_move_mail_all_mails:Success");
1386 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
1387 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1391 if (!emipc_execute_stub_api(a_hAPI)) {
1392 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1396 EM_SAFE_FREE(multi_user_name);
1397 EM_DEBUG_FUNC_END();
1400 void stb_set_flags_field(HIPC_API a_hAPI)
1402 EM_DEBUG_FUNC_BEGIN();
1403 int err = EMAIL_ERROR_NONE;
1404 email_flags_field_type field_type = 0;
1410 int *mail_ids = NULL;
1411 int nAPPID = emipc_get_app_id(a_hAPI);
1412 char *multi_user_name = NULL;
1414 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1415 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1416 multi_user_name = NULL;
1420 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
1421 EM_DEBUG_LOG("account_id [%d]", account_id);
1423 /* Number of mail_ids */
1424 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &num);
1425 EM_DEBUG_LOG("number of mails [%d]", num);
1428 mail_ids = em_malloc(sizeof(int) * num);
1431 EM_DEBUG_EXCEPTION("em_malloc failed ");
1432 err = EMAIL_ERROR_OUT_OF_MEMORY;
1436 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, num * sizeof(int), mail_ids);
1438 for(counter=0; counter < num; counter++)
1439 EM_DEBUG_LOG("mailids [%d]", mail_ids[counter]);
1442 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &field_type);
1443 EM_DEBUG_LOG("field_type [%d]", field_type);
1446 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 4, sizeof(int), &value);
1447 EM_DEBUG_LOG("value [%d]", value);
1450 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 5, sizeof(int), &onserver);
1451 EM_DEBUG_LOG("onserver [%d]", onserver);
1453 if(emdaemon_set_flags_field(multi_user_name, account_id, mail_ids, num, field_type, value, onserver, &err))
1454 EM_DEBUG_LOG("emdaemon_set_flags_field - success");
1458 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1459 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
1461 if (!emipc_execute_stub_api(a_hAPI))
1462 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
1465 EM_SAFE_FREE(mail_ids);
1467 EM_SAFE_FREE(multi_user_name);
1468 EM_DEBUG_FUNC_END();
1471 void stb_add_mail(HIPC_API a_hAPI)
1473 EM_DEBUG_FUNC_BEGIN();
1474 int buffer_size = 0;
1475 int local_result = 0;
1476 int result_attachment_data_count = 0;
1477 int param_index = 0;
1478 int sync_server = 0;
1479 int err = EMAIL_ERROR_NONE;
1481 email_mail_data_t result_mail_data = {0};
1482 email_attachment_data_t *result_attachment_data = NULL;
1483 email_meeting_request_t result_meeting_request = {0};
1484 emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI;
1485 email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE;
1486 int nAPPID = emipc_get_app_id(a_hAPI);
1487 char *multi_user_name = NULL;
1488 char *prefix_path = NULL;
1489 char real_file_path[255] = {0};
1491 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1492 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1493 multi_user_name = NULL;
1496 /* email_mail_data_t */;
1497 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1498 EM_DEBUG_LOG("email_mail_data_t buffer_size[%d]", buffer_size);
1501 if(buffer_size > 0) {
1502 char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
1503 em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data);
1506 if (em_get_account_server_type_by_account_id(multi_user_name, result_mail_data.account_id, &account_server_type, true, &err) == false) {
1507 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
1511 /* Get the absolute path */
1512 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
1513 err = emcore_get_container_path(multi_user_name, &prefix_path);
1514 if (err != EMAIL_ERROR_NONE) {
1515 EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
1519 prefix_path = strdup("");
1522 /* check smack rule for accessing file path */
1523 if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_mail_data.file_path_html) {
1524 memset(real_file_path, 0x00, sizeof(real_file_path));
1525 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_html);
1527 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1528 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1529 err = EMAIL_ERROR_NO_SMACK_RULE;
1534 if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_mail_data.file_path_plain) {
1535 memset(real_file_path, 0x00, sizeof(real_file_path));
1536 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_plain);
1538 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1539 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1540 err = EMAIL_ERROR_NO_SMACK_RULE;
1545 if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_mail_data.file_path_mime_entity) {
1546 memset(real_file_path, 0x00, sizeof(real_file_path));
1547 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_mime_entity);
1549 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1550 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1551 err = EMAIL_ERROR_NO_SMACK_RULE;
1555 /* check smack rule - END */
1558 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1559 EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size);
1561 if(buffer_size > 0) {
1562 char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index);
1563 em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count);
1565 EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count);
1566 if (!result_attachment_data_count) {
1567 EM_DEBUG_LOG("Not include attachment data");
1569 if(!result_attachment_data) {
1570 EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed");
1571 err = EMAIL_ERROR_ON_PARSING;
1578 /* check smack rule for accessing file path */
1579 for (i = 0; i < result_attachment_data_count ; i++) {
1580 if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_attachment_data[i].attachment_path && result_attachment_data[i].save_status) {
1581 memset(real_file_path, 0x00, sizeof(real_file_path));
1582 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_attachment_data[i].attachment_path);
1584 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1585 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1586 err = EMAIL_ERROR_NO_SMACK_RULE;
1592 /* meeting request */
1593 EM_DEBUG_LOG("email_meeting_request_t");
1594 if ( result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST
1595 || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE
1596 || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
1597 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1599 if(buffer_size > 0) {
1600 char* stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
1601 em_convert_byte_stream_to_meeting_req(stream, buffer_size, &result_meeting_request);
1605 EM_DEBUG_LOG("sync_server");
1606 emipc_get_parameter(a_hAPI, ePARAMETER_IN, param_index++, sizeof(int), &sync_server);
1608 if( (err = emdaemon_add_mail(multi_user_name, &result_mail_data, result_attachment_data, result_attachment_data_count, &result_meeting_request, sync_server)) != EMAIL_ERROR_NONE) {
1609 EM_DEBUG_EXCEPTION("emdaemon_add_mail failed [%d]", err);
1614 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1615 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1616 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.mail_id, sizeof(int)))
1617 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1618 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.thread_id, sizeof(int)))
1619 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1620 if (!emipc_execute_stub_api(a_hAPI))
1621 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1624 if ( local_result == 0 ) {
1625 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1626 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1627 if (!emipc_execute_stub_api(a_hAPI))
1628 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1631 EM_SAFE_FREE(prefix_path);
1633 emcore_free_mail_data(&result_mail_data);
1635 if(result_attachment_data)
1636 emcore_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL);
1638 emstorage_free_meeting_request(&result_meeting_request);
1642 EM_SAFE_FREE(multi_user_name);
1643 EM_DEBUG_FUNC_END();
1647 void stb_update_mail(HIPC_API a_hAPI)
1649 EM_DEBUG_FUNC_BEGIN();
1650 int buffer_size = 0;
1651 int local_result = 0;
1652 int result_attachment_data_count = 0;
1653 int param_index = 0;
1654 int sync_server = 0;
1655 int *temp_buffer = NULL;
1656 int err = EMAIL_ERROR_NONE;
1658 email_mail_data_t result_mail_data = {0};
1659 email_attachment_data_t *result_attachment_data = NULL;
1660 email_meeting_request_t result_meeting_request = {0};
1661 emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI;
1662 int nAPPID = emipc_get_app_id(a_hAPI);
1663 char *multi_user_name = NULL;
1664 char *prefix_path = NULL;
1665 char real_file_path[255] = {0};
1667 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1668 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1669 multi_user_name = NULL;
1672 EM_DEBUG_LOG("email_mail_data_t");
1673 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1675 if(buffer_size > 0) {
1676 char* stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
1677 em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data);
1680 /* Get the absolute path */
1681 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
1682 err = emcore_get_container_path(multi_user_name, &prefix_path);
1683 if (err != EMAIL_ERROR_NONE) {
1684 EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
1688 prefix_path = strdup("");
1691 /* check smack rule for accessing file path */
1692 if (result_mail_data.file_path_html) {
1693 memset(real_file_path, 0x00, sizeof(real_file_path));
1694 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_html);
1696 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1697 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1698 err = EMAIL_ERROR_NO_SMACK_RULE;
1703 if (result_mail_data.file_path_plain) {
1704 memset(real_file_path, 0x00, sizeof(real_file_path));
1705 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_plain);
1707 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1708 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1709 err = EMAIL_ERROR_NO_SMACK_RULE;
1714 if (result_mail_data.file_path_mime_entity) {
1715 memset(real_file_path, 0x00, sizeof(real_file_path));
1716 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_mime_entity);
1718 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1719 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1720 err = EMAIL_ERROR_NO_SMACK_RULE;
1724 /* check smack rule - END */
1725 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1726 if(buffer_size > 0) {
1727 char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index);
1728 em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count);
1730 EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count);
1731 if (!result_attachment_data_count) {
1732 EM_DEBUG_LOG("Not include attachment data");
1734 if(!result_attachment_data) {
1735 EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed");
1736 err = EMAIL_ERROR_ON_PARSING;
1743 /* check smack rule for accessing file path */
1744 for (i = 0; i < result_attachment_data_count ; i++) {
1745 if (result_attachment_data[i].attachment_path) {
1746 memset(real_file_path, 0x00, sizeof(real_file_path));
1747 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_attachment_data[i].attachment_path);
1749 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1750 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1751 err = EMAIL_ERROR_NO_SMACK_RULE;
1757 EM_DEBUG_LOG("email_meeting_request_t");
1758 if ( result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST
1759 || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE
1760 || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
1761 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1763 if(buffer_size > 0) {
1764 char* stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
1765 em_convert_byte_stream_to_meeting_req(stream, buffer_size, &result_meeting_request);
1769 EM_DEBUG_LOG("sync_server");
1771 temp_buffer = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
1774 EM_DEBUG_EXCEPTION("emipc_get_nth_parameter_data[%d] failed", param_index - 1);
1775 err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
1779 sync_server = *temp_buffer;
1781 if( (err = emdaemon_update_mail(multi_user_name, &result_mail_data, result_attachment_data,
1782 result_attachment_data_count, &result_meeting_request, sync_server)) != EMAIL_ERROR_NONE) {
1783 EM_DEBUG_EXCEPTION("emdaemon_update_mail failed [%d]", err);
1788 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1789 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1790 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.mail_id, sizeof(int)))
1791 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1792 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.thread_id, sizeof(int)))
1793 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1794 if (!emipc_execute_stub_api(a_hAPI))
1795 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1798 if ( local_result == 0 ) {
1799 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1800 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1801 if (!emipc_execute_stub_api(a_hAPI))
1802 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1805 emcore_free_mail_data(&result_mail_data);
1807 EM_SAFE_FREE(prefix_path);
1809 if(result_attachment_data)
1810 emcore_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL);
1812 emstorage_free_meeting_request(&result_meeting_request);
1816 EM_SAFE_FREE(multi_user_name);
1817 EM_DEBUG_FUNC_END();
1821 void stb_move_thread_to_mailbox(HIPC_API a_hAPI)
1823 EM_DEBUG_FUNC_BEGIN();
1824 int mailbox_id = 0, thread_id = 0, move_always_flag = 0;
1825 int err = EMAIL_ERROR_NONE;
1826 char *target_mailbox_name = NULL;
1827 int nAPPID = emipc_get_app_id(a_hAPI);
1828 char *multi_user_name = NULL;
1830 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1831 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1832 multi_user_name = NULL;
1835 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &thread_id);
1836 EM_DEBUG_LOG("thread_id [%d]", thread_id);
1838 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mailbox_id);
1839 EM_DEBUG_LOG("mailbox_id [%d]", mailbox_id);
1841 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &move_always_flag);
1842 EM_DEBUG_LOG("move_always_flag [%d]", move_always_flag);
1844 if(emdaemon_move_mail_thread_to_mailbox(multi_user_name, thread_id, mailbox_id, move_always_flag, &err))
1845 EM_DEBUG_LOG("emdaemon_move_mail_thread_to_mailbox success");
1847 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
1848 EM_DEBUG_EXCEPTION("emipc_add_parameter fail");
1849 EM_SAFE_FREE(target_mailbox_name);
1850 EM_SAFE_FREE(multi_user_name);
1854 if (!emipc_execute_stub_api(a_hAPI)) {
1855 EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail");
1856 EM_SAFE_FREE(target_mailbox_name);
1857 EM_SAFE_FREE(multi_user_name);
1861 EM_SAFE_FREE(target_mailbox_name);
1862 EM_SAFE_FREE(multi_user_name);
1863 EM_DEBUG_FUNC_END();
1866 void stb_delete_thread(HIPC_API a_hAPI)
1868 EM_DEBUG_FUNC_BEGIN();
1870 int thread_id = 0, delete_always_flag = 0;
1872 int err = EMAIL_ERROR_NONE;
1873 int nAPPID = emipc_get_app_id(a_hAPI);
1874 char *multi_user_name = NULL;
1876 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1877 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1878 multi_user_name = NULL;
1881 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &thread_id);
1882 EM_DEBUG_LOG("thread_id [%d]", thread_id);
1884 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &delete_always_flag);
1885 EM_DEBUG_LOG("delete_always_flag [%d]", delete_always_flag);
1887 if(emdaemon_delete_mail_thread(multi_user_name, thread_id, delete_always_flag, &handle, &err))
1888 EM_DEBUG_LOG("emdaemon_delete_mail_thread success");
1890 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
1891 EM_DEBUG_EXCEPTION("emipc_add_parameter fail");
1892 EM_SAFE_FREE(multi_user_name);
1896 if (!emipc_execute_stub_api(a_hAPI)) {
1897 EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail");
1898 EM_SAFE_FREE(multi_user_name);
1902 EM_SAFE_FREE(multi_user_name);
1903 EM_DEBUG_FUNC_END();
1906 void stb_modify_seen_flag_of_thread(HIPC_API a_hAPI)
1908 EM_DEBUG_FUNC_BEGIN();
1910 int thread_id = 0, seen_flag = 0, on_server = 0;
1912 int err = EMAIL_ERROR_NONE;
1913 int nAPPID = emipc_get_app_id(a_hAPI);
1914 char *multi_user_name = NULL;
1916 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1917 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1918 multi_user_name = NULL;
1921 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &thread_id);
1922 EM_DEBUG_LOG("thread_id [%d]", thread_id);
1924 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &seen_flag);
1925 EM_DEBUG_LOG("seen_flag [%d]", seen_flag);
1927 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &on_server);
1928 EM_DEBUG_LOG("on_server [%d]", on_server);
1930 if(emdaemon_modify_seen_flag_of_thread(multi_user_name, thread_id, seen_flag, on_server, &handle, &err))
1931 EM_DEBUG_LOG("emdaemon_modify_seen_flag_of_thread success");
1933 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
1934 EM_DEBUG_EXCEPTION("emipc_add_parameter fail");
1935 EM_SAFE_FREE(multi_user_name);
1939 if (!emipc_execute_stub_api(a_hAPI)) {
1940 EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail");
1941 EM_SAFE_FREE(multi_user_name);
1945 EM_SAFE_FREE(multi_user_name);
1946 EM_DEBUG_FUNC_END();
1949 void stb_expunge_mails_deleted_flagged(HIPC_API a_hAPI)
1951 EM_DEBUG_FUNC_BEGIN();
1953 int mailbox_id = 0, on_server = 0;
1955 int err = EMAIL_ERROR_NONE;
1956 int nAPPID = emipc_get_app_id(a_hAPI);
1957 char *multi_user_name = NULL;
1959 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1960 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1961 multi_user_name = NULL;
1964 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), (void*)&mailbox_id);
1965 EM_DEBUG_LOG("mailbox_id [%d]", mailbox_id);
1967 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), (void*)&on_server);
1968 EM_DEBUG_LOG("on_server [%d]", on_server);
1970 if( (err = emdaemon_expunge_mails_deleted_flagged(multi_user_name, mailbox_id, on_server, &handle)) != EMAIL_ERROR_NONE)
1971 EM_DEBUG_LOG("emdaemon_expunge_mails_deleted_flagged success");
1973 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
1974 EM_DEBUG_EXCEPTION("emipc_add_parameter fail");
1978 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int))) {
1979 EM_DEBUG_LOG("ipcAPI_AddParameter local_result failed ");
1983 if (!emipc_execute_stub_api(a_hAPI)) {
1984 EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail");
1988 EM_SAFE_FREE(multi_user_name);
1989 EM_DEBUG_FUNC_END();
1992 void stb_move_mail(HIPC_API a_hAPI)
1994 int err = EMAIL_ERROR_NONE;
1995 int num = 0, counter = 0, mailbox_id = 0;
1996 int nAPPID = emipc_get_app_id(a_hAPI);
1997 char *multi_user_name = NULL;
1999 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2000 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2001 multi_user_name = NULL;
2004 /* Number of mail_ids */
2005 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &num);
2006 EM_DEBUG_LOG("number of mails [%d]", num);
2010 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, num * sizeof(int), mail_ids);
2012 for(counter = 0; counter < num; counter++)
2013 EM_DEBUG_LOG("mailids [%d]", mail_ids[counter]);
2015 /* target_mailbox_id */
2016 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &mailbox_id);
2017 EM_DEBUG_LOG("target_mailbox_id [%d]", mailbox_id);
2020 EM_DEBUG_LOG("mailbox_id [%d]", mailbox_id);
2022 EM_DEBUG_LOG("mailbox_id == 0");
2024 if(emdaemon_move_mail(multi_user_name, mail_ids, num, mailbox_id, EMAIL_MOVED_BY_COMMAND, 0, &err))
2025 EM_DEBUG_LOG("emdaemon_move_mail success");
2027 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2028 EM_DEBUG_EXCEPTION("emipc_add_parameter fail");
2030 if (!emipc_execute_stub_api(a_hAPI))
2031 EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail");
2033 EM_SAFE_FREE(multi_user_name);
2034 EM_DEBUG_FUNC_END();
2037 void stb_delete_rule(HIPC_API a_hAPI)
2039 EM_DEBUG_FUNC_BEGIN();
2042 int err = EMAIL_ERROR_NONE;
2043 int nAPPID = emipc_get_app_id(a_hAPI);
2044 char *multi_user_name = NULL;
2046 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2047 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2048 multi_user_name = NULL;
2052 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &filter_id);
2054 if(emdaemon_delete_filter(multi_user_name, filter_id, &err))
2055 err = EMAIL_ERROR_NONE;
2057 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2058 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2060 if (!emipc_execute_stub_api(a_hAPI))
2061 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2063 EM_SAFE_FREE(multi_user_name);
2064 EM_DEBUG_FUNC_END();
2067 void stb_apply_rule(HIPC_API a_hAPI)
2069 EM_DEBUG_FUNC_BEGIN();
2072 int err = EMAIL_ERROR_NONE;
2073 int nAPPID = emipc_get_app_id(a_hAPI);
2074 char *multi_user_name = NULL;
2076 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2077 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2078 multi_user_name = NULL;
2082 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &filter_id);
2084 if(emdaemon_apply_filter(multi_user_name, filter_id, &err))
2085 err = EMAIL_ERROR_NONE;
2087 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2088 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2090 if (!emipc_execute_stub_api(a_hAPI))
2091 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2093 EM_SAFE_FREE(multi_user_name);
2094 EM_DEBUG_FUNC_END();
2097 void stb_add_attachment(HIPC_API a_hAPI)
2099 EM_DEBUG_FUNC_BEGIN();
2100 int buffer_size = 0;
2101 int err = EMAIL_ERROR_NONE;
2103 int attachment_count = 0;
2105 char* attachment_stream = NULL;
2106 email_attachment_data_t* attachment = NULL;
2107 emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI;
2108 int nAPPID = emipc_get_app_id(a_hAPI);
2109 char *multi_user_name = NULL;
2110 char *prefix_path = NULL;
2111 char real_file_path[255] = {0};
2113 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2114 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2115 multi_user_name = NULL;
2119 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
2122 buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
2124 if(buffer_size > 0) {
2125 attachment_stream = (char*)em_malloc(buffer_size);
2126 if (attachment_stream == NULL) {
2127 EM_DEBUG_EXCEPTION("em_malloc failed");
2128 err = EMAIL_ERROR_OUT_OF_MEMORY;
2132 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, attachment_stream);
2133 em_convert_byte_stream_to_attachment_data(attachment_stream, buffer_size, &attachment, &attachment_count);
2134 EM_SAFE_FREE(attachment_stream);
2138 EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed ");
2139 err = EMAIL_ERROR_ON_PARSING;
2143 /* Get the absolute path */
2144 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
2145 err = emcore_get_container_path(multi_user_name, &prefix_path);
2146 if (err != EMAIL_ERROR_NONE) {
2147 EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
2151 prefix_path = strdup("");
2154 /* check smack rule for accessing file path */
2155 for (i = 0; i < attachment_count ; i++) {
2156 if (attachment[i].attachment_path) {
2157 memset(real_file_path, 0x00, sizeof(real_file_path));
2158 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, attachment[i].attachment_path);
2160 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
2161 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
2162 err = EMAIL_ERROR_NO_SMACK_RULE;
2168 emdaemon_add_attachment(multi_user_name, mail_id, attachment, &err);
2172 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2173 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2174 if(EMAIL_ERROR_NONE == err) {
2175 EM_DEBUG_LOG("emdaemon_add_attachment -Success");
2177 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &(attachment->attachment_id), sizeof(int)))
2178 EM_DEBUG_EXCEPTION("emipc_add_parameter attachment_id failed ");
2180 if (!emipc_execute_stub_api(a_hAPI))
2181 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2183 EM_SAFE_FREE(attachment);
2184 EM_SAFE_FREE(multi_user_name);
2185 EM_SAFE_FREE(prefix_path);
2187 EM_DEBUG_FUNC_END();
2190 void stb_get_attachment(HIPC_API a_hAPI)
2192 EM_DEBUG_FUNC_BEGIN();
2193 int err = EMAIL_ERROR_NONE;
2195 char* attachment_stream = NULL;
2196 email_attachment_data_t* attachment = NULL;
2198 int nAPPID = emipc_get_app_id(a_hAPI);
2199 char *multi_user_name = NULL;
2201 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2202 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2203 multi_user_name = NULL;
2207 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &attachment_id);
2209 emdaemon_get_attachment(multi_user_name, attachment_id, &attachment, &err);
2211 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2212 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2214 if(EMAIL_ERROR_NONE == err) {
2215 EM_DEBUG_LOG("emdaemon_get_attachment - Success");
2217 attachment_stream = em_convert_attachment_data_to_byte_stream(attachment, 1, &size);
2218 if(!attachment_stream) { /*prevent 26263*/
2219 emcore_free_attachment_data(&attachment, 1, &err);
2220 EM_SAFE_FREE(multi_user_name);
2223 EM_NULL_CHECK_FOR_VOID(attachment_stream);
2225 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, attachment_stream, size))
2226 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2229 if (!emipc_execute_stub_api(a_hAPI)) {
2230 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2233 EM_SAFE_FREE(attachment_stream);
2234 emcore_free_attachment_data(&attachment, 1, &err);
2236 EM_SAFE_FREE(multi_user_name);
2237 EM_DEBUG_FUNC_END();
2240 void stb_get_imap_mailbox_list(HIPC_API a_hAPI)
2242 EM_DEBUG_FUNC_BEGIN();
2243 int err = EMAIL_ERROR_NONE;
2246 int nAPPID = emipc_get_app_id(a_hAPI);
2247 char *multi_user_name = NULL;
2249 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2250 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2251 multi_user_name = NULL;
2255 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2257 /*need to check: why err value is changed? */
2258 if(emdaemon_get_imap_mailbox_list(multi_user_name, account_id, "", &handle, &err))
2259 err = EMAIL_ERROR_NONE;
2261 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2262 EM_DEBUG_LOG("ipcAPI_AddParameter local_result failed ");
2263 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
2264 EM_DEBUG_LOG("ipcAPI_AddParameter local_result failed ");
2265 if (!emipc_execute_stub_api(a_hAPI))
2266 EM_DEBUG_LOG("emipc_execute_stub_api failed ");
2268 EM_SAFE_FREE(multi_user_name);
2269 EM_DEBUG_FUNC_END();
2272 void stb_delete_attachment(HIPC_API a_hAPI)
2274 EM_DEBUG_FUNC_BEGIN();
2275 int err = EMAIL_ERROR_NONE;
2276 int attachment_id = 0;
2277 int nAPPID = emipc_get_app_id(a_hAPI);
2278 char *multi_user_name = NULL;
2280 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2281 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2282 multi_user_name = NULL;
2285 /* attachment_index */
2286 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &attachment_id);
2288 emdaemon_delete_mail_attachment(multi_user_name, attachment_id, &err);
2290 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2291 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2292 if (!emipc_execute_stub_api(a_hAPI))
2293 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2295 EM_SAFE_FREE(multi_user_name);
2296 EM_DEBUG_FUNC_END();
2299 void stb_download_attachment(HIPC_API a_hAPI)
2301 EM_DEBUG_FUNC_BEGIN();
2303 int err = EMAIL_ERROR_NONE;
2308 int nAPPID = emipc_get_app_id(a_hAPI);
2309 char *multi_user_name = NULL;
2311 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2312 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2313 multi_user_name = NULL;
2316 EM_DEBUG_LOG("account_id");
2317 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2319 EM_DEBUG_LOG("mail_id");
2320 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mail_id);
2322 EM_DEBUG_LOG("nth");
2323 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &nth);
2325 if(emdaemon_download_attachment(multi_user_name, account_id, mail_id, nth, &handle, &err)) {
2326 err = EMAIL_ERROR_NONE;
2328 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2329 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2330 EM_DEBUG_LOG(">>>>>>>>>> HANDLE = %d", handle);
2331 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
2332 EM_DEBUG_EXCEPTION("emipc_add_parameter handle failed ");
2333 if (!emipc_execute_stub_api(a_hAPI))
2334 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2337 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2338 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2339 /* Download handle - 17-Apr-09 */
2340 EM_DEBUG_LOG(">>>>>>>>>> HANDLE = %d", handle);
2341 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
2342 EM_DEBUG_EXCEPTION("emipc_add_parameter handle failed ");
2343 if (!emipc_execute_stub_api(a_hAPI))
2344 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2347 EM_SAFE_FREE(multi_user_name);
2348 EM_DEBUG_FUNC_END();
2351 void stb_mail_send_saved(HIPC_API a_hAPI)
2353 EM_DEBUG_FUNC_BEGIN();
2354 int err = EMAIL_ERROR_NONE;
2356 int nAPPID = emipc_get_app_id(a_hAPI);
2357 char *multi_user_name = NULL;
2359 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2360 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2361 multi_user_name = NULL;
2365 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2367 EM_DEBUG_LOG("calling emdaemon_send_mail_saved");
2368 if(emdaemon_send_mail_saved(multi_user_name, account_id, NULL, &err))
2369 err = EMAIL_ERROR_NONE;
2371 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2372 EM_DEBUG_EXCEPTION("emipc_add_parameter result failed ");
2374 if (!emipc_execute_stub_api(a_hAPI))
2375 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2377 EM_SAFE_FREE(multi_user_name);
2378 EM_DEBUG_FUNC_END();
2381 void stb_add_read_receipt(HIPC_API a_hAPI){
2382 EM_DEBUG_FUNC_BEGIN();
2383 int read_mail_id = 0;
2384 int receipt_mail_id = 0;
2385 int err = EMAIL_ERROR_NONE;
2386 int nAPPID = emipc_get_app_id(a_hAPI);
2387 char *multi_user_name = NULL;
2389 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2390 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2391 multi_user_name = NULL;
2395 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &read_mail_id);
2396 EM_DEBUG_LOG("read_mail_id [%d]", read_mail_id);
2398 if( (err = emcore_add_read_receipt(multi_user_name, read_mail_id, &receipt_mail_id)) != EMAIL_ERROR_NONE )
2399 EM_DEBUG_EXCEPTION("emcore_add_read_receipt failed [%d]", err);
2401 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2402 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2404 if (err == EMAIL_ERROR_NONE) {
2405 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &receipt_mail_id, sizeof(int)))
2406 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2409 if (!emipc_execute_stub_api(a_hAPI))
2410 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2412 EM_SAFE_FREE(multi_user_name);
2413 EM_DEBUG_FUNC_END("err [%d]", err);
2416 void stb_retry_sending_mail(HIPC_API a_hAPI)
2419 EM_DEBUG_FUNC_BEGIN();
2421 int timeout_in_sec = 0;
2422 int err = EMAIL_ERROR_NONE;
2423 int nAPPID = emipc_get_app_id(a_hAPI);
2424 char *multi_user_name = NULL;
2426 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2427 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2428 multi_user_name = NULL;
2432 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
2433 EM_DEBUG_LOG("mail_id [%d]", mail_id);
2435 /* timeout_in_sec */
2436 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &timeout_in_sec);
2437 EM_DEBUG_LOG("timeout_in_sec [%d]", timeout_in_sec);
2439 if(emdaemon_send_mail_retry(multi_user_name, mail_id, timeout_in_sec,&err))
2440 EM_DEBUG_LOG("emdaemon_get_mailbox_list - success");
2442 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2443 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2445 if (!emipc_execute_stub_api(a_hAPI))
2446 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2448 EM_SAFE_FREE(multi_user_name);
2449 EM_DEBUG_FUNC_END();
2452 void stb_cancel_job(HIPC_API a_hAPI)
2454 EM_DEBUG_FUNC_BEGIN();
2457 int err = EMAIL_ERROR_NONE;
2458 int nAPPID = emipc_get_app_id(a_hAPI);
2459 char *multi_user_name = NULL;
2461 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2462 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2463 multi_user_name = NULL;
2466 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2467 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &handle);
2468 EM_DEBUG_LOG("account_id [%d] handle [%d]", account_id, handle);
2470 if(emdaemon_cancel_job(account_id, handle, &err))
2471 err = EMAIL_ERROR_NONE;
2473 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2474 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2475 if (!emipc_execute_stub_api(a_hAPI))
2476 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2478 EM_SAFE_FREE(multi_user_name);
2479 EM_DEBUG_FUNC_END();
2482 void stb_cancel_send_mail_job(HIPC_API a_hAPI)
2484 EM_DEBUG_FUNC_BEGIN();
2486 int err = EMAIL_ERROR_NONE;
2488 int nAPPID = emipc_get_app_id(a_hAPI);
2489 char *multi_user_name = NULL;
2491 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2492 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2493 multi_user_name = NULL;
2497 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2498 EM_DEBUG_LOG("account_id [%d]", account_id);
2501 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mail_id);
2502 EM_DEBUG_LOG("mail_id [%d]", mail_id);
2504 if(emdaemon_cancel_sending_mail_job(account_id,mail_id,&err))
2505 EM_DEBUG_LOG("success");
2507 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2508 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2510 if (!emipc_execute_stub_api(a_hAPI))
2511 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2513 EM_SAFE_FREE(multi_user_name);
2514 EM_DEBUG_FUNC_END();
2517 void stb_search_mail_on_server(HIPC_API a_hAPI)
2519 EM_DEBUG_FUNC_BEGIN();
2520 int err = EMAIL_ERROR_NONE;
2523 int buffer_size = 0;
2524 int search_filter_count = 0;
2525 char *stream_for_search_filter_list = NULL;
2526 unsigned int job_handle = 0;
2527 email_search_filter_t *search_filter_list = NULL;
2528 int nAPPID = emipc_get_app_id(a_hAPI);
2529 char *multi_user_name = NULL;
2531 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2532 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2533 multi_user_name = NULL;
2537 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2538 EM_DEBUG_LOG("account_id [%d]", account_id);
2541 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mailbox_id);
2542 EM_DEBUG_LOG("mailbox_id [%d]", mailbox_id);
2544 /* search_filter_list */
2545 buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 2);
2547 if(buffer_size > 0) {
2548 stream_for_search_filter_list = (char*)em_malloc(buffer_size);
2549 if (stream_for_search_filter_list == NULL) {
2550 EM_DEBUG_EXCEPTION("out of memory");
2551 EM_SAFE_FREE(multi_user_name);
2555 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, buffer_size, stream_for_search_filter_list);
2556 em_convert_byte_stream_to_search_filter(stream_for_search_filter_list, &search_filter_list, &search_filter_count);
2557 EM_SAFE_FREE(stream_for_search_filter_list);
2560 if(!emdaemon_search_mail_on_server(multi_user_name, account_id ,mailbox_id, search_filter_list, search_filter_count, &job_handle, &err))
2561 EM_DEBUG_LOG("success");
2563 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2564 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2566 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &job_handle, sizeof(int)))
2567 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2569 if (!emipc_execute_stub_api(a_hAPI))
2570 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2572 EM_SAFE_FREE(multi_user_name);
2573 EM_DEBUG_FUNC_END();
2576 void stb_clear_result_of_search_mail_on_server(HIPC_API a_hAPI)
2578 EM_DEBUG_FUNC_BEGIN();
2579 int err = EMAIL_ERROR_NONE;
2581 emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
2582 int nAPPID = emipc_get_app_id(a_hAPI);
2583 char *multi_user_name = NULL;
2585 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2586 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2587 multi_user_name = NULL;
2591 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2593 EM_DEBUG_LOG("account_id [%d]", account_id);
2595 if (!emstorage_get_mailbox_by_name(multi_user_name, account_id, -1, EMAIL_SEARCH_RESULT_MAILBOX_NAME, &mailbox_tbl, false, &err)) {
2596 EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_name failed [%d]", err);
2600 if (!emstorage_delete_mail_by_mailbox(multi_user_name, mailbox_tbl, true, &err))
2601 EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
2606 emstorage_free_mailbox(&mailbox_tbl, 1, NULL);
2609 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2610 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2612 if (!emipc_execute_stub_api(a_hAPI))
2613 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2615 EM_SAFE_FREE(multi_user_name);
2616 EM_DEBUG_FUNC_END();
2621 void stb_add_account_with_validation(HIPC_API a_hAPI)
2623 EM_DEBUG_FUNC_BEGIN();
2624 int buffer_size = 0;
2625 int local_result = 0;
2627 char* stream = NULL;
2628 email_account_t *account = NULL;
2629 email_account_t *ref_account = NULL;
2630 int ref_check_interval = 0;
2631 int ref_account_id = 0;
2632 int err = EMAIL_ERROR_NONE;
2633 int nAPPID = emipc_get_app_id(a_hAPI);
2634 char *multi_user_name = NULL;
2636 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2637 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2638 multi_user_name = NULL;
2641 /* get account info */
2642 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 0);
2643 EM_DEBUG_LOG("size [%d]", buffer_size);
2644 if(buffer_size <= 0) {
2645 err = EMAIL_ERROR_INVALID_PARAM;
2649 stream =(char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0);
2651 err = EMAIL_ERROR_INVALID_PARAM;
2655 account = em_malloc(sizeof(email_account_t));
2657 if(account == NULL) {
2658 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
2659 err = EMAIL_ERROR_OUT_OF_MEMORY;
2663 em_convert_byte_stream_to_account(stream, buffer_size, account);
2664 account->user_name = EM_SAFE_STRDUP(multi_user_name);
2666 if((err = emcore_add_account_to_unvalidated_account_list(account)) != EMAIL_ERROR_NONE) {
2667 EM_DEBUG_EXCEPTION("emcore_add_account_to_unvalidated_account_list failed [%d]", err);
2671 ref_account = emcore_get_account_reference(multi_user_name, account->account_id, false);
2673 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", err);
2677 ref_check_interval = ref_account->check_interval;
2678 ref_account_id = ref_account->account_id;
2680 if(!emdaemon_validate_account_and_create(multi_user_name, ref_account, &handle, &err)) {
2681 EM_DEBUG_EXCEPTION("emdaemon_validate_account_and_create fail [%d]", err);
2684 #ifdef __FEATURE_AUTO_POLLING__
2685 /* start auto polling, if check_interval not zero */
2686 if(ref_check_interval > 0 || (ref_account->peak_days > 0 && ref_account->peak_interval > 0)) {
2687 if(!emdaemon_add_polling_alarm(multi_user_name, ref_account_id))
2688 EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm[NOTI_ACCOUNT_ADD] : start auto poll failed >>> ");
2690 #ifdef __FEATURE_IMAP_IDLE__
2691 else if(ref_check_interval == 0 || (ref_account->peak_days > 0 && ref_account->peak_interval == 0))
2692 emcore_refresh_imap_idle_thread();
2693 #endif /* __FEATURE_IMAP_IDLE__ */
2694 #endif /* __FEATURE_AUTO_POLLING__ */
2695 /* add account details to contact DB */
2696 /* emdaemon_insert_accountinfo_to_contact(account); */
2699 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
2700 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2701 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
2702 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2703 if (!emipc_execute_stub_api(a_hAPI))
2704 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2707 if ( local_result == 0 ) { /* there is an error */
2708 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
2709 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : local_result ");
2710 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2711 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : err");
2712 if (!emipc_execute_stub_api(a_hAPI))
2713 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2716 /* note: account is freed in thread_func_branch_command, which is run by other thread */
2717 /* emcore_free_account(account); */
2719 EM_SAFE_FREE(multi_user_name);
2720 EM_DEBUG_FUNC_END();
2723 void stb_backup_account(HIPC_API a_hAPI)
2725 EM_DEBUG_FUNC_BEGIN();
2727 #ifdef __FEATURE_BACKUP_ACCOUNT__
2728 char *file_path = NULL;
2729 int local_result = 0, err_code = 0, file_path_length = 0;
2730 int nAPPID = emipc_get_app_id(a_hAPI);
2731 char *multi_user_name = NULL;
2733 if ((err_code = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2734 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err_code);
2735 multi_user_name = NULL;
2738 /* file_path_length */
2739 file_path_length = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
2740 if(file_path_length > 0) {
2741 EM_DEBUG_LOG("file_path_length [%d]", file_path_length);
2742 file_path = em_malloc(file_path_length);
2743 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, file_path_length, file_path);
2744 EM_DEBUG_LOG_SEC("file_path [%s]", file_path);
2745 local_result = emcore_backup_accounts(multi_user_name, (const char*)file_path, &err_code);
2748 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
2749 EM_DEBUG_LOG("emipc_add_parameter failed ");
2751 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
2752 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2754 if (!emipc_execute_stub_api(a_hAPI))
2755 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2757 EM_SAFE_FREE(file_path);
2758 EM_SAFE_FREE(multi_user_name);
2759 #endif /* __FEATURE_BACKUP_ACCOUNT__ */
2760 EM_DEBUG_FUNC_END();
2763 void stb_restore_account(HIPC_API a_hAPI)
2765 EM_DEBUG_FUNC_BEGIN();
2766 #ifdef __FEATURE_BACKUP_ACCOUNT__
2767 char *file_path = NULL;
2768 int result = 0, err_code = 0, file_path_length = 0;
2769 int nAPPID = emipc_get_app_id(a_hAPI);
2770 char *multi_user_name = NULL;
2772 if ((err_code = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2773 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err_code);
2774 multi_user_name = NULL;
2777 /* file_path_length */
2778 file_path_length = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
2779 if(file_path_length > 0) {
2780 EM_DEBUG_LOG("file_path_length [%d]", file_path_length);
2781 file_path = em_malloc(file_path_length);
2782 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, file_path_length, file_path);
2783 EM_DEBUG_LOG_SEC("file_path [%s]", file_path);
2786 /* file_path could be NULL */
2787 err_code = emcore_restore_accounts(multi_user_name, (const char*)file_path);
2789 result = (err_code == EMAIL_ERROR_NONE)?1:0;
2791 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result, sizeof(int)))
2792 EM_DEBUG_LOG("emipc_add_parameter failed ");
2794 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
2795 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2797 if (!emipc_execute_stub_api(a_hAPI))
2798 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2800 EM_SAFE_FREE(file_path);
2801 EM_SAFE_FREE(multi_user_name);
2802 #endif /* __FEATURE_BACKUP_ACCOUNT__ */
2803 EM_DEBUG_FUNC_END();
2807 void stb_get_password_length(HIPC_API a_hAPI)
2809 EM_DEBUG_FUNC_BEGIN();
2811 int password_type = 0;
2812 int local_result = 0;
2814 int password_length = 0;
2815 int nAPPID = emipc_get_app_id(a_hAPI);
2816 char *multi_user_name = NULL;
2818 if ((err_code = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2819 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err_code);
2820 multi_user_name = NULL;
2824 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2825 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &password_type);
2827 local_result = emstorage_get_password_length_of_account(multi_user_name, account_id, password_type, &password_length,&err_code);
2829 EM_DEBUG_LOG("password_length [%d]", password_length);
2831 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
2832 EM_DEBUG_LOG("emipc_add_parameter failed ");
2834 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
2835 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2837 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &password_length, sizeof(int)))
2838 EM_DEBUG_EXCEPTION("emipc_add_parameter result failed ");
2840 if (!emipc_execute_stub_api(a_hAPI))
2841 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2843 EM_SAFE_FREE(multi_user_name);
2844 EM_DEBUG_FUNC_END();
2847 void stb_get_task_information(HIPC_API a_hAPI)
2849 EM_DEBUG_FUNC_BEGIN();
2851 int task_information_count = 0;
2853 email_task_information_t *task_information = NULL;
2854 char *task_information_stream = NULL;
2855 int nAPPID = emipc_get_app_id(a_hAPI);
2856 char *multi_user_name = NULL;
2858 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2859 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2860 multi_user_name = NULL;
2863 err = emcore_get_task_information(&task_information, &task_information_count);
2865 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2866 EM_DEBUG_LOG("emipc_add_parameter failed ");
2868 /* email_task_information_t */
2869 if(task_information_count) {
2870 task_information_stream = em_convert_task_information_to_byte_stream(task_information, task_information_count, &stream_length);
2872 if((stream_length > 0) && !emipc_add_dynamic_parameter(a_hAPI, ePARAMETER_OUT, task_information_stream, stream_length)) {
2873 EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed");
2874 err = EMAIL_ERROR_OUT_OF_MEMORY;
2878 if (!emipc_execute_stub_api(a_hAPI))
2879 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2881 if(task_information) {
2882 EM_SAFE_FREE(task_information);
2885 EM_SAFE_FREE(multi_user_name);
2886 EM_DEBUG_FUNC_END();
2889 void stb_add_certificate(HIPC_API a_hAPI)
2891 int err = EMAIL_ERROR_NONE;
2892 int cert_file_len = 0;
2893 int email_address_len = 0;
2894 char *cert_file_path = NULL;
2895 char *email_address = NULL;
2896 emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI;
2897 int nAPPID = emipc_get_app_id(a_hAPI);
2898 char *multi_user_name = NULL;
2899 char *prefix_path = NULL;
2900 char real_file_path[255] = {0};
2902 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2903 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2904 multi_user_name = NULL;
2907 /* Get the absolute path */
2908 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
2909 err = emcore_get_container_path(multi_user_name, &prefix_path);
2910 if (err != EMAIL_ERROR_NONE) {
2911 EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
2915 prefix_path = strdup("");
2918 cert_file_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
2919 if (cert_file_len > 0) {
2920 cert_file_path = em_malloc(cert_file_len + 1);
2921 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, cert_file_len, cert_file_path);
2924 /* check smack rule for accessing file path */
2925 if (cert_file_path) {
2926 memset(real_file_path, 0x00, sizeof(real_file_path));
2927 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, cert_file_path);
2929 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
2930 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
2931 err = EMAIL_ERROR_NO_SMACK_RULE;
2936 email_address_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
2937 if (email_address_len > 0) {
2938 email_address = em_malloc(email_address_len + 1);
2939 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, email_address_len, email_address);
2942 if (!emcore_add_public_certificate(multi_user_name, cert_file_path, email_address, &err)) {
2943 EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed");
2948 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2949 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2951 if (EMAIL_ERROR_NONE == err) {
2952 EM_DEBUG_LOG("email_mail_add_attachment -Success");
2955 if (!emipc_execute_stub_api(a_hAPI))
2956 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2958 EM_SAFE_FREE(prefix_path);
2959 EM_SAFE_FREE(cert_file_path);
2960 EM_SAFE_FREE(email_address);
2961 EM_SAFE_FREE(multi_user_name);
2962 EM_DEBUG_FUNC_END();
2965 void stb_delete_certificate(HIPC_API a_hAPI)
2967 int err = EMAIL_ERROR_NONE;
2968 int email_address_len = 0;
2969 char *email_address = NULL;
2970 char temp_email_address[130] = {0, };
2971 int nAPPID = emipc_get_app_id(a_hAPI);
2972 char *multi_user_name = NULL;
2974 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2975 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2976 multi_user_name = NULL;
2979 email_address_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
2980 if (email_address_len > 0) {
2981 EM_DEBUG_LOG("email address string length [%d]", email_address_len);
2982 email_address = em_malloc(email_address_len + 1);
2983 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, email_address_len, email_address);
2984 EM_DEBUG_LOG_SEC("email address [%s]", email_address);
2987 SNPRINTF(temp_email_address, sizeof(temp_email_address), "<%s>", email_address);
2988 if (!emcore_delete_public_certificate(multi_user_name, temp_email_address, &err)) {
2989 EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed");
2992 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2993 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2995 if (EMAIL_ERROR_NONE == err) {
2996 EM_DEBUG_LOG("email_mail_add_attachment -Success");
2999 if (!emipc_execute_stub_api(a_hAPI))
3000 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3003 EM_SAFE_FREE(email_address);
3004 EM_SAFE_FREE(multi_user_name);
3005 EM_DEBUG_FUNC_END();
3008 void stb_verify_signature(HIPC_API a_hAPI)
3010 int err = EMAIL_ERROR_NONE;
3014 int attachment_tbl_count = 0;
3015 email_mail_data_t *mail_data = NULL;
3016 emstorage_attachment_tbl_t *attachment_tbl_list = NULL;
3017 int nAPPID = emipc_get_app_id(a_hAPI);
3018 char *multi_user_name = NULL;
3020 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3021 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3022 multi_user_name = NULL;
3025 err = emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
3026 if (err != EMAIL_ERROR_NONE) {
3027 EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
3031 if (!emcore_get_mail_data(multi_user_name, mail_id, &mail_data)) {
3032 EM_DEBUG_EXCEPTION("emcore_get_mail_data failed");
3036 if ((err = emstorage_get_attachment_list(multi_user_name, mail_id, true, &attachment_tbl_list, &attachment_tbl_count)) != EMAIL_ERROR_NONE) {
3037 EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed : [%d]", err);
3041 if (attachment_tbl_count <= 0) {
3042 EM_DEBUG_EXCEPTION("Invalid signed mail");
3043 err = EMAIL_ERROR_INVALID_MAIL;
3047 for (count = 0; count < attachment_tbl_count ; count++) {
3048 if (attachment_tbl_list[count].attachment_mime_type && strcasestr(attachment_tbl_list[count].attachment_mime_type, "SIGNATURE"))
3052 if (mail_data->smime_type == EMAIL_SMIME_SIGNED) {
3053 if (!emcore_verify_signature(attachment_tbl_list[count].attachment_path, mail_data->file_path_mime_entity, &verify, &err)) {
3054 EM_DEBUG_EXCEPTION("emcore_verify_signature failed");
3057 } else if (mail_data->smime_type == EMAIL_PGP_SIGNED) {
3058 if ((err = emcore_pgp_get_verify_signature(attachment_tbl_list[count].attachment_path, mail_data->file_path_mime_entity, mail_data->digest_type, &verify)) != EMAIL_ERROR_NONE) {
3059 EM_DEBUG_EXCEPTION("emcore_pgp_get_verify_signature failed : [%d]", err);
3063 EM_DEBUG_LOG("Invalid signed mail");
3064 err = EMAIL_ERROR_INVALID_PARAM;
3069 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &verify, sizeof(int)))
3070 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
3073 EM_DEBUG_LOG("Verify S/MIME signed mail-Success");
3076 if (!emipc_execute_stub_api(a_hAPI))
3077 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3080 if (attachment_tbl_list)
3081 emstorage_free_attachment(&attachment_tbl_list, attachment_tbl_count, NULL);
3084 emcore_free_mail_data(mail_data);
3085 EM_SAFE_FREE(mail_data);
3088 EM_SAFE_FREE(multi_user_name);
3089 EM_DEBUG_FUNC_END();
3092 void stb_verify_certificate(HIPC_API a_hAPI)
3094 int err = EMAIL_ERROR_NONE;
3096 int cert_file_len = 0;
3097 char *cert_file_path = 0;
3098 int nAPPID = emipc_get_app_id(a_hAPI);
3099 char *multi_user_name = NULL;
3101 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3102 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3103 multi_user_name = NULL;
3106 cert_file_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
3107 if (cert_file_len > 0) {
3108 cert_file_path = em_malloc(cert_file_len + 1);
3109 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, cert_file_len, cert_file_path);
3112 if (!emcore_verify_certificate(cert_file_path, &verify, &err)) {
3113 EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed");
3116 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &verify, sizeof(int)))
3117 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
3120 EM_DEBUG_LOG("Verify S/MIME signed mail-Success");
3123 if (!emipc_execute_stub_api(a_hAPI))
3124 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3126 EM_SAFE_FREE(cert_file_path);
3127 EM_SAFE_FREE(multi_user_name);
3128 EM_DEBUG_FUNC_END();
3131 void stb_ping_service(HIPC_API a_hAPI)
3133 EM_DEBUG_FUNC_BEGIN();
3134 int err = EMAIL_ERROR_NONE;
3136 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3137 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3139 if (!emipc_execute_stub_api(a_hAPI))
3140 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3142 EM_DEBUG_FUNC_END();
3145 void stb_update_notification_bar_for_unread_mail(HIPC_API a_hAPI)
3147 EM_DEBUG_FUNC_BEGIN();
3148 int err = EMAIL_ERROR_NONE, account_id;
3149 int total_mail_count = 0, unread_mail_count = 0;
3150 int input_from_eas = 0;
3151 /* Get Container name */
3152 int nAPPID = emipc_get_app_id(a_hAPI);
3153 char *multi_user_name = NULL;
3155 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3156 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3157 multi_user_name = NULL;
3161 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
3162 EM_DEBUG_LOG("account_id [%d]", account_id);
3164 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &total_mail_count);
3165 EM_DEBUG_LOG("total_mail_count [%d]", total_mail_count);
3167 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &unread_mail_count);
3168 EM_DEBUG_LOG("unread_mail_count [%d]", unread_mail_count);
3170 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &input_from_eas);
3171 EM_DEBUG_LOG("unread_mail_count [%d]", input_from_eas);
3173 emcore_display_unread_in_badge(multi_user_name);
3175 if(!emdaemon_finalize_sync(multi_user_name, account_id, total_mail_count, unread_mail_count, 0, 0, input_from_eas, &err)) {
3176 EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed [%d]", err);
3179 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3180 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3182 if (!emipc_execute_stub_api(a_hAPI))
3183 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3185 EM_SAFE_FREE(multi_user_name);
3186 EM_DEBUG_FUNC_END();
3189 void stb_clear_notification_bar(HIPC_API a_hAPI)
3191 EM_DEBUG_FUNC_BEGIN();
3192 int err = EMAIL_ERROR_NONE, account_id;
3193 int nAPPID = emipc_get_app_id(a_hAPI);
3194 char *multi_user_name = NULL;
3196 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3197 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3198 multi_user_name = NULL;
3202 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
3203 EM_DEBUG_LOG("account_id [%d]", account_id);
3205 if((err = emcore_clear_notifications(multi_user_name, account_id)) != EMAIL_ERROR_NONE)
3206 EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed [%d]", err);
3208 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3209 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3211 if (!emipc_execute_stub_api(a_hAPI))
3212 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3214 EM_SAFE_FREE(multi_user_name);
3215 EM_DEBUG_FUNC_END();
3218 void stb_show_user_message(HIPC_API a_hAPI)
3220 EM_DEBUG_FUNC_BEGIN();
3221 int err = EMAIL_ERROR_NONE;
3223 int param_error = 0;
3224 email_action_t param_action = 0;
3225 int nAPPID = emipc_get_app_id(a_hAPI);
3226 char *multi_user_name = NULL;
3228 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3229 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3230 multi_user_name = NULL;
3234 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), ¶m_id);
3235 EM_DEBUG_LOG("param_id [%d]", param_id);
3238 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), ¶m_action);
3239 EM_DEBUG_LOG("param_action [%d]", param_action);
3242 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), ¶m_error);
3243 EM_DEBUG_LOG("param_error [%d]", param_error);
3245 if(!emcore_show_user_message(multi_user_name, param_id, param_action, param_error)) {
3246 EM_DEBUG_EXCEPTION("emcore_show_user_message failed");
3249 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3250 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3252 if (!emipc_execute_stub_api(a_hAPI))
3253 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3255 EM_SAFE_FREE(multi_user_name);
3256 EM_DEBUG_FUNC_END("err [%d]", err);
3259 void stb_write_mime_file(HIPC_API a_hAPI)
3261 EM_DEBUG_FUNC_BEGIN();
3262 int err = EMAIL_ERROR_NONE;
3264 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3265 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3267 if (!emipc_execute_stub_api(a_hAPI))
3268 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3270 EM_DEBUG_FUNC_END();
3274 void stb_validate_account_ex(HIPC_API a_hAPI)
3276 EM_DEBUG_FUNC_BEGIN();
3277 int buffer_size = 0;
3278 int local_result = 0;
3280 char* stream = NULL;
3281 email_account_t *account = NULL;
3282 email_account_t *ref_account = NULL;
3283 int err = EMAIL_ERROR_NONE;
3284 int nAPPID = emipc_get_app_id(a_hAPI);
3285 char *multi_user_name = NULL;
3287 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3288 EM_DEBUG_EXCEPTION("emcore_get_user_name failed : [%d]", err);
3289 multi_user_name = NULL;
3292 /* get account info */
3293 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 0);
3294 EM_DEBUG_LOG("size [%d]", buffer_size);
3295 if(buffer_size <= 0) {
3296 err = EMAIL_ERROR_INVALID_PARAM;
3300 stream =(char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0);
3302 err = EMAIL_ERROR_INVALID_PARAM;
3306 account = em_malloc(sizeof(email_account_t));
3308 if(account == NULL) {
3309 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
3310 err = EMAIL_ERROR_OUT_OF_MEMORY;
3314 em_convert_byte_stream_to_account(stream, buffer_size, account);
3315 account->user_name = EM_SAFE_STRDUP(multi_user_name);
3317 if((err = emcore_add_account_to_unvalidated_account_list(account)) != EMAIL_ERROR_NONE) {
3318 EM_DEBUG_EXCEPTION("emcore_add_account_to_unvalidated_account_list failed [%d]", err);
3322 ref_account = emcore_get_account_reference(multi_user_name, account->account_id, false);
3325 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", err);
3329 /* ref_account will be removed by worker_event_queue() */
3330 if((err = emdaemon_validate_account_ex(multi_user_name, ref_account, &handle)) != EMAIL_ERROR_NONE) {
3331 EM_DEBUG_EXCEPTION("emdaemon_validate_account_ex fail [%d]", err);
3336 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
3337 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3338 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
3339 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3340 if (!emipc_execute_stub_api(a_hAPI))
3341 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3344 if ( local_result == 0 ) { /* there is an error */
3345 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
3346 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : local_result ");
3347 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3348 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : err");
3349 if (!emipc_execute_stub_api(a_hAPI))
3350 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3353 EM_SAFE_FREE(multi_user_name);
3354 EM_DEBUG_FUNC_END();
3357 void stb_handle_task(int task_type, HIPC_API a_hAPI)
3359 EM_DEBUG_FUNC_BEGIN();
3360 int param_index = 0;
3361 int is_async_task = (task_type > EMAIL_ASYNC_TASK_BOUNDARY_START)?1:0;
3362 int err = EMAIL_ERROR_NONE;
3364 int task_parameter_length = 0;
3365 char *task_parameter = NULL;
3367 /* task_parameter_length */;
3368 task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
3369 EM_DEBUG_LOG("task_parameter_length [%d]", task_parameter_length);
3371 /* task_parameter */
3372 if(task_parameter_length > 0) {
3373 task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
3377 /* add async task */
3378 if((err = emcore_add_task_to_task_table(NULL, task_type, EMAIL_TASK_PRIORITY_MID, task_parameter, task_parameter_length, &task_id)) != EMAIL_ERROR_NONE) {
3379 EM_DEBUG_EXCEPTION("emcore_add_task_to_task_pool failed [%d]", err);
3385 email_task_t sync_task;
3387 memset(&sync_task, 0, sizeof(email_task_t));
3388 sync_task.task_type = task_type;
3389 sync_task.task_priority = EMAIL_TASK_PRIORITY_MID;
3390 sync_task.task_parameter = task_parameter;
3391 sync_task.task_parameter_length = task_parameter_length;
3393 if((err = (int)emcore_default_sync_task_handler(&sync_task)) != EMAIL_ERROR_NONE) {
3394 EM_DEBUG_EXCEPTION("emcore_default_sync_task_handler failed [%d]", err);
3400 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3401 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3404 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &task_id, sizeof(int)))
3405 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3408 if (!emipc_execute_stub_api(a_hAPI))
3409 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3412 EM_DEBUG_FUNC_END("err [%d]", err);
3415 void* thread_func_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param)
3417 EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
3418 int err = EMAIL_ERROR_NONE;
3419 int err_for_signal = EMAIL_ERROR_NONE;
3421 int task_id = THREAD_SELF();
3422 task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_param = input_param;
3424 /* Send start signal */
3425 if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_STARTED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE)
3426 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3428 for(i = 0; i < task_param->mail_id_count; i++) {
3429 if((err = emcore_move_mail_to_another_account(task_param->multi_user_name, task_param->mail_id_array[i], task_param->source_mailbox_id, task_param->target_mailbox_id, task_id)) != EMAIL_ERROR_NONE) {
3430 EM_DEBUG_EXCEPTION("emcore_move_mail_to_another_account failed [%d]", err);
3434 /* Send progress signal */
3435 if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_IN_PROGRESS, i, task_param->mail_id_count)) != EMAIL_ERROR_NONE)
3436 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3440 /* Send finish signal */
3441 if(err == EMAIL_ERROR_NONE) {
3442 if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_FINISHED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE)
3443 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3446 if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_FAILED, err, 0)) != EMAIL_ERROR_NONE)
3447 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3450 /* Free task parameter */
3451 EM_SAFE_FREE(task_param->multi_user_name);
3452 EM_SAFE_FREE(task_param->mail_id_array);
3453 EM_SAFE_FREE(task_param);
3455 emcore_close_recv_stream_list();
3456 EM_DEBUG_FUNC_END("err [%d]", err);
3460 void stb_move_mails_to_mailbox_of_another_account(HIPC_API a_hAPI)
3462 EM_DEBUG_FUNC_BEGIN();
3463 int param_index = 0;
3464 int err = EMAIL_ERROR_NONE;
3465 int task_parameter_length = 0;
3468 char *task_parameter = NULL;
3469 task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *decoded_parameter = NULL;
3471 int nAPPID = emipc_get_app_id(a_hAPI);
3472 char *multi_user_name = NULL;
3474 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3475 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3476 multi_user_name = NULL;
3479 /* task_parameter_length */;
3480 task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
3482 if(task_parameter_length <= 0) {
3483 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : task_parameter_length [%d]", task_parameter_length);
3484 err = EMAIL_ERROR_INVALID_PARAM;
3488 /* task_parameter */
3489 task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
3491 if((err = email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(task_parameter, task_parameter_length, (void**)&decoded_parameter)) != EMAIL_ERROR_NONE) {
3492 EM_DEBUG_EXCEPTION("email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT failed[%d]", err);
3496 decoded_parameter->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
3498 THREAD_CREATE(task_id, thread_func_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, (void*)decoded_parameter, thread_error);
3500 if(thread_error != 0) {
3501 EM_DEBUG_EXCEPTION("THREAD_CREATE failed [%d]", thread_error);
3502 err = EMAIL_ERROR_SYSTEM_FAILURE;
3506 THREAD_DETACH(task_id);
3509 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3510 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3512 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &task_id, sizeof(int)))
3513 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3515 if (!emipc_execute_stub_api(a_hAPI))
3516 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3518 EM_SAFE_FREE(multi_user_name);
3520 EM_DEBUG_FUNC_END("err [%d]", err);
3523 void* thread_func_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param)
3525 EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
3526 int err = EMAIL_ERROR_NONE;
3527 int err_for_signal = EMAIL_ERROR_NONE;
3529 int task_id = THREAD_SELF();
3530 email_account_t* ref_account = NULL;
3531 task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_param = input_param;
3533 ref_account = emcore_get_account_reference(task_param->multi_user_name, task_param->account_id, false);
3535 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", task_param->account_id);
3536 err = EMAIL_ERROR_INVALID_ACCOUNT;
3540 /* on_server is allowed to be only 0 when server_type is EMAIL_SERVER_TYPE_ACTIVE_SYNC */
3541 if ( ref_account->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
3545 /* Send start signal */
3546 if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, task_id, EMAIL_TASK_STATUS_STARTED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE)
3547 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3549 if((err = emcore_delete_mailbox_ex(task_param->multi_user_name, task_param->account_id, task_param->mailbox_id_array, task_param->mailbox_id_count, task_param->on_server, recursive)) != EMAIL_ERROR_NONE) {
3550 EM_DEBUG_EXCEPTION("emcore_delete_mailbox_ex failed[%d]", err);
3555 /* Send finish signal */
3556 if(err == EMAIL_ERROR_NONE) {
3557 if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, task_id, EMAIL_TASK_STATUS_FINISHED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE)
3558 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3561 if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, task_id, EMAIL_TASK_STATUS_FAILED, err, 0)) != EMAIL_ERROR_NONE)
3562 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3565 if (ref_account) { /*prevent 49435*/
3566 emcore_free_account(ref_account);
3567 EM_SAFE_FREE(ref_account);
3570 /* Free task parameter */
3571 EM_SAFE_FREE(task_param->mailbox_id_array);
3572 EM_SAFE_FREE(task_param->multi_user_name);
3573 EM_SAFE_FREE(task_param);
3575 EM_DEBUG_FUNC_END("err [%d]", err);
3579 void stb_delete_mailbox_ex(HIPC_API a_hAPI)
3581 EM_DEBUG_FUNC_BEGIN();
3582 int param_index = 0;
3583 int err = EMAIL_ERROR_NONE;
3584 int task_parameter_length = 0;
3585 int thread_error = 0;
3587 char *task_parameter = NULL;
3588 task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *decoded_parameter = NULL;
3589 int nAPPID = emipc_get_app_id(a_hAPI);
3590 char *multi_user_name = NULL;
3592 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3593 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3594 multi_user_name = NULL;
3597 /* task_parameter_length */;
3598 task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
3600 if(task_parameter_length <= 0) {
3601 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : task_parameter_length [%d]", task_parameter_length);
3602 err = EMAIL_ERROR_INVALID_PARAM;
3606 /* task_parameter */
3607 task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
3609 if((err = email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(task_parameter, task_parameter_length, (void**)&decoded_parameter)) != EMAIL_ERROR_NONE) {
3610 EM_DEBUG_EXCEPTION("email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT failed[%d]", err);
3614 decoded_parameter->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
3616 THREAD_CREATE(task_id, thread_func_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, (void*)decoded_parameter, thread_error);
3618 if(thread_error != 0) {
3619 EM_DEBUG_EXCEPTION("THREAD_CREATE failed [%d]", thread_error);
3620 err = EMAIL_ERROR_SYSTEM_FAILURE;
3624 THREAD_DETACH(task_id);
3627 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3628 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3630 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &task_id, sizeof(int)))
3631 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3633 if (!emipc_execute_stub_api(a_hAPI))
3634 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3636 EM_SAFE_FREE(multi_user_name);
3637 EM_DEBUG_FUNC_END("err [%d]", err);
3640 void* thread_func_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_param)
3642 EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
3643 int err = EMAIL_ERROR_NONE;
3644 int err_for_signal = EMAIL_ERROR_NONE;
3645 int task_id = THREAD_SELF();
3646 task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_param = input_param;
3648 /* Send start signal */
3649 if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, task_id, EMAIL_TASK_STATUS_STARTED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE)
3650 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3652 if((err = emcore_send_mail_with_downloading_attachment_of_original_mail(task_param->multi_user_name, task_param->mail_id)) != EMAIL_ERROR_NONE) {
3653 EM_DEBUG_EXCEPTION("emcore_send_mail_with_downloading_attachment_of_original_mail failed [%d]", err);
3658 /* Send finish signal */
3659 if(err == EMAIL_ERROR_NONE) {
3660 if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, task_id, EMAIL_TASK_STATUS_FINISHED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE)
3661 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3664 if((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, task_id, EMAIL_TASK_STATUS_FAILED, err, 0)) != EMAIL_ERROR_NONE)
3665 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3668 /* Free task parameter */
3669 EM_SAFE_FREE(task_param->multi_user_name);
3670 EM_SAFE_FREE(task_param);
3671 emcore_close_smtp_stream_list();
3672 EM_DEBUG_FUNC_END("err [%d]", err);
3676 void stb_send_mail_with_downloading_attachment_of_original_mail(HIPC_API a_hAPI)
3678 EM_DEBUG_FUNC_BEGIN();
3679 int param_index = 0;
3680 int err = EMAIL_ERROR_NONE;
3681 int task_parameter_length = 0;
3682 int thread_error = 0;
3684 char *task_parameter = NULL;
3685 task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *decoded_parameter = NULL;
3686 int nAPPID = emipc_get_app_id(a_hAPI);
3687 char *multi_user_name = NULL;
3689 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3690 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3691 multi_user_name = NULL;
3694 /* task_parameter_length */;
3695 task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
3697 if(task_parameter_length <= 0) {
3698 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : task_parameter_length [%d]", task_parameter_length);
3699 err = EMAIL_ERROR_INVALID_PARAM;
3703 /* task_parameter */
3704 task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
3706 if((err = email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(task_parameter, task_parameter_length, (void**)&decoded_parameter)) != EMAIL_ERROR_NONE) {
3707 EM_DEBUG_EXCEPTION("email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT failed[%d]", err);
3711 decoded_parameter->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
3713 THREAD_CREATE(task_id, thread_func_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, (void*)decoded_parameter, thread_error);
3715 if(thread_error != 0) {
3716 EM_DEBUG_EXCEPTION("THREAD_CREATE failed [%d]", thread_error);
3717 err = EMAIL_ERROR_SYSTEM_FAILURE;
3721 THREAD_DETACH(task_id);
3724 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3725 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3727 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &task_id, sizeof(int)))
3728 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3730 if (!emipc_execute_stub_api(a_hAPI))
3731 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3733 EM_SAFE_FREE(multi_user_name);
3734 EM_DEBUG_FUNC_END("err [%d]", err);
3737 void stb_save_default_account_id(HIPC_API a_hAPI)
3739 EM_DEBUG_FUNC_BEGIN();
3740 int err = EMAIL_ERROR_NONE;
3743 int nAPPID = emipc_get_app_id(a_hAPI);
3744 char *multi_user_name = NULL;
3746 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3747 EM_DEBUG_EXCEPTION("emcore_get_user_name failed : [%d]", err);
3748 multi_user_name = NULL;
3752 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
3753 EM_DEBUG_LOG("account_id [%d]", account_id);
3755 err = emcore_save_default_account_id(multi_user_name, account_id);
3756 if (err != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_save_default_account_id failed [%d]", err);
3758 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3759 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3761 if (!emipc_execute_stub_api(a_hAPI))
3762 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3764 EM_SAFE_FREE(multi_user_name);
3765 EM_DEBUG_FUNC_END();
3768 void stb_load_default_account_id(HIPC_API a_hAPI)
3770 EM_DEBUG_FUNC_BEGIN();
3771 int err = EMAIL_ERROR_NONE;
3774 int nAPPID = emipc_get_app_id(a_hAPI);
3775 char *multi_user_name = NULL;
3777 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3778 EM_DEBUG_EXCEPTION("emcore_get_user_name failed : [%d]", err);
3779 multi_user_name = NULL;
3782 err = emcore_load_default_account_id(multi_user_name, &account_id);
3783 if (err != EMAIL_ERROR_NONE) {
3784 EM_DEBUG_EXCEPTION("emcore_save_default_account_id failed [%d]", err);
3787 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3788 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3790 if (err == EMAIL_ERROR_NONE) {
3791 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &account_id, sizeof(int)))
3792 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3795 if (!emipc_execute_stub_api(a_hAPI))
3796 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3798 EM_SAFE_FREE(multi_user_name);
3799 EM_DEBUG_FUNC_END();
3802 void stb_get_user_name(HIPC_API a_hAPI)
3804 EM_DEBUG_FUNC_BEGIN();
3806 int err = EMAIL_ERROR_NONE;
3809 char *user_name = NULL;
3811 pid = emipc_get_app_id(a_hAPI);
3812 EM_DEBUG_LOG("Peer PID : [%d]", pid);
3815 if ((err = emcore_get_user_name(pid, &user_name)) != EMAIL_ERROR_NONE)
3816 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3818 EM_DEBUG_LOG("Domain name : [%s]", user_name);
3820 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3821 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3824 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, user_name, EM_SAFE_STRLEN(user_name) + 1))
3825 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3829 if (!emipc_execute_stub_api(a_hAPI))
3830 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3832 EM_SAFE_FREE(user_name);
3834 EM_DEBUG_FUNC_END();
3837 void stb_API_mapper(HIPC_API a_hAPI)
3839 EM_DEBUG_FUNC_BEGIN();
3840 int err = EMAIL_ERROR_NONE;
3841 int nAPIID = emipc_get_api_id(a_hAPI);
3842 int client_fd = emipc_get_response_id(a_hAPI);
3844 err = emcore_check_privilege(client_fd);
3845 if (err != EMAIL_ERROR_NONE) {
3846 EM_DEBUG_EXCEPTION("emcore_check_privilege failed : [%d]", err);
3848 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3849 EM_DEBUG_EXCEPTION("emipc_add_paramter failed");
3851 if (!emipc_execute_stub_api(a_hAPI))
3852 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3858 case _EMAIL_API_ADD_ACCOUNT:
3859 stb_create_account(a_hAPI);
3862 case _EMAIL_API_ADD_MAILBOX:
3863 stb_create_mailbox(a_hAPI);
3866 case _EMAIL_API_DELETE_MAILBOX:
3867 stb_delete_mailbox(a_hAPI);
3870 case _EMAIL_API_SET_MAILBOX_TYPE:
3871 stb_set_mailbox_type(a_hAPI);
3874 case _EMAIL_API_SET_LOCAL_MAILBOX:
3875 stb_set_local_mailbox(a_hAPI);
3878 case _EMAIL_API_STAMP_SYNC_TIME_OF_MAILBOX:
3879 stb_stamp_sync_time_of_mailbox(a_hAPI);
3882 case _EMAIL_API_SET_MAIL_SLOT_SIZE:
3883 stb_set_mail_slot_size_of_mailbox(a_hAPI);
3886 case _EMAIL_API_RENAME_MAILBOX:
3887 stb_rename_mailbox(a_hAPI);
3890 case _EMAIL_API_RENAME_MAILBOX_EX:
3891 stb_rename_mailbox_ex(a_hAPI);
3894 case _EMAIL_API_SEND_MAIL:
3895 stb_send_mail(a_hAPI);
3898 case _EMAIL_API_QUERY_SMTP_MAIL_SIZE_LIMIT:
3899 stb_query_smtp_mail_size_limit(a_hAPI);
3902 case _EMAIL_API_GET_MAILBOX_LIST:
3903 stb_get_mailbox_list(a_hAPI);
3906 case _EMAIL_API_SYNC_HEADER:
3907 stb_sync_header(a_hAPI);
3910 case _EMAIL_API_DOWNLOAD_BODY:
3911 stb_download_body(a_hAPI);
3914 case _EMAIL_API_CLEAR_DATA:
3915 stb_clear_mail_data (a_hAPI);
3918 case _EMAIL_API_DELETE_ALL_MAIL:
3919 stb_delete_all_mails(a_hAPI);
3922 case _EMAIL_API_DELETE_MAIL:
3923 stb_delete_mail(a_hAPI);
3926 case _EMAIL_API_ADD_RULE:
3927 stb_add_rule(a_hAPI);
3930 case _EMAIL_API_GET_RULE:
3931 stb_get_rule(a_hAPI);
3934 case _EMAIL_API_GET_RULE_LIST:
3935 stb_get_rule_list(a_hAPI);
3938 case _EMAIL_API_FIND_RULE:
3939 stb_find_rule(a_hAPI);
3942 case _EMAIL_API_UPDATE_RULE:
3943 stb_update_rule(a_hAPI);
3946 case _EMAIL_API_DELETE_RULE:
3947 stb_delete_rule(a_hAPI);
3950 case _EMAIL_API_APPLY_RULE:
3951 stb_apply_rule(a_hAPI);
3954 case _EMAIL_API_MOVE_MAIL:
3955 stb_move_mail(a_hAPI);
3958 case _EMAIL_API_MOVE_ALL_MAIL:
3959 stb_move_all_mails(a_hAPI);
3962 case _EMAIL_API_SET_FLAGS_FIELD:
3963 stb_set_flags_field(a_hAPI);
3966 case _EMAIL_API_ADD_MAIL:
3967 stb_add_mail(a_hAPI);
3970 case _EMAIL_API_UPDATE_MAIL:
3971 stb_update_mail(a_hAPI);
3974 case _EMAIL_API_MOVE_THREAD_TO_MAILBOX:
3975 stb_move_thread_to_mailbox(a_hAPI);
3978 case _EMAIL_API_DELETE_THREAD:
3979 stb_delete_thread(a_hAPI);
3982 case _EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD:
3983 stb_modify_seen_flag_of_thread(a_hAPI);
3986 case _EMAIL_API_EXPUNGE_MAILS_DELETED_FLAGGED:
3987 stb_expunge_mails_deleted_flagged(a_hAPI);
3990 case _EMAIL_API_DELETE_ACCOUNT:
3991 stb_delete_account(a_hAPI);
3994 case _EMAIL_API_UPDATE_ACCOUNT:
3995 stb_update_account(a_hAPI);
3998 case _EMAIL_API_ADD_ATTACHMENT:
3999 stb_add_attachment(a_hAPI);
4002 case _EMAIL_API_GET_IMAP_MAILBOX_LIST:
4003 stb_get_imap_mailbox_list(a_hAPI);
4006 case _EMAIL_API_GET_ATTACHMENT:
4007 stb_get_attachment(a_hAPI);
4010 case _EMAIL_API_DELETE_ATTACHMENT:
4011 stb_delete_attachment(a_hAPI);
4014 case _EMAIL_API_DOWNLOAD_ATTACHMENT:
4015 stb_download_attachment(a_hAPI);
4018 case _EMAIL_API_GET_ACCOUNT_LIST:
4019 stb_get_account_list(a_hAPI);
4022 case _EMAIL_API_SEND_SAVED:
4023 stb_mail_send_saved(a_hAPI);
4026 case _EMAIL_API_ADD_READ_RECEIPT:
4027 stb_add_read_receipt(a_hAPI);
4030 case _EMAIL_API_CANCEL_JOB:
4031 stb_cancel_job(a_hAPI);
4034 case _EMAIL_API_SEND_RETRY:
4035 stb_retry_sending_mail(a_hAPI);
4038 case _EMAIL_API_VALIDATE_ACCOUNT :
4039 stb_validate_account(a_hAPI);
4042 case _EMAIL_API_SEND_MAIL_CANCEL_JOB :
4043 stb_cancel_send_mail_job(a_hAPI);
4046 case _EMAIL_API_SEARCH_MAIL_ON_SERVER :
4047 stb_search_mail_on_server(a_hAPI);
4050 case _EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER :
4051 stb_clear_result_of_search_mail_on_server(a_hAPI);
4054 case _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION :
4055 stb_add_account_with_validation(a_hAPI);
4058 case _EMAIL_API_BACKUP_ACCOUNTS:
4059 stb_backup_account(a_hAPI);
4062 case _EMAIL_API_RESTORE_ACCOUNTS:
4063 stb_restore_account(a_hAPI);
4066 case _EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT:
4067 stb_get_password_length(a_hAPI);
4070 case _EMAIL_API_GET_TASK_INFORMATION:
4071 stb_get_task_information(a_hAPI);
4074 case _EMAIL_API_ADD_CERTIFICATE:
4075 stb_add_certificate(a_hAPI);
4078 case _EMAIL_API_DELETE_CERTIFICATE:
4079 stb_delete_certificate(a_hAPI);
4082 case _EMAIL_API_VERIFY_SIGNATURE:
4083 stb_verify_signature(a_hAPI);
4086 case _EMAIL_API_VERIFY_CERTIFICATE:
4087 stb_verify_certificate(a_hAPI);
4090 case _EMAIL_API_PING_SERVICE :
4091 stb_ping_service(a_hAPI);
4094 case _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL :
4095 stb_update_notification_bar_for_unread_mail(a_hAPI);
4098 case _EMAIL_API_CLEAR_NOTIFICATION_BAR :
4099 stb_clear_notification_bar(a_hAPI);
4102 case _EMAIL_API_SHOW_USER_MESSAGE :
4103 stb_show_user_message(a_hAPI);
4106 case _EMAIL_API_WRITE_MIME_FILE :
4107 stb_write_mime_file(a_hAPI);
4110 case _EMAIL_API_VALIDATE_ACCOUNT_EX :
4111 stb_validate_account_ex(a_hAPI);
4114 case EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT :
4115 stb_move_mails_to_mailbox_of_another_account(a_hAPI);
4118 case EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX :
4119 stb_delete_mailbox_ex(a_hAPI);
4122 case EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL :
4123 stb_send_mail_with_downloading_attachment_of_original_mail(a_hAPI);
4126 case _EMAIL_API_GET_USER_NAME :
4127 stb_get_user_name(a_hAPI);
4130 case _EMAIL_API_SAVE_DEFAULT_ACCOUNT_ID :
4131 stb_save_default_account_id(a_hAPI);
4134 case _EMAIL_API_LOAD_DEFAULT_ACCOUNT_ID :
4135 stb_load_default_account_id(a_hAPI);
4139 if(EMAIL_SYNC_TASK_BOUNDARY_START < nAPIID && nAPIID < EMAIL_ASYNC_TASK_BOUNDARY_END)
4140 stb_handle_task(nAPIID, a_hAPI);
4143 EM_DEBUG_FUNC_END();
4146 GMainLoop *g_mainloop = NULL;
4148 /* this func should be called in main_loop */
4149 INTERNAL_FUNC int kill_daemon_if_no_account()
4151 EM_DEBUG_FUNC_BEGIN();
4152 int err = EMAIL_ERROR_NONE;
4153 email_account_t *account_list = NULL;
4154 int account_count = 0;
4155 int total_account_count = 0;
4157 GList *zone_name_list = NULL;
4159 /* each container check the account */
4160 if ((err = emcore_get_zone_name_list(&zone_name_list)) != EMAIL_ERROR_NONE) {
4161 EM_DEBUG_EXCEPTION("emcore_get_zone_name_list failed : err[%d]", err);
4162 if (zone_name_list) g_list_free(zone_name_list);
4166 if (g_list_length(zone_name_list) == 1) {
4167 if ((err = emcore_get_account_reference_list(NULL, &account_list, &account_count)) != EMAIL_ERROR_NONE) {
4168 EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err);
4172 emcore_free_account_list(&account_list, account_count, NULL);
4174 total_account_count += account_count;
4176 node = g_list_first(zone_name_list);
4177 while (node != NULL) {
4179 node = g_list_next(node);
4183 if ((err = emcore_get_account_reference_list(node->data, &account_list, &account_count)) != EMAIL_ERROR_NONE) {
4184 EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err);
4188 emcore_free_account_list(&account_list, account_count, NULL);
4190 total_account_count += account_count;
4191 EM_SAFE_FREE(node->data);
4192 node = g_list_next(node);
4197 g_list_free(zone_name_list);
4199 EM_DEBUG_LOG("account_count [%d]", total_account_count);
4201 if (total_account_count == 0) {
4202 EM_DEBUG_LOG("email-service is going to shutdown");
4203 g_main_loop_quit (g_mainloop);
4208 EM_DEBUG_FUNC_END("err [%d]", err);
4212 static void callback_for_sigterm(int signum)
4214 EM_DEBUG_FUNC_BEGIN("signum [%d]", signum);
4217 g_main_loop_quit(g_mainloop);
4219 EM_DEBUG_FUNC_END();
4222 extern int launch_pid;
4224 gboolean callback_for_shutdown(gpointer user_data)
4226 EM_DEBUG_FUNC_BEGIN("user_data[%p]", user_data);
4228 if (launch_pid == 0) {
4229 kill_daemon_if_no_account();
4232 EM_DEBUG_FUNC_END();
4236 gboolean callback_for_del_account (GIOChannel *ch, GIOCondition cond, gpointer data)
4238 static int file_del = 0;
4239 static int db_del = 0;
4242 g_io_channel_read_chars (ch, (gchar*) &event, sizeof (event), &len, NULL);
4244 if (event==EMAIL_SIGNAL_DB_DELETED) {
4247 else if (event==EMAIL_SIGNAL_FILE_DELETED) {
4250 EM_DEBUG_LOG ("callback_for_del_account called file_del[%d] db_del[%d]", file_del, db_del);
4252 /* if called twice, process termination begins.
4253 two threads should complete the delete task */
4254 if (file_del && db_del) {
4255 kill_daemon_if_no_account();
4256 file_del = db_del = 0; /* if there is an account, reset status */
4261 /* gdbus variables */
4262 static GDBusNodeInfo *introspection_data = NULL;
4263 extern gchar introspection_xml[];
4266 handle_method_call (GDBusConnection *connection,
4267 const gchar *sender,
4268 const gchar *object_path,
4269 const gchar *interface_name,
4270 const gchar *method_name,
4271 GVariant *parameters,
4272 GDBusMethodInvocation *invocation,
4275 /* called by emipc_launch_email_service */
4276 if (g_strcmp0 (method_name, "Launch") == 0) {
4278 g_variant_get (parameters, "(i)", &caller_pid);
4280 launch_pid = caller_pid;
4281 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(i)", EMAIL_ERROR_NONE));
4282 EM_DEBUG_LOG ("email-service launched by pid [%d]", caller_pid);
4285 else if (g_strcmp0 (method_name, "SetContactsLog") == 0) {
4286 GVariant* ret = em_gdbus_set_contact_log(parameters);
4287 g_dbus_method_invocation_return_value (invocation, ret);
4289 else if (g_strcmp0 (method_name, "DeleteContactsLog") == 0) {
4290 GVariant* ret = em_gdbus_delete_contact_log(parameters);
4291 g_dbus_method_invocation_return_value (invocation, ret);
4294 else if (g_strcmp0 (method_name, "GetDisplayName") == 0) {
4295 GVariant* ret = em_gdbus_get_display_name(parameters);
4296 g_dbus_method_invocation_return_value (invocation, ret);
4298 else if (g_strcmp0 (method_name, "CheckBlockingMode") == 0) {
4299 GVariant* ret = em_gdbus_check_blocking_mode(parameters);
4300 g_dbus_method_invocation_return_value (invocation, ret);
4305 GDBusInterfaceVTable interface_vtable =
4313 on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
4315 EM_DEBUG_LOG ("on_bus_acquired begin");
4318 GError *error = NULL;
4320 reg_id = g_dbus_connection_register_object (connection,
4322 introspection_data->interfaces[0],
4324 NULL, /* user_data */
4325 NULL, /* user_data_free_func */
4326 &error); /* GError** */
4328 EM_DEBUG_EXCEPTION ("g_dbus_connection_register_object error[%s]",error->message);
4329 g_error_free (error);
4331 EM_DEBUG_LOG ("on_bus_acquired end [%d]", reg_id);
4334 static void on_name_acquired (GDBusConnection *connection,
4338 EM_DEBUG_LOG ("on_name_acquired [%s]", name);
4341 static void on_name_lost (GDBusConnection *connection,
4345 EM_DEBUG_EXCEPTION ("on_name_lost [%p] [%s]", connection, name);
4348 INTERNAL_FUNC int main(int argc, char *argv[])
4350 /* Do the email-service Initialization
4351 1. Create all DB tables and load the email engine */
4352 EM_DEBUG_LOG("Email service begin");
4354 GMainLoop *mainloop = NULL;
4357 GList *zone_name_list = NULL;
4359 #if !GLIB_CHECK_VERSION(2, 36, 0)
4363 /* Init container for daemon */
4364 emcore_create_container();
4366 EM_DEBUG_LOG("ipcEmailStub_Initialize Start");
4368 ret = emipc_initialize_stub(stb_API_mapper);
4371 EM_DEBUG_LOG("ipcEmailStub_Initialize Success");
4373 EM_DEBUG_EXCEPTION("ipcEmailStub_Initialize failed");
4375 signal(SIGPIPE, SIG_IGN); /* to ignore signal 13(SIGPIPE) */
4376 signal(SIGTERM, callback_for_sigterm); /* to handle signal 15(SIGTERM) - power off case*/
4378 emcore_gmime_init();
4380 /* each container initialize */
4381 if ((err = emcore_get_zone_name_list(&zone_name_list)) != EMAIL_ERROR_NONE) {
4382 EM_DEBUG_EXCEPTION("emcore_get_zone_name_list failed : err[%d]", err);
4383 if (zone_name_list) g_list_free(zone_name_list);
4387 if (g_list_length(zone_name_list) <= 1) {
4388 emdaemon_initialize(NULL, &err);
4389 emcore_connect_contacts_service(NULL);
4391 node = g_list_first(zone_name_list);
4392 while (node != NULL) {
4394 node = g_list_next(node);
4396 emdaemon_initialize(node->data, &err);
4397 emcore_connect_contacts_service(node->data);
4399 EM_SAFE_FREE(node->data);
4400 node = g_list_next(node);
4405 g_list_free(zone_name_list);
4407 g_timeout_add(5000, callback_for_shutdown, NULL);
4409 /* pipe between main and del account thread */
4410 int *pipefd = emcore_init_pipe_for_del_account ();
4411 /* main loop uses IO channel for listening an event */
4413 GIOChannel *ch = g_io_channel_unix_new (pipefd[0]);
4414 EM_DEBUG_LOG ("main pipe[%d][%d]", pipefd[0], pipefd[1]);
4415 /* non-blocking mode */
4416 g_io_channel_set_flags (ch, g_io_channel_get_flags (ch) | G_IO_FLAG_NONBLOCK, NULL);
4417 /* main loop watches the IO, and call the cb when data is ready */
4418 g_io_add_watch (ch, G_IO_IN, &callback_for_del_account, NULL);
4422 GError *error = NULL;
4423 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
4424 if (!introspection_data) {
4425 /* introspection_xml may be invalid */
4426 EM_DEBUG_EXCEPTION ("g_dbus_node_info_new_for_xml error [%s]", error->message);
4427 g_error_free (error);
4430 owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
4432 G_BUS_NAME_OWNER_FLAGS_NONE,
4439 EM_DEBUG_EXCEPTION ("g_bus_own_name error");
4441 EM_DEBUG_LOG ("owner_id [%d]", owner_id);
4443 mainloop = g_main_loop_new(NULL, 0);
4444 g_mainloop = mainloop;
4446 g_main_loop_run(mainloop);
4448 /* Clean up resources */
4449 g_bus_unown_name (owner_id);
4450 g_main_loop_unref(mainloop);
4455 emipc_finalize_stub();
4456 emdaemon_finalize(NULL);
4457 emcore_gmime_shutdown();
4459 EM_DEBUG_LOG ("Goodbye, world");
4460 EM_DEBUG_FUNC_END();
4461 exit(44); /* exit with exit code 44 to prevent restarting */