4 * Copyright (c) 2000 - 2011 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.
26 * This file contains the data structures and interfaces needed for application,
27 * to interact with email-service.
28 * @file email-api-network.c
29 * @brief This file contains the data structures and interfaces of Network related Functionality provided by
33 #include "email-api.h"
35 #include "email-convert.h"
36 #include "email-api-mailbox.h"
37 #include "email-types.h"
38 #include "email-utilities.h"
39 #include "email-ipc.h"
40 #include "email-storage.h"
42 #ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
44 #include <dbus/dbus.h>
45 #endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
47 #ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
50 #define ACTIVE_SYNC_HANDLE_INIT_VALUE (-1)
51 #define ACTIVE_SYNC_HANDLE_BOUNDARY (-100000000)
54 static int email_get_account_server_type_by_account_id(int account_id, emf_account_server_t* account_server_type, int flag, int *error)
56 EM_DEBUG_FUNC_BEGIN();
57 emf_account_t *account=NULL;
59 int err= EMF_ERROR_NONE;
61 if (account_server_type == NULL ) {
62 EM_DEBUG_EXCEPTION("account_server_type is NULL");
63 err = EMF_ERROR_INVALID_PARAM;
68 if( (err = email_get_account(account_id,WITHOUT_OPTION,&account)) < 0) {
69 EM_DEBUG_EXCEPTION ("email_get_account failed [%d] ", err);
74 if ( flag == false ) { /* sending server */
75 *account_server_type = account->sending_server_type;
76 } else if ( flag == true ) { /* receiving server */
77 *account_server_type = account->receiving_server_type;
83 if ( account != NULL ) {
84 email_free_account(&account, 1);
86 if ( error != NULL ) {
93 static int email_get_handle_for_activesync(int *handle, int *error)
95 EM_DEBUG_FUNC_BEGIN();
97 static int next_handle = 0;
99 int err = EMF_ERROR_NONE;
101 if ( handle == NULL ) {
102 EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed : handle is NULL");
103 err = EMF_ERROR_INVALID_PARAM;
107 if ( vconf_get_int(VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE, &next_handle) != 0 ) {
108 EM_DEBUG_EXCEPTION("vconf_get_int failed");
109 if ( next_handle != 0 ) {
110 err = EMF_ERROR_GCONF_FAILURE;
115 EM_DEBUG_LOG(">>>>>> VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE : get lastest handle[%d]", next_handle);
117 /* set the value of the handle for active sync */
119 if ( next_handle < ACTIVE_SYNC_HANDLE_BOUNDARY ) {
120 next_handle = ACTIVE_SYNC_HANDLE_INIT_VALUE;
122 if ( vconf_set_int(VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE, next_handle) != 0) {
123 EM_DEBUG_EXCEPTION("vconf_set_int failed");
124 err = EMF_ERROR_GCONF_FAILURE;
128 *handle = next_handle;
129 EM_DEBUG_LOG(">>>>>> return next handle[%d]", *handle);
132 if ( error != NULL ) {
139 static int email_send_notification_to_active_sync_engine(int subType, ASNotiData *data)
141 EM_DEBUG_FUNC_BEGIN("subType [%d], data [%p]", subType, data);
143 DBusConnection *connection;
144 DBusMessage *signal = NULL;
146 const char *nullString = "";
148 dbus_int32_t array_for_time_type[9] = { 0 , };
150 dbus_error_init (&error);
151 connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
153 if(connection == NULL)
156 signal = dbus_message_new_signal("/User/Email/ActiveSync", EMF_ACTIVE_SYNC_NOTI, "email");
158 dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
160 case ACTIVE_SYNC_NOTI_SEND_MAIL:
161 EM_DEBUG_LOG("handle:[%d]", data->send_mail.handle);
162 EM_DEBUG_LOG("account_id:[%d]", data->send_mail.account_id);
163 EM_DEBUG_LOG("mailbox_name:[%s]", data->send_mail.mailbox_name);
164 EM_DEBUG_LOG("mail_id:[%d]", data->send_mail.mail_id);
165 EM_DEBUG_LOG("options.priority:[%d]", data->send_mail.options.priority);
166 EM_DEBUG_LOG("options.keep_local_copy:[%d]", data->send_mail.options.keep_local_copy);
167 EM_DEBUG_LOG("options.req_delivery_receipt:[%d]", data->send_mail.options.req_delivery_receipt);
168 EM_DEBUG_LOG("options.req_read_receipt:[%d]", data->send_mail.options.req_read_receipt);
169 /* download_limit, block_address, block_subject might not be needed */
170 EM_DEBUG_LOG("options.download_limit:[%d]", data->send_mail.options.download_limit);
171 EM_DEBUG_LOG("options.block_address:[%d]", data->send_mail.options.block_address);
172 EM_DEBUG_LOG("options.block_subject:[%d]", data->send_mail.options.block_subject);
173 EM_DEBUG_LOG("options.display_name_from:[%s]", data->send_mail.options.display_name_from);
174 EM_DEBUG_LOG("options.reply_with_body:[%d]", data->send_mail.options.reply_with_body);
175 EM_DEBUG_LOG("options.forward_with_files:[%d]", data->send_mail.options.forward_with_files);
176 EM_DEBUG_LOG("options.add_myname_card:[%d]", data->send_mail.options.add_myname_card);
177 EM_DEBUG_LOG("options.add_signature:[%d]", data->send_mail.options.add_signature);
178 EM_DEBUG_LOG("options.signature:[%s]", data->send_mail.options.signature);
180 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.handle), DBUS_TYPE_INVALID);
181 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.account_id), DBUS_TYPE_INVALID);
182 if ( data->send_mail.mailbox_name == NULL )
183 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
185 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.mailbox_name), DBUS_TYPE_INVALID);
186 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.mail_id), DBUS_TYPE_INVALID);
187 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.priority), DBUS_TYPE_INVALID);
188 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.keep_local_copy), DBUS_TYPE_INVALID);
189 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.req_delivery_receipt), DBUS_TYPE_INVALID);
190 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.req_read_receipt), DBUS_TYPE_INVALID);
191 if ( data->send_mail.options.display_name_from == NULL )
192 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
194 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.options.display_name_from), DBUS_TYPE_INVALID);
196 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.reply_with_body), DBUS_TYPE_INVALID);
197 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.forward_with_files), DBUS_TYPE_INVALID);
198 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.add_myname_card), DBUS_TYPE_INVALID);
199 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.add_signature), DBUS_TYPE_INVALID);
200 if ( data->send_mail.options.signature == NULL )
201 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
203 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.options.signature), DBUS_TYPE_INVALID);
206 case ACTIVE_SYNC_NOTI_SEND_SAVED: /* publish a send notification to ASE (active sync engine) */
207 EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_SEND_SAVED]", subType);
209 case ACTIVE_SYNC_NOTI_SEND_REPORT:
210 EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_SEND_REPORT]", subType);
212 case ACTIVE_SYNC_NOTI_SYNC_HEADER:
213 EM_DEBUG_LOG("handle:[%d]", data->sync_header.handle);
214 EM_DEBUG_LOG("account_id:[%d]", data->sync_header.account_id);
215 EM_DEBUG_LOG("mailbox_name:[%s]", data->sync_header.mailbox_name);
217 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.handle ), DBUS_TYPE_INVALID);
218 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.account_id ), DBUS_TYPE_INVALID);
219 if ( data->sync_header.mailbox_name == NULL )
220 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
222 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->sync_header.mailbox_name), DBUS_TYPE_INVALID);
224 case ACTIVE_SYNC_NOTI_DOWNLOAD_BODY: /* publish a download body notification to ASE */
225 EM_DEBUG_LOG("handle:[%d]", data->download_body.handle);
226 EM_DEBUG_LOG("account_id:[%d]", data->download_body.account_id);
227 EM_DEBUG_LOG("mail_id:[%d]", data->download_body.mail_id);
228 EM_DEBUG_LOG("with_attachment:[%d]", data->download_body.with_attachment);
230 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.handle ), DBUS_TYPE_INVALID);
231 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.account_id ), DBUS_TYPE_INVALID);
232 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.mail_id ), DBUS_TYPE_INVALID);
233 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.with_attachment ), DBUS_TYPE_INVALID);
235 case ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT:
236 EM_DEBUG_LOG("handle:[%d]", data->download_attachment.handle);
237 EM_DEBUG_LOG("account_id:[%d]", data->download_attachment.account_id );
238 EM_DEBUG_LOG("mail_id:[%d]", data->download_attachment.mail_id);
239 EM_DEBUG_LOG("with_attachment:[%s]", data->download_attachment.attachment_order );
241 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.handle ), DBUS_TYPE_INVALID);
242 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.account_id ), DBUS_TYPE_INVALID);
243 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.mail_id ), DBUS_TYPE_INVALID);
244 if ( data->download_attachment.attachment_order == NULL )
245 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
247 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->download_attachment.attachment_order), DBUS_TYPE_INVALID);
249 case ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT:
250 EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT]", subType);
252 case ACTIVE_SYNC_NOTI_CANCEL_JOB:
253 EM_DEBUG_LOG("account_id:[%d]", data->cancel_job.account_id );
254 EM_DEBUG_LOG("handle to cancel:[%d]", data->cancel_job.handle);
256 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.account_id ), DBUS_TYPE_INVALID);
257 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.handle ), DBUS_TYPE_INVALID);
259 case ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER:
260 EM_DEBUG_LOG("account_id:[%d]", data->search_mail_on_server.account_id );
261 EM_DEBUG_LOG("mailbox_name:[%s]", data->search_mail_on_server.mailbox_name );
262 EM_DEBUG_LOG("search_filter_count:[%d]", data->search_mail_on_server.search_filter_count );
263 EM_DEBUG_LOG("handle to cancel:[%d]", data->search_mail_on_server.handle);
265 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.account_id), DBUS_TYPE_INVALID);
266 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->search_mail_on_server.mailbox_name), DBUS_TYPE_INVALID);
267 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_count), DBUS_TYPE_INVALID);
268 for(i = 0; i < data->search_mail_on_server.search_filter_count; i++) {
269 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_list[i].search_filter_type), DBUS_TYPE_INVALID);
270 switch(data->search_mail_on_server.search_filter_list[i].search_filter_type) {
271 case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO :
272 case EMAIL_SEARCH_FILTER_TYPE_UID :
273 case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER :
274 case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER :
275 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED :
276 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED :
277 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT :
278 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED :
279 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT :
280 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN :
281 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.integer_type_key_value), DBUS_TYPE_INVALID);
284 case EMAIL_SEARCH_FILTER_TYPE_BCC :
285 case EMAIL_SEARCH_FILTER_TYPE_CC :
286 case EMAIL_SEARCH_FILTER_TYPE_FROM :
287 case EMAIL_SEARCH_FILTER_TYPE_KEYWORD :
288 case EMAIL_SEARCH_FILTER_TYPE_SUBJECT :
289 case EMAIL_SEARCH_FILTER_TYPE_TO :
290 case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID :
291 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.string_type_key_value), DBUS_TYPE_INVALID);
294 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE :
295 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON :
296 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE : {
297 array_for_time_type[0] = data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value.tm_sec;
298 array_for_time_type[1] = data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value.tm_min;
299 array_for_time_type[2] = data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value.tm_hour;
300 array_for_time_type[3] = data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value.tm_mday;
301 array_for_time_type[4] = data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value.tm_mon;
302 array_for_time_type[5] = data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value.tm_year;
303 array_for_time_type[6] = data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value.tm_wday;
304 array_for_time_type[7] = data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value.tm_yday;
305 array_for_time_type[8] = data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value.tm_isdst;
306 dbus_message_append_args(signal, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, array_for_time_type, 9, DBUS_TYPE_INVALID);
310 EM_DEBUG_EXCEPTION("Invalid filter type [%d]", data->search_mail_on_server.search_filter_list[i].search_filter_type);
314 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.handle), DBUS_TYPE_INVALID);
317 EM_DEBUG_EXCEPTION("Invalid Notification type of Active Sync : subType[%d]", subType);
321 if(!dbus_connection_send (connection, signal, NULL)) {
322 EM_DEBUG_EXCEPTION("dbus_connection_send is failed");
325 EM_DEBUG_LOG("dbus_connection_send is successful");
327 dbus_connection_flush(connection);
332 dbus_message_unref(signal);
337 #endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
340 EXPORT_API int email_send_mail( emf_mailbox_t* mailbox, int mail_id, emf_option_t* sending_option, unsigned* handle)
342 EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], sending_option[%p], handle[%p]", mailbox, mail_id, sending_option, handle);
344 char* mailbox_stream = NULL;
345 char* pSendingOption = NULL;
347 int err = EMF_ERROR_NONE;
349 EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
350 EM_IF_NULL_RETURN_VALUE(mailbox->name, EMF_ERROR_INVALID_PARAM);
351 EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
353 EM_DEBUG_LOG("Account ID [ %d],mailbox->name[%s], mailbox->account_id[%d] ", mailbox->account_id, mailbox->name, mailbox->account_id);
355 #ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
356 emf_account_server_t account_server_type;
357 HIPC_API hAPI = NULL;
358 ASNotiData as_noti_data;
359 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
361 /* check account bind type and branch off */
362 if ( email_get_account_server_type_by_account_id(mailbox->account_id, &account_server_type, false, &err) == false ) {
363 EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
364 err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
368 if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
370 if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
371 EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
372 err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
376 /* noti to active sync */
377 as_noti_data.send_mail.handle = as_handle;
378 as_noti_data.send_mail.account_id = mailbox->account_id;
379 as_noti_data.send_mail.mailbox_name = strdup(mailbox->name);
380 as_noti_data.send_mail.mail_id = mail_id;
382 memcpy(&as_noti_data.send_mail.options, sending_option, sizeof(emf_option_t));
384 if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEND_MAIL, &as_noti_data) == false) {
385 EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
386 err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
393 hAPI = emipc_create_email_api(_EMAIL_API_SEND_MAIL);
395 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
398 mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
400 EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
402 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)){
403 EM_DEBUG_EXCEPTION("email_send_mail--Add Param mailbox failed");
404 EM_SAFE_FREE(mailbox_stream);
405 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
409 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))){
410 EM_DEBUG_EXCEPTION("email_send_mail--Add Param mail_id failed");
411 EM_SAFE_FREE(mailbox_stream);
412 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
415 /* sending options */
416 pSendingOption = em_convert_option_to_byte_stream(sending_option, &size);
418 if ( NULL == pSendingOption) {
419 EM_SAFE_FREE(mailbox_stream);
420 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
423 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pSendingOption, size)){
424 EM_DEBUG_EXCEPTION("email_send_mail--Add Param Sending_Option failed ");
425 EM_SAFE_FREE(mailbox_stream);
426 EM_SAFE_FREE(pSendingOption);
427 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
430 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
431 EM_DEBUG_EXCEPTION("email_send_mail--emipc_execute_proxy_api failed ");
432 EM_SAFE_FREE(pSendingOption);
433 EM_SAFE_FREE(mailbox_stream);
434 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_CRASH);
437 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
438 if (err == EMF_ERROR_NONE) {
440 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
445 emipc_destroy_email_api(hAPI);
446 hAPI = (HIPC_API)NULL;
447 EM_SAFE_FREE(pSendingOption);
448 EM_SAFE_FREE(mailbox_stream);
449 EM_SAFE_FREE(as_noti_data.send_mail.mailbox_name);
450 #else /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
451 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SEND_MAIL);
453 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
456 mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
458 EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
460 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)){
461 EM_DEBUG_EXCEPTION("Add Param mailbox failed ");
462 EM_SAFE_FREE(mailbox_stream);
463 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
467 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))){
468 EM_DEBUG_EXCEPTION("Add Param mail_id failed ");
469 EM_SAFE_FREE(mailbox_stream);
470 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
473 /* sending options */
474 pSendingOption = em_convert_option_to_byte_stream(sending_option, &size);
476 if ( NULL == pSendingOption)
477 EM_SAFE_FREE(mailbox_stream);
478 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
481 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pSendingOption, size)){
482 EM_DEBUG_EXCEPTION("Add Param Sending_Option failed ");
483 EM_SAFE_FREE(mailbox_stream);
484 EM_SAFE_FREE(pSendingOption);
485 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
488 if(!emipc_execute_proxy_api(hAPI, NULL)) {
489 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed ");
490 EM_SAFE_FREE(pSendingOption);
491 EM_SAFE_FREE(mailbox_stream);
492 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
495 err emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), );
496 if (err == EMF_ERROR_NONE)
499 handle = *(unsigned int*)emipc_get_parameter(hAPI, ePARAMETER_OUT, 1); /* Warning removal changes */
502 EM_DEBUG_LOG(" >>>>>> ERROR CODE : %d ", err);
504 emipc_destroy_email_api(hAPI);
506 EM_SAFE_FREE(pSendingOption);
507 EM_SAFE_FREE(mailbox_stream);
508 #endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
509 EM_DEBUG_FUNC_END("err [%d]", err);
513 EXPORT_API int email_send_saved(int account_id, emf_option_t* sending_option, unsigned* handle)
515 EM_DEBUG_FUNC_BEGIN("account_id[%d], sending_option[%p], handle[%p]", account_id, sending_option, handle);
517 char* pOptionStream = NULL;
518 int err = EMF_ERROR_NONE;
521 EM_IF_NULL_RETURN_VALUE(account_id, EMF_ERROR_INVALID_PARAM);
522 EM_IF_NULL_RETURN_VALUE(sending_option, EMF_ERROR_INVALID_PARAM);
523 EM_IF_ACCOUNT_ID_NULL(account_id, EMF_ERROR_INVALID_PARAM);
525 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SEND_SAVED);
527 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
530 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(account_id), sizeof(int))) {
531 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id failed");
532 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
536 pOptionStream = em_convert_option_to_byte_stream(sending_option, &size);
538 EM_PROXY_IF_NULL_RETURN_VALUE(pOptionStream, hAPI, EMF_ERROR_NULL_VALUE);
540 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pOptionStream, size)) {
541 EM_DEBUG_EXCEPTION("Add Param sending option failed");
542 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
546 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
547 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
548 EM_SAFE_FREE(pOptionStream);
549 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
552 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
553 emipc_destroy_email_api(hAPI);
556 EM_SAFE_FREE(pOptionStream);
558 EM_DEBUG_FUNC_END("err [%d]", err);
562 EXPORT_API int email_sync_local_activity(int account_id)
564 EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
566 int err = EMF_ERROR_NONE;
568 if (account_id < 0 || account_id == 0) {
569 EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
571 return EMF_ERROR_INVALID_PARAM;
574 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SYNC_LOCAL_ACTIVITY);
576 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
579 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
580 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
581 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
584 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
585 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
586 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
589 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
591 emipc_destroy_email_api(hAPI);
594 EM_DEBUG_FUNC_END("err [%d]", err);
598 int EmfMailboxSyncHeader(emf_mailbox_t* mailbox, unsigned* handle, int* err_code)
600 EM_DEBUG_FUNC_BEGIN("mailbox[%p], handle[%p], err_code[%p]", mailbox, handle, err_code);
601 int err = EMF_ERROR_NONE;
603 err = email_sync_header(mailbox,handle);
605 if (err_code != NULL)
611 EXPORT_API int email_sync_header(emf_mailbox_t* mailbox, unsigned* handle)
613 EM_DEBUG_FUNC_BEGIN("mailbox[%p], handle[%p]", mailbox, handle);
614 char* mailbox_stream = NULL;
615 int err = EMF_ERROR_NONE;
617 /* int total_count = 0; */
619 EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
620 EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
622 #ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
623 emf_account_server_t account_server_type;
624 HIPC_API hAPI = NULL;
625 ASNotiData as_noti_data;
626 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
628 /* 2010/02/12 ch715.lee : check account bind type and branch off */
629 if ( email_get_account_server_type_by_account_id(mailbox->account_id, &account_server_type, true, &err) == false ) {
630 EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
634 if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
636 if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
637 EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
641 /* noti to active sync */
642 as_noti_data.sync_header.handle = as_handle;
643 as_noti_data.sync_header.account_id = mailbox->account_id;
644 /* In case that Mailbox is NULL, SYNC ALL MAILBOX */
645 as_noti_data.sync_header.mailbox_name = (mailbox && mailbox->name) ? strdup(mailbox->name) : NULL;
647 if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SYNC_HEADER, &as_noti_data) == false) {
648 EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
649 err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
658 hAPI = emipc_create_email_api(_EMAIL_API_SYNC_HEADER);
660 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
662 mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
664 EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
666 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
667 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
668 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
671 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
672 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
673 EM_SAFE_FREE(mailbox_stream);
674 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
677 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
679 if (err != EMF_ERROR_NONE)
683 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
687 emipc_destroy_email_api(hAPI);
689 EM_SAFE_FREE(mailbox_stream);
690 EM_SAFE_FREE(as_noti_data.sync_header.mailbox_name);
691 #else /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
692 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SYNC_HEADER);
694 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
696 mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
698 EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
700 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
701 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
702 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
705 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
706 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
707 EM_SAFE_FREE(mailbox_stream);
708 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
711 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
713 EM_DEBUG_LOG("RETURN VALUE : %d ", err);
715 if (err != EMF_ERROR_NONE)
719 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
721 emipc_destroy_email_api(hAPI);
723 EM_SAFE_FREE(mailbox_stream);
724 #endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
726 EM_DEBUG_FUNC_END("err [%d]", err);
731 EXPORT_API int email_sync_header_for_all_account(unsigned* handle)
733 EM_DEBUG_FUNC_BEGIN("handle[%p]", handle);
734 char* mailbox_stream = NULL;
735 emf_mailbox_t mailbox;
736 int err = EMF_ERROR_NONE;
738 HIPC_API hAPI = NULL;
740 #ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
741 ASNotiData as_noti_data;
742 int i, account_count = 0;
743 emstorage_account_tbl_t *account_tbl_array = NULL;
747 hAPI = emipc_create_email_api(_EMAIL_API_SYNC_HEADER);
749 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
751 mailbox.account_id = ALL_ACCOUNT;
753 mailbox.alias = NULL;
754 mailbox.account_name = NULL;
756 mailbox_stream = em_convert_mailbox_to_byte_stream(&mailbox, &size);
758 EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
760 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
761 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
762 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
765 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
766 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
767 EM_SAFE_FREE(mailbox_stream);
768 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
771 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
773 if (err != EMF_ERROR_NONE)
776 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &return_handle);
778 #ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
779 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
781 /* Get all accounts for sending notification to active sync engine. */
782 if (!emstorage_get_account_list(&account_count, &account_tbl_array , true, false, &as_err)) {
783 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [ %d ] ", as_err);
788 for(i = 0; i < account_count; i++) {
789 if ( account_tbl_array[i].receiving_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
790 /* use returned handle value for a active sync handle */
793 if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
794 EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
799 /* noti to active sync */
800 as_noti_data.sync_header.handle = return_handle;
801 as_noti_data.sync_header.account_id = account_tbl_array[i].account_id;
802 /* In case that Mailbox is NULL, SYNC ALL MAILBOX */
803 as_noti_data.sync_header.mailbox_name = NULL;
805 if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SYNC_HEADER, &as_noti_data) == false) {
806 EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
807 err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
812 #endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
816 *handle = return_handle;
820 emipc_destroy_email_api(hAPI);
822 EM_SAFE_FREE(mailbox_stream);
823 if ( account_tbl_array )
824 emstorage_free_account(&account_tbl_array, account_count, NULL);
826 EM_DEBUG_FUNC_END("err [%d]", err);
830 EXPORT_API int email_download_body(emf_mailbox_t* mailbox, int mail_id, int with_attachment, unsigned* handle)
832 EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d],with_attachment[%d]", mailbox, mail_id, with_attachment);
833 char* mailbox_stream = NULL;
834 int err = EMF_ERROR_NONE;
837 EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
838 EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
839 EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
841 #ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
842 emf_account_server_t account_server_type;
843 HIPC_API hAPI = NULL;
844 ASNotiData as_noti_data;
845 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
847 /* 2010/02/12 ch715.lee : check account bind type and branch off */
848 if ( email_get_account_server_type_by_account_id(mailbox->account_id, &account_server_type, true, &err) == false ) {
849 EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
853 if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
855 if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
856 EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
860 /* noti to active sync */
861 as_noti_data.download_body.handle = as_handle;
862 as_noti_data.download_body.account_id = mailbox->account_id;
863 as_noti_data.download_body.mail_id = mail_id;
864 as_noti_data.download_body.with_attachment = with_attachment;
866 if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DOWNLOAD_BODY, &as_noti_data) == false) {
867 EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
868 err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
875 hAPI = emipc_create_email_api(_EMAIL_API_DOWNLOAD_BODY);
877 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
879 mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
881 EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
883 /* MailBox Information */
884 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
885 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
886 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
890 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
891 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
892 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
895 /* with_attachment */
896 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&with_attachment, sizeof(int))) {
897 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
898 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
901 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
902 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
903 EM_SAFE_FREE(mailbox_stream);
904 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
907 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
908 if (err != EMF_ERROR_NONE)
913 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
914 EM_DEBUG_LOG("RETURN VALUE : %d handle %d", err, *handle);
920 emipc_destroy_email_api(hAPI);
922 EM_SAFE_FREE(mailbox_stream);
923 #else /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
924 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_DOWNLOAD_BODY);
926 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
928 mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
930 EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
932 /* MailBox Information */
933 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
934 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
935 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
939 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, size)) {
940 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
941 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
944 /* with_attachment */
945 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&with_attachment, size)) {
946 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
947 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
950 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
951 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
952 EM_SAFE_FREE(mailbox_stream);
953 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
956 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
957 if (err != EMF_ERROR_NONE)
960 /* Download handle */
962 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
963 EM_DEBUG_LOG("RETURN VALUE : %d handle %d", err, *handle);
968 emipc_destroy_email_api(hAPI);
970 EM_SAFE_FREE(mailbox_stream);
972 #endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
974 EM_DEBUG_FUNC_END("err [%d]", err);
983 /* API - Downloads the Email Attachment Information [ INTERNAL ] */
985 EXPORT_API int email_download_attachment(emf_mailbox_t* mailbox,int mail_id, const char* nth,unsigned* handle)
987 EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], nth[%p], handle[%p]", mailbox, mail_id, nth, handle);
988 char* mailbox_stream = NULL;
989 int err = EMF_ERROR_NONE;
992 EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
993 EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
994 EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
995 /* EM_IF_NULL_RETURN_VALUE(nth, EMF_ERROR_INVALID_PARAM); */
997 #ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
998 emf_account_server_t account_server_type;
999 HIPC_API hAPI = NULL;
1000 ASNotiData as_noti_data;
1001 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
1003 if ( email_get_account_server_type_by_account_id(mailbox->account_id, &account_server_type, true, &err) == false ) {
1004 EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
1008 if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
1010 if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
1011 EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
1015 /* noti to active sync */
1016 as_noti_data.download_attachment.handle = as_handle;
1017 as_noti_data.download_attachment.account_id = mailbox->account_id;
1018 as_noti_data.download_attachment.mail_id = mail_id;
1019 as_noti_data.download_attachment.attachment_order = strdup(nth);
1020 if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT, &as_noti_data) == false) {
1021 EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
1022 err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
1027 *handle = as_handle;
1029 hAPI = emipc_create_email_api(_EMAIL_API_DOWNLOAD_ATTACHMENT);
1031 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
1034 mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
1036 EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
1038 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
1039 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1040 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1044 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
1045 EM_DEBUG_EXCEPTION("emipc_add_parameter mail_id failed");
1046 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1050 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*) nth, sizeof(nth))) {
1051 EM_DEBUG_EXCEPTION("emipc_add_parameter mail_id failed");
1052 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1056 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1057 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1058 EM_SAFE_FREE(mailbox_stream);
1059 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
1062 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1063 if (err != EMF_ERROR_NONE)
1067 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
1072 emipc_destroy_email_api(hAPI);
1074 EM_SAFE_FREE(mailbox_stream);
1075 EM_SAFE_FREE(as_noti_data.download_attachment.attachment_order);
1076 #else /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
1077 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_DOWNLOAD_ATTACHMENT);
1079 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
1082 mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
1084 EM_PROXY_IF_NULL_RETURN_VALUE(mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
1086 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
1087 EM_DEBUG_EXCEPTION("Add Param mailbox failed");
1088 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1092 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
1093 EM_DEBUG_EXCEPTION("emipc_add_parameter mail_id failed");
1094 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1098 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, nth, sizeof(nth))) {
1099 EM_DEBUG_EXCEPTION("emipc_add_parameter mail_id failed");
1100 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1104 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1105 EM_DEBUG_EXCEPTION("EmfDownloadAttachment--emipc_execute_proxy_api failed");
1106 EM_SAFE_FREE(mailbox_stream);
1107 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
1110 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1112 EM_DEBUG_LOG(" >>>>> EmfDownloadAttachment RETURN VALUE : %d ", err);
1114 if (err != EMF_ERROR_NONE)
1118 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
1120 /* Prevent defect 36700 */
1121 /* EM_DEBUG_LOG(" >>>>> Handle_proxy : %d ", *handle); */
1123 emipc_destroy_email_api(hAPI);
1125 EM_SAFE_FREE(mailbox_stream);
1126 #endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
1128 EM_DEBUG_FUNC_END("err [%d]", err);
1134 EXPORT_API int email_cancel_job(int account_id, int handle)
1136 EM_DEBUG_FUNC_BEGIN("account_id [%d], handle [%d]", account_id, handle);
1137 int err = EMF_ERROR_NONE;
1140 return EMF_ERROR_INVALID_PARAM;
1141 #ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
1142 emf_account_server_t account_server_type;
1143 HIPC_API hAPI = NULL;
1144 ASNotiData as_noti_data;
1145 emstorage_account_tbl_t *account_list = NULL;
1146 int i, account_count = 0;
1148 if ( account_id == ALL_ACCOUNT ) { /* this means that job is executed with all account */
1149 /* Get all accounts for sending notification to active sync engine. */
1150 if (!emstorage_get_account_list(&account_count, &account_list , true, false, &err)) {
1151 EM_DEBUG_EXCEPTION("email_get_account_list-- Failed [ %d ] ", err);
1156 for(i = 0; i < account_count; i++) {
1157 if ( email_get_account_server_type_by_account_id(account_list[i].account_id, &account_server_type, true, &err) == false ) {
1158 EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
1162 if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
1163 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
1164 as_noti_data.cancel_job.account_id = account_list[i].account_id;
1165 as_noti_data.cancel_job.handle = handle;
1167 if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CANCEL_JOB, &as_noti_data) == false) {
1168 EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
1169 err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
1175 /* request canceling to stub */
1176 hAPI = emipc_create_email_api(_EMAIL_API_CANCEL_JOB);
1178 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
1180 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) { /* account_id == 0 */
1181 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1182 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1185 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &handle, sizeof(int))) {
1186 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1187 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1191 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1192 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1193 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
1196 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1197 emipc_destroy_email_api(hAPI);
1201 if ( email_get_account_server_type_by_account_id(account_id, &account_server_type, true, &err) == false ) {
1202 EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
1206 if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
1207 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
1208 as_noti_data.cancel_job.account_id = account_id;
1209 as_noti_data.cancel_job.handle = handle;
1211 if ( email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CANCEL_JOB, &as_noti_data) == false) {
1212 EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
1213 err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
1217 hAPI = emipc_create_email_api(_EMAIL_API_CANCEL_JOB);
1219 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
1221 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) {
1222 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1223 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1226 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &handle, sizeof(int))) {
1227 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1228 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1232 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1233 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1234 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
1236 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1237 emipc_destroy_email_api(hAPI);
1243 emipc_destroy_email_api(hAPI);
1246 emstorage_free_account(&account_list, account_count, NULL);
1248 #else /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
1249 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_CANCEL_JOB);
1251 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
1253 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) {
1254 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1255 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1258 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &handle, sizeof(int))) {
1259 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1260 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1264 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1265 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1266 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
1269 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1271 EM_DEBUG_LOG(" >>>>> EmfCancelJob RETURN VALUE : %d ", err);
1273 emipc_destroy_email_api(hAPI);
1275 #endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
1277 EM_DEBUG_FUNC_END("err [%d]", err);
1283 EXPORT_API int email_get_pending_job(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t * status)
1285 EM_DEBUG_FUNC_BEGIN("action[%d], account_id[%d], mail_id[%d], status[%p]", action, account_id, mail_id, status);
1287 int err = EMF_ERROR_NONE;
1289 EM_IF_ACCOUNT_ID_NULL(account_id, EMF_ERROR_NULL_VALUE);
1291 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_GET_PENDING_JOB);
1293 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
1295 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &action, sizeof(int))) {
1296 EM_DEBUG_EXCEPTION("emipc_add_parameter action failed ");
1297 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1300 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) {
1301 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id failed ");
1302 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1305 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &mail_id, sizeof(int))) {
1306 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id failed ");
1307 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1311 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1312 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed ");
1313 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
1316 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1319 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), status);
1320 EM_DEBUG_LOG("status : %d ", *status);
1323 emipc_destroy_email_api(hAPI);
1326 EM_DEBUG_FUNC_END("err [%d]", err);
1333 EXPORT_API int email_get_network_status(int* on_sending, int* on_receiving)
1335 EM_DEBUG_FUNC_BEGIN("on_sending[%p], on_receiving[%p]", on_sending, on_receiving);
1336 int err = EMF_ERROR_NONE;
1338 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_NETWORK_GET_STATUS);
1340 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
1343 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1344 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1345 emipc_destroy_email_api(hAPI);
1347 err = EMF_ERROR_IPC_SOCKET_FAILURE ;
1348 EM_DEBUG_FUNC_END("err [%d]", err); return err;
1352 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), on_sending );
1354 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), on_receiving);
1356 emipc_destroy_email_api(hAPI);
1358 EM_DEBUG_FUNC_END("err [%d]", err);
1362 EXPORT_API int email_get_imap_mailbox_list(int account_id, const char* mailbox, unsigned* handle)
1364 EM_DEBUG_FUNC_BEGIN();
1366 int err = EMF_ERROR_NONE;
1368 if(account_id <= 0 || !mailbox) {
1369 EM_DEBUG_LOG("invalid parameters");
1370 return EMF_ERROR_INVALID_PARAM;
1373 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_GET_IMAP_MAILBOX_LIST);
1376 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
1377 EM_DEBUG_LOG("emipc_add_parameter failed ");
1378 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
1381 if(!emipc_execute_proxy_api(hAPI)) {
1382 EM_DEBUG_LOG("ipcProxy_ExecuteAsyncAPI failed");
1383 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
1386 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1388 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
1390 emipc_destroy_email_api(hAPI);
1393 EM_DEBUG_FUNC_END("err [%d]", err);
1397 EXPORT_API int email_search_mail_on_server(int input_account_id, const char *input_mailbox_name, email_search_filter_t *input_search_filter_list, int input_search_filter_count, unsigned *output_handle)
1399 EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_name [%p], input_search_filter_list [%p], input_search_filter_count [%d], output_handle [%p]", input_account_id, input_mailbox_name, input_search_filter_list, input_search_filter_count, output_handle);
1401 int err = EMF_ERROR_NONE;
1402 int return_value = 0;
1403 int stream_size_for_search_filter_list = 0;
1404 char *stream_for_search_filter_list = NULL;
1405 HIPC_API hAPI = NULL;
1407 EM_IF_NULL_RETURN_VALUE(input_account_id, EMF_ERROR_INVALID_PARAM);
1408 EM_IF_NULL_RETURN_VALUE(input_mailbox_name, EMF_ERROR_INVALID_PARAM);
1409 EM_IF_NULL_RETURN_VALUE(input_search_filter_list, EMF_ERROR_INVALID_PARAM);
1411 #ifdef __FEATURE_SUPPORT_ACTIVE_SYNC__
1412 emf_account_server_t account_server_type = EMF_SERVER_TYPE_NONE;
1413 ASNotiData as_noti_data;
1415 memset(&as_noti_data, 0, sizeof(ASNotiData)); /* initialization of union members */
1417 if ( email_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) {
1418 EM_DEBUG_EXCEPTION("email_get_account_server_type_by_account_id failed[%d]", err);
1422 if ( account_server_type == EMF_SERVER_TYPE_ACTIVE_SYNC ) {
1425 if ( email_get_handle_for_activesync(&as_handle, &err) == false ) {
1426 EM_DEBUG_EXCEPTION("email_get_handle_for_activesync failed[%d].", err);
1430 /* noti to active sync */
1431 as_noti_data.search_mail_on_server.handle = as_handle;
1432 as_noti_data.search_mail_on_server.account_id = input_account_id;
1433 as_noti_data.search_mail_on_server.mailbox_name = EM_SAFE_STRDUP(input_mailbox_name);
1434 as_noti_data.search_mail_on_server.search_filter_list = input_search_filter_list;
1435 as_noti_data.search_mail_on_server.search_filter_count = input_search_filter_count;
1437 return_value = email_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER, &as_noti_data);
1439 EM_SAFE_FREE(as_noti_data.search_mail_on_server.mailbox_name);
1441 if ( return_value == false ) {
1442 EM_DEBUG_EXCEPTION("email_send_notification_to_active_sync_engine failed.");
1443 err = EMF_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
1448 *output_handle = as_handle;
1451 #endif /* __FEATURE_SUPPORT_ACTIVE_SYNC__ */
1453 hAPI = emipc_create_email_api(_EMAIL_API_SEARCH_MAIL_ON_SERVER);
1455 EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
1457 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)&input_account_id, sizeof(int))) {
1458 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1459 err = EMF_ERROR_IPC_PROTOCOL_FAILURE;
1463 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)input_mailbox_name, strlen(input_mailbox_name))){
1464 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1465 err = EMF_ERROR_IPC_PROTOCOL_FAILURE;
1469 stream_for_search_filter_list = em_convert_search_filter_to_byte_stream(input_search_filter_list, input_search_filter_count, &stream_size_for_search_filter_list);
1471 EM_PROXY_IF_NULL_RETURN_VALUE(stream_for_search_filter_list, hAPI, EMF_ERROR_NULL_VALUE);
1473 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, stream_for_search_filter_list, stream_size_for_search_filter_list)) {
1474 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1475 err = EMF_ERROR_IPC_PROTOCOL_FAILURE;
1479 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1480 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1481 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
1484 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1486 if (err != EMF_ERROR_NONE) {
1487 EM_DEBUG_EXCEPTION("_EMAIL_API_SEARCH_MAIL_ON_SERVER failed [%d]", err);
1492 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), output_handle);
1497 emipc_destroy_email_api(hAPI);
1501 EM_DEBUG_FUNC_END("err [%d]", err);