2.0_alpha release commit
[framework/messaging/email-service.git] / email-api / email-api-etc.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2000 - 2011 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  * This file contains the data structures and interfaces needed for application,
26  * to interact with email-service.
27  * @file                email-api-etc.c
28  * @brief               This file contains the data structures and interfaces of functionalities provided by email-service .
29  */
30
31 #include "email-api.h"
32 #include "email-types.h"
33 #include "email-ipc.h"
34 #include "email-debug-log.h"
35 #include "email-core-utils.h"
36 #include "email-core-mime.h"
37
38 EXPORT_API int email_show_user_message(int id, email_action_t action, int error_code)
39 {
40         EM_DEBUG_FUNC_BEGIN("id [%d], action [%d], error_code [%d]", id, action, error_code);
41         int err = EMAIL_ERROR_NONE;
42
43         if(id < 0 || action < 0) {
44                 EM_DEBUG_LOG("EMAIL_ERROR_INVALID_PARAM");
45                 return EMAIL_ERROR_INVALID_PARAM;
46         }
47
48         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SHOW_USER_MESSAGE);
49
50         /* id */
51         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&id, sizeof(int))) {
52                 EM_DEBUG_LOG("emipc_add_parameter failed  ");
53                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
54         }
55
56         /* action */
57         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&action, sizeof(int))) {
58                 EM_DEBUG_LOG("emipc_add_parameter failed  ");
59                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
60         }
61
62         /* error_code */
63         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&error_code, sizeof(int))) {
64                 EM_DEBUG_LOG("emipc_add_parameter failed  ");
65                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
66         }
67
68         if(!emipc_execute_proxy_api(hAPI))  {
69                 EM_DEBUG_LOG("ipcProxy_ExecuteAsyncAPI failed");
70                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
71         }
72
73         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
74
75         emipc_destroy_email_api(hAPI);
76         hAPI = NULL;
77
78         EM_DEBUG_FUNC_END("err [%d]", err);
79         return err;
80 }
81
82 EXPORT_API int email_open_eml_file(char *eml_file_path, email_mail_data_t **output_mail_data, email_attachment_data_t **output_attachment_data, int *output_attachment_count)
83 {
84         EM_DEBUG_FUNC_BEGIN("eml_file_path : [%s], output_mail_data : [%p], output_attachment_data : [%p]", eml_file_path, output_mail_data, output_attachment_data);
85         int err = EMAIL_ERROR_NONE;
86
87         EM_IF_NULL_RETURN_VALUE(eml_file_path, EMAIL_ERROR_INVALID_PARAM);
88
89         if (!emcore_load_eml_file_to_mail(eml_file_path, output_mail_data, output_attachment_data, output_attachment_count, &err) || !*output_mail_data)
90                 EM_DEBUG_EXCEPTION("emcore_load_eml_file_to_mail_data failed [%d]", err);
91
92         EM_DEBUG_FUNC_END("err [%d]", err);
93         return err;
94 }
95
96 EXPORT_API int email_delete_eml_data(email_mail_data_t *input_mail_data)
97 {
98         EM_DEBUG_FUNC_BEGIN("mail_data : [%p]", input_mail_data);
99         int err = EMAIL_ERROR_NONE;
100
101         EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM);
102
103         if (!emcore_delete_eml_data(input_mail_data, &err))
104                 EM_DEBUG_EXCEPTION("emcore_load_eml_file_to_mail_data failed [%d]", err);
105
106         EM_DEBUG_FUNC_END("err [%d]", err);
107         return err;
108 }
109
110 EXPORT_API int email_get_mime_entity(char *mime_path, char **mime_entity)
111 {
112         EM_DEBUG_FUNC_BEGIN("mime_path : [%s]", mime_path);
113         int err = EMAIL_ERROR_NONE;
114
115         EM_IF_NULL_RETURN_VALUE(mime_path, EMAIL_ERROR_INVALID_PARAM);
116
117         if (!emcore_get_mime_entity(mime_path, mime_entity, &err)) 
118                 EM_DEBUG_EXCEPTION("emcore_get_mime_entity failed [%d]", err);
119
120         EM_DEBUG_FUNC_END();
121         return err;
122 }