summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-13 01:45:53 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-13 01:45:53 +0900
commit7a8f63a4cb7f9a8f9baf52261acc9cfb19ccff82 (patch)
tree1ef952a544303103ace066f6c83f8807ebdf0a67
parentcb9665baa95abaeac5268efb421afd4f2e3d5152 (diff)
downloademail-tizen_2.1.tar.gz
email-tizen_2.1.tar.bz2
email-tizen_2.1.zip
-rwxr-xr-xAUTHORS1
-rwxr-xr-xCMakeLists.txt95
-rwxr-xr-xLICENSE204
-rwxr-xr-xcapi-messaging-email.pc.in15
-rwxr-xr-xinclude/email.h266
-rwxr-xr-xinclude/email_error.h63
-rwxr-xr-xinclude/email_private.h48
-rwxr-xr-xinclude/email_types.h74
-rw-r--r--packaging/capi-messaging-email.manifest5
-rwxr-xr-xpackaging/capi-messaging-email.spec58
-rwxr-xr-xsrc/email.c867
11 files changed, 1696 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100755
index 0000000..b7b0832
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+WonYoung Choi <wy80.choi@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755
index 0000000..3d71d97
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,95 @@
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-messaging-email")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(dependents "dlog glib-2.0 edbus capi-base-common email-service")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${dependents})
+FOREACH(flag ${${fw_name}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+ ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DTIZEN_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
+
+aux_source_directory(src SOURCES)
+ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+SET_TARGET_PROPERTIES(${fw_name}
+ PROPERTIES
+ VERSION ${FULLVER}
+ SOVERSION ${MAJORVER}
+ CLEAN_DIRECT_OUTPUT 1
+)
+
+INSTALL(TARGETS ${fw_name} DESTINATION lib)
+INSTALL(
+ DIRECTORY ${INC_DIR}/ DESTINATION include/messaging
+ FILES_MATCHING
+ PATTERN "*_private.h" EXCLUDE
+ PATTERN "${INC_DIR}/*.h"
+)
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${dependents})
+SET(PC_LDFLAGS -l${fw_name})
+SET(PC_CFLAGS -I\${includedir}/messaging)
+
+CONFIGURE_FILE(
+ ${fw_name}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig)
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+ DEPENDS clean
+ COMMENT "distribution clean"
+ COMMAND find
+ ARGS .
+ -not -name config.cmake -and \(
+ -name tester.c -or
+ -name Testing -or
+ -name CMakeFiles -or
+ -name cmake.depends -or
+ -name cmake.check_depends -or
+ -name CMakeCache.txt -or
+ -name cmake.check_cache -or
+ -name *.cmake -or
+ -name Makefile -or
+ -name core -or
+ -name core.* -or
+ -name gmon.out -or
+ -name install_manifest.txt -or
+ -name *.pc -or
+ -name *~ \)
+ | grep -v TC | xargs rm -rf
+ TARGET distclean
+ VERBATIM
+)
+
+ENDIF(UNIX)
+
diff --git a/LICENSE b/LICENSE
new file mode 100755
index 0000000..311e5ba
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
diff --git a/capi-messaging-email.pc.in b/capi-messaging-email.pc.in
new file mode 100755
index 0000000..9dc94c8
--- /dev/null
+++ b/capi-messaging-email.pc.in
@@ -0,0 +1,15 @@
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib
+includedir=/usr/include
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir} @PC_CFLAGS@
+
diff --git a/include/email.h b/include/email.h
new file mode 100755
index 0000000..6167680
--- /dev/null
+++ b/include/email.h
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ #ifndef __MESSAGING_EMAIL_H__
+ #define __MESSAGING_EMAIL_H__
+
+/**
+ * @addtogroup CAPI_MESSAGING_EMAIL_MODULE
+ * @{
+ */
+
+/**
+ * @file email.h
+ * @ingroup CAPI_MESSAGING_FRAMEWORK
+ * @brief Messaging API file, support for sending email messages.
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <email_types.h>
+#include <email_error.h>
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+/**
+ * @brief Creates an email message handle for sending an email message.
+ *
+ * @remarks a email must be released with email_destroy_message() by you.
+ *
+ * @param[out] email A handle to the email message
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #EMAIL_ERROR_ACCOUNT_NOT_FOUND Email account not found
+ *
+ * @see email_destroy_message()
+ */
+int email_create_message(email_h *email);
+
+/**
+ * @brief Destroys the email message handle and releases all its resources.
+ *
+ * @param[in] email The handle to the email message
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #EMAIL_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @see email_create_message()
+ */
+int email_destroy_message(email_h email);
+
+/**
+ * @brief Sets a subject of the email message.
+ *
+ * @param[in] email The handle to the email message
+ * @param[in] subject The subject of the email message
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #EMAIL_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see email_create_message()
+ */
+int email_set_subject(email_h email, const char *subject);
+
+/**
+ * @brief Populates a body of the email message.
+ * @details Email message body means the text data to be delivered.
+ *
+ * @param[in] email The handle to the email message
+ * @param[in] body The message body
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval # EMAIL_ERROR_OPERATION_FAILED Operation failed
+ * @pre An email message handle is created using #email_create_message().
+ * @see email_create_message()
+ */
+int email_set_body(email_h email, const char *body);
+
+/**
+ * @brief Adds a recipient to the email message.
+ * @details The email API supports sending an email message to multiple recipients.
+ *
+ * @remarks Email address should be in standard format (as described in
+ * Internet standards RFC 5321 and RFC 5322).\n
+ *
+ * @param[in] email The handle to the email message
+ * @param[in] type The recipient type
+ * @param[in] address The recipient email address
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #EMAIL_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see email_create_message()
+ * @see email_remove_all_recipients()
+ */
+int email_add_recipient(email_h email, email_recipient_type_e type, const char *address);
+
+/**
+ * @brief Removes all recipients for the email message.
+ *
+ * @param[in] email The handle to the email message
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see email_add_recipient()
+ */
+int email_remove_all_recipients(email_h email);
+
+/**
+ * @brief Adds a file as an attachment to the email message.
+ * @details It should be used to add a file to the attachment list
+ * of the email message.
+ *
+ * @remarks The maximum attachment file size is 10MB.
+ *
+ * @param[in] email The handle to the email message
+ * @param[in] filepath The absolute full path of the file to be attached
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #EMAIL_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see email_remove_all_attachments()
+ *
+ */
+int email_add_attach(email_h email, const char *filepath);
+
+/**
+ * @brief Clears all attachments of the email message.
+ *
+ * @param[in] email The handle to the email message
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see email_create_message()
+ * @see email_add_attach()
+ */
+int email_remove_all_attachments(email_h email);
+
+/**
+ * @brief Save the email message at outbox.
+ *
+ * @remarks Get the id of mail.
+ *
+ *
+ * @param[in] email The handle to the email message
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_COMMUNICATION_WITH_SERVER_FAILED Communication with server failed.
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see email_create_message()
+ * @see email_add_recipient()
+ * @see email_set_body()
+ * @see email_save_message
+ */
+int email_save_message(email_h email);
+
+
+/**
+ * @brief Sends the email message.
+ *
+ * @remarks In order to check whether sending a message succeeds, \n you should register email_message_sent_cb() using #email_set_message_sent_cb().
+ *
+ *
+ * @param[in] email The handle to the email message
+ * @param[in] save_to_sentbox Set to true to save the message in the sentbox, else false
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_COMMUNICATION_WITH_SERVER_FAILED Communication with server failed.
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see email_save_message()
+ * @see email_set_message_sent_cb()
+ */
+int email_send_message(email_h email, bool save_to_sentbox);
+
+
+/**
+ * @brief Called when the process of sending an email finishes.
+ * @details You can check whether sending an email succeeds using this function.
+ *
+ *
+ * @param[in] email The handle to the email message
+ * @param[in] result The result of email message sending\n
+ * #EMAIL_SENDING_FAILED or #EMAIL_SENDING_SUCCEEDED
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ * @pre email_send_message() will invoke this callback if you register this callback using email_set_message_sent_cb().
+ *
+ * @see email_send_message()
+ * @see email_set_message_sent_cb()
+ * @see email_unset_message_sent_cb()
+ */
+typedef void (* email_message_sent_cb)(email_h email, email_sending_e result, void *user_data);
+
+/**
+ * @brief Registers a callback function to be invoked when an email message is sent.
+ * @details You will be notified when sending a message finishes and check whether it succeeds using this function.
+ *
+ * @param[in] email The handle to the email message
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post It will invoke email_message_sent_cb().
+ * @see email_message_sent_cb()
+ * @see email_unset_message_sent_cb()
+ * @see email_send_message()
+ */
+int email_set_message_sent_cb(email_h email, email_message_sent_cb callback, void *user_data);
+
+/**
+ * @brief Unregisters the callback function.
+ *
+ * @param[in] email The handle to the email message
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #EMAIL_ERROR_NONE Successful
+ * @retval #EMAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see email_message_sent_cb()
+ * @see email_set_message_sent_cb()
+ * @see email_send_message()
+ */
+int email_unset_message_sent_cb(email_h msg);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+* @}
+*/
+
+#endif /* __MESSAGING_EMAIL_H__ */
diff --git a/include/email_error.h b/include/email_error.h
new file mode 100755
index 0000000..fea6a50
--- /dev/null
+++ b/include/email_error.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __EMAILAPI_ERROR_H__
+#define __EMAILAPI_ERROR_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @addtogroup CAPI_MESSAGING_EMAIL_MODULE
+ * @{
+ */
+
+/**
+ * @file email_error.h
+ * @brief Email error definitions.
+ */
+
+
+/**
+ * @brief Enumerations of error codes for email API.
+ */
+typedef enum
+{
+ EMAIL_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ EMAIL_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Memory cannot be allocated */
+ EMAIL_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+
+ EMAIL_ERROR_SERVER_NOT_READY = TIZEN_ERROR_MESSAGING_CLASS|0x200, /**< Server not ready */
+ EMAIL_ERROR_COMMUNICATION_WITH_SERVER_FAILED = TIZEN_ERROR_MESSAGING_CLASS|0x201, /**< Communication with server failed */
+ EMAIL_ERROR_OPERATION_FAILED = TIZEN_ERROR_MESSAGING_CLASS|0x202, /**< Operation failed */
+ EMAIL_ERROR_ACCOUNT_NOT_FOUND = TIZEN_ERROR_MESSAGING_CLASS|0x203, /**< Email account not found */
+ EMAIL_ERROR_DB_FAILED = TIZEN_ERROR_MESSAGING_CLASS|0x204, /**< Email database failed */
+} email_error_e;
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __EMAILAPI_ERROR_H__*/
diff --git a/include/email_private.h b/include/email_private.h
new file mode 100755
index 0000000..c4bd56b
--- /dev/null
+++ b/include/email_private.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __TIZEN_EMAIL_PRIVATE_TYPES_H__
+#define __TIZEN_EMAIL_PRIVATE_TYPES_H__
+
+#include <email-types.h>
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define MAX_ATTACHEMENT_COUNT 50
+
+#define MAX_RECIPIENT_ADDRESS_LEN 234
+
+typedef struct _email_s {
+ email_mailbox_t *mbox;
+ email_mail_data_t *mail;
+ email_attachment_data_t attachment[MAX_ATTACHEMENT_COUNT];
+} email_s;
+
+typedef struct _mailstatus_s {
+ int mailId;
+ int accountId;
+ int status;
+ int errorCode;
+} mailstatus_s;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_EMAIL_PRIVATE_TYPES_H__*/
diff --git a/include/email_types.h b/include/email_types.h
new file mode 100755
index 0000000..cf01ba8
--- /dev/null
+++ b/include/email_types.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __TIZEN_EMAIL_TYPES_H__
+#define __TIZEN_EMAIL_TYPES_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @addtogroup CAPI_MESSAGING_EMAIL_MODULE
+ * @{
+ */
+
+
+/**
+ * @file email_types.h
+ * @ingroup CAPI_MESSAGING_FRAMEWORK
+ * @brief This file defines common types and enums of EMAIL.
+ */
+
+
+/**
+ * @brief Email message handle type.
+ */
+typedef struct email_s *email_h;
+
+
+/**
+ * @brief Enumerations for the result values of email transport.
+ */
+typedef enum
+{
+ EMAIL_SENDING_FAILED = -1, /**< Email sending failed */
+ EMAIL_SENDING_SUCCEEDED = 0, /**< Email sending succeeded */
+} email_sending_e;
+
+
+/**
+ * @brief Enumerations of the email recipient types.
+ */
+typedef enum
+{
+ EMAIL_RECIPIENT_TYPE_TO = 1, /**< Normal recipient */
+ EMAIL_RECIPIENT_TYPE_CC , /**< CC(carbon copy) recipient */
+ EMAIL_RECIPIENT_TYPE_BCC , /**< BCC(blind carbon copy) recipient */
+} email_recipient_type_e;
+
+
+/**
+ * @}
+ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_EMAIL_TYPES_H__*/
+
diff --git a/packaging/capi-messaging-email.manifest b/packaging/capi-messaging-email.manifest
new file mode 100644
index 0000000..017d22d
--- /dev/null
+++ b/packaging/capi-messaging-email.manifest
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
diff --git a/packaging/capi-messaging-email.spec b/packaging/capi-messaging-email.spec
new file mode 100755
index 0000000..c8f923c
--- /dev/null
+++ b/packaging/capi-messaging-email.spec
@@ -0,0 +1,58 @@
+Name: capi-messaging-email
+Summary: Email library in Tizen Native API
+Version: 0.1.14
+Release: 3
+Group: TO_BE/FILLED_IN
+License: TO BE FILLED IN
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(edbus)
+BuildRequires: pkgconfig(email-service)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(capi-appfw-application)
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%description
+
+
+%package devel
+Summary: Email library in Tizen Native API (Development)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+
+
+
+%prep
+%setup -q
+
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+
+%files
+%{_libdir}/libcapi-messaging-email.so.*
+
+%files devel
+%{_includedir}/messaging/*.h
+%{_libdir}/pkgconfig/*.pc
+%{_libdir}/libcapi-messaging-email.so
+
+
diff --git a/src/email.c b/src/email.c
new file mode 100755
index 0000000..a6d4476
--- /dev/null
+++ b/src/email.c
@@ -0,0 +1,867 @@
+/*
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <memory.h>
+#include <dlog.h>
+#include <E_DBus.h>
+#include <email-api-mail.h>
+#include <email-api-account.h>
+#include <email-api-network.h>
+#include <email-api-mailbox.h>
+#include <email-api-init.h>
+#include <email-api.h>
+
+#define EMAIL_API_ERROR_NONE 1
+#define EMAIL_API_ERROR_OUT_OF_MEMORY -1028
+#define EMAIL_API_ERROR_ACCOUNT_NOT_FOUND -1014
+
+#undef EMAIL_ERROR_NONE
+#undef EMAIL_ERROR_OUT_OF_MEMORY
+#undef EMAIL_ERROR_ACCOUNT_NOT_FOUND
+
+#include<email.h>
+#include<email_private.h>
+#include<email_types.h>
+#include<email_error.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "CAPI_EMAIL"
+#define DBG_MODE (1)
+
+#define EM_SAFE_STRDUP(s) \
+({\
+ char* _s = (char*)s;\
+ (_s)? strdup(_s) : NULL;\
+})
+
+typedef struct {
+ email_message_sent_cb callback;
+ email_s *handle;
+ void *user_data;
+} email_cb_context;
+
+GSList *gEmailcbList= NULL;
+
+E_DBus_Signal_Handler *handler = NULL;
+//------------- Utility Or Miscellaneous
+void _email_add_dbus_filter();
+int _email_error_converter(int err, const char *func, int line);
+int _email_copy_handle(email_s **dst_handle, email_s *src_handle);
+void _email_free_cb_context(email_cb_context *cbcontext);
+
+#define CONVERT_ERROR(err) _email_error_converter(err, __FUNCTION__, __LINE__);
+
+//------------------------------------
+
+int email_create_message(email_h *msg)
+{
+ int ret;
+ email_s * msg_s = NULL;
+ email_account_t* account = NULL;
+ int len;
+
+ if(msg == NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : msg is NULL.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ // 1. create service for ipc
+ ret=email_service_begin();
+ msg_s= (email_s*)calloc(1,sizeof(email_s));
+ if (msg_s != NULL) {
+ msg_s->mail = (email_mail_data_t *)calloc(1,sizeof(email_mail_data_t));
+ if (msg_s->mail == NULL) {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to create msg_s->mail", __FUNCTION__, EMAIL_ERROR_OUT_OF_MEMORY);
+ free(msg_s);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ msg_s->mbox = (email_mailbox_t *)calloc(1,sizeof(email_mailbox_t));
+ if (msg_s->mbox == NULL) {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to create msg_s->mbox", __FUNCTION__, EMAIL_ERROR_OUT_OF_MEMORY);
+ email_free_mail_data(&msg_s->mail, 1);
+ free(msg_s);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+ } else {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to create msg_s", __FUNCTION__, EMAIL_ERROR_OUT_OF_MEMORY);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+
+
+ //return error from F/W
+ //EMAIL_ERROR_INVALID_PARAM/EMAIL_API_ERROR_NONE/EMAIL_ERROR_DB_FAILURE/EMAIL_ERROR_ACCOUNT_NOT_FOUND/EMAIL_ERROR_OUT_OF_MEMORY
+ int default_account_id = 0;
+ if ((ret = email_load_default_account_id(&default_account_id)) != EMAIL_API_ERROR_NONE) {
+ LOGE("[%s] email_load_default_account_id failed : [%d]",__FUNCTION__, ret);
+ email_free_mail_data(&msg_s->mail, 1);
+ email_free_mailbox(&msg_s->mbox, 1);
+ free(msg_s);
+ return CONVERT_ERROR(ret);
+ }
+
+ ret = email_get_account(default_account_id, GET_FULL_DATA, &account);
+ if(ret!=EMAIL_API_ERROR_NONE) {
+ LOGE("[%s] email_get_account failed : [%d]",__FUNCTION__, ret);
+ email_free_mail_data(&msg_s->mail, 1);
+ email_free_mailbox(&msg_s->mbox, 1);
+ free(msg_s);
+ return CONVERT_ERROR(ret);
+ }
+
+ LOGD_IF(DBG_MODE,"account address = %s",account->user_email_address);
+ LOGD_IF(DBG_MODE,"account id = %d",account->account_id);
+ LOGD_IF(DBG_MODE,"account name = %s",account->account_name);
+ LOGD_IF(DBG_MODE,"account user_name = %s",account->incoming_server_user_name);
+
+ msg_s->mail->full_address_from = (char *)calloc(1,sizeof(char)*(strlen(account->incoming_server_user_name)+strlen(account->user_email_address)+1+1+1+1+1));//"++"+<+ address +> + NULL
+ len= (strlen(account->incoming_server_user_name)+strlen(account->user_email_address)+1+1+1+1+1);
+ char *strfrom = msg_s->mail->full_address_from;
+
+ snprintf(strfrom,len,"%s%s%s%s%s%s","\"",account->incoming_server_user_name,"\"","<",account->user_email_address,">");
+
+ //mbox
+ email_mailbox_t *mbox =msg_s->mbox;
+
+ if ((ret = email_get_mailbox_by_mailbox_type(default_account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mbox)) != EMAIL_API_ERROR_NONE) {
+ LOGE("[%s] email_get_mailbox_by_mailbox_type failed %d", __FUNCTION__, ret);
+ email_free_mail_data(&msg_s->mail, 1);
+ email_free_mailbox(&msg_s->mbox, 1);
+ free(msg_s);
+ return EMAIL_ERROR_DB_FAILED;
+ }
+
+ //info
+ msg_s->mail->account_id = account->account_id;
+ msg_s->mail->flags_draft_field = 1;
+ msg_s->mail->flags_seen_field = 1;
+ msg_s->mail->priority = EMAIL_MAIL_PRIORITY_NORMAL;
+ msg_s->mail->mailbox_id = mbox->mailbox_id;
+ msg_s->mail->mailbox_type = mbox->mailbox_type;
+ msg_s->mail->attachment_count = 0;
+
+ *msg = (email_h)msg_s;
+ return EMAIL_ERROR_NONE;
+}
+
+int email_destroy_message(email_h msg)
+{
+ int ret;
+
+ if(msg == NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : msg is NULL.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ email_s* msg_s = (email_s* )msg;
+
+ if(msg_s)
+ {
+ if (msg_s->mail)
+ email_free_mail_data(&msg_s->mail, 1);
+
+ if (msg_s->mbox)
+ email_free_mailbox(&msg_s->mbox, 1);
+
+ free(msg_s);
+ }
+
+
+ ret=email_service_end();
+
+ if(ret!=EMAIL_API_ERROR_NONE) {
+ LOGE("[%s] OPERATION_FAILED(0x%08x) : Finishing email service failed", __FUNCTION__, EMAIL_ERROR_OPERATION_FAILED);
+ return EMAIL_ERROR_OPERATION_FAILED;
+ }
+
+
+ return EMAIL_ERROR_NONE;
+}
+
+int email_set_subject (email_h msg, const char *subject)
+{
+ int len;
+ if(msg ==NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : msg is NULL", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ email_s* msg_s = (email_s* )msg;
+
+ msg_s->mail->subject=(char*)calloc(1,sizeof(char)*strlen(subject)+1);
+
+ if(msg_s->mail->subject ==NULL) {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to create msg_s->mail->head->subject", __FUNCTION__, EMAIL_ERROR_OUT_OF_MEMORY);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ len =strlen(subject)+1;
+ snprintf(msg_s->mail->subject ,len,"%s",subject);
+
+ return EMAIL_ERROR_NONE;
+}
+
+int email_set_body (email_h msg, const char *body)
+{
+ int len;
+
+ if (msg == NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : msg is null.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ email_s* msg_s = (email_s* )msg;
+
+ FILE* file = NULL;
+
+ file = fopen("/tmp/capimail.txt", "w");
+ if (file != NULL) {
+ fputs(body, file);
+ fclose(file);
+ } else {
+ LOGE("[%s] OPERATION_FAILED(0x%08x) : opening file for email body failed.", __FUNCTION__, EMAIL_ERROR_OPERATION_FAILED);
+ return EMAIL_ERROR_OPERATION_FAILED;
+ }
+
+ msg_s->mail->file_path_plain =(char *)calloc(1,sizeof(char)*strlen("/tmp/capimail.txt")+1);
+
+ if(msg_s->mail->file_path_plain == NULL) {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to allocate body(plain).", __FUNCTION__, EMAIL_ERROR_OUT_OF_MEMORY);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ len =strlen("/tmp/capimail.txt")+1;
+ snprintf(msg_s->mail->file_path_plain,len,"%s","/tmp/capimail.txt");
+
+ return EMAIL_ERROR_NONE;
+}
+
+int email_add_recipient (email_h msg, email_recipient_type_e type, const char *address)
+{
+ char *tmp;
+ int total_len,in_len,pre_len,len;
+
+ if(msg == NULL || type < EMAIL_RECIPIENT_TYPE_TO || type > EMAIL_RECIPIENT_TYPE_BCC) {
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ email_s* msg_s = (email_s* )msg;
+
+ if(strlen(address) > MAX_RECIPIENT_ADDRESS_LEN) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : The length of address should be less than 234.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if(type == EMAIL_RECIPIENT_TYPE_TO) {
+ if(msg_s->mail->full_address_to == NULL) {
+ msg_s->mail->full_address_to = (char*)calloc(1,sizeof(char)*strlen(address)+2+1+1);//<>+;+end of string
+ if(msg_s->mail->full_address_to == NULL)
+ {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to create head->to.", __FUNCTION__, EMAIL_ERROR_OUT_OF_MEMORY);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+ len =strlen(address)+2+1+1;
+ snprintf(msg_s->mail->full_address_to,len,"%s%s%s","<",address,">");
+ } else {
+ in_len = strlen(address);
+ pre_len = strlen(msg_s->mail->full_address_to);
+ total_len = pre_len+in_len+3+1;// length of ",<>" + NULL
+
+ //add new address
+ tmp = msg_s->mail->full_address_to;
+ msg_s->mail->full_address_to = (char*)calloc(1,sizeof(char)*total_len);
+ snprintf(msg_s->mail->full_address_to,total_len,"%s%s%s%s",tmp,",<",address,">");
+ free(tmp);
+ }
+ } else if (type == EMAIL_RECIPIENT_TYPE_CC) { //MESSAGING_RECIPIENT_TYPE_CC
+ if(msg_s->mail->full_address_cc == NULL) {
+ msg_s->mail->full_address_cc = (char*)calloc(1,sizeof(char)*strlen(address)+2+1+1);//<>+;+end of string
+ if(msg_s->mail->full_address_cc == NULL) {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to create head->cc.", __FUNCTION__, EMAIL_ERROR_OUT_OF_MEMORY);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+ len =strlen(address)+2+1+1;
+ snprintf(msg_s->mail->full_address_cc,len,"%s%s%s","<",address,">");
+ } else {
+ in_len = strlen(address);
+ pre_len = strlen(msg_s->mail->full_address_cc);
+ total_len = pre_len+in_len+3+1;// length of ",<>" + NULL
+
+ //add new address
+ tmp = msg_s->mail->full_address_cc;
+ msg_s->mail->full_address_cc = (char*)calloc(1,sizeof(char)*total_len);
+ snprintf(msg_s->mail->full_address_cc,total_len,"%s%s%s%s",tmp,",<",address,">");
+ free(tmp);
+ }
+ } else { //MESSAGING_RECIPIENT_TYPE_BCC
+ if (msg_s->mail->full_address_bcc == NULL) {
+ msg_s->mail->full_address_bcc = (char*)calloc(1,sizeof(char)*strlen(address)+2+1+1);//<>+;+end of string
+ if(msg_s->mail->full_address_bcc==NULL) {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to create head->bcc.", __FUNCTION__, EMAIL_ERROR_OUT_OF_MEMORY);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+ len =strlen(address)+2+1+1;
+ snprintf(msg_s->mail->full_address_bcc,len,"%s%s%s","<",address,">");
+ } else {
+ in_len = strlen(address);
+ pre_len = strlen(msg_s->mail->full_address_bcc);
+ total_len = pre_len+in_len+3+1;// length of ",<>" + NULL
+
+ //add new address
+ tmp = msg_s->mail->full_address_bcc;
+ msg_s->mail->full_address_bcc = (char*)calloc(1,sizeof(char)*total_len);
+ snprintf(msg_s->mail->full_address_bcc,total_len,"%s%s%s%s",tmp,",<",address,">");
+ free(tmp);
+ }
+ }
+
+ return EMAIL_ERROR_NONE;
+}
+
+int email_remove_all_recipients(email_h msg)
+{
+ if(msg ==NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : fail to create tmp memory.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ email_s *msg_s = (email_s *)msg;
+
+ if (msg_s->mail->full_address_to != NULL) {
+ free(msg_s->mail->full_address_to);
+ msg_s->mail->full_address_to = NULL;
+ }
+
+ if (msg_s->mail->full_address_cc != NULL) {
+ free(msg_s->mail->full_address_cc);
+ msg_s->mail->full_address_cc = NULL;
+ }
+
+ if (msg_s->mail->full_address_bcc != NULL) {
+ free(msg_s->mail->full_address_bcc);
+ msg_s->mail->full_address_bcc = NULL;
+ }
+
+ return EMAIL_ERROR_NONE;
+}
+
+int email_add_attach(email_h msg, const char *filepath)
+{
+ int len;
+ char *pos,*last;
+ struct stat st;
+
+ if(msg ==NULL || filepath == NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : msg or filepath is null.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ email_s *msg_s = (email_s *)msg;
+
+ int attachment_count = msg_s->mail->attachment_count;
+ email_attachment_data_t *new_attach = msg_s->attachment;
+
+ stat(filepath, &st);
+ if(st.st_size > 10*1024*1024) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : the size of attachment file is beyond the limit(MAX:10M).", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!S_ISREG(st.st_mode)) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : the filepath is not regular file.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ pos=strpbrk(filepath, "//");
+ len =strlen(filepath);
+ if(pos == NULL) {
+ new_attach[attachment_count].attachment_name = (char*)calloc(1,sizeof(char)*len+1);
+ snprintf(new_attach[attachment_count].attachment_name,len+1,"%s",filepath);
+ } else {
+ while(pos != NULL) {
+ last=pos;
+ pos=strpbrk(pos,"//");
+ if(pos != NULL) pos++;
+ }
+
+ new_attach[attachment_count].attachment_name = strdup(last);
+ }
+ new_attach[attachment_count].attachment_path =(char*)calloc(1,sizeof(char)*len+1);
+ if (new_attach[attachment_count].attachment_path == NULL) return EMAIL_ERROR_OUT_OF_MEMORY;
+
+ snprintf(new_attach[attachment_count].attachment_path, len+1, "%s", filepath);
+ new_attach[attachment_count].attachment_size = st.st_size;
+ new_attach[attachment_count].save_status = 1;
+
+ msg_s->mail->attachment_count++;
+
+ return EMAIL_ERROR_NONE;
+}
+
+int email_remove_all_attachments (email_h msg)
+{
+ if (msg ==NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : msg is null.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ email_s* msg_s = (email_s* )msg;
+ msg_s->mail->attachment_count = 0;
+
+ return EMAIL_ERROR_NONE;
+}
+
+int email_save_message (email_h msg)
+{
+ int i, ret;
+ email_attachment_data_t *tmp_attach = NULL;
+ struct tm *struct_time;
+
+ if (msg == NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : msg is null.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ email_s *msg_s = (email_s *)msg;
+
+ /*--------- head ----------*/
+ LOGD_IF(DBG_MODE, " ----------head---------");
+ LOGD_IF(DBG_MODE, " mid: %s\n",msg_s->mail->message_id);
+ LOGD_IF(DBG_MODE, " subject: %s\n",msg_s->mail->subject);
+ LOGD_IF(DBG_MODE, " to: %s\n",msg_s->mail->full_address_to);
+ LOGD_IF(DBG_MODE, " from: %s\n",msg_s->mail->full_address_from);
+ LOGD_IF(DBG_MODE, " cc: %s\n",msg_s->mail->full_address_cc);
+ LOGD_IF(DBG_MODE, " bcc: %s\n",msg_s->mail->full_address_bcc);
+ LOGD_IF(DBG_MODE, " reply_to: %s\n",msg_s->mail->full_address_reply);
+ LOGD_IF(DBG_MODE, " return_path: %s\n",msg_s->mail->full_address_return);
+ LOGD_IF(DBG_MODE, " previewBodyText: %s\n",msg_s->mail->preview_text);
+
+ struct_time = localtime(&msg_s->mail->date_time);
+
+ LOGD_IF(DBG_MODE, " %4d year\n", struct_time->tm_year+1900);
+ LOGD_IF(DBG_MODE, " %2d month\n", struct_time->tm_mon+1);
+ LOGD_IF(DBG_MODE, " %2d day\n", struct_time->tm_mday);
+ LOGD_IF(DBG_MODE, " %2d:%2d:%2d \n", struct_time->tm_hour, struct_time->tm_min, struct_time->tm_sec);
+
+ /*--------- body ----------*/
+ LOGD_IF(DBG_MODE, " ----------body---------");
+ LOGD_IF(DBG_MODE, " body\n");
+ LOGD_IF(DBG_MODE, " plain: %s\n",msg_s->mail->file_path_plain);
+ LOGD_IF(DBG_MODE, " html: %s\n",msg_s->mail->file_path_html);
+ LOGD_IF(DBG_MODE, " attachment_num: %d\n",msg_s->mail->attachment_count);
+ tmp_attach = msg_s->attachment;
+ for (i=0; i < msg_s->mail->attachment_count; i++) {
+ LOGD_IF(DBG_MODE, " ----------attachment[%d]---------", i+1);
+ LOGD_IF(DBG_MODE, " name: %s\n",tmp_attach[i].attachment_name);
+ LOGD_IF(DBG_MODE, " savename: %s\n",tmp_attach[i].attachment_path);
+ LOGD_IF(DBG_MODE, " downloaded: %d\n",tmp_attach[i].save_status);
+ LOGD_IF(DBG_MODE, " size: %d\n",tmp_attach[i].attachment_size);
+ }
+
+ /*--------- info ----------*/
+ LOGD_IF(DBG_MODE, " ----------info---------");
+ LOGD_IF(DBG_MODE, " account_id: %d\n",msg_s->mail->account_id);
+ LOGD_IF(DBG_MODE, " mail_id: %d\n",msg_s->mail->mail_id);
+ LOGD_IF(DBG_MODE, " mail_size: %d\n",msg_s->mail->mail_size);
+ LOGD_IF(DBG_MODE, " body_download_status: %d\n",msg_s->mail->body_download_status);
+ LOGD_IF(DBG_MODE, " server_id: %s\n",msg_s->mail->server_mail_id);
+ LOGD_IF(DBG_MODE, " meeting_request_status: %d\n",msg_s->mail->meeting_request_status);
+
+ email_mailbox_t * box;
+ box=msg_s->mbox;
+ LOGD_IF(DBG_MODE, " ----------box---------");
+ LOGD_IF(DBG_MODE, " email_mailbox_t \n");
+ LOGD_IF(DBG_MODE, " name: %s\n",box->mailbox_name);
+ LOGD_IF(DBG_MODE, " mailbox_type: %d\n",box->mailbox_type);
+ LOGD_IF(DBG_MODE, " alias: %s\n",box->alias);
+ LOGD_IF(DBG_MODE, " unread_count: %d\n",box->unread_count);
+ LOGD_IF(DBG_MODE, " total_mail_count_on_local: %d\n",box->total_mail_count_on_local);
+ LOGD_IF(DBG_MODE, " total_mail_count_on_server: %d\n",box->total_mail_count_on_server);
+ LOGD_IF(DBG_MODE, " local: %d\n",box->local);
+ LOGD_IF(DBG_MODE, " account_id: %d\n",box->account_id);
+ LOGD_IF(DBG_MODE, " mail_slot_size: %d\n",box->mail_slot_size);
+
+ ret=email_add_mail(msg_s->mail, msg_s->attachment, msg_s->mail->attachment_count, NULL, 0);
+
+ ret=CONVERT_ERROR(ret);
+
+ return ret;
+}
+
+int email_send_message (email_h msg, bool save_to_sentbox)
+{
+ int ret;
+ int handle;
+
+ if (msg == NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : msg is null.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ email_s *msg_s = (email_s *)msg;
+
+ ret = email_send_mail(msg_s->mail->mail_id, &handle);
+
+ ret = CONVERT_ERROR(ret);
+
+ _email_add_dbus_filter();
+
+ return ret;
+}
+
+email_cb_context *_email_search_callback_by_emailid(int mailid)
+{
+ int count;
+ int ntmp=0;
+ GSList *node;
+ email_cb_context *cbContext;
+ count = g_slist_length(gEmailcbList);
+
+ LOGD_IF(DBG_MODE, "Count : [%d]\n", count);
+ while (count) {
+ node = g_slist_nth(gEmailcbList, ntmp);
+
+ if (node == NULL)
+ break;
+
+ cbContext = (email_cb_context *)node->data;
+ LOGD_IF(DBG_MODE, "mail_id : [%d]\n", cbContext->handle->mail->mail_id);
+ if (cbContext->handle->mail->mail_id == mailid) {
+ return cbContext;
+ }
+
+ ntmp++;
+ count--;
+ }
+
+ return NULL;
+}
+
+int email_set_message_sent_cb (email_h handle, email_message_sent_cb cb, void *user_data)
+{
+ int count;
+ int ntmp=0;
+ int ret = EMAIL_ERROR_NONE;
+ GSList *node;
+ email_cb_context *cbContext;
+ count = g_slist_length(gEmailcbList);
+
+ if(handle == NULL || cb == NULL) return EMAIL_ERROR_INVALID_PARAMETER;
+
+ email_s* msg_s = NULL;
+
+ while (count) {
+ node = g_slist_nth(gEmailcbList, ntmp);
+
+ if (node == NULL)
+ break;
+
+ cbContext = (email_cb_context *)node->data;
+ if (cbContext->handle == (email_s *)handle) {
+ gEmailcbList = g_slist_remove(gEmailcbList,node);
+ _email_free_cb_context(cbContext);
+ break;
+ }
+
+ ntmp++;
+ count--;
+ }
+
+ if ((ret = _email_copy_handle(&msg_s, (email_s *)handle)) != EMAIL_ERROR_NONE) {
+ LOGE("[%s] _email_copy_handle failed", __FUNCTION__);
+ return ret;
+ }
+
+ email_cb_context *cbcontext = (email_cb_context *)calloc(1, sizeof(email_cb_context) );
+
+ cbcontext->handle = msg_s;
+ cbcontext->callback = cb;
+ cbcontext->user_data = user_data;
+
+ gEmailcbList = g_slist_append(gEmailcbList,cbcontext);
+
+
+ return EMAIL_ERROR_NONE;
+}
+
+int email_unset_message_sent_cb (email_h msg)
+{
+ int i,count;
+ count = g_slist_length(gEmailcbList);
+ GSList *node;
+ email_cb_context *cbContext;
+
+ if (msg ==NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : msg is null.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ }
+
+ email_s* msg_s = (email_s* )msg;
+ for (i=0;i<count;i++) {
+ node = g_slist_nth(gEmailcbList, i);
+ if( node == NULL )
+ break;
+
+ cbContext = (email_cb_context *)node->data;
+ if(cbContext->handle == msg_s) {
+ gEmailcbList = g_slist_remove(gEmailcbList,node);
+ _email_free_cb_context(cbContext);
+ break;
+ }
+ }
+ return EMAIL_ERROR_NONE;
+}
+
+int _email_error_converter(int err, const char *func, int line)
+{
+ switch(err) {
+ case EMAIL_ERROR_INVALID_PARAM :
+ LOGE("[%s:%d] INVALID_PARAM(0x%08x) : Error from Email F/W. ret: (0x%08x) ", func, line, EMAIL_ERROR_INVALID_PARAMETER, err);
+ return EMAIL_ERROR_INVALID_PARAMETER;
+ case EMAIL_ERROR_DB_FAILURE :
+ LOGE("[%s:%d] DB_FAILURE(0x%08x) : Error from Email F/W. ret: (0x%08x) ", func, line, EMAIL_ERROR_DB_FAILED, err);
+ return EMAIL_ERROR_DB_FAILED;
+ case EMAIL_API_ERROR_ACCOUNT_NOT_FOUND :
+ LOGE("[%s:%d] ACCOUNT_NOT_FOUND(0x%08x) : Error from Email F/W. ret: (0x%08x) ", func, line, EMAIL_ERROR_ACCOUNT_NOT_FOUND,err);
+ return EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+ case EMAIL_API_ERROR_OUT_OF_MEMORY :
+ LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) : Error from Email F/W. ret: (0x%08x) ", func, line, EMAIL_ERROR_OUT_OF_MEMORY,err);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ // Tizen email F/W is often using this error type when it gets a null value from server
+ //It could be caused from server or IPC.
+ case EMAIL_ERROR_NULL_VALUE :
+ LOGE("[%s:%d] NULL_VALUE(0x%08x) : Error from Email F/W. ret: (0x%08x) ", func, line, EMAIL_ERROR_COMMUNICATION_WITH_SERVER_FAILED,err);
+ return EMAIL_ERROR_COMMUNICATION_WITH_SERVER_FAILED;
+ case EMAIL_ERROR_IPC_SOCKET_FAILURE :
+ LOGE("[%s:%d] IPC_SOCKET_FAILURE(0x%08x) : Error from Email F/W. ret: (0x%08x) ", func, line, EMAIL_ERROR_COMMUNICATION_WITH_SERVER_FAILED,err);
+ return EMAIL_ERROR_COMMUNICATION_WITH_SERVER_FAILED;
+ case EMAIL_API_ERROR_NONE :
+ return EMAIL_ERROR_NONE;
+ default :
+ LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : Error from Email F/W. ret: (0x%08x) ", func, line, EMAIL_ERROR_OPERATION_FAILED,err);
+ return EMAIL_ERROR_OPERATION_FAILED;
+ }
+}
+
+static void _monitorSendStatusCb(void* data, DBusMessage *message)
+{
+ DBusError error;
+ email_cb_context *cbContext = NULL;
+ if (dbus_message_is_signal(message, "User.Email.NetworkStatus", "email")) {
+ dbus_error_init(&error);
+
+ int status=0;
+ int accountid=0;
+ char* fileid=NULL;
+ int mailid=0;
+ int errorcode=0;
+ if(dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &status, DBUS_TYPE_INT32, &accountid, DBUS_TYPE_STRING, &fileid, DBUS_TYPE_INT32, &mailid, DBUS_TYPE_INT32, &errorcode, DBUS_TYPE_INVALID)) {
+ LOGD_IF(DBG_MODE, "status:[%d], account_id:[%d], file_id:[%s], mail_id:[%d], error_code:[%d]", status, accountid, fileid, mailid, errorcode);
+ cbContext = _email_search_callback_by_emailid(mailid);
+ if(cbContext == NULL) {
+ LOGD_IF(DBG_MODE, "no callback matched!\n");
+ } else {
+ switch (status) {
+ case NOTI_SEND_START:
+ break;
+ case NOTI_SEND_FAIL:
+ switch(errorcode) {
+ case EMAIL_ERROR_NO_SIM_INSERTED:
+ case EMAIL_ERROR_FLIGHT_MODE:
+ case EMAIL_ERROR_SMTP_SEND_FAILURE:
+ case EMAIL_ERROR_NO_SUCH_HOST:
+ case EMAIL_ERROR_CONNECTION_FAILURE:
+ case EMAIL_ERROR_CONNECTION_BROKEN:
+ case EMAIL_ERROR_INVALID_SERVER:
+ case EMAIL_ERROR_NO_RESPONSE:
+ break;
+ default:
+ break;
+ }
+ cbContext->callback((email_h)cbContext->handle, (email_sending_e)EMAIL_SENDING_FAILED, cbContext->user_data);
+ break;
+ case NOTI_SEND_FINISH:
+ cbContext->callback((email_h)cbContext->handle, (email_sending_e)EMAIL_SENDING_SUCCEEDED, cbContext->user_data);
+ break;
+ }
+ }
+ }
+ }
+}
+
+void _email_add_dbus_filter()
+{
+ E_DBus_Connection* connection=NULL;
+ DBusError error;
+
+ if (handler != NULL)
+ return;
+
+ dbus_error_init(&error);
+
+ connection = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+ if (NULL == connection) {
+ return;
+ }
+
+ if (e_dbus_request_name(connection, "User.Email.NetworkStatus", 0, NULL, NULL) == NULL) {
+ LOGD_IF(DBG_MODE, "Failed in e_dbus_request_name()\n");
+ return;
+ }
+
+ handler = e_dbus_signal_handler_add(connection, NULL, "/User/Email/NetworkStatus", "User.Email.NetworkStatus", "email", _monitorSendStatusCb, NULL);
+
+ if (handler == NULL) {
+ LOGD_IF(DBG_MODE, "Failed in e_dbus_signal_handler_add()");
+ }
+}
+
+int _email_copy_mail_data(email_mail_data_t **dst_mail_data, email_mail_data_t *src_mail_data)
+{
+ email_mail_data_t *temp_mail_data = NULL;
+
+ temp_mail_data = (email_mail_data_t *)calloc(1, sizeof(email_mail_data_t));
+ if (temp_mail_data == NULL) {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to create email_mail_data_t", __FUNCTION__, EMAIL_ERROR_OUT_OF_MEMORY);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ temp_mail_data->mail_id = src_mail_data->mail_id;
+ temp_mail_data->account_id = src_mail_data->account_id;
+ temp_mail_data->mailbox_id = src_mail_data->mailbox_id;
+ temp_mail_data->mailbox_type = src_mail_data->mailbox_type;
+ temp_mail_data->subject = EM_SAFE_STRDUP(src_mail_data->subject);
+ temp_mail_data->date_time = src_mail_data->date_time;
+ temp_mail_data->server_mail_status = src_mail_data->server_mail_status;
+ temp_mail_data->server_mailbox_name = EM_SAFE_STRDUP(src_mail_data->server_mailbox_name);
+ temp_mail_data->server_mail_id = EM_SAFE_STRDUP(src_mail_data->server_mail_id);
+ temp_mail_data->message_id = EM_SAFE_STRDUP(src_mail_data->message_id);
+ temp_mail_data->full_address_from = EM_SAFE_STRDUP(src_mail_data->full_address_from);
+ temp_mail_data->full_address_reply = EM_SAFE_STRDUP(src_mail_data->full_address_reply);
+ temp_mail_data->full_address_to = EM_SAFE_STRDUP(src_mail_data->full_address_to);
+ temp_mail_data->full_address_cc = EM_SAFE_STRDUP(src_mail_data->full_address_cc);
+ temp_mail_data->full_address_bcc = EM_SAFE_STRDUP(src_mail_data->full_address_bcc);
+ temp_mail_data->full_address_return = EM_SAFE_STRDUP(src_mail_data->full_address_return);
+ temp_mail_data->email_address_sender = EM_SAFE_STRDUP(src_mail_data->email_address_sender);
+ temp_mail_data->email_address_recipient = EM_SAFE_STRDUP(src_mail_data->email_address_recipient);
+ temp_mail_data->alias_sender = EM_SAFE_STRDUP(src_mail_data->alias_sender);
+ temp_mail_data->alias_recipient = EM_SAFE_STRDUP(src_mail_data->alias_recipient);
+ temp_mail_data->body_download_status = src_mail_data->body_download_status;
+ temp_mail_data->file_path_plain = EM_SAFE_STRDUP(src_mail_data->file_path_plain);
+ temp_mail_data->file_path_html = EM_SAFE_STRDUP(src_mail_data->file_path_html);
+ temp_mail_data->file_path_mime_entity = EM_SAFE_STRDUP(src_mail_data->file_path_mime_entity);
+ temp_mail_data->mail_size = src_mail_data->mail_size;
+ temp_mail_data->flags_seen_field = src_mail_data->flags_seen_field;
+ temp_mail_data->flags_deleted_field = src_mail_data->flags_deleted_field;
+ temp_mail_data->flags_flagged_field = src_mail_data->flags_flagged_field;
+ temp_mail_data->flags_answered_field = src_mail_data->flags_answered_field;
+ temp_mail_data->flags_recent_field = src_mail_data->flags_recent_field;
+ temp_mail_data->flags_draft_field = src_mail_data->flags_draft_field;
+ temp_mail_data->flags_forwarded_field = src_mail_data->flags_forwarded_field;
+ temp_mail_data->DRM_status = src_mail_data->DRM_status;
+ temp_mail_data->priority = src_mail_data->priority;
+ temp_mail_data->save_status = src_mail_data->save_status;
+ temp_mail_data->lock_status = src_mail_data->lock_status;
+ temp_mail_data->report_status = src_mail_data->report_status;
+ temp_mail_data->attachment_count = src_mail_data->attachment_count;
+ temp_mail_data->inline_content_count = src_mail_data->inline_content_count;
+ temp_mail_data->thread_id = src_mail_data->thread_id;
+ temp_mail_data->thread_item_count = src_mail_data->thread_item_count;
+ temp_mail_data->preview_text = EM_SAFE_STRDUP(src_mail_data->preview_text);
+ temp_mail_data->meeting_request_status = src_mail_data->meeting_request_status;
+ temp_mail_data->message_class = src_mail_data->message_class;
+ temp_mail_data->digest_type = src_mail_data->digest_type;
+ temp_mail_data->smime_type = src_mail_data->smime_type;
+
+ *dst_mail_data = temp_mail_data;
+
+ return EMAIL_ERROR_NONE;
+}
+
+int _email_copy_mailbox(email_mailbox_t **dst_mailbox, email_mailbox_t *src_mailbox)
+{
+ email_mailbox_t *temp_mailbox = NULL;
+
+ temp_mailbox = (email_mailbox_t *)calloc(1,sizeof(email_mailbox_t));
+ if (temp_mailbox == NULL) {
+ LOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to create mailbox", __FUNCTION__, EMAIL_ERROR_OUT_OF_MEMORY);
+ return EMAIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ temp_mailbox->mailbox_id = src_mailbox->mailbox_id;
+ temp_mailbox->mailbox_name = EM_SAFE_STRDUP(src_mailbox->mailbox_name);
+ temp_mailbox->mailbox_type = src_mailbox->mailbox_type;
+ temp_mailbox->alias = EM_SAFE_STRDUP(src_mailbox->alias);
+ temp_mailbox->unread_count = src_mailbox->unread_count;
+ temp_mailbox->total_mail_count_on_local = src_mailbox->total_mail_count_on_local;
+ temp_mailbox->total_mail_count_on_server = src_mailbox->total_mail_count_on_server;
+ temp_mailbox->local = src_mailbox->local;
+ temp_mailbox->account_id = src_mailbox->account_id;
+ temp_mailbox->mail_slot_size = src_mailbox->mail_slot_size;
+ temp_mailbox->last_sync_time = src_mailbox->last_sync_time;
+
+ *dst_mailbox = temp_mailbox;
+
+ return EMAIL_ERROR_NONE;
+}
+
+int _email_copy_handle(email_s **dst_handle, email_s *src_handle)
+{
+ int ret = EMAIL_ERROR_NONE;
+ email_s *msg_s = NULL;
+
+ msg_s = (email_s *)calloc(1,sizeof(email_s));
+ if ((ret = _email_copy_mail_data(&msg_s->mail, src_handle->mail)) != EMAIL_ERROR_NONE) {
+ LOGE("[%s] _email_copy_mail_data failed", __FUNCTION__);
+ email_destroy_message((email_h)msg_s); /*prevent 25431*/
+ return ret;
+ }
+
+ if ((ret = _email_copy_mailbox(&msg_s->mbox, src_handle->mbox)) != EMAIL_ERROR_NONE) {
+ LOGE("[%s] _email_copy_mailbox failed", __FUNCTION__);
+ email_destroy_message((email_h)msg_s); /*prevent 25431*/
+ return ret;
+ }
+
+ *dst_handle = msg_s;
+ return ret;
+}
+
+void _email_free_cb_context(email_cb_context *cbcontext)
+{
+ if(cbcontext == NULL) {
+ LOGE("[%s] INVALID_PARAMETER(0x%08x) : msg is NULL.", __FUNCTION__, EMAIL_ERROR_INVALID_PARAMETER);
+ return;
+ }
+
+ email_s* msg_s = cbcontext->handle;
+
+ if(msg_s)
+ {
+ if (msg_s->mail)
+ email_free_mail_data(&msg_s->mail, 1);
+
+ if (msg_s->mbox)
+ email_free_mailbox(&msg_s->mbox, 1);
+
+ free(msg_s);
+ }
+
+ cbcontext = NULL;
+}