fix ABI Issue
[platform/core/messaging/email-service.git] / email-api / email-api-smime.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7 *
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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.
19 *
20 */
21
22
23
24 /**
25  *
26  * This file contains the data structures and interfaces needed for application,
27  * to interact with Email Engine.
28  * @file                email-api-smime.c
29  * @brief               This file contains the data structures and interfaces of SMIME related Functionality provided by
30  *                      Email Engine .
31  */
32
33 #include "string.h"
34 #include "email-api-mail.h"
35 #include "email-convert.h"
36 #include "email-api-account.h"
37 #include "email-storage.h"
38 #include "email-utilities.h"
39 #include "email-core-mail.h"
40 #include "email-core-mime.h"
41 #include "email-core-account.h"
42 #include "email-core-cert.h"
43 #include "email-core-smime.h"
44 #include "email-core-pgp.h"
45 #include "email-core-signal.h"
46 #include "email-ipc.h"
47
48 EXPORT_API int email_add_certificate(char *certificate_path, char *email_address)
49 {
50         EM_DEBUG_API_BEGIN("");
51         return EMAIL_ERROR_NOT_SUPPORTED;
52 }
53
54 EXPORT_API int email_delete_certificate(char *email_address)
55 {
56         EM_DEBUG_API_BEGIN("");
57         return EMAIL_ERROR_NOT_SUPPORTED;
58 }
59
60 EXPORT_API int email_get_certificate(char *email_address, email_certificate_t **certificate)
61 {
62         EM_DEBUG_API_BEGIN("");
63         return EMAIL_ERROR_NOT_SUPPORTED;
64 }
65
66 EXPORT_API int email_verify_certificate(char *certificate_path, int *verify)
67 {
68         EM_DEBUG_API_BEGIN("");
69         return EMAIL_ERROR_NOT_SUPPORTED;
70 }
71
72 EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output_mail_data,
73                                                                                 email_attachment_data_t **output_attachment_data,
74                                                                                 int *output_attachment_count, int *verify)
75 {
76         EM_DEBUG_API_BEGIN("mail_id[%d]", mail_id);
77         int err = EMAIL_ERROR_NONE;
78         int p_output_attachment_count = 0;
79     int i = 0;
80         char *decrypt_filepath = NULL;
81     char *search = NULL;
82     char *multi_user_name = NULL;
83         email_mail_data_t *p_output_mail_data = NULL;
84         email_attachment_data_t *p_output_attachment_data = NULL;
85         emstorage_account_tbl_t *p_account_tbl = NULL;
86
87         EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM);
88
89         if (!output_mail_data || !output_attachment_data || !output_attachment_count) {
90                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
91                 err = EMAIL_ERROR_INVALID_PARAM;
92                 goto FINISH_OFF;
93         }
94
95     if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
96         EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]");
97         goto FINISH_OFF;
98     }
99
100         if ((err = emcore_get_mail_data(multi_user_name, mail_id, &p_output_mail_data)) != EMAIL_ERROR_NONE) {
101                 EM_DEBUG_EXCEPTION("emcore_get_mail_data failed");
102                 goto FINISH_OFF;
103         }
104
105         if (!emstorage_get_account_by_id(multi_user_name, p_output_mail_data->account_id, EMAIL_ACC_GET_OPT_OPTIONS, &p_account_tbl, false, &err)) {
106                 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed : [%d]", err);
107                 goto FINISH_OFF;
108         }
109
110         if ((err = emcore_get_attachment_data_list(multi_user_name, mail_id, &p_output_attachment_data, &p_output_attachment_count)) != EMAIL_ERROR_NONE) {
111                 EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed");
112                 goto FINISH_OFF;
113         }
114
115         for (i = 0; i < p_output_attachment_count; i++) {
116                 EM_DEBUG_LOG("mime_type : [%s]", p_output_attachment_data[i].attachment_mime_type);
117                 if (p_output_attachment_data[i].attachment_mime_type && (search = strcasestr(p_output_attachment_data[i].attachment_mime_type, "PKCS7-MIME"))) {
118                         EM_DEBUG_LOG("Found the encrypt file");
119                         break;
120                 } else if (p_output_attachment_data[i].attachment_mime_type && (search = strcasestr(p_output_attachment_data[i].attachment_mime_type, "octet-stream"))) {
121                         EM_DEBUG_LOG("Found the encrypt file");
122                         break;
123                 }
124         }
125
126         if (!search) {
127                 EM_DEBUG_EXCEPTION("No have a decrypt file");
128                 err = EMAIL_ERROR_INVALID_PARAM;
129                 goto FINISH_OFF;
130         }
131
132         if (p_output_mail_data->smime_type == EMAIL_SMIME_ENCRYPTED || p_output_mail_data->smime_type == EMAIL_SMIME_SIGNED_AND_ENCRYPTED) {
133                 emcore_init_openssl_library();
134                 if (!emcore_smime_get_decrypt_message(p_output_attachment_data[i].attachment_path, p_account_tbl->certificate_path, &decrypt_filepath, &err)) {
135                         EM_DEBUG_EXCEPTION("emcore_smime_get_decrypt_message failed");
136                         emcore_clean_openssl_library();
137                         goto FINISH_OFF;
138                 }
139                 emcore_clean_openssl_library();
140         } else if (p_output_mail_data->smime_type == EMAIL_PGP_ENCRYPTED) {
141                 if ((err = emcore_pgp_get_decrypted_message(p_output_attachment_data[i].attachment_path, p_output_mail_data->pgp_password, false, &decrypt_filepath, verify)) != EMAIL_ERROR_NONE) {
142                         EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err);
143                         goto FINISH_OFF;
144                 }
145         } else if (p_output_mail_data->smime_type == EMAIL_PGP_SIGNED_AND_ENCRYPTED) {
146                 if ((err = emcore_pgp_get_decrypted_message(p_output_attachment_data[i].attachment_path, p_output_mail_data->pgp_password, true, &decrypt_filepath, verify)) != EMAIL_ERROR_NONE) {
147                         EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err);
148                         goto FINISH_OFF;
149                 }
150         } else {
151                 EM_DEBUG_LOG("Invalid encrypted mail");
152                 err = EMAIL_ERROR_INVALID_PARAM;
153                 goto FINISH_OFF;
154         }
155
156         /* Change decrpyt_message to mail_data_t */
157         if (!emcore_parse_mime_file_to_mail(decrypt_filepath, output_mail_data, output_attachment_data, output_attachment_count, &err)) {
158                 EM_DEBUG_EXCEPTION("emcore_parse_mime_file_to_mail failed : [%d]", err);
159                 goto FINISH_OFF;
160         }
161
162         (*output_mail_data)->subject                 = EM_SAFE_STRDUP(p_output_mail_data->subject);
163         (*output_mail_data)->date_time               = p_output_mail_data->date_time;
164         (*output_mail_data)->full_address_return     = EM_SAFE_STRDUP(p_output_mail_data->full_address_return);
165         (*output_mail_data)->email_address_recipient = EM_SAFE_STRDUP(p_output_mail_data->email_address_recipient);
166         (*output_mail_data)->email_address_sender    = EM_SAFE_STRDUP(p_output_mail_data->email_address_sender);
167         (*output_mail_data)->full_address_reply      = EM_SAFE_STRDUP(p_output_mail_data->full_address_reply);
168         (*output_mail_data)->full_address_from       = EM_SAFE_STRDUP(p_output_mail_data->full_address_from);
169         (*output_mail_data)->full_address_to         = EM_SAFE_STRDUP(p_output_mail_data->full_address_to);
170         (*output_mail_data)->full_address_cc         = EM_SAFE_STRDUP(p_output_mail_data->full_address_cc);
171         (*output_mail_data)->full_address_bcc        = EM_SAFE_STRDUP(p_output_mail_data->full_address_bcc);
172         (*output_mail_data)->flags_flagged_field     = p_output_mail_data->flags_flagged_field;
173
174 FINISH_OFF:
175
176     EM_SAFE_FREE(decrypt_filepath);
177
178         if (p_account_tbl)
179                 emstorage_free_account(&p_account_tbl, 1, NULL);
180
181         if (p_output_mail_data)
182                 email_free_mail_data(&p_output_mail_data, 1);
183
184         if (p_output_attachment_data)
185                 email_free_attachment_data(&p_output_attachment_data, p_output_attachment_count);
186
187     EM_SAFE_FREE(multi_user_name);
188
189         EM_DEBUG_API_END("err[%d]", err);
190         return err;
191 }
192
193 EXPORT_API int email_get_decrypt_message_ex(email_mail_data_t *input_mail_data,
194                                                                                         email_attachment_data_t *input_attachment_data,
195                                                                                         int input_attachment_count,
196                                             email_mail_data_t **output_mail_data,
197                                                                                         email_attachment_data_t **output_attachment_data,
198                                                                                         int *output_attachment_count,
199                                                                                         int *verify)
200 {
201         EM_DEBUG_API_BEGIN();
202         int err = EMAIL_ERROR_NONE;
203     int i = 0;
204         char *decrypt_filepath = NULL;
205     char *search = NULL;
206     char *multi_user_name = NULL;
207         emstorage_account_tbl_t *p_account_tbl = NULL;
208
209         EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM);
210
211         if (!output_mail_data || !output_attachment_data || !output_attachment_count) {
212                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
213                 err = EMAIL_ERROR_INVALID_PARAM;
214                 goto FINISH_OFF;
215         }
216
217     if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
218         EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
219         goto FINISH_OFF;
220     }
221
222         if (!emstorage_get_account_by_id(multi_user_name, input_mail_data->account_id, EMAIL_ACC_GET_OPT_OPTIONS, &p_account_tbl, false, &err)) {
223                 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed : [%d]", err);
224                 goto FINISH_OFF;
225         }
226
227         for (i = 0; i < input_attachment_count; i++) {
228                 EM_DEBUG_LOG("mime_type : [%s]", input_attachment_data[i].attachment_mime_type);
229                 if (input_attachment_data[i].attachment_mime_type && (search = strcasestr(input_attachment_data[i].attachment_mime_type, "PKCS7-MIME"))) {
230                         EM_DEBUG_LOG("Found the encrypt file");
231                         break;
232                 } else if (input_attachment_data[i].attachment_mime_type && (search = strcasestr(input_attachment_data[i].attachment_mime_type, "octet-stream"))) {
233                         EM_DEBUG_LOG("Found the encrypt file");
234                         break;
235                 }
236         }
237
238         if (!search) {
239                 EM_DEBUG_EXCEPTION("No have a decrypt file");
240                 err = EMAIL_ERROR_INVALID_PARAM;
241                 goto FINISH_OFF;
242         }
243
244         if (input_mail_data->smime_type == EMAIL_SMIME_ENCRYPTED || input_mail_data->smime_type == EMAIL_SMIME_SIGNED_AND_ENCRYPTED) {
245                 emcore_init_openssl_library();
246                 if (!emcore_smime_get_decrypt_message(input_attachment_data[i].attachment_path, p_account_tbl->certificate_path, &decrypt_filepath, &err)) {
247                         EM_DEBUG_EXCEPTION("emcore_smime_get_decrypt_message failed");
248                         emcore_clean_openssl_library();
249                         goto FINISH_OFF;
250                 }
251                 emcore_clean_openssl_library();
252         } else if (input_mail_data->smime_type == EMAIL_PGP_ENCRYPTED) {
253                 if ((err = emcore_pgp_get_decrypted_message(input_attachment_data[i].attachment_path, input_mail_data->pgp_password, false, &decrypt_filepath, verify)) != EMAIL_ERROR_NONE) {
254                         EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err);
255                         goto FINISH_OFF;
256                 }
257         } else if (input_mail_data->smime_type == EMAIL_PGP_SIGNED_AND_ENCRYPTED) {
258                 if ((err = emcore_pgp_get_decrypted_message(input_attachment_data[i].attachment_path, input_mail_data->pgp_password, true, &decrypt_filepath, verify)) != EMAIL_ERROR_NONE) {
259                         EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err);
260                         goto FINISH_OFF;
261                 }
262         } else {
263                 EM_DEBUG_LOG("Invalid encrypted mail");
264                 err = EMAIL_ERROR_INVALID_PARAM;
265                 goto FINISH_OFF;
266         }
267
268         /* Change decrpyt_message to mail_data_t */
269         if (!emcore_parse_mime_file_to_mail(decrypt_filepath, output_mail_data, output_attachment_data, output_attachment_count, &err)) {
270                 EM_DEBUG_EXCEPTION("emcore_parse_mime_file_to_mail failed : [%d]", err);
271                 goto FINISH_OFF;
272         }
273
274         (*output_mail_data)->subject                 = EM_SAFE_STRDUP(input_mail_data->subject);
275         (*output_mail_data)->date_time               = input_mail_data->date_time;
276         (*output_mail_data)->full_address_return     = EM_SAFE_STRDUP(input_mail_data->full_address_return);
277         (*output_mail_data)->email_address_recipient = EM_SAFE_STRDUP(input_mail_data->email_address_recipient);
278         (*output_mail_data)->email_address_sender    = EM_SAFE_STRDUP(input_mail_data->email_address_sender);
279         (*output_mail_data)->full_address_reply      = EM_SAFE_STRDUP(input_mail_data->full_address_reply);
280         (*output_mail_data)->full_address_from       = EM_SAFE_STRDUP(input_mail_data->full_address_from);
281         (*output_mail_data)->full_address_to         = EM_SAFE_STRDUP(input_mail_data->full_address_to);
282         (*output_mail_data)->full_address_cc         = EM_SAFE_STRDUP(input_mail_data->full_address_cc);
283         (*output_mail_data)->full_address_bcc        = EM_SAFE_STRDUP(input_mail_data->full_address_bcc);
284         (*output_mail_data)->flags_flagged_field     = input_mail_data->flags_flagged_field;
285
286 FINISH_OFF:
287
288     EM_SAFE_FREE(decrypt_filepath);
289     EM_SAFE_FREE(multi_user_name);
290
291         if (p_account_tbl)
292                 emstorage_free_account(&p_account_tbl, 1, NULL);
293
294         EM_DEBUG_API_END("err[%d]", err);
295         return err;
296 }
297
298 EXPORT_API int email_verify_signature(int mail_id, int *verify)
299 {
300         EM_DEBUG_API_BEGIN("mail_id[%d]", mail_id);
301
302         if (mail_id <= 0) {
303                 EM_DEBUG_EXCEPTION("Invalid parameter");
304                 return EMAIL_ERROR_INVALID_PARAM;
305         }
306
307         int result_from_ipc = 0;
308         int p_verify = 0;
309         int err = EMAIL_ERROR_NONE;
310
311         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_VERIFY_SIGNATURE);
312         if (hAPI == NULL) {
313                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
314                 err = EMAIL_ERROR_NULL_VALUE;
315                 goto FINISH_OFF;
316         }
317
318         if (!emipc_add_parameter(hAPI, ePARAMETER_IN, &mail_id, sizeof(int))) {
319                 EM_DEBUG_EXCEPTION("emipc_add_parameter pass_phrase[%d] failed", mail_id);
320                 err = EMAIL_ERROR_NULL_VALUE;
321                 goto FINISH_OFF;
322         }
323
324         if (emipc_execute_proxy_api(hAPI) < 0) {
325                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
326                 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
327                 goto FINISH_OFF;
328         }
329
330         result_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &p_verify);
331         if (result_from_ipc != EMAIL_ERROR_NONE) {
332                 EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
333                 err = EMAIL_ERROR_IPC_CRASH;
334                 goto FINISH_OFF;
335         }
336
337 FINISH_OFF:
338
339         if (hAPI)
340                 emipc_destroy_email_api(hAPI);
341
342         if (verify != NULL)
343                 *verify = p_verify;
344
345         EM_DEBUG_API_END("err[%d]", err);
346         return err;
347 }
348
349 EXPORT_API int email_verify_signature_ex(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data, int input_attachment_count, int *verify)
350 {
351         EM_DEBUG_API_BEGIN();
352
353         if (!input_mail_data || !input_attachment_data || input_attachment_count <= 0) {
354                 EM_DEBUG_EXCEPTION("Invalid parameter");
355                 return EMAIL_ERROR_INVALID_PARAM;
356         }
357
358         int count = 0;
359         int err = EMAIL_ERROR_NONE;
360
361         for (count = 0; count < input_attachment_count ; count++) {
362                 if (input_attachment_data[count].attachment_mime_type && strcasestr(input_attachment_data[count].attachment_mime_type, "SIGNATURE"))
363                         break;
364         }
365
366         if (count == input_attachment_count) {
367                 EM_DEBUG_LOG("No have the signed attachment");
368                 EM_DEBUG_EXCEPTION("Invalid parameter");
369                 return EMAIL_ERROR_INVALID_PARAM;
370         }
371
372         if (input_mail_data->smime_type == EMAIL_SMIME_SIGNED) {
373                 emcore_init_openssl_library();
374                 if (!emcore_verify_signature(input_attachment_data[count].attachment_path, input_mail_data->file_path_mime_entity, verify, &err))
375                         EM_DEBUG_EXCEPTION("emcore_verify_signature failed : [%d]", err);
376
377                 emcore_clean_openssl_library();
378         } else if (input_mail_data->smime_type == EMAIL_PGP_SIGNED) {
379                 if ((err = emcore_pgp_get_verify_signature(input_attachment_data[count].attachment_path, input_mail_data->file_path_mime_entity, input_mail_data->digest_type, verify)) != EMAIL_ERROR_NONE)
380                         EM_DEBUG_EXCEPTION("emcore_pgp_get_verify_siganture failed : [%d]", err);
381         } else {
382                 EM_DEBUG_LOG("Invalid signed mail : mime_type[%d]", input_mail_data->smime_type);
383                 err = EMAIL_ERROR_INVALID_PARAM;
384         }
385
386
387         EM_DEBUG_API_END("err[%d]", err);
388         return err;
389 }
390
391 /*
392 EXPORT_API int email_check_ocsp_status(char *email_address, char *response_url, unsigned *handle)
393 {
394         EM_DEBUG_FUNC_BEGIN_SEC("email_address : [%s], response_url : [%s], handle : [%p]", email_address, response_url, handle);
395
396         EM_IF_NULL_RETURN_VALUE(email_address, EMAIL_ERROR_INVALID_PARAM);
397
398         int err = EMAIL_ERROR_NONE;
399         HIPC_API hAPI = NULL;
400
401         hAPI = emipc_create_email_api(_EMAIL_API_CHECK_OCSP_STATUS);
402
403         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
404
405         if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, EM_SAFE_STRLEN(email_address)+1)) {
406                 EM_DEBUG_EXCEPTION("email_check_ocsp_status--ADD Param email_address failed");
407                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
408         }
409
410         if (!emipc_add_parameter(hAPI, ePARAMETER_IN, response_url, EM_SAFE_STRLEN(response_url)+1)) {
411                 EM_DEBUG_EXCEPTION("email_check_ocsp_status--ADD Param response_url failed");
412                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
413         }
414
415         if (emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
416                 EM_DEBUG_EXCEPTION("email_check_oscp_status--emipc_execute_proxy_api failed");
417                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
418         }
419
420         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
421         if (err == EMAIL_ERROR_NONE) {
422                 if (handle)
423                         emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
424         }
425 }
426 */
427 EXPORT_API int email_validate_certificate(int account_id, char *email_address, unsigned *handle)
428 {
429         EM_DEBUG_API_BEGIN("account_id[%d]", account_id);
430         EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d] email_address[%s] handle[%p]", account_id, email_address, handle);
431
432         EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM);
433         EM_IF_NULL_RETURN_VALUE(email_address, EMAIL_ERROR_INVALID_PARAM);
434
435         int err = EMAIL_ERROR_NONE;
436         int as_handle = 0;
437     char *multi_user_name = NULL;
438         email_account_server_t account_server_type;
439         ASNotiData as_noti_data;
440
441     if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
442         EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
443         goto FINISH_OFF;
444     }
445
446         memset(&as_noti_data, 0x00, sizeof(ASNotiData));
447
448         if (em_get_account_server_type_by_account_id(multi_user_name, account_id, &account_server_type, false, &err) == false) {
449                 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
450                 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
451                 goto FINISH_OFF;
452         }
453
454         if (account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
455                 EM_DEBUG_EXCEPTION("This api is not supported except of active sync");
456                 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
457                 goto FINISH_OFF;
458         }
459
460         if (em_get_handle_for_activesync(&as_handle, &err) == false) {
461                 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync_failed[%d]", err);
462                 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
463                 goto FINISH_OFF;
464         }
465
466         as_noti_data.validate_certificate.handle = as_handle;
467         as_noti_data.validate_certificate.account_id = account_id;
468         as_noti_data.validate_certificate.email_address = email_address;
469     as_noti_data.validate_certificate.multi_user_name = multi_user_name;
470
471         if (em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_VALIDATE_CERTIFICATE, &as_noti_data) == false) {
472                 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed");
473                 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
474                 goto FINISH_OFF;
475         }
476
477         if (handle)
478                 *handle = as_handle;
479
480 FINISH_OFF:
481
482     EM_SAFE_FREE(multi_user_name);
483         EM_DEBUG_API_END("err[%d]", err);
484         return err;
485 }
486
487 EXPORT_API int email_get_resolve_recipients(int account_id, char *email_address, unsigned *handle)
488 {
489         EM_DEBUG_API_BEGIN("account_id[%d]", account_id);
490         EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d] email_address[%s] handle[%p]", account_id, email_address, handle);
491
492         EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM);
493         EM_IF_NULL_RETURN_VALUE(email_address, EMAIL_ERROR_INVALID_PARAM);
494
495         int err = EMAIL_ERROR_NONE;
496         int as_handle = 0;
497     char *multi_user_name = NULL;
498         email_account_server_t account_server_type;
499         ASNotiData as_noti_data;
500
501     if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
502         EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
503         goto FINISH_OFF;
504     }
505
506         memset(&as_noti_data, 0x00, sizeof(ASNotiData));
507
508         if (em_get_account_server_type_by_account_id(multi_user_name, account_id, &account_server_type, false, &err) == false) {
509                 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
510                 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
511                 goto FINISH_OFF;
512         }
513
514         if (account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
515                 EM_DEBUG_EXCEPTION("This api is not supported except of active sync");
516                 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
517                 goto FINISH_OFF;
518         }
519
520         if (em_get_handle_for_activesync(&as_handle, &err) == false) {
521                 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync_failed[%d]", err);
522                 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
523                 goto FINISH_OFF;
524         }
525
526         as_noti_data.get_resolve_recipients.handle          = as_handle;
527         as_noti_data.get_resolve_recipients.account_id      = account_id;
528         as_noti_data.get_resolve_recipients.email_address   = email_address;
529     as_noti_data.get_resolve_recipients.multi_user_name = multi_user_name;
530
531         if (em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_RESOLVE_RECIPIENT, &as_noti_data) == false) {
532                 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed");
533                 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
534                 goto FINISH_OFF;
535         }
536
537         if (handle)
538                 *handle = as_handle;
539
540 FINISH_OFF:
541
542     EM_SAFE_FREE(multi_user_name);
543         EM_DEBUG_API_END("err[%d]", err);
544         return err;
545 }
546
547 EXPORT_API int email_free_certificate(email_certificate_t **certificate, int count)
548 {
549         EM_DEBUG_API_BEGIN("");
550         return EMAIL_ERROR_NOT_SUPPORTED;
551 }
552
553