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.
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 .
31 #include "email-types.h"
32 #include "email-ipc.h"
33 #include "email-debug-log.h"
34 #include "email-core-utils.h"
35 #include "email-core-smtp.h"
36 #include "email-core-mime.h"
37 #include "email-convert.h"
38 #include "email-utilities.h"
39 #include "email-core-gmime.h"
41 EXPORT_API int email_show_user_message(int id, email_action_t action, int error_code)
43 EM_DEBUG_API_BEGIN("id[%d] action[%d] error_code[%d]", id, action, error_code);
44 int err = EMAIL_ERROR_NONE;
46 if (id < 0 || action < 0) {
47 EM_DEBUG_LOG("EMAIL_ERROR_INVALID_PARAM");
48 return EMAIL_ERROR_INVALID_PARAM;
51 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SHOW_USER_MESSAGE);
54 if (!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&id, sizeof(int))) {
55 EM_DEBUG_LOG("emipc_add_parameter failed ");
56 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
60 if (!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&action, sizeof(int))) {
61 EM_DEBUG_LOG("emipc_add_parameter failed ");
62 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
66 if (!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&error_code, sizeof(int))) {
67 EM_DEBUG_LOG("emipc_add_parameter failed ");
68 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
71 if (!emipc_execute_proxy_api(hAPI)) {
72 EM_DEBUG_LOG("ipcProxy_ExecuteAsyncAPI failed");
73 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
76 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
78 emipc_destroy_email_api(hAPI);
81 EM_DEBUG_API_END("err[%d]", err);
85 EXPORT_API int email_parse_mime_file(char *eml_file_path, email_mail_data_t **output_mail_data,
86 email_attachment_data_t **output_attachment_data, int *output_attachment_count)
88 EM_DEBUG_API_BEGIN("eml_file_path[%p] output_mail_data[%p] output_attachment_data[%p]",
89 eml_file_path, output_mail_data, output_attachment_data);
90 int err = EMAIL_ERROR_NONE;
92 EM_IF_NULL_RETURN_VALUE(eml_file_path, EMAIL_ERROR_INVALID_PARAM);
94 if (!emcore_parse_mime_file_to_mail(eml_file_path, output_mail_data, output_attachment_data,
95 output_attachment_count, &err) || !*output_mail_data)
96 EM_DEBUG_EXCEPTION("emcore_parse_mime_file_to_mail failed [%d]", err);
98 EM_DEBUG_API_END("err[%d]", err);
102 EXPORT_API int email_write_mime_file(email_mail_data_t *input_mail_data,
103 email_attachment_data_t *input_attachment_data,
104 int input_attachment_count, char **output_file_path)
106 EM_DEBUG_API_BEGIN("input_mail_data[%p] input_attachment_data[%p] input_attachment_count[%d]",
107 input_mail_data, input_attachment_data, input_attachment_count);
109 int err = EMAIL_ERROR_NONE;
110 int ret_from_ipc = EMAIL_ERROR_NONE;
111 HIPC_API hAPI = NULL;
113 EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM);
114 EM_IF_NULL_RETURN_VALUE(output_file_path, EMAIL_ERROR_INVALID_PARAM);
116 hAPI = emipc_create_email_api(_EMAIL_API_WRITE_MIME_FILE);
118 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
119 err = EMAIL_ERROR_NULL_VALUE;
123 if (!emipc_execute_proxy_api(hAPI)) {
124 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
125 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
130 if ((ret_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err)) != EMAIL_ERROR_NONE) {
131 EM_DEBUG_EXCEPTION("emipc_get_parameter failed:[%d]", ret_from_ipc);
136 if (!emcore_make_rfc822_file(NULL, input_mail_data, input_attachment_data, input_attachment_count, false,
137 output_file_path, &err)) {
138 EM_DEBUG_EXCEPTION("emcore_make_rfc822_file failed : [%d]", err);
144 emipc_destroy_email_api(hAPI);
146 EM_DEBUG_API_END("err[%d]", err);
150 EXPORT_API int email_delete_parsed_data(email_mail_data_t *input_mail_data)
152 EM_DEBUG_API_BEGIN("mail_data[%p]", input_mail_data);
153 int err = EMAIL_ERROR_NONE;
154 char *multi_user_name = NULL;
156 EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM);
158 if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
159 EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
163 if (!emcore_delete_parsed_data(multi_user_name, input_mail_data, &err))
164 EM_DEBUG_EXCEPTION("emcore_delete_parsed_data failed [%d]", err);
166 EM_SAFE_FREE(multi_user_name);
168 EM_DEBUG_API_END("err[%d]", err);
172 EXPORT_API int email_get_mime_entity(char *mime_path, char **mime_entity)
174 EM_DEBUG_API_BEGIN("mime_path[%p]", mime_path);
175 int err = EMAIL_ERROR_NONE;
177 EM_IF_NULL_RETURN_VALUE(mime_path, EMAIL_ERROR_INVALID_PARAM);
179 if (!emcore_get_mime_entity(mime_path, mime_entity, &err))
180 EM_DEBUG_EXCEPTION("emcore_get_mime_entity failed [%d]", err);
186 EXPORT_API int email_verify_email_address(char *input_email_address)
188 EM_DEBUG_API_BEGIN("input_email_address[%p]", input_email_address);
189 int err = EMAIL_ERROR_NONE;
191 EM_IF_NULL_RETURN_VALUE(input_email_address, EMAIL_ERROR_INVALID_PARAM);
193 if ((err = em_verify_email_address(input_email_address)) != EMAIL_ERROR_NONE)
194 EM_DEBUG_EXCEPTION("em_verify_email_address failed [%d]", err);
196 EM_DEBUG_API_END("err [%d]", err);
200 EXPORT_API int email_convert_mutf7_to_utf8(const char *mutf7_str, char **utf8_str)
202 EM_DEBUG_API_BEGIN("mutf7_str[%p]", mutf7_str);
203 int err = EMAIL_ERROR_NONE;
205 EM_IF_NULL_RETURN_VALUE(mutf7_str, EMAIL_ERROR_INVALID_PARAM);
209 char *tmp_mutf7_str = g_strdup(mutf7_str);
210 *utf8_str = emcore_convert_mutf7_to_utf8(tmp_mutf7_str);
211 if (!(*utf8_str) || EM_SAFE_STRLEN(*utf8_str) == 0) {
212 EM_DEBUG_EXCEPTION("emcore_convert_mutf7_to_utf8 failed");
213 err = EMAIL_ERROR_UNKNOWN;
215 EM_SAFE_FREE(tmp_mutf7_str);
217 emcore_gmime_shutdown();
219 EM_DEBUG_API_END("ret[%d]", err);