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);
1193 EM_SAFE_FREE(local_rule_stream);
1194 EM_SAFE_FREE(multi_user_name);
1196 EM_DEBUG_FUNC_END();
1199 /* obsolete - there is no api calling this function */
1200 void stb_get_rule_list(HIPC_API a_hAPI)
1202 EM_DEBUG_FUNC_BEGIN();
1203 int err = EMAIL_ERROR_NONE;
1205 char* local_stream = NULL;
1208 email_rule_t* filtering_list = NULL;
1209 int nAPPID = emipc_get_app_id(a_hAPI);
1210 char *multi_user_name = NULL;
1212 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1213 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1214 multi_user_name = NULL;
1217 emdaemon_get_filter_list(multi_user_name, &filtering_list, &count, &err);
1219 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1220 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1222 /* insert rules if there exist rules*/
1224 EM_DEBUG_LOG("num of rules [%d]", count);
1225 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &count, sizeof(int)))
1226 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1228 for(i=0; i<count; i++) {
1229 EM_DEBUG_LOG("Value - %s", filtering_list[i].value);
1231 local_stream = em_convert_rule_to_byte_stream(filtering_list+i, &size);
1233 if(!local_stream) break;
1235 if(!emipc_add_dynamic_parameter(a_hAPI, ePARAMETER_OUT, local_stream, size))
1236 EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed ");
1242 if (!emipc_execute_stub_api(a_hAPI)) {
1243 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
1246 EM_SAFE_FREE(multi_user_name);
1247 EM_DEBUG_FUNC_END();
1250 /* obsolete - there is no api calling this function */
1251 void stb_find_rule(HIPC_API a_hAPI)
1253 EM_DEBUG_FUNC_BEGIN();
1254 int buffer_size = 0;
1255 int err = EMAIL_ERROR_NONE;
1256 char* local_rule_stream = NULL;
1257 email_rule_t rule = { 0 };
1258 int nAPPID = emipc_get_app_id(a_hAPI);
1259 char *multi_user_name = NULL;
1261 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1262 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1263 multi_user_name = NULL;
1266 buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
1267 if(buffer_size > 0) {
1268 local_rule_stream = (char*)em_malloc(buffer_size);
1269 if (local_rule_stream == NULL) {
1270 EM_DEBUG_EXCEPTION("Out of memory");
1271 err = EMAIL_ERROR_OUT_OF_MEMORY;
1275 if (local_rule_stream) {
1276 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, buffer_size, local_rule_stream);
1277 em_convert_byte_stream_to_rule(local_rule_stream, buffer_size, &rule);
1278 EM_SAFE_FREE(local_rule_stream);
1279 EM_DEBUG_LOG("account ID [%d]", rule.account_id);
1281 if (!emdaemon_find_filter(multi_user_name, &rule, &err)) {
1282 EM_DEBUG_EXCEPTION("emdaemon_find_filter failed : [%d]", err);
1289 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1290 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1292 if (!emipc_execute_stub_api(a_hAPI))
1293 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
1295 EM_SAFE_FREE(multi_user_name);
1296 EM_DEBUG_FUNC_END();
1299 void stb_update_rule(HIPC_API a_hAPI)
1301 EM_DEBUG_FUNC_BEGIN();
1304 int buffer_size = 0;
1305 int err = EMAIL_ERROR_NONE;
1306 int *ret_nth_value = NULL;
1307 char* rule_stream = NULL;
1308 email_rule_t rule = {0};
1309 int nAPPID = emipc_get_app_id(a_hAPI);
1310 char *multi_user_name = NULL;
1312 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1313 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1314 multi_user_name = NULL;
1318 if ((ret_nth_value = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0))) {
1319 filter_id = *ret_nth_value;
1321 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1326 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 1);
1327 EM_DEBUG_LOG("size [%d]", buffer_size);
1328 if(buffer_size <= 0) {
1329 err = EMAIL_ERROR_INVALID_PARAM;
1332 rule_stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 1);
1334 err = EMAIL_ERROR_INVALID_PARAM;
1337 em_convert_byte_stream_to_rule(rule_stream, buffer_size, &rule);
1339 /* call update handler */
1340 emdaemon_update_filter(multi_user_name, filter_id, &rule, &err);
1343 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1344 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1346 if (!emipc_execute_stub_api(a_hAPI))
1347 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1349 emcore_free_rule(&rule);
1351 EM_SAFE_FREE(multi_user_name);
1352 EM_DEBUG_FUNC_END();
1355 void stb_move_all_mails(HIPC_API a_hAPI)
1357 EM_DEBUG_FUNC_BEGIN();
1358 int err = EMAIL_ERROR_NONE;
1359 int src_mailbox_id = 0, dst_mailbox_id = 0;
1360 int nAPPID = emipc_get_app_id(a_hAPI);
1361 char *multi_user_name = NULL;
1363 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1364 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1365 multi_user_name = NULL;
1368 /* src_mailbox_id */
1369 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &src_mailbox_id);
1370 EM_DEBUG_LOG("src_mailbox_id [%d]", src_mailbox_id);
1372 if (src_mailbox_id > 0)
1373 EM_DEBUG_LOG("src_mailbox_id [%d]", src_mailbox_id);
1375 EM_DEBUG_LOG("src_mailbox_id == 0");
1377 /* dst_mailbox_id */
1378 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &dst_mailbox_id);
1379 EM_DEBUG_LOG("dst_mailbox_id [%d]", dst_mailbox_id);
1381 if (dst_mailbox_id > 0)
1382 EM_DEBUG_LOG("dst_mailbox_id [%d]", dst_mailbox_id);
1384 EM_DEBUG_LOG("dst_mailbox_id == 0");
1386 if(emdaemon_move_mail_all_mails(multi_user_name, src_mailbox_id, dst_mailbox_id, &err))
1387 EM_DEBUG_LOG("emdaemon_move_mail_all_mails:Success");
1389 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
1390 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1393 if (!emipc_execute_stub_api(a_hAPI)) {
1394 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1397 EM_SAFE_FREE(multi_user_name);
1398 EM_DEBUG_FUNC_END();
1401 void stb_set_flags_field(HIPC_API a_hAPI)
1403 EM_DEBUG_FUNC_BEGIN();
1404 int err = EMAIL_ERROR_NONE;
1405 email_flags_field_type field_type = 0;
1411 int *mail_ids = NULL;
1412 int nAPPID = emipc_get_app_id(a_hAPI);
1413 char *multi_user_name = NULL;
1415 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1416 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1417 multi_user_name = NULL;
1421 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
1422 EM_DEBUG_LOG("account_id [%d]", account_id);
1424 /* Number of mail_ids */
1425 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &num);
1426 EM_DEBUG_LOG("number of mails [%d]", num);
1429 mail_ids = em_malloc(sizeof(int) * num);
1432 EM_DEBUG_EXCEPTION("em_malloc failed ");
1433 err = EMAIL_ERROR_OUT_OF_MEMORY;
1437 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, num * sizeof(int), mail_ids);
1439 for(counter=0; counter < num; counter++)
1440 EM_DEBUG_LOG("mailids [%d]", mail_ids[counter]);
1443 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &field_type);
1444 EM_DEBUG_LOG("field_type [%d]", field_type);
1447 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 4, sizeof(int), &value);
1448 EM_DEBUG_LOG("value [%d]", value);
1451 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 5, sizeof(int), &onserver);
1452 EM_DEBUG_LOG("onserver [%d]", onserver);
1454 if(emdaemon_set_flags_field(multi_user_name, account_id, mail_ids, num, field_type, value, onserver, &err))
1455 EM_DEBUG_LOG("emdaemon_set_flags_field - success");
1459 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1460 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
1462 if (!emipc_execute_stub_api(a_hAPI))
1463 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
1466 EM_SAFE_FREE(mail_ids);
1468 EM_SAFE_FREE(multi_user_name);
1469 EM_DEBUG_FUNC_END();
1472 void stb_add_mail(HIPC_API a_hAPI)
1474 EM_DEBUG_FUNC_BEGIN();
1475 int buffer_size = 0;
1476 int local_result = 0;
1477 int result_attachment_data_count = 0;
1478 int param_index = 0;
1479 int sync_server = 0;
1480 int err = EMAIL_ERROR_NONE;
1482 email_mail_data_t result_mail_data = {0};
1483 email_attachment_data_t *result_attachment_data = NULL;
1484 email_meeting_request_t result_meeting_request = {0};
1485 emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI;
1486 email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE;
1487 int nAPPID = emipc_get_app_id(a_hAPI);
1488 char *multi_user_name = NULL;
1489 char *prefix_path = NULL;
1490 char real_file_path[255] = {0};
1492 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1493 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1494 multi_user_name = NULL;
1497 /* email_mail_data_t */;
1498 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1499 EM_DEBUG_LOG("email_mail_data_t buffer_size[%d]", buffer_size);
1502 if(buffer_size > 0) {
1503 char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
1504 em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data);
1507 if (em_get_account_server_type_by_account_id(multi_user_name, result_mail_data.account_id, &account_server_type, true, &err) == false) {
1508 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
1512 /* Get the absolute path */
1513 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
1514 err = emcore_get_container_path(multi_user_name, &prefix_path);
1515 if (err != EMAIL_ERROR_NONE) {
1516 EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
1520 prefix_path = strdup("");
1523 /* check smack rule for accessing file path */
1524 if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_mail_data.file_path_html) {
1525 memset(real_file_path, 0x00, sizeof(real_file_path));
1526 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_html);
1528 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1529 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1530 err = EMAIL_ERROR_NO_SMACK_RULE;
1535 if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_mail_data.file_path_plain) {
1536 memset(real_file_path, 0x00, sizeof(real_file_path));
1537 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_plain);
1539 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1540 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1541 err = EMAIL_ERROR_NO_SMACK_RULE;
1546 if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_mail_data.file_path_mime_entity) {
1547 memset(real_file_path, 0x00, sizeof(real_file_path));
1548 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_mime_entity);
1550 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1551 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1552 err = EMAIL_ERROR_NO_SMACK_RULE;
1556 /* check smack rule - END */
1559 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1560 EM_DEBUG_LOG("email_attachment_data_t buffer_size[%d]", buffer_size);
1562 if(buffer_size > 0) {
1563 char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index);
1564 em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count);
1566 EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count);
1567 if (!result_attachment_data_count) {
1568 EM_DEBUG_LOG("Not include attachment data");
1570 if(!result_attachment_data) {
1571 EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed");
1572 err = EMAIL_ERROR_ON_PARSING;
1579 /* check smack rule for accessing file path */
1580 for (i = 0; i < result_attachment_data_count ; i++) {
1581 if ((account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && result_attachment_data[i].attachment_path && result_attachment_data[i].save_status) {
1582 memset(real_file_path, 0x00, sizeof(real_file_path));
1583 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_attachment_data[i].attachment_path);
1585 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1586 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1587 err = EMAIL_ERROR_NO_SMACK_RULE;
1593 /* meeting request */
1594 EM_DEBUG_LOG("email_meeting_request_t");
1595 if ( result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST
1596 || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE
1597 || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
1598 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1600 if(buffer_size > 0) {
1601 char* stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
1602 em_convert_byte_stream_to_meeting_req(stream, buffer_size, &result_meeting_request);
1606 EM_DEBUG_LOG("sync_server");
1607 emipc_get_parameter(a_hAPI, ePARAMETER_IN, param_index++, sizeof(int), &sync_server);
1609 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) {
1610 EM_DEBUG_EXCEPTION("emdaemon_add_mail failed [%d]", err);
1615 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1616 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1617 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.mail_id, sizeof(int)))
1618 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1619 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.thread_id, sizeof(int)))
1620 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1621 if (!emipc_execute_stub_api(a_hAPI))
1622 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1625 if ( local_result == 0 ) {
1626 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1627 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1628 if (!emipc_execute_stub_api(a_hAPI))
1629 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1632 EM_SAFE_FREE(prefix_path);
1634 emcore_free_mail_data(&result_mail_data);
1636 if(result_attachment_data)
1637 emcore_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL);
1639 emstorage_free_meeting_request(&result_meeting_request);
1641 EM_SAFE_FREE(multi_user_name);
1642 EM_DEBUG_FUNC_END();
1646 void stb_update_mail(HIPC_API a_hAPI)
1648 EM_DEBUG_FUNC_BEGIN();
1649 int buffer_size = 0;
1650 int local_result = 0;
1651 int result_attachment_data_count = 0;
1652 int param_index = 0;
1653 int sync_server = 0;
1654 int *temp_buffer = NULL;
1655 int err = EMAIL_ERROR_NONE;
1657 email_mail_data_t result_mail_data = {0};
1658 email_attachment_data_t *result_attachment_data = NULL;
1659 email_meeting_request_t result_meeting_request = {0};
1660 emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI;
1661 int nAPPID = emipc_get_app_id(a_hAPI);
1662 char *multi_user_name = NULL;
1663 char *prefix_path = NULL;
1664 char real_file_path[255] = {0};
1666 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1667 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1668 multi_user_name = NULL;
1671 EM_DEBUG_LOG("email_mail_data_t");
1672 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1674 if(buffer_size > 0) {
1675 char* stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
1676 em_convert_byte_stream_to_mail_data(stream, buffer_size, &result_mail_data);
1679 /* Get the absolute path */
1680 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
1681 err = emcore_get_container_path(multi_user_name, &prefix_path);
1682 if (err != EMAIL_ERROR_NONE) {
1683 EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
1687 prefix_path = strdup("");
1690 /* check smack rule for accessing file path */
1691 if (result_mail_data.file_path_html) {
1692 memset(real_file_path, 0x00, sizeof(real_file_path));
1693 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_html);
1695 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1696 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1697 err = EMAIL_ERROR_NO_SMACK_RULE;
1702 if (result_mail_data.file_path_plain) {
1703 memset(real_file_path, 0x00, sizeof(real_file_path));
1704 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_plain);
1706 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1707 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1708 err = EMAIL_ERROR_NO_SMACK_RULE;
1713 if (result_mail_data.file_path_mime_entity) {
1714 memset(real_file_path, 0x00, sizeof(real_file_path));
1715 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_mail_data.file_path_mime_entity);
1717 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1718 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1719 err = EMAIL_ERROR_NO_SMACK_RULE;
1723 /* check smack rule - END */
1724 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1725 if(buffer_size > 0) {
1726 char *stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index);
1727 em_convert_byte_stream_to_attachment_data(stream, buffer_size, &result_attachment_data, &result_attachment_data_count);
1729 EM_DEBUG_LOG("result_attachment_data_count[%d]", result_attachment_data_count);
1730 if (!result_attachment_data_count) {
1731 EM_DEBUG_LOG("Not include attachment data");
1733 if(!result_attachment_data) {
1734 EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed");
1735 err = EMAIL_ERROR_ON_PARSING;
1742 /* check smack rule for accessing file path */
1743 for (i = 0; i < result_attachment_data_count ; i++) {
1744 if (result_attachment_data[i].attachment_path) {
1745 memset(real_file_path, 0x00, sizeof(real_file_path));
1746 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, result_attachment_data[i].attachment_path);
1748 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
1749 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
1750 err = EMAIL_ERROR_NO_SMACK_RULE;
1756 EM_DEBUG_LOG("email_meeting_request_t");
1757 if ( result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST
1758 || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE
1759 || result_mail_data.meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
1760 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
1762 if(buffer_size > 0) {
1763 char* stream = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
1764 em_convert_byte_stream_to_meeting_req(stream, buffer_size, &result_meeting_request);
1768 EM_DEBUG_LOG("sync_server");
1770 temp_buffer = emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
1773 EM_DEBUG_EXCEPTION("emipc_get_nth_parameter_data[%d] failed", param_index - 1);
1774 err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
1778 sync_server = *temp_buffer;
1780 if( (err = emdaemon_update_mail(multi_user_name, &result_mail_data, result_attachment_data,
1781 result_attachment_data_count, &result_meeting_request, sync_server)) != EMAIL_ERROR_NONE) {
1782 EM_DEBUG_EXCEPTION("emdaemon_update_mail failed [%d]", err);
1787 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1788 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1789 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.mail_id, sizeof(int)))
1790 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1791 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result_mail_data.thread_id, sizeof(int)))
1792 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1793 if (!emipc_execute_stub_api(a_hAPI))
1794 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1797 if ( local_result == 0 ) {
1798 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
1799 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1800 if (!emipc_execute_stub_api(a_hAPI))
1801 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
1804 emcore_free_mail_data(&result_mail_data);
1806 EM_SAFE_FREE(prefix_path);
1808 if(result_attachment_data)
1809 emcore_free_attachment_data(&result_attachment_data, result_attachment_data_count, NULL);
1811 emstorage_free_meeting_request(&result_meeting_request);
1813 EM_SAFE_FREE(multi_user_name);
1814 EM_DEBUG_FUNC_END();
1818 void stb_move_thread_to_mailbox(HIPC_API a_hAPI)
1820 EM_DEBUG_FUNC_BEGIN();
1821 int mailbox_id = 0, thread_id = 0, move_always_flag = 0;
1822 int err = EMAIL_ERROR_NONE;
1823 char *target_mailbox_name = NULL;
1824 int nAPPID = emipc_get_app_id(a_hAPI);
1825 char *multi_user_name = NULL;
1827 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1828 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1829 multi_user_name = NULL;
1832 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &thread_id);
1833 EM_DEBUG_LOG("thread_id [%d]", thread_id);
1835 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mailbox_id);
1836 EM_DEBUG_LOG("mailbox_id [%d]", mailbox_id);
1838 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &move_always_flag);
1839 EM_DEBUG_LOG("move_always_flag [%d]", move_always_flag);
1841 if(emdaemon_move_mail_thread_to_mailbox(multi_user_name, thread_id, mailbox_id, move_always_flag, &err))
1842 EM_DEBUG_LOG("emdaemon_move_mail_thread_to_mailbox success");
1844 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
1845 EM_DEBUG_EXCEPTION("emipc_add_parameter fail");
1846 EM_SAFE_FREE(target_mailbox_name);
1847 EM_SAFE_FREE(multi_user_name);
1851 if (!emipc_execute_stub_api(a_hAPI)) {
1852 EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail");
1853 EM_SAFE_FREE(target_mailbox_name);
1854 EM_SAFE_FREE(multi_user_name);
1858 EM_SAFE_FREE(target_mailbox_name);
1859 EM_SAFE_FREE(multi_user_name);
1860 EM_DEBUG_FUNC_END();
1863 void stb_delete_thread(HIPC_API a_hAPI)
1865 EM_DEBUG_FUNC_BEGIN();
1867 int thread_id = 0, delete_always_flag = 0;
1869 int err = EMAIL_ERROR_NONE;
1870 int nAPPID = emipc_get_app_id(a_hAPI);
1871 char *multi_user_name = NULL;
1873 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1874 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1875 multi_user_name = NULL;
1878 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &thread_id);
1879 EM_DEBUG_LOG("thread_id [%d]", thread_id);
1881 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &delete_always_flag);
1882 EM_DEBUG_LOG("delete_always_flag [%d]", delete_always_flag);
1884 if(emdaemon_delete_mail_thread(multi_user_name, thread_id, delete_always_flag, &handle, &err))
1885 EM_DEBUG_LOG("emdaemon_delete_mail_thread success");
1887 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
1888 EM_DEBUG_EXCEPTION("emipc_add_parameter fail");
1889 EM_SAFE_FREE(multi_user_name);
1893 if (!emipc_execute_stub_api(a_hAPI)) {
1894 EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail");
1895 EM_SAFE_FREE(multi_user_name);
1899 EM_SAFE_FREE(multi_user_name);
1900 EM_DEBUG_FUNC_END();
1903 void stb_modify_seen_flag_of_thread(HIPC_API a_hAPI)
1905 EM_DEBUG_FUNC_BEGIN();
1907 int thread_id = 0, seen_flag = 0, on_server = 0;
1909 int err = EMAIL_ERROR_NONE;
1910 int nAPPID = emipc_get_app_id(a_hAPI);
1911 char *multi_user_name = NULL;
1913 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1914 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1915 multi_user_name = NULL;
1918 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &thread_id);
1919 EM_DEBUG_LOG("thread_id [%d]", thread_id);
1921 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &seen_flag);
1922 EM_DEBUG_LOG("seen_flag [%d]", seen_flag);
1924 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &on_server);
1925 EM_DEBUG_LOG("on_server [%d]", on_server);
1927 if(emdaemon_modify_seen_flag_of_thread(multi_user_name, thread_id, seen_flag, on_server, &handle, &err))
1928 EM_DEBUG_LOG("emdaemon_modify_seen_flag_of_thread success");
1930 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
1931 EM_DEBUG_EXCEPTION("emipc_add_parameter fail");
1932 EM_SAFE_FREE(multi_user_name);
1936 if (!emipc_execute_stub_api(a_hAPI)) {
1937 EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail");
1938 EM_SAFE_FREE(multi_user_name);
1942 EM_SAFE_FREE(multi_user_name);
1943 EM_DEBUG_FUNC_END();
1946 void stb_expunge_mails_deleted_flagged(HIPC_API a_hAPI)
1948 EM_DEBUG_FUNC_BEGIN();
1950 int mailbox_id = 0, on_server = 0;
1952 int err = EMAIL_ERROR_NONE;
1953 int nAPPID = emipc_get_app_id(a_hAPI);
1954 char *multi_user_name = NULL;
1956 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1957 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1958 multi_user_name = NULL;
1961 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), (void*)&mailbox_id);
1962 EM_DEBUG_LOG("mailbox_id [%d]", mailbox_id);
1964 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), (void*)&on_server);
1965 EM_DEBUG_LOG("on_server [%d]", on_server);
1967 if( (err = emdaemon_expunge_mails_deleted_flagged(multi_user_name, mailbox_id, on_server, &handle)) != EMAIL_ERROR_NONE)
1968 EM_DEBUG_LOG("emdaemon_expunge_mails_deleted_flagged success");
1970 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int))) {
1971 EM_DEBUG_EXCEPTION("emipc_add_parameter fail");
1974 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int))) {
1975 EM_DEBUG_LOG("ipcAPI_AddParameter local_result failed ");
1978 if (!emipc_execute_stub_api(a_hAPI)) {
1979 EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail");
1982 EM_SAFE_FREE(multi_user_name);
1983 EM_DEBUG_FUNC_END();
1986 void stb_move_mail(HIPC_API a_hAPI)
1988 int err = EMAIL_ERROR_NONE;
1989 int num = 0, counter = 0, mailbox_id = 0;
1990 int nAPPID = emipc_get_app_id(a_hAPI);
1991 char *multi_user_name = NULL;
1993 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
1994 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
1995 multi_user_name = NULL;
1998 /* Number of mail_ids */
1999 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &num);
2000 EM_DEBUG_LOG("number of mails [%d]", num);
2004 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, num * sizeof(int), mail_ids);
2006 for(counter = 0; counter < num; counter++)
2007 EM_DEBUG_LOG("mailids [%d]", mail_ids[counter]);
2009 /* target_mailbox_id */
2010 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &mailbox_id);
2011 EM_DEBUG_LOG("target_mailbox_id [%d]", mailbox_id);
2014 EM_DEBUG_LOG("mailbox_id [%d]", mailbox_id);
2016 EM_DEBUG_LOG("mailbox_id == 0");
2018 if(emdaemon_move_mail(multi_user_name, mail_ids, num, mailbox_id, EMAIL_MOVED_BY_COMMAND, 0, &err))
2019 EM_DEBUG_LOG("emdaemon_move_mail success");
2021 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2022 EM_DEBUG_EXCEPTION("emipc_add_parameter fail");
2024 if (!emipc_execute_stub_api(a_hAPI))
2025 EM_DEBUG_EXCEPTION("emipc_execute_stub_api fail");
2027 EM_SAFE_FREE(multi_user_name);
2028 EM_DEBUG_FUNC_END();
2031 void stb_delete_rule(HIPC_API a_hAPI)
2033 EM_DEBUG_FUNC_BEGIN();
2036 int err = EMAIL_ERROR_NONE;
2037 int nAPPID = emipc_get_app_id(a_hAPI);
2038 char *multi_user_name = NULL;
2040 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2041 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2042 multi_user_name = NULL;
2046 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &filter_id);
2048 if(emdaemon_delete_filter(multi_user_name, filter_id, &err))
2049 err = EMAIL_ERROR_NONE;
2051 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2052 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2054 if (!emipc_execute_stub_api(a_hAPI))
2055 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2057 EM_SAFE_FREE(multi_user_name);
2058 EM_DEBUG_FUNC_END();
2061 void stb_apply_rule(HIPC_API a_hAPI)
2063 EM_DEBUG_FUNC_BEGIN();
2066 int err = EMAIL_ERROR_NONE;
2067 int nAPPID = emipc_get_app_id(a_hAPI);
2068 char *multi_user_name = NULL;
2070 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2071 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2072 multi_user_name = NULL;
2076 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &filter_id);
2078 if(emdaemon_apply_filter(multi_user_name, filter_id, &err))
2079 err = EMAIL_ERROR_NONE;
2081 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2082 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2084 if (!emipc_execute_stub_api(a_hAPI))
2085 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2087 EM_SAFE_FREE(multi_user_name);
2088 EM_DEBUG_FUNC_END();
2091 void stb_add_attachment(HIPC_API a_hAPI)
2093 EM_DEBUG_FUNC_BEGIN();
2094 int buffer_size = 0;
2095 int err = EMAIL_ERROR_NONE;
2097 int attachment_count = 0;
2099 char* attachment_stream = NULL;
2100 email_attachment_data_t* attachment = NULL;
2101 emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI;
2102 int nAPPID = emipc_get_app_id(a_hAPI);
2103 char *multi_user_name = NULL;
2104 char *prefix_path = NULL;
2105 char real_file_path[255] = {0};
2107 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2108 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2109 multi_user_name = NULL;
2113 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
2116 buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
2118 if(buffer_size > 0) {
2119 attachment_stream = (char*)em_malloc(buffer_size);
2120 if (attachment_stream == NULL) {
2121 EM_DEBUG_EXCEPTION("em_malloc failed");
2122 err = EMAIL_ERROR_OUT_OF_MEMORY;
2126 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, buffer_size, attachment_stream);
2127 em_convert_byte_stream_to_attachment_data(attachment_stream, buffer_size, &attachment, &attachment_count);
2128 EM_SAFE_FREE(attachment_stream);
2132 EM_DEBUG_EXCEPTION("em_convert_byte_stream_to_attachment_data failed ");
2133 err = EMAIL_ERROR_ON_PARSING;
2137 /* Get the absolute path */
2138 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
2139 err = emcore_get_container_path(multi_user_name, &prefix_path);
2140 if (err != EMAIL_ERROR_NONE) {
2141 EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
2145 prefix_path = strdup("");
2148 /* check smack rule for accessing file path */
2149 for (i = 0; i < attachment_count ; i++) {
2150 if (attachment[i].attachment_path) {
2151 memset(real_file_path, 0x00, sizeof(real_file_path));
2152 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, attachment[i].attachment_path);
2154 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
2155 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
2156 err = EMAIL_ERROR_NO_SMACK_RULE;
2162 emdaemon_add_attachment(multi_user_name, mail_id, attachment, &err);
2166 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2167 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2168 if(EMAIL_ERROR_NONE == err) {
2169 EM_DEBUG_LOG("emdaemon_add_attachment -Success");
2171 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &(attachment->attachment_id), sizeof(int)))
2172 EM_DEBUG_EXCEPTION("emipc_add_parameter attachment_id failed ");
2174 if (!emipc_execute_stub_api(a_hAPI))
2175 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2177 EM_SAFE_FREE(attachment);
2178 EM_SAFE_FREE(multi_user_name);
2179 EM_SAFE_FREE(prefix_path);
2181 EM_DEBUG_FUNC_END();
2184 void stb_get_attachment(HIPC_API a_hAPI)
2186 EM_DEBUG_FUNC_BEGIN();
2187 int err = EMAIL_ERROR_NONE;
2189 char* attachment_stream = NULL;
2190 email_attachment_data_t* attachment = NULL;
2192 int nAPPID = emipc_get_app_id(a_hAPI);
2193 char *multi_user_name = NULL;
2195 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2196 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2197 multi_user_name = NULL;
2201 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &attachment_id);
2203 emdaemon_get_attachment(multi_user_name, attachment_id, &attachment, &err);
2205 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2206 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2208 if(EMAIL_ERROR_NONE == err) {
2209 EM_DEBUG_LOG("emdaemon_get_attachment - Success");
2211 attachment_stream = em_convert_attachment_data_to_byte_stream(attachment, 1, &size);
2212 if(!attachment_stream) { /*prevent 26263*/
2213 emcore_free_attachment_data(&attachment, 1, &err);
2214 EM_SAFE_FREE(multi_user_name);
2217 EM_NULL_CHECK_FOR_VOID(attachment_stream);
2219 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, attachment_stream, size))
2220 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2223 if (!emipc_execute_stub_api(a_hAPI)) {
2224 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2227 EM_SAFE_FREE(attachment_stream);
2228 emcore_free_attachment_data(&attachment, 1, &err);
2230 EM_SAFE_FREE(multi_user_name);
2231 EM_DEBUG_FUNC_END();
2234 void stb_get_imap_mailbox_list(HIPC_API a_hAPI)
2236 EM_DEBUG_FUNC_BEGIN();
2237 int err = EMAIL_ERROR_NONE;
2240 int nAPPID = emipc_get_app_id(a_hAPI);
2241 char *multi_user_name = NULL;
2243 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2244 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2245 multi_user_name = NULL;
2249 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2251 /*need to check: why err value is changed? */
2252 if(emdaemon_get_imap_mailbox_list(multi_user_name, account_id, "", &handle, &err))
2253 err = EMAIL_ERROR_NONE;
2255 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2256 EM_DEBUG_LOG("ipcAPI_AddParameter local_result failed ");
2257 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
2258 EM_DEBUG_LOG("ipcAPI_AddParameter local_result failed ");
2259 if (!emipc_execute_stub_api(a_hAPI))
2260 EM_DEBUG_LOG("emipc_execute_stub_api failed ");
2262 EM_SAFE_FREE(multi_user_name);
2263 EM_DEBUG_FUNC_END();
2266 void stb_delete_attachment(HIPC_API a_hAPI)
2268 EM_DEBUG_FUNC_BEGIN();
2269 int err = EMAIL_ERROR_NONE;
2270 int attachment_id = 0;
2271 int nAPPID = emipc_get_app_id(a_hAPI);
2272 char *multi_user_name = NULL;
2274 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2275 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2276 multi_user_name = NULL;
2279 /* attachment_index */
2280 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &attachment_id);
2282 emdaemon_delete_mail_attachment(multi_user_name, attachment_id, &err);
2284 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2285 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2286 if (!emipc_execute_stub_api(a_hAPI))
2287 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2289 EM_SAFE_FREE(multi_user_name);
2290 EM_DEBUG_FUNC_END();
2293 void stb_download_attachment(HIPC_API a_hAPI)
2295 EM_DEBUG_FUNC_BEGIN();
2297 int err = EMAIL_ERROR_NONE;
2302 int nAPPID = emipc_get_app_id(a_hAPI);
2303 char *multi_user_name = NULL;
2305 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2306 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2307 multi_user_name = NULL;
2310 EM_DEBUG_LOG("account_id");
2311 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2313 EM_DEBUG_LOG("mail_id");
2314 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mail_id);
2316 EM_DEBUG_LOG("nth");
2317 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &nth);
2319 if(emdaemon_download_attachment(multi_user_name, account_id, mail_id, nth, &handle, &err)) {
2320 err = EMAIL_ERROR_NONE;
2322 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2323 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2324 EM_DEBUG_LOG(">>>>>>>>>> HANDLE = %d", handle);
2325 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
2326 EM_DEBUG_EXCEPTION("emipc_add_parameter handle failed ");
2327 if (!emipc_execute_stub_api(a_hAPI))
2328 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2331 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2332 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2333 /* Download handle - 17-Apr-09 */
2334 EM_DEBUG_LOG(">>>>>>>>>> HANDLE = %d", handle);
2335 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
2336 EM_DEBUG_EXCEPTION("emipc_add_parameter handle failed ");
2337 if (!emipc_execute_stub_api(a_hAPI))
2338 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2341 EM_SAFE_FREE(multi_user_name);
2342 EM_DEBUG_FUNC_END();
2345 void stb_mail_send_saved(HIPC_API a_hAPI)
2347 EM_DEBUG_FUNC_BEGIN();
2348 int err = EMAIL_ERROR_NONE;
2350 int nAPPID = emipc_get_app_id(a_hAPI);
2351 char *multi_user_name = NULL;
2353 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2354 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2355 multi_user_name = NULL;
2359 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2361 EM_DEBUG_LOG("calling emdaemon_send_mail_saved");
2362 if(emdaemon_send_mail_saved(multi_user_name, account_id, NULL, &err))
2363 err = EMAIL_ERROR_NONE;
2365 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2366 EM_DEBUG_EXCEPTION("emipc_add_parameter result failed ");
2368 if (!emipc_execute_stub_api(a_hAPI))
2369 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2371 EM_SAFE_FREE(multi_user_name);
2372 EM_DEBUG_FUNC_END();
2375 void stb_add_read_receipt(HIPC_API a_hAPI){
2376 EM_DEBUG_FUNC_BEGIN();
2377 int read_mail_id = 0;
2378 int receipt_mail_id = 0;
2379 int err = EMAIL_ERROR_NONE;
2380 int nAPPID = emipc_get_app_id(a_hAPI);
2381 char *multi_user_name = NULL;
2383 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2384 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2385 multi_user_name = NULL;
2389 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &read_mail_id);
2390 EM_DEBUG_LOG("read_mail_id [%d]", read_mail_id);
2392 if( (err = emcore_add_read_receipt(multi_user_name, read_mail_id, &receipt_mail_id)) != EMAIL_ERROR_NONE )
2393 EM_DEBUG_EXCEPTION("emcore_add_read_receipt failed [%d]", err);
2395 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2396 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2398 if (err == EMAIL_ERROR_NONE) {
2399 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &receipt_mail_id, sizeof(int)))
2400 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2403 if (!emipc_execute_stub_api(a_hAPI))
2404 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2406 EM_SAFE_FREE(multi_user_name);
2407 EM_DEBUG_FUNC_END("err [%d]", err);
2410 void stb_retry_sending_mail(HIPC_API a_hAPI)
2413 EM_DEBUG_FUNC_BEGIN();
2415 int timeout_in_sec = 0;
2416 int err = EMAIL_ERROR_NONE;
2417 int nAPPID = emipc_get_app_id(a_hAPI);
2418 char *multi_user_name = NULL;
2420 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2421 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2422 multi_user_name = NULL;
2426 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
2427 EM_DEBUG_LOG("mail_id [%d]", mail_id);
2429 /* timeout_in_sec */
2430 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &timeout_in_sec);
2431 EM_DEBUG_LOG("timeout_in_sec [%d]", timeout_in_sec);
2433 if(emdaemon_send_mail_retry(multi_user_name, mail_id, timeout_in_sec,&err))
2434 EM_DEBUG_LOG("emdaemon_get_mailbox_list - success");
2436 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2437 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2439 if (!emipc_execute_stub_api(a_hAPI))
2440 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2442 EM_SAFE_FREE(multi_user_name);
2443 EM_DEBUG_FUNC_END();
2446 void stb_cancel_job(HIPC_API a_hAPI)
2448 EM_DEBUG_FUNC_BEGIN();
2451 int err = EMAIL_ERROR_NONE;
2452 int nAPPID = emipc_get_app_id(a_hAPI);
2453 char *multi_user_name = NULL;
2455 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2456 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2457 multi_user_name = NULL;
2460 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2461 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &handle);
2462 EM_DEBUG_LOG("account_id [%d] handle [%d]", account_id, handle);
2464 if(emdaemon_cancel_job(account_id, handle, &err))
2465 err = EMAIL_ERROR_NONE;
2467 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2468 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2469 if (!emipc_execute_stub_api(a_hAPI))
2470 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2472 EM_SAFE_FREE(multi_user_name);
2473 EM_DEBUG_FUNC_END();
2476 void stb_cancel_send_mail_job(HIPC_API a_hAPI)
2478 EM_DEBUG_FUNC_BEGIN();
2480 int err = EMAIL_ERROR_NONE;
2482 int nAPPID = emipc_get_app_id(a_hAPI);
2483 char *multi_user_name = NULL;
2485 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2486 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2487 multi_user_name = NULL;
2491 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2492 EM_DEBUG_LOG("account_id [%d]", account_id);
2495 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mail_id);
2496 EM_DEBUG_LOG("mail_id [%d]", mail_id);
2498 if(emdaemon_cancel_sending_mail_job(account_id,mail_id,&err))
2499 EM_DEBUG_LOG("success");
2501 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2502 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2504 if (!emipc_execute_stub_api(a_hAPI))
2505 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2507 EM_SAFE_FREE(multi_user_name);
2508 EM_DEBUG_FUNC_END();
2511 void stb_search_mail_on_server(HIPC_API a_hAPI)
2513 EM_DEBUG_FUNC_BEGIN();
2514 int err = EMAIL_ERROR_NONE;
2517 int buffer_size = 0;
2518 int search_filter_count = 0;
2519 char *stream_for_search_filter_list = NULL;
2520 unsigned int job_handle = 0;
2521 email_search_filter_t *search_filter_list = NULL;
2522 int nAPPID = emipc_get_app_id(a_hAPI);
2523 char *multi_user_name = NULL;
2525 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2526 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2527 multi_user_name = NULL;
2531 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2532 EM_DEBUG_LOG("account_id [%d]", account_id);
2535 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &mailbox_id);
2536 EM_DEBUG_LOG("mailbox_id [%d]", mailbox_id);
2538 /* search_filter_list */
2539 buffer_size = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 2);
2541 if(buffer_size > 0) {
2542 stream_for_search_filter_list = (char*)em_malloc(buffer_size);
2543 if (stream_for_search_filter_list == NULL) {
2544 EM_DEBUG_EXCEPTION("out of memory");
2545 EM_SAFE_FREE(multi_user_name);
2549 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, buffer_size, stream_for_search_filter_list);
2550 em_convert_byte_stream_to_search_filter(stream_for_search_filter_list, &search_filter_list, &search_filter_count);
2551 EM_SAFE_FREE(stream_for_search_filter_list);
2554 if(!emdaemon_search_mail_on_server(multi_user_name, account_id ,mailbox_id, search_filter_list, search_filter_count, &job_handle, &err))
2555 EM_DEBUG_LOG("success");
2557 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2558 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2560 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &job_handle, sizeof(int)))
2561 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2563 if (!emipc_execute_stub_api(a_hAPI))
2564 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2566 EM_SAFE_FREE(multi_user_name);
2567 EM_DEBUG_FUNC_END();
2570 void stb_clear_result_of_search_mail_on_server(HIPC_API a_hAPI)
2572 EM_DEBUG_FUNC_BEGIN();
2573 int err = EMAIL_ERROR_NONE;
2575 emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
2576 int nAPPID = emipc_get_app_id(a_hAPI);
2577 char *multi_user_name = NULL;
2579 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2580 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2581 multi_user_name = NULL;
2585 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2587 EM_DEBUG_LOG("account_id [%d]", account_id);
2589 if (!emstorage_get_mailbox_by_name(multi_user_name, account_id, -1, EMAIL_SEARCH_RESULT_MAILBOX_NAME, &mailbox_tbl, false, &err)) {
2590 EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_name failed [%d]", err);
2594 if (!emstorage_delete_mail_by_mailbox(multi_user_name, mailbox_tbl, true, &err))
2595 EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
2600 emstorage_free_mailbox(&mailbox_tbl, 1, NULL);
2603 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2604 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2606 if (!emipc_execute_stub_api(a_hAPI))
2607 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2609 EM_SAFE_FREE(multi_user_name);
2610 EM_DEBUG_FUNC_END();
2615 void stb_add_account_with_validation(HIPC_API a_hAPI)
2617 EM_DEBUG_FUNC_BEGIN();
2618 int buffer_size = 0;
2619 int local_result = 0;
2621 char* stream = NULL;
2622 email_account_t *account = NULL;
2623 email_account_t *ref_account = NULL;
2624 int ref_check_interval = 0;
2625 int ref_account_id = 0;
2626 int err = EMAIL_ERROR_NONE;
2627 int nAPPID = emipc_get_app_id(a_hAPI);
2628 char *multi_user_name = NULL;
2630 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2631 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2632 multi_user_name = NULL;
2635 /* get account info */
2636 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 0);
2637 EM_DEBUG_LOG("size [%d]", buffer_size);
2638 if(buffer_size <= 0) {
2639 err = EMAIL_ERROR_INVALID_PARAM;
2643 stream =(char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0);
2645 err = EMAIL_ERROR_INVALID_PARAM;
2649 account = em_malloc(sizeof(email_account_t));
2650 if (account == NULL) {
2651 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
2652 err = EMAIL_ERROR_OUT_OF_MEMORY;
2656 em_convert_byte_stream_to_account(stream, buffer_size, account);
2657 account->user_name = EM_SAFE_STRDUP(multi_user_name);
2659 if ((err = emcore_add_account_to_unvalidated_account_list(account)) != EMAIL_ERROR_NONE) {
2660 EM_DEBUG_EXCEPTION("emcore_add_account_to_unvalidated_account_list failed [%d]", err);
2664 ref_account = emcore_get_account_reference(multi_user_name, account->account_id, false);
2666 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", err);
2670 ref_check_interval = ref_account->check_interval;
2671 ref_account_id = ref_account->account_id;
2673 if (!emdaemon_validate_account_and_create(multi_user_name, ref_account, &handle, &err)) {
2674 EM_DEBUG_EXCEPTION("emdaemon_validate_account_and_create fail [%d]", err);
2677 #ifdef __FEATURE_AUTO_POLLING__
2678 /* start auto polling, if check_interval not zero */
2679 if (ref_check_interval > 0 || (ref_account->peak_days > 0 && ref_account->peak_interval > 0)) {
2680 if(!emdaemon_add_polling_alarm(multi_user_name, ref_account_id))
2681 EM_DEBUG_EXCEPTION("emdaemon_add_polling_alarm[NOTI_ACCOUNT_ADD] : start auto poll failed >>> ");
2683 #ifdef __FEATURE_IMAP_IDLE__
2684 else if (ref_check_interval == 0 || (ref_account->peak_days > 0 && ref_account->peak_interval == 0))
2685 emcore_refresh_imap_idle_thread();
2686 #endif /* __FEATURE_IMAP_IDLE__ */
2687 #endif /* __FEATURE_AUTO_POLLING__ */
2688 /* add account details to contact DB */
2689 /* emdaemon_insert_accountinfo_to_contact(account); */
2692 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
2693 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2694 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
2695 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2696 if (!emipc_execute_stub_api(a_hAPI))
2697 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2700 if ( local_result == 0 ) { /* there is an error */
2701 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
2702 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : local_result ");
2703 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2704 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : err");
2705 if (!emipc_execute_stub_api(a_hAPI))
2706 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2709 /* note: account is freed in thread_func_branch_command, which is run by other thread */
2710 /* emcore_free_account(account); */
2712 EM_SAFE_FREE(multi_user_name);
2713 EM_DEBUG_FUNC_END();
2716 void stb_backup_account(HIPC_API a_hAPI)
2718 EM_DEBUG_FUNC_BEGIN();
2720 #ifdef __FEATURE_BACKUP_ACCOUNT__
2721 char *file_path = NULL;
2722 int local_result = 0, err_code = 0, file_path_length = 0;
2723 int nAPPID = emipc_get_app_id(a_hAPI);
2724 char *multi_user_name = NULL;
2726 if ((err_code = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2727 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err_code);
2728 multi_user_name = NULL;
2731 /* file_path_length */
2732 file_path_length = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
2733 if(file_path_length > 0) {
2734 EM_DEBUG_LOG("file_path_length [%d]", file_path_length);
2735 file_path = em_malloc(file_path_length);
2736 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, file_path_length, file_path);
2737 EM_DEBUG_LOG_SEC("file_path [%s]", file_path);
2738 local_result = emcore_backup_accounts(multi_user_name, (const char*)file_path, &err_code);
2741 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
2742 EM_DEBUG_LOG("emipc_add_parameter failed ");
2744 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
2745 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2747 if (!emipc_execute_stub_api(a_hAPI))
2748 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2750 EM_SAFE_FREE(file_path);
2751 EM_SAFE_FREE(multi_user_name);
2752 #endif /* __FEATURE_BACKUP_ACCOUNT__ */
2753 EM_DEBUG_FUNC_END();
2756 void stb_restore_account(HIPC_API a_hAPI)
2758 EM_DEBUG_FUNC_BEGIN();
2759 #ifdef __FEATURE_BACKUP_ACCOUNT__
2760 char *file_path = NULL;
2761 int result = 0, err_code = 0, file_path_length = 0;
2762 int nAPPID = emipc_get_app_id(a_hAPI);
2763 char *multi_user_name = NULL;
2765 if ((err_code = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2766 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err_code);
2767 multi_user_name = NULL;
2770 /* file_path_length */
2771 file_path_length = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
2772 if(file_path_length > 0) {
2773 EM_DEBUG_LOG("file_path_length [%d]", file_path_length);
2774 file_path = em_malloc(file_path_length);
2775 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, file_path_length, file_path);
2776 EM_DEBUG_LOG_SEC("file_path [%s]", file_path);
2779 /* file_path could be NULL */
2780 err_code = emcore_restore_accounts(multi_user_name, (const char*)file_path);
2782 result = (err_code == EMAIL_ERROR_NONE)?1:0;
2784 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &result, sizeof(int)))
2785 EM_DEBUG_LOG("emipc_add_parameter failed ");
2787 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
2788 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2790 if (!emipc_execute_stub_api(a_hAPI))
2791 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2793 EM_SAFE_FREE(file_path);
2794 EM_SAFE_FREE(multi_user_name);
2795 #endif /* __FEATURE_BACKUP_ACCOUNT__ */
2796 EM_DEBUG_FUNC_END();
2800 void stb_get_password_length(HIPC_API a_hAPI)
2802 EM_DEBUG_FUNC_BEGIN();
2804 int password_type = 0;
2805 int local_result = 0;
2807 int password_length = 0;
2808 int nAPPID = emipc_get_app_id(a_hAPI);
2809 char *multi_user_name = NULL;
2811 if ((err_code = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2812 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err_code);
2813 multi_user_name = NULL;
2817 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
2818 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &password_type);
2820 local_result = emstorage_get_password_length_of_account(multi_user_name, account_id, password_type, &password_length,&err_code);
2822 EM_DEBUG_LOG("password_length [%d]", password_length);
2824 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
2825 EM_DEBUG_LOG("emipc_add_parameter failed ");
2827 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err_code, sizeof(int)))
2828 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
2830 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &password_length, sizeof(int)))
2831 EM_DEBUG_EXCEPTION("emipc_add_parameter result failed ");
2833 if (!emipc_execute_stub_api(a_hAPI))
2834 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2836 EM_SAFE_FREE(multi_user_name);
2837 EM_DEBUG_FUNC_END();
2840 void stb_get_task_information(HIPC_API a_hAPI)
2842 EM_DEBUG_FUNC_BEGIN();
2844 int task_information_count = 0;
2846 email_task_information_t *task_information = NULL;
2847 char *task_information_stream = NULL;
2848 int nAPPID = emipc_get_app_id(a_hAPI);
2849 char *multi_user_name = NULL;
2851 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2852 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2853 multi_user_name = NULL;
2856 err = emcore_get_task_information(&task_information, &task_information_count);
2858 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2859 EM_DEBUG_LOG("emipc_add_parameter failed ");
2861 /* email_task_information_t */
2862 if(task_information_count) {
2863 task_information_stream = em_convert_task_information_to_byte_stream(task_information, task_information_count, &stream_length);
2865 if((stream_length > 0) && !emipc_add_dynamic_parameter(a_hAPI, ePARAMETER_OUT, task_information_stream, stream_length)) {
2866 EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed");
2867 err = EMAIL_ERROR_OUT_OF_MEMORY;
2871 if (!emipc_execute_stub_api(a_hAPI))
2872 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2874 if(task_information) {
2875 EM_SAFE_FREE(task_information);
2878 EM_SAFE_FREE(multi_user_name);
2879 EM_DEBUG_FUNC_END();
2882 void stb_add_certificate(HIPC_API a_hAPI)
2884 int err = EMAIL_ERROR_NONE;
2885 int cert_file_len = 0;
2886 int email_address_len = 0;
2887 char *cert_file_path = NULL;
2888 char *email_address = NULL;
2889 emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI;
2890 int nAPPID = emipc_get_app_id(a_hAPI);
2891 char *multi_user_name = NULL;
2892 char *prefix_path = NULL;
2893 char real_file_path[255] = {0};
2895 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2896 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2897 multi_user_name = NULL;
2900 /* Get the absolute path */
2901 if (EM_SAFE_STRLEN(multi_user_name) > 0) {
2902 err = emcore_get_container_path(multi_user_name, &prefix_path);
2903 if (err != EMAIL_ERROR_NONE) {
2904 EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
2908 prefix_path = strdup("");
2911 cert_file_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
2912 if (cert_file_len > 0) {
2913 cert_file_path = em_malloc(cert_file_len + 1);
2914 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, cert_file_len, cert_file_path);
2917 /* check smack rule for accessing file path */
2918 if (cert_file_path) {
2919 memset(real_file_path, 0x00, sizeof(real_file_path));
2920 SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, cert_file_path);
2922 if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
2923 EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
2924 err = EMAIL_ERROR_NO_SMACK_RULE;
2929 email_address_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
2930 if (email_address_len > 0) {
2931 email_address = em_malloc(email_address_len + 1);
2932 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, email_address_len, email_address);
2935 if (!emcore_add_public_certificate(multi_user_name, cert_file_path, email_address, &err)) {
2936 EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed");
2941 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2942 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2944 if (EMAIL_ERROR_NONE == err) {
2945 EM_DEBUG_LOG("email_mail_add_attachment -Success");
2948 if (!emipc_execute_stub_api(a_hAPI))
2949 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
2951 EM_SAFE_FREE(prefix_path);
2952 EM_SAFE_FREE(cert_file_path);
2953 EM_SAFE_FREE(email_address);
2954 EM_SAFE_FREE(multi_user_name);
2955 EM_DEBUG_FUNC_END();
2958 void stb_delete_certificate(HIPC_API a_hAPI)
2960 int err = EMAIL_ERROR_NONE;
2961 int email_address_len = 0;
2962 char *email_address = NULL;
2963 char temp_email_address[130] = {0, };
2964 int nAPPID = emipc_get_app_id(a_hAPI);
2965 char *multi_user_name = NULL;
2967 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
2968 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
2969 multi_user_name = NULL;
2972 email_address_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
2973 if (email_address_len > 0) {
2974 EM_DEBUG_LOG("email address string length [%d]", email_address_len);
2975 email_address = em_malloc(email_address_len + 1);
2976 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, email_address_len, email_address);
2977 EM_DEBUG_LOG_SEC("email address [%s]", email_address);
2980 SNPRINTF(temp_email_address, sizeof(temp_email_address), "<%s>", email_address);
2981 if (!emcore_delete_public_certificate(multi_user_name, temp_email_address, &err)) {
2982 EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed");
2985 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
2986 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
2988 if (EMAIL_ERROR_NONE == err) {
2989 EM_DEBUG_LOG("email_mail_add_attachment -Success");
2992 if (!emipc_execute_stub_api(a_hAPI))
2993 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
2996 EM_SAFE_FREE(email_address);
2997 EM_SAFE_FREE(multi_user_name);
2998 EM_DEBUG_FUNC_END();
3001 void stb_verify_signature(HIPC_API a_hAPI)
3003 int err = EMAIL_ERROR_NONE;
3007 int attachment_tbl_count = 0;
3008 email_mail_data_t *mail_data = NULL;
3009 emstorage_attachment_tbl_t *attachment_tbl_list = NULL;
3010 int nAPPID = emipc_get_app_id(a_hAPI);
3011 char *multi_user_name = NULL;
3013 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3014 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3015 multi_user_name = NULL;
3018 err = emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &mail_id);
3019 if (err != EMAIL_ERROR_NONE) {
3020 EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
3024 if (!emcore_get_mail_data(multi_user_name, mail_id, &mail_data)) {
3025 EM_DEBUG_EXCEPTION("emcore_get_mail_data failed");
3029 if ((err = emstorage_get_attachment_list(multi_user_name, mail_id, true, &attachment_tbl_list, &attachment_tbl_count)) != EMAIL_ERROR_NONE) {
3030 EM_DEBUG_EXCEPTION("emstorage_get_attachment_list failed : [%d]", err);
3034 if (attachment_tbl_count <= 0) {
3035 EM_DEBUG_EXCEPTION("Invalid signed mail");
3036 err = EMAIL_ERROR_INVALID_MAIL;
3040 for (count = 0; count < attachment_tbl_count ; count++) {
3041 if (attachment_tbl_list[count].attachment_mime_type && strcasestr(attachment_tbl_list[count].attachment_mime_type, "SIGNATURE"))
3045 if (mail_data->smime_type == EMAIL_SMIME_SIGNED) {
3046 if (!emcore_verify_signature(attachment_tbl_list[count].attachment_path, mail_data->file_path_mime_entity, &verify, &err)) {
3047 EM_DEBUG_EXCEPTION("emcore_verify_signature failed");
3050 } else if (mail_data->smime_type == EMAIL_PGP_SIGNED) {
3051 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) {
3052 EM_DEBUG_EXCEPTION("emcore_pgp_get_verify_signature failed : [%d]", err);
3056 EM_DEBUG_LOG("Invalid signed mail");
3057 err = EMAIL_ERROR_INVALID_PARAM;
3062 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &verify, sizeof(int)))
3063 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
3066 EM_DEBUG_LOG("Verify S/MIME signed mail-Success");
3069 if (!emipc_execute_stub_api(a_hAPI))
3070 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3073 if (attachment_tbl_list)
3074 emstorage_free_attachment(&attachment_tbl_list, attachment_tbl_count, NULL);
3077 emcore_free_mail_data(mail_data);
3078 EM_SAFE_FREE(mail_data);
3081 EM_SAFE_FREE(multi_user_name);
3082 EM_DEBUG_FUNC_END();
3085 void stb_verify_certificate(HIPC_API a_hAPI)
3087 int err = EMAIL_ERROR_NONE;
3089 int cert_file_len = 0;
3090 char *cert_file_path = 0;
3091 int nAPPID = emipc_get_app_id(a_hAPI);
3092 char *multi_user_name = NULL;
3094 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3095 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3096 multi_user_name = NULL;
3099 cert_file_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
3100 if (cert_file_len > 0) {
3101 cert_file_path = em_malloc(cert_file_len + 1);
3102 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, cert_file_len, cert_file_path);
3105 if (!emcore_verify_certificate(cert_file_path, &verify, &err)) {
3106 EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed");
3109 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &verify, sizeof(int)))
3110 EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
3113 EM_DEBUG_LOG("Verify S/MIME signed mail-Success");
3116 if (!emipc_execute_stub_api(a_hAPI))
3117 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3119 EM_SAFE_FREE(cert_file_path);
3120 EM_SAFE_FREE(multi_user_name);
3121 EM_DEBUG_FUNC_END();
3124 void stb_ping_service(HIPC_API a_hAPI)
3126 EM_DEBUG_FUNC_BEGIN();
3127 int err = EMAIL_ERROR_NONE;
3129 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3130 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3132 if (!emipc_execute_stub_api(a_hAPI))
3133 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3135 EM_DEBUG_FUNC_END();
3138 void stb_update_notification_bar_for_unread_mail(HIPC_API a_hAPI)
3140 EM_DEBUG_FUNC_BEGIN();
3141 int err = EMAIL_ERROR_NONE, account_id;
3142 int total_mail_count = 0, unread_mail_count = 0;
3143 int input_from_eas = 0;
3144 /* Get Container name */
3145 int nAPPID = emipc_get_app_id(a_hAPI);
3146 char *multi_user_name = NULL;
3148 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3149 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3150 multi_user_name = NULL;
3154 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
3155 EM_DEBUG_LOG("account_id [%d]", account_id);
3157 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), &total_mail_count);
3158 EM_DEBUG_LOG("total_mail_count [%d]", total_mail_count);
3160 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), &unread_mail_count);
3161 EM_DEBUG_LOG("unread_mail_count [%d]", unread_mail_count);
3163 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 3, sizeof(int), &input_from_eas);
3164 EM_DEBUG_LOG("unread_mail_count [%d]", input_from_eas);
3166 emcore_display_unread_in_badge(multi_user_name);
3168 if(!emdaemon_finalize_sync(multi_user_name, account_id, total_mail_count, unread_mail_count, 0, 0, input_from_eas, &err)) {
3169 EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed [%d]", err);
3172 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3173 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3175 if (!emipc_execute_stub_api(a_hAPI))
3176 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3178 EM_SAFE_FREE(multi_user_name);
3179 EM_DEBUG_FUNC_END();
3182 void stb_clear_notification_bar(HIPC_API a_hAPI)
3184 EM_DEBUG_FUNC_BEGIN();
3185 int err = EMAIL_ERROR_NONE, account_id;
3186 int nAPPID = emipc_get_app_id(a_hAPI);
3187 char *multi_user_name = NULL;
3189 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3190 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3191 multi_user_name = NULL;
3195 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
3196 EM_DEBUG_LOG("account_id [%d]", account_id);
3198 if((err = emcore_clear_notifications(multi_user_name, account_id)) != EMAIL_ERROR_NONE)
3199 EM_DEBUG_EXCEPTION("emdaemon_finalize_sync failed [%d]", err);
3201 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3202 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3204 if (!emipc_execute_stub_api(a_hAPI))
3205 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3207 EM_SAFE_FREE(multi_user_name);
3208 EM_DEBUG_FUNC_END();
3211 void stb_show_user_message(HIPC_API a_hAPI)
3213 EM_DEBUG_FUNC_BEGIN();
3214 int err = EMAIL_ERROR_NONE;
3216 int param_error = 0;
3217 email_action_t param_action = 0;
3218 int nAPPID = emipc_get_app_id(a_hAPI);
3219 char *multi_user_name = NULL;
3221 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3222 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3223 multi_user_name = NULL;
3227 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), ¶m_id);
3228 EM_DEBUG_LOG("param_id [%d]", param_id);
3231 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, sizeof(int), ¶m_action);
3232 EM_DEBUG_LOG("param_action [%d]", param_action);
3235 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 2, sizeof(int), ¶m_error);
3236 EM_DEBUG_LOG("param_error [%d]", param_error);
3238 if(!emcore_show_user_message(multi_user_name, param_id, param_action, param_error)) {
3239 EM_DEBUG_EXCEPTION("emcore_show_user_message failed");
3242 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3243 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3245 if (!emipc_execute_stub_api(a_hAPI))
3246 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3248 EM_SAFE_FREE(multi_user_name);
3249 EM_DEBUG_FUNC_END("err [%d]", err);
3252 void stb_write_mime_file(HIPC_API a_hAPI)
3254 EM_DEBUG_FUNC_BEGIN();
3255 int err = EMAIL_ERROR_NONE;
3257 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3258 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3260 if (!emipc_execute_stub_api(a_hAPI))
3261 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3263 EM_DEBUG_FUNC_END();
3267 void stb_validate_account_ex(HIPC_API a_hAPI)
3269 EM_DEBUG_FUNC_BEGIN();
3270 int buffer_size = 0;
3271 int local_result = 0;
3273 char* stream = NULL;
3274 email_account_t *account = NULL;
3275 email_account_t *ref_account = NULL;
3276 int err = EMAIL_ERROR_NONE;
3277 int nAPPID = emipc_get_app_id(a_hAPI);
3278 char *multi_user_name = NULL;
3280 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3281 EM_DEBUG_EXCEPTION("emcore_get_user_name failed : [%d]", err);
3282 multi_user_name = NULL;
3285 /* get account info */
3286 buffer_size = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, 0);
3287 EM_DEBUG_LOG("size [%d]", buffer_size);
3288 if(buffer_size <= 0) {
3289 err = EMAIL_ERROR_INVALID_PARAM;
3293 stream =(char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, 0);
3295 err = EMAIL_ERROR_INVALID_PARAM;
3299 account = em_malloc(sizeof(email_account_t));
3301 if(account == NULL) {
3302 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
3303 err = EMAIL_ERROR_OUT_OF_MEMORY;
3307 em_convert_byte_stream_to_account(stream, buffer_size, account);
3308 account->user_name = EM_SAFE_STRDUP(multi_user_name);
3310 if((err = emcore_add_account_to_unvalidated_account_list(account)) != EMAIL_ERROR_NONE) {
3311 EM_DEBUG_EXCEPTION("emcore_add_account_to_unvalidated_account_list failed [%d]", err);
3315 ref_account = emcore_get_account_reference(multi_user_name, account->account_id, false);
3318 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", err);
3322 /* ref_account will be removed by worker_event_queue() */
3323 if((err = emdaemon_validate_account_ex(multi_user_name, ref_account, &handle)) != EMAIL_ERROR_NONE) {
3324 EM_DEBUG_EXCEPTION("emdaemon_validate_account_ex fail [%d]", err);
3329 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
3330 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3331 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &handle, sizeof(int)))
3332 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
3333 if (!emipc_execute_stub_api(a_hAPI))
3334 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3337 if ( local_result == 0 ) { /* there is an error */
3338 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &local_result, sizeof(int)))
3339 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : local_result ");
3340 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3341 EM_DEBUG_EXCEPTION("emipc_add_parameter failed : err");
3342 if (!emipc_execute_stub_api(a_hAPI))
3343 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
3346 EM_SAFE_FREE(multi_user_name);
3347 EM_DEBUG_FUNC_END();
3350 void stb_handle_task(int task_type, HIPC_API a_hAPI)
3352 EM_DEBUG_FUNC_BEGIN();
3353 int param_index = 0;
3354 int is_async_task = (task_type > EMAIL_ASYNC_TASK_BOUNDARY_START)?1:0;
3355 int err = EMAIL_ERROR_NONE;
3357 int task_parameter_length = 0;
3358 char *task_parameter = NULL;
3360 /* task_parameter_length */;
3361 task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
3362 EM_DEBUG_LOG("task_parameter_length [%d]", task_parameter_length);
3364 /* task_parameter */
3365 if(task_parameter_length > 0) {
3366 task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
3370 /* add async task */
3371 if((err = emcore_add_task_to_task_table(NULL,
3373 EMAIL_TASK_PRIORITY_MID,
3375 task_parameter_length,
3376 &task_id)) != EMAIL_ERROR_NONE) {
3377 EM_DEBUG_EXCEPTION("emcore_add_task_to_task_pool failed [%d]", err);
3383 email_task_t sync_task;
3385 memset(&sync_task, 0, sizeof(email_task_t));
3386 sync_task.task_type = task_type;
3387 sync_task.task_priority = EMAIL_TASK_PRIORITY_MID;
3388 sync_task.task_parameter = task_parameter;
3389 sync_task.task_parameter_length = task_parameter_length;
3391 if((err = emcore_default_sync_task_handler(&sync_task)) != EMAIL_ERROR_NONE) {
3392 EM_DEBUG_EXCEPTION("emcore_default_sync_task_handler failed [%d]", err);
3398 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3399 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3402 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &task_id, sizeof(int)))
3403 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3406 if (!emipc_execute_stub_api(a_hAPI))
3407 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3409 EM_DEBUG_FUNC_END("err [%d]", err);
3412 void* thread_func_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param)
3414 EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
3415 int err = EMAIL_ERROR_NONE;
3416 int err_for_signal = EMAIL_ERROR_NONE;
3418 int task_id = THREAD_SELF();
3419 task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_param = input_param;
3421 /* Send start signal */
3422 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)
3423 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3425 for(i = 0; i < task_param->mail_id_count; i++) {
3426 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) {
3427 EM_DEBUG_EXCEPTION("emcore_move_mail_to_another_account failed [%d]", err);
3431 /* Send progress signal */
3432 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)
3433 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3437 /* Send finish signal */
3438 if(err == EMAIL_ERROR_NONE) {
3439 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)
3440 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3443 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)
3444 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3447 /* Free task parameter */
3448 EM_SAFE_FREE(task_param->multi_user_name);
3449 EM_SAFE_FREE(task_param->mail_id_array);
3450 EM_SAFE_FREE(task_param);
3452 emcore_close_recv_stream_list();
3453 EM_DEBUG_FUNC_END("err [%d]", err);
3457 void stb_move_mails_to_mailbox_of_another_account(HIPC_API a_hAPI)
3459 EM_DEBUG_FUNC_BEGIN();
3460 int param_index = 0;
3461 int err = EMAIL_ERROR_NONE;
3462 int task_parameter_length = 0;
3465 char *task_parameter = NULL;
3466 task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *decoded_parameter = NULL;
3468 int nAPPID = emipc_get_app_id(a_hAPI);
3469 char *multi_user_name = NULL;
3471 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3472 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3473 multi_user_name = NULL;
3476 /* task_parameter_length */;
3477 task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
3479 if(task_parameter_length <= 0) {
3480 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : task_parameter_length [%d]", task_parameter_length);
3481 err = EMAIL_ERROR_INVALID_PARAM;
3485 /* task_parameter */
3486 task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
3488 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) {
3489 EM_DEBUG_EXCEPTION("email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT failed[%d]", err);
3493 decoded_parameter->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
3495 THREAD_CREATE(task_id, thread_func_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, (void*)decoded_parameter, thread_error);
3497 if(thread_error != 0) {
3498 EM_DEBUG_EXCEPTION("THREAD_CREATE failed [%d]", thread_error);
3499 err = EMAIL_ERROR_SYSTEM_FAILURE;
3503 THREAD_DETACH(task_id);
3506 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3507 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3509 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &task_id, sizeof(int)))
3510 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3512 if (!emipc_execute_stub_api(a_hAPI))
3513 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3515 EM_SAFE_FREE(multi_user_name);
3517 EM_DEBUG_FUNC_END("err [%d]", err);
3520 void* thread_func_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param)
3522 EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
3523 int err = EMAIL_ERROR_NONE;
3524 int err_for_signal = EMAIL_ERROR_NONE;
3526 int task_id = THREAD_SELF();
3527 email_account_t* ref_account = NULL;
3528 task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_param = input_param;
3530 ref_account = emcore_get_account_reference(task_param->multi_user_name, task_param->account_id, false);
3532 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed [%d]", task_param->account_id);
3533 err = EMAIL_ERROR_INVALID_ACCOUNT;
3537 /* on_server is allowed to be only 0 when server_type is EMAIL_SERVER_TYPE_ACTIVE_SYNC */
3538 if ( ref_account->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
3542 /* Send start signal */
3543 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)
3544 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3546 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) {
3547 EM_DEBUG_EXCEPTION("emcore_delete_mailbox_ex failed[%d]", err);
3552 /* Send finish signal */
3553 if(err == EMAIL_ERROR_NONE) {
3554 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)
3555 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3558 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)
3559 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3562 if (ref_account) { /*prevent 49435*/
3563 emcore_free_account(ref_account);
3564 EM_SAFE_FREE(ref_account);
3567 /* Free task parameter */
3568 EM_SAFE_FREE(task_param->mailbox_id_array);
3569 EM_SAFE_FREE(task_param->multi_user_name);
3570 EM_SAFE_FREE(task_param);
3572 EM_DEBUG_FUNC_END("err [%d]", err);
3576 void stb_delete_mailbox_ex(HIPC_API a_hAPI)
3578 EM_DEBUG_FUNC_BEGIN();
3579 int param_index = 0;
3580 int err = EMAIL_ERROR_NONE;
3581 int task_parameter_length = 0;
3582 int thread_error = 0;
3584 char *task_parameter = NULL;
3585 task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *decoded_parameter = NULL;
3586 int nAPPID = emipc_get_app_id(a_hAPI);
3587 char *multi_user_name = NULL;
3589 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3590 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3591 multi_user_name = NULL;
3594 /* task_parameter_length */;
3595 task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
3597 if(task_parameter_length <= 0) {
3598 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : task_parameter_length [%d]", task_parameter_length);
3599 err = EMAIL_ERROR_INVALID_PARAM;
3603 /* task_parameter */
3604 task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
3606 if((err = email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(task_parameter, task_parameter_length, (void**)&decoded_parameter)) != EMAIL_ERROR_NONE) {
3607 EM_DEBUG_EXCEPTION("email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT failed[%d]", err);
3611 decoded_parameter->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
3613 THREAD_CREATE(task_id, thread_func_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, (void*)decoded_parameter, thread_error);
3615 if(thread_error != 0) {
3616 EM_DEBUG_EXCEPTION("THREAD_CREATE failed [%d]", thread_error);
3617 err = EMAIL_ERROR_SYSTEM_FAILURE;
3621 THREAD_DETACH(task_id);
3624 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3625 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3627 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &task_id, sizeof(int)))
3628 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3630 if (!emipc_execute_stub_api(a_hAPI))
3631 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3633 EM_SAFE_FREE(multi_user_name);
3634 EM_DEBUG_FUNC_END("err [%d]", err);
3637 void* thread_func_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_param)
3639 EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
3640 int err = EMAIL_ERROR_NONE;
3641 int err_for_signal = EMAIL_ERROR_NONE;
3642 int task_id = THREAD_SELF();
3643 task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_param = input_param;
3645 /* Send start signal */
3646 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)
3647 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3649 if((err = emcore_send_mail_with_downloading_attachment_of_original_mail(task_param->multi_user_name, task_param->mail_id)) != EMAIL_ERROR_NONE) {
3650 EM_DEBUG_EXCEPTION("emcore_send_mail_with_downloading_attachment_of_original_mail failed [%d]", err);
3655 /* Send finish signal */
3656 if(err == EMAIL_ERROR_NONE) {
3657 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)
3658 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3661 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)
3662 EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
3665 /* Free task parameter */
3666 EM_SAFE_FREE(task_param->multi_user_name);
3667 EM_SAFE_FREE(task_param);
3668 emcore_close_smtp_stream_list();
3669 EM_DEBUG_FUNC_END("err [%d]", err);
3673 void stb_send_mail_with_downloading_attachment_of_original_mail(HIPC_API a_hAPI)
3675 EM_DEBUG_FUNC_BEGIN();
3676 int param_index = 0;
3677 int err = EMAIL_ERROR_NONE;
3678 int task_parameter_length = 0;
3679 int thread_error = 0;
3681 char *task_parameter = NULL;
3682 task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *decoded_parameter = NULL;
3683 int nAPPID = emipc_get_app_id(a_hAPI);
3684 char *multi_user_name = NULL;
3686 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3687 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3688 multi_user_name = NULL;
3691 /* task_parameter_length */;
3692 task_parameter_length = emipc_get_nth_parameter_length(a_hAPI, ePARAMETER_IN, param_index);
3694 if(task_parameter_length <= 0) {
3695 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : task_parameter_length [%d]", task_parameter_length);
3696 err = EMAIL_ERROR_INVALID_PARAM;
3700 /* task_parameter */
3701 task_parameter = (char*) emipc_get_nth_parameter_data(a_hAPI, ePARAMETER_IN, param_index++);
3703 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) {
3704 EM_DEBUG_EXCEPTION("email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT failed[%d]", err);
3708 decoded_parameter->multi_user_name = EM_SAFE_STRDUP(multi_user_name);
3710 THREAD_CREATE(task_id, thread_func_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, (void*)decoded_parameter, thread_error);
3712 if(thread_error != 0) {
3713 EM_DEBUG_EXCEPTION("THREAD_CREATE failed [%d]", thread_error);
3714 err = EMAIL_ERROR_SYSTEM_FAILURE;
3718 THREAD_DETACH(task_id);
3721 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3722 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3724 if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &task_id, sizeof(int)))
3725 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3727 if (!emipc_execute_stub_api(a_hAPI))
3728 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3730 EM_SAFE_FREE(multi_user_name);
3731 EM_DEBUG_FUNC_END("err [%d]", err);
3734 void stb_save_default_account_id(HIPC_API a_hAPI)
3736 EM_DEBUG_FUNC_BEGIN();
3737 int err = EMAIL_ERROR_NONE;
3740 int nAPPID = emipc_get_app_id(a_hAPI);
3741 char *multi_user_name = NULL;
3743 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3744 EM_DEBUG_EXCEPTION("emcore_get_user_name failed : [%d]", err);
3745 multi_user_name = NULL;
3749 emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, sizeof(int), &account_id);
3750 EM_DEBUG_LOG("account_id [%d]", account_id);
3752 err = emcore_save_default_account_id(multi_user_name, account_id);
3753 if (err != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_save_default_account_id failed [%d]", err);
3755 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3756 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3758 if (!emipc_execute_stub_api(a_hAPI))
3759 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3761 EM_SAFE_FREE(multi_user_name);
3762 EM_DEBUG_FUNC_END();
3765 void stb_load_default_account_id(HIPC_API a_hAPI)
3767 EM_DEBUG_FUNC_BEGIN();
3768 int err = EMAIL_ERROR_NONE;
3771 int nAPPID = emipc_get_app_id(a_hAPI);
3772 char *multi_user_name = NULL;
3774 if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
3775 EM_DEBUG_EXCEPTION("emcore_get_user_name failed : [%d]", err);
3776 multi_user_name = NULL;
3779 err = emcore_load_default_account_id(multi_user_name, &account_id);
3780 if (err != EMAIL_ERROR_NONE) {
3781 EM_DEBUG_EXCEPTION("emcore_save_default_account_id failed [%d]", err);
3784 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3785 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3787 if (err == EMAIL_ERROR_NONE) {
3788 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &account_id, sizeof(int)))
3789 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3792 if (!emipc_execute_stub_api(a_hAPI))
3793 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3795 EM_SAFE_FREE(multi_user_name);
3796 EM_DEBUG_FUNC_END();
3799 void stb_get_user_name(HIPC_API a_hAPI)
3801 EM_DEBUG_FUNC_BEGIN();
3803 int err = EMAIL_ERROR_NONE;
3806 char *user_name = NULL;
3808 pid = emipc_get_app_id(a_hAPI);
3809 EM_DEBUG_LOG("Peer PID : [%d]", pid);
3812 if ((err = emcore_get_user_name(pid, &user_name)) != EMAIL_ERROR_NONE)
3813 EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
3815 EM_DEBUG_LOG("Domain name : [%s]", user_name);
3817 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3818 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3821 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, user_name, EM_SAFE_STRLEN(user_name) + 1))
3822 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
3826 if (!emipc_execute_stub_api(a_hAPI))
3827 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3829 EM_SAFE_FREE(user_name);
3831 EM_DEBUG_FUNC_END();
3834 void stb_API_mapper(HIPC_API a_hAPI)
3836 EM_DEBUG_FUNC_BEGIN();
3837 int err = EMAIL_ERROR_NONE;
3838 int nAPIID = emipc_get_api_id(a_hAPI);
3839 int client_fd = emipc_get_response_id(a_hAPI);
3841 err = emcore_check_privilege(client_fd);
3842 if (err != EMAIL_ERROR_NONE) {
3843 EM_DEBUG_EXCEPTION("emcore_check_privilege failed : [%d]", err);
3845 if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
3846 EM_DEBUG_EXCEPTION("emipc_add_paramter failed");
3848 if (!emipc_execute_stub_api(a_hAPI))
3849 EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
3855 case _EMAIL_API_ADD_ACCOUNT:
3856 stb_create_account(a_hAPI);
3859 case _EMAIL_API_ADD_MAILBOX:
3860 stb_create_mailbox(a_hAPI);
3863 case _EMAIL_API_DELETE_MAILBOX:
3864 stb_delete_mailbox(a_hAPI);
3867 case _EMAIL_API_SET_MAILBOX_TYPE:
3868 stb_set_mailbox_type(a_hAPI);
3871 case _EMAIL_API_SET_LOCAL_MAILBOX:
3872 stb_set_local_mailbox(a_hAPI);
3875 case _EMAIL_API_STAMP_SYNC_TIME_OF_MAILBOX:
3876 stb_stamp_sync_time_of_mailbox(a_hAPI);
3879 case _EMAIL_API_SET_MAIL_SLOT_SIZE:
3880 stb_set_mail_slot_size_of_mailbox(a_hAPI);
3883 case _EMAIL_API_RENAME_MAILBOX:
3884 stb_rename_mailbox(a_hAPI);
3887 case _EMAIL_API_RENAME_MAILBOX_EX:
3888 stb_rename_mailbox_ex(a_hAPI);
3891 case _EMAIL_API_SEND_MAIL:
3892 stb_send_mail(a_hAPI);
3895 case _EMAIL_API_QUERY_SMTP_MAIL_SIZE_LIMIT:
3896 stb_query_smtp_mail_size_limit(a_hAPI);
3899 case _EMAIL_API_GET_MAILBOX_LIST:
3900 stb_get_mailbox_list(a_hAPI);
3903 case _EMAIL_API_SYNC_HEADER:
3904 stb_sync_header(a_hAPI);
3907 case _EMAIL_API_DOWNLOAD_BODY:
3908 stb_download_body(a_hAPI);
3911 case _EMAIL_API_CLEAR_DATA:
3912 stb_clear_mail_data (a_hAPI);
3915 case _EMAIL_API_DELETE_ALL_MAIL:
3916 stb_delete_all_mails(a_hAPI);
3919 case _EMAIL_API_DELETE_MAIL:
3920 stb_delete_mail(a_hAPI);
3923 case _EMAIL_API_ADD_RULE:
3924 stb_add_rule(a_hAPI);
3927 case _EMAIL_API_GET_RULE:
3928 stb_get_rule(a_hAPI);
3931 case _EMAIL_API_GET_RULE_LIST:
3932 stb_get_rule_list(a_hAPI);
3935 case _EMAIL_API_FIND_RULE:
3936 stb_find_rule(a_hAPI);
3939 case _EMAIL_API_UPDATE_RULE:
3940 stb_update_rule(a_hAPI);
3943 case _EMAIL_API_DELETE_RULE:
3944 stb_delete_rule(a_hAPI);
3947 case _EMAIL_API_APPLY_RULE:
3948 stb_apply_rule(a_hAPI);
3951 case _EMAIL_API_MOVE_MAIL:
3952 stb_move_mail(a_hAPI);
3955 case _EMAIL_API_MOVE_ALL_MAIL:
3956 stb_move_all_mails(a_hAPI);
3959 case _EMAIL_API_SET_FLAGS_FIELD:
3960 stb_set_flags_field(a_hAPI);
3963 case _EMAIL_API_ADD_MAIL:
3964 stb_add_mail(a_hAPI);
3967 case _EMAIL_API_UPDATE_MAIL:
3968 stb_update_mail(a_hAPI);
3971 case _EMAIL_API_MOVE_THREAD_TO_MAILBOX:
3972 stb_move_thread_to_mailbox(a_hAPI);
3975 case _EMAIL_API_DELETE_THREAD:
3976 stb_delete_thread(a_hAPI);
3979 case _EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD:
3980 stb_modify_seen_flag_of_thread(a_hAPI);
3983 case _EMAIL_API_EXPUNGE_MAILS_DELETED_FLAGGED:
3984 stb_expunge_mails_deleted_flagged(a_hAPI);
3987 case _EMAIL_API_DELETE_ACCOUNT:
3988 stb_delete_account(a_hAPI);
3991 case _EMAIL_API_UPDATE_ACCOUNT:
3992 stb_update_account(a_hAPI);
3995 case _EMAIL_API_ADD_ATTACHMENT:
3996 stb_add_attachment(a_hAPI);
3999 case _EMAIL_API_GET_IMAP_MAILBOX_LIST:
4000 stb_get_imap_mailbox_list(a_hAPI);
4003 case _EMAIL_API_GET_ATTACHMENT:
4004 stb_get_attachment(a_hAPI);
4007 case _EMAIL_API_DELETE_ATTACHMENT:
4008 stb_delete_attachment(a_hAPI);
4011 case _EMAIL_API_DOWNLOAD_ATTACHMENT:
4012 stb_download_attachment(a_hAPI);
4015 case _EMAIL_API_GET_ACCOUNT_LIST:
4016 stb_get_account_list(a_hAPI);
4019 case _EMAIL_API_SEND_SAVED:
4020 stb_mail_send_saved(a_hAPI);
4023 case _EMAIL_API_ADD_READ_RECEIPT:
4024 stb_add_read_receipt(a_hAPI);
4027 case _EMAIL_API_CANCEL_JOB:
4028 stb_cancel_job(a_hAPI);
4031 case _EMAIL_API_SEND_RETRY:
4032 stb_retry_sending_mail(a_hAPI);
4035 case _EMAIL_API_VALIDATE_ACCOUNT :
4036 stb_validate_account(a_hAPI);
4039 case _EMAIL_API_SEND_MAIL_CANCEL_JOB :
4040 stb_cancel_send_mail_job(a_hAPI);
4043 case _EMAIL_API_SEARCH_MAIL_ON_SERVER :
4044 stb_search_mail_on_server(a_hAPI);
4047 case _EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER :
4048 stb_clear_result_of_search_mail_on_server(a_hAPI);
4051 case _EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION :
4052 stb_add_account_with_validation(a_hAPI);
4055 case _EMAIL_API_BACKUP_ACCOUNTS:
4056 stb_backup_account(a_hAPI);
4059 case _EMAIL_API_RESTORE_ACCOUNTS:
4060 stb_restore_account(a_hAPI);
4063 case _EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT:
4064 stb_get_password_length(a_hAPI);
4067 case _EMAIL_API_GET_TASK_INFORMATION:
4068 stb_get_task_information(a_hAPI);
4071 case _EMAIL_API_ADD_CERTIFICATE:
4072 stb_add_certificate(a_hAPI);
4075 case _EMAIL_API_DELETE_CERTIFICATE:
4076 stb_delete_certificate(a_hAPI);
4079 case _EMAIL_API_VERIFY_SIGNATURE:
4080 stb_verify_signature(a_hAPI);
4083 case _EMAIL_API_VERIFY_CERTIFICATE:
4084 stb_verify_certificate(a_hAPI);
4087 case _EMAIL_API_PING_SERVICE :
4088 stb_ping_service(a_hAPI);
4091 case _EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL :
4092 stb_update_notification_bar_for_unread_mail(a_hAPI);
4095 case _EMAIL_API_CLEAR_NOTIFICATION_BAR :
4096 stb_clear_notification_bar(a_hAPI);
4099 case _EMAIL_API_SHOW_USER_MESSAGE :
4100 stb_show_user_message(a_hAPI);
4103 case _EMAIL_API_WRITE_MIME_FILE :
4104 stb_write_mime_file(a_hAPI);
4107 case _EMAIL_API_VALIDATE_ACCOUNT_EX :
4108 stb_validate_account_ex(a_hAPI);
4111 case EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT :
4112 stb_move_mails_to_mailbox_of_another_account(a_hAPI);
4115 case EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX :
4116 stb_delete_mailbox_ex(a_hAPI);
4119 case EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL :
4120 stb_send_mail_with_downloading_attachment_of_original_mail(a_hAPI);
4123 case _EMAIL_API_GET_USER_NAME :
4124 stb_get_user_name(a_hAPI);
4127 case _EMAIL_API_SAVE_DEFAULT_ACCOUNT_ID :
4128 stb_save_default_account_id(a_hAPI);
4131 case _EMAIL_API_LOAD_DEFAULT_ACCOUNT_ID :
4132 stb_load_default_account_id(a_hAPI);
4136 if(EMAIL_SYNC_TASK_BOUNDARY_START < nAPIID && nAPIID < EMAIL_ASYNC_TASK_BOUNDARY_END)
4137 stb_handle_task(nAPIID, a_hAPI);
4140 EM_DEBUG_FUNC_END();
4143 GMainLoop *g_mainloop = NULL;
4145 /* this func should be called in main_loop */
4146 INTERNAL_FUNC int kill_daemon_if_no_account()
4148 EM_DEBUG_FUNC_BEGIN();
4149 int err = EMAIL_ERROR_NONE;
4150 email_account_t *account_list = NULL;
4151 int account_count = 0;
4152 int total_account_count = 0;
4154 GList *zone_name_list = NULL;
4156 /* each container check the account */
4157 if ((err = emcore_get_zone_name_list(&zone_name_list)) != EMAIL_ERROR_NONE) {
4158 EM_DEBUG_EXCEPTION("emcore_get_zone_name_list failed : err[%d]", err);
4159 if (zone_name_list) g_list_free(zone_name_list);
4163 if (g_list_length(zone_name_list) == 1) {
4164 if ((err = emcore_get_account_reference_list(NULL, &account_list, &account_count)) != EMAIL_ERROR_NONE) {
4165 EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err);
4169 emcore_free_account_list(&account_list, account_count, NULL);
4171 total_account_count += account_count;
4173 node = g_list_first(zone_name_list);
4174 while (node != NULL) {
4176 node = g_list_next(node);
4180 if ((err = emcore_get_account_reference_list(node->data, &account_list, &account_count)) != EMAIL_ERROR_NONE) {
4181 EM_DEBUG_LOG("emcore_get_account_reference_list failed [%d]", err);
4185 emcore_free_account_list(&account_list, account_count, NULL);
4187 total_account_count += account_count;
4188 EM_SAFE_FREE(node->data);
4189 node = g_list_next(node);
4194 g_list_free(zone_name_list);
4196 EM_DEBUG_LOG("account_count [%d]", total_account_count);
4198 if (total_account_count == 0) {
4199 EM_DEBUG_LOG("email-service is going to shutdown");
4200 g_main_loop_quit (g_mainloop);
4205 EM_DEBUG_FUNC_END("err [%d]", err);
4209 static void callback_for_sigterm(int signum)
4211 EM_DEBUG_FUNC_BEGIN("signum [%d]", signum);
4214 g_main_loop_quit(g_mainloop);
4216 EM_DEBUG_FUNC_END();
4219 extern int launch_pid;
4221 gboolean callback_for_shutdown(gpointer user_data)
4223 EM_DEBUG_FUNC_BEGIN("user_data[%p]", user_data);
4225 if (launch_pid == 0) {
4226 kill_daemon_if_no_account();
4229 EM_DEBUG_FUNC_END();
4233 gboolean callback_for_del_account (GIOChannel *ch, GIOCondition cond, gpointer data)
4235 static int file_del = 0;
4236 static int db_del = 0;
4239 g_io_channel_read_chars (ch, (gchar*) &event, sizeof (event), &len, NULL);
4241 if (event==EMAIL_SIGNAL_DB_DELETED) {
4244 else if (event==EMAIL_SIGNAL_FILE_DELETED) {
4247 EM_DEBUG_LOG ("callback_for_del_account called file_del[%d] db_del[%d]", file_del, db_del);
4249 /* if called twice, process termination begins.
4250 two threads should complete the delete task */
4251 if (file_del && db_del) {
4252 kill_daemon_if_no_account();
4253 file_del = db_del = 0; /* if there is an account, reset status */
4258 /* gdbus variables */
4259 static GDBusNodeInfo *introspection_data = NULL;
4260 extern gchar introspection_xml[];
4263 handle_method_call (GDBusConnection *connection,
4264 const gchar *sender,
4265 const gchar *object_path,
4266 const gchar *interface_name,
4267 const gchar *method_name,
4268 GVariant *parameters,
4269 GDBusMethodInvocation *invocation,
4272 /* called by emipc_launch_email_service */
4273 if (g_strcmp0 (method_name, "Launch") == 0) {
4275 g_variant_get (parameters, "(i)", &caller_pid);
4277 launch_pid = caller_pid;
4278 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(i)", EMAIL_ERROR_NONE));
4279 EM_DEBUG_LOG ("email-service launched by pid [%d]", caller_pid);
4282 else if (g_strcmp0 (method_name, "SetContactsLog") == 0) {
4283 GVariant* ret = em_gdbus_set_contact_log(parameters);
4284 g_dbus_method_invocation_return_value (invocation, ret);
4286 else if (g_strcmp0 (method_name, "DeleteContactsLog") == 0) {
4287 GVariant* ret = em_gdbus_delete_contact_log(parameters);
4288 g_dbus_method_invocation_return_value (invocation, ret);
4291 else if (g_strcmp0 (method_name, "GetDisplayName") == 0) {
4292 GVariant* ret = em_gdbus_get_display_name(parameters);
4293 g_dbus_method_invocation_return_value (invocation, ret);
4295 else if (g_strcmp0 (method_name, "CheckBlockingMode") == 0) {
4296 GVariant* ret = em_gdbus_check_blocking_mode(parameters);
4297 g_dbus_method_invocation_return_value (invocation, ret);
4302 GDBusInterfaceVTable interface_vtable =
4310 on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
4312 EM_DEBUG_LOG ("on_bus_acquired begin");
4315 GError *error = NULL;
4317 reg_id = g_dbus_connection_register_object (connection,
4319 introspection_data->interfaces[0],
4321 NULL, /* user_data */
4322 NULL, /* user_data_free_func */
4323 &error); /* GError** */
4325 EM_DEBUG_EXCEPTION ("g_dbus_connection_register_object error[%s]",error->message);
4326 g_error_free (error);
4328 EM_DEBUG_LOG ("on_bus_acquired end [%d]", reg_id);
4331 static void on_name_acquired (GDBusConnection *connection,
4335 EM_DEBUG_LOG ("on_name_acquired [%s]", name);
4338 static void on_name_lost (GDBusConnection *connection,
4342 EM_DEBUG_EXCEPTION ("on_name_lost [%p] [%s]", connection, name);
4345 INTERNAL_FUNC int main(int argc, char *argv[])
4347 /* Do the email-service Initialization
4348 1. Create all DB tables and load the email engine */
4349 EM_DEBUG_LOG("Email service begin");
4351 GMainLoop *mainloop = NULL;
4354 GList *zone_name_list = NULL;
4356 #if !GLIB_CHECK_VERSION(2, 36, 0)
4360 /* Init container for daemon */
4361 emcore_create_container();
4363 EM_DEBUG_LOG("ipcEmailStub_Initialize Start");
4365 ret = emipc_initialize_stub(stb_API_mapper);
4368 EM_DEBUG_LOG("ipcEmailStub_Initialize Success");
4370 EM_DEBUG_EXCEPTION("ipcEmailStub_Initialize failed");
4372 signal(SIGPIPE, SIG_IGN); /* to ignore signal 13(SIGPIPE) */
4373 signal(SIGTERM, callback_for_sigterm); /* to handle signal 15(SIGTERM) - power off case*/
4375 emcore_gmime_init();
4377 /* each container initialize */
4378 if ((err = emcore_get_zone_name_list(&zone_name_list)) != EMAIL_ERROR_NONE) {
4379 EM_DEBUG_EXCEPTION("emcore_get_zone_name_list failed : err[%d]", err);
4380 if (zone_name_list) g_list_free(zone_name_list);
4384 if (g_list_length(zone_name_list) <= 1) {
4385 emdaemon_initialize(NULL, &err);
4386 emcore_connect_contacts_service(NULL);
4388 node = g_list_first(zone_name_list);
4389 while (node != NULL) {
4391 node = g_list_next(node);
4393 emdaemon_initialize(node->data, &err);
4394 emcore_connect_contacts_service(node->data);
4396 EM_SAFE_FREE(node->data);
4397 node = g_list_next(node);
4402 g_list_free(zone_name_list);
4404 g_timeout_add(5000, callback_for_shutdown, NULL);
4406 /* pipe between main and del account thread */
4407 int *pipefd = emcore_init_pipe_for_del_account ();
4408 /* main loop uses IO channel for listening an event */
4410 GIOChannel *ch = g_io_channel_unix_new (pipefd[0]);
4411 EM_DEBUG_LOG ("main pipe[%d][%d]", pipefd[0], pipefd[1]);
4412 /* non-blocking mode */
4413 g_io_channel_set_flags (ch, g_io_channel_get_flags (ch) | G_IO_FLAG_NONBLOCK, NULL);
4414 /* main loop watches the IO, and call the cb when data is ready */
4415 g_io_add_watch (ch, G_IO_IN, &callback_for_del_account, NULL);
4419 GError *error = NULL;
4420 introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
4421 if (!introspection_data) {
4422 /* introspection_xml may be invalid */
4423 EM_DEBUG_EXCEPTION ("g_dbus_node_info_new_for_xml error [%s]", error->message);
4424 g_error_free (error);
4427 owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
4429 G_BUS_NAME_OWNER_FLAGS_NONE,
4436 EM_DEBUG_EXCEPTION ("g_bus_own_name error");
4438 EM_DEBUG_LOG ("owner_id [%d]", owner_id);
4440 mainloop = g_main_loop_new(NULL, 0);
4441 g_mainloop = mainloop;
4443 g_main_loop_run(mainloop);
4445 /* Clean up resources */
4446 g_bus_unown_name (owner_id);
4447 g_main_loop_unref(mainloop);
4452 emipc_finalize_stub();
4453 emdaemon_finalize(NULL);
4454 emcore_gmime_shutdown();
4456 EM_DEBUG_LOG ("Goodbye, world");
4457 EM_DEBUG_FUNC_END();
4458 exit(44); /* exit with exit code 44 to prevent restarting */