diff options
Diffstat (limited to 'common')
-rwxr-xr-x | common/CMakeLists.txt | 45 | ||||
-rwxr-xr-x | common/include/email-common-types.h | 57 | ||||
-rwxr-xr-x | common/include/email-debug.h | 165 | ||||
-rwxr-xr-x | common/include/email-engine.h | 50 | ||||
-rwxr-xr-x | common/include/email-locale.h | 52 | ||||
-rwxr-xr-x | common/include/email-utils.h | 78 | ||||
-rwxr-xr-x | common/src/email-debug.c | 239 | ||||
-rwxr-xr-x | common/src/email-engine.c | 263 | ||||
-rwxr-xr-x | common/src/email-utils.c | 448 |
9 files changed, 1397 insertions, 0 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100755 index 0000000..ec8f5a9 --- /dev/null +++ b/common/CMakeLists.txt @@ -0,0 +1,45 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(email-common C) + +SET(PROJECT_NAME "email-common") +SET(SRCS-common + ./src/email-debug.c + ./src/email-engine.c + ./src/email-utils.c +) + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") +MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") + +SET(CMAKE_COMMON_SOURCE_DIR "${CMAKE_SOURCE_DIR}/common") +INCLUDE_DIRECTORIES(${CMAKE_COMMON_SOURCE_DIR}/include) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs-common REQUIRED ecore ecore-imf appcore-common glib-2.0 gobject-2.0 email-service + dlog db-util elementary efreet-mime drm-client ecore-x sysman vconf evas eina edje icu-i18n) + +FOREACH(flag ${pkgs-common_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -finstrument-functions") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") + SET(CMAKE_C_FLAGS_RELEASE "-mabi=aapcs-linux -msoft-float -O2") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DDEBUG") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS-common}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs-common_LDFLAGS}) + +INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIBDIR}) diff --git a/common/include/email-common-types.h b/common/include/email-common-types.h new file mode 100755 index 0000000..8a06658 --- /dev/null +++ b/common/include/email-common-types.h @@ -0,0 +1,57 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 _EMAIL_COMMON_TYPES_H_ +#define _EMAIL_COMMON_TYPES_H_ + +#include <email-types.h> +#include "email-locale.h" + +#define MAX_STR_LEN 1024 +#define MAX_PATH_LEN 1024 +#define MAX_URL_LEN 1024 +#define MAX_RECPT_LEN (MAX_STR_LEN * 8 + 1) + +/* define bundle key */ +#define EMAIL_BUNDLE_KEY_ACCOUNT_ID "ACCOUNT_ID" +#define EMAIL_BUNDLE_KEY_MAILBOX "MAILBOX" +#define EMAIL_BUNDLE_KEY_SAVE_ALL "SAVE_ALL" +#define EMAIL_BUNDLE_KEY_CANCEL_ALL "CANCEL_ALL" +#define EMAIL_BUNDLE_KEY_RUN_TYPE "RUN_TYPE" +#define EMAIL_BUNDLE_KEY_MAIL_ID "MAIL_ID" +#define EMAIL_BUNDLE_KEY_TO "TO" +#define EMAIL_BUNDLE_KEY_CC "CC" +#define EMAIL_BUNDLE_KEY_BCC "BCC" +#define EMAIL_BUNDLE_KEY_SUBJECT "SUBJECT" +#define EMAIL_BUNDLE_KEY_BODY "BODY" +#define EMAIL_BUNDLE_KEY_ATTACHMENT "ATTACHMENT" + +#define EMAIL_BUNDLE_KEY_VIDEO_PLAYER_LAUNCH_APP "launching_application" + +typedef enum { + RUN_TYPE_UNKNOWN = -1, + RUN_COMPOSER_NEW, /*< Specific new type. this type is used to create new email */ + RUN_COMPOSER_EDIT, /*< Specific edit type. this type is used to open draft email */ + RUN_COMPOSER_REPLY, /*< Specific reply type. this type is used to reply email */ + RUN_COMPOSER_REPLY_ALL, /*< Specific reply all type. this type is used to replay email to all */ + RUN_COMPOSER_FORWARD, /*< Specific forward type. this type is used to forward email */ + RUN_COMPOSER_EXTERNAL, /*< Specific external type. this type is used to create new email from external app except email app */ + RUN_TYPE_MAX +} EmailRunType; + +#endif /* _EMAIL_COMMON_TYPES_H_ */ + +/* EOF */ diff --git a/common/include/email-debug.h b/common/include/email-debug.h new file mode 100755 index 0000000..2114a91 --- /dev/null +++ b/common/include/email-debug.h @@ -0,0 +1,165 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 _EMAIL_DEBUG_H_ +#define _EMAIL_DEBUG_H_ + +#include <string.h> +#include <glib.h> +#include <glib-object.h> +G_BEGIN_DECLS + +typedef enum { + EMAIL_DEBUG_CRITICAL = 0, + EMAIL_DEBUG_WARNING, + EMAIL_DEBUG_EXPR, + EMAIL_DEBUG_TIME, + EMAIL_DEBUG_LOG, + EMAIL_DEBUG_MAX +} EmailDebugType; + +#undef debug_trace +#undef debug_log +#undef debug_assert +#undef debug_warning +#undef debug_critical +#undef debug_time + +#ifndef DEBUG +#define DEBUG +#endif + +#ifdef DEBUG + +#define GET_FILE_NAME(p) \ + do { \ + char *f = __FILE__; \ + p = strrchr(f, '/'); \ + if (p) p++; \ + else p = f; \ + } while (0) + +#include "dlog.h" + +#define MODULE_TAG "email_svc" + +#define debug_trace(fmt, args...) SLOG(LOG_DEBUG, MODULE_TAG, "[%s:%s():#%d] " fmt, (rindex(__FILE__, '/') ? rindex(__FILE__, '/')+1 : __FILE__), __func__, __LINE__, ##args) +#define debug_log(fmt, args...) SLOG(LOG_DEBUG, MODULE_TAG, "[%s:%s():#%d] " fmt, (rindex(__FILE__, '/') ? rindex(__FILE__, '/')+1 : __FILE__), __func__, __LINE__, ##args) +#define debug_assert(fmt, args...) SLOG(LOG_DEBUG, MODULE_TAG, "[%s:%s():#%d] " fmt, (rindex(__FILE__, '/') ? rindex(__FILE__, '/')+1 : __FILE__), __func__, __LINE__, ##args) +#define debug_warning(fmt, args...) SLOG(LOG_DEBUG, MODULE_TAG, "[%s:%s():#%d] * Warning * " fmt, (rindex(__FILE__, '/') ? rindex(__FILE__, '/')+1 : __FILE__), __func__, __LINE__, ##args) +#define debug_critical(fmt, args...) SLOG(LOG_ERROR, MODULE_TAG, "[%s:%s():#%d] * Critical * " fmt, (rindex(__FILE__, '/') ? rindex(__FILE__, '/')+1 : __FILE__), __func__, __LINE__, ##args) +#define debug_enter() SLOG(LOG_DEBUG, MODULE_TAG, "[%s:%s():#%d] *ENTER*" , (rindex(__FILE__, '/') ? rindex(__FILE__, '/')+1 : __FILE__), __func__, __LINE__) +#define debug_leave() SLOG(LOG_DEBUG, MODULE_TAG, "[%s:%s():#%d] *LEAVE*" , (rindex(__FILE__, '/') ? rindex(__FILE__, '/')+1 : __FILE__), __func__, __LINE__) + +# define debug_time() \ + do { \ + char *p = NULL; \ + GET_FILE_NAME(p); \ + email_time_elapsed_message(p, __FUNCTION__, __LINE__); \ + } while (0) + +#else /* DEBUG */ + +#define debug_trace() +#define debug_log(fmt, args...) +#define debug_assert(fmt, args...) +#define debug_warning(fmt, args...) +#define debug_critical(fmt, args...) +#define debug_time() + +#endif /* DEBUG */ + +#define PROFILE_BEGIN(pfid) \ + unsigned int __prf_l1_##pfid = __LINE__;\ + struct timeval __prf_1_##pfid;\ + struct timeval __prf_2_##pfid;\ + do {\ + gettimeofday(&__prf_1_##pfid, 0);\ + debug_log("[%s:%s():#%u] * PROFILE (" #pfid ") BEGIN *",\ + (rindex(__FILE__, '/') ? rindex(__FILE__, '/')+1 : __FILE__), \ + __FUNCTION__,\ + __prf_l1_##pfid);\ + } while (0) + +#define PROFILE_END(pfid) \ + unsigned int __prf_l2_##pfid = __LINE__;\ + do { \ + gettimeofday(&__prf_2_##pfid, 0);\ + long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\ + long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\ + if (__dm < 0) { __ds--; __dm = 1000000 + __dm; } \ + debug_log("[%s:%s(): #%u ~ #%u] * PROFILE(" #pfid ") END * "\ + " %u.%06u seconds elapsed\n",\ + (rindex(__FILE__, '/') ? rindex(__FILE__, '/')+1 : __FILE__),\ + __FUNCTION__,\ + __prf_l1_##pfid,\ + __prf_l2_##pfid,\ + (unsigned int)(__ds),\ + (unsigned int)(__dm));\ + } while (0) + +#define RETURN_IF_FAIL(expr) \ + do { \ + if (!(expr)) { \ + debug_assert("expr : (%s) failed", #expr); \ + return; \ + } \ + } while (0) + +#define RETURN_VAL_IF_FAIL(expr, val) \ + do { \ + if (!(expr)) { \ + debug_assert("expr : (%s) failed", #expr); \ + return (val); \ + } \ + } while (0) + +#define warn_if(expr, fmt, arg...) do { \ + if (expr) { \ + debug_warning(fmt, ##arg); \ + } \ + } while (0) +#define ret_if(expr) do { \ + if (expr) { \ + return; \ + } \ + } while (0) +#define retv_if(expr, val) do { \ + if (expr) { \ + return (val); \ + } \ + } while (0) +#define retm_if(expr, fmt, arg...) do { \ + if (expr) { \ + debug_assert(fmt, ##arg); \ + return; \ + } \ + } while (0) +#define retvm_if(expr, val, fmt, arg...) do { \ + if (expr) { \ + debug_assert(fmt, ##arg); \ + return (val); \ + } \ + } while (0) + +void email_debug_message(EmailDebugType type, const gchar *file_name, const gchar *func, gint line_number, const gchar *format, ...); +void email_time_elapsed_message(const gchar *file_name, const gchar *func, gint line_number); +void email_time_elapsed_reset(void); + +G_END_DECLS +#endif /* _EMAIL_DEBUG_H_ */ + +/* EOF */ diff --git a/common/include/email-engine.h b/common/include/email-engine.h new file mode 100755 index 0000000..9375880 --- /dev/null +++ b/common/include/email-engine.h @@ -0,0 +1,50 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 _EMAIL_ENGINE_H_ +#define _EMAIL_ENGINE_H_ + +#include <glib.h> +#include <email-api.h> + +G_BEGIN_DECLS + +/* Array length definition */ + +#define TAG_LEN 20 /*tag for hightlight keyword <color=#ff0000>key</>*/ +#define FROM_LEN 100 +#define SUBJECT_LEN 100 +#define FOLDER_LEN 100 +#define ADDR_LEN 320 +#define RECIPIENT_LEN 100 + + +gboolean email_engine_initialize(void); +void email_engine_finalize(void); +gboolean email_engine_get_account_full_data(int acctid, email_account_t **account); +gboolean email_engine_get_default_account(gint *account_id); +gboolean email_engine_set_default_account(gint account_id); + +void email_engine_stop_working(gint account_id, unsigned handle); + +gboolean email_engine_delete_mail(gint account_id, int mailbox_id, gint mail_id, int sync); + +gchar *email_engine_get_attachment_path(gint attach_id); /* g_free(). */ + +G_END_DECLS +#endif /* _EMAIL_ENGINE_H_ */ + +/* EOF */ diff --git a/common/include/email-locale.h b/common/include/email-locale.h new file mode 100755 index 0000000..ed51c29 --- /dev/null +++ b/common/include/email-locale.h @@ -0,0 +1,52 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 __DEF_EMAIL_LOCALE_H_ +#define __DEF_EMAIL_LOCALE_H_ + +#ifndef PACKAGE +#define PACKAGE "email" +#endif + +#ifndef PKGNAME +#define PKGNAME "org.tizen.email" +#endif + +#ifndef LOCALEDIR +#define LOCALEDIR "/opt/apps/org.tizen.email/res/locale" +#endif + +#ifndef EDJDIR +#define EDJDIR "/opt/apps/org.tizen.email/res/edje" +#endif + +#ifndef IMGDIR +#define IMGDIR "/opt/apps/org.tizen.email/res/images" +#endif + +#ifndef DATADIR +#define DATADIR "/opt/apps/org.tizen.email/data" +#endif + +#undef _ +#undef N_ +#define _(s) dgettext(PACKAGE, s) +#define dgettext_noop(s) (s) +#define N_(s) dgettext_noop(s) + +#endif /* __DEF_EMAIL_LOCALE_H__ */ + +/* EOF */ diff --git a/common/include/email-utils.h b/common/include/email-utils.h new file mode 100755 index 0000000..cf2324e --- /dev/null +++ b/common/include/email-utils.h @@ -0,0 +1,78 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 _EMAIL_UTILS_H_ +#define _EMAIL_UTILS_H_ + +#include "email-common-types.h" +#include "email-debug.h" + +#include <errno.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> +#include <string.h> + +#include <unicode/uloc.h> +#include <unicode/ucal.h> +#include <unicode/udat.h> +#include <unicode/udatpg.h> +#include <unicode/ustring.h> + +G_BEGIN_DECLS + +/* + * String utility. + */ +#undef STR_VALID +#define STR_VALID(str) \ + ((str != NULL && strlen(str) > 0) ? TRUE : FALSE) +#undef STR_INVALID +#define STR_INVALID(str) \ + ((str == NULL || strlen(str) == 0) ? TRUE : FALSE) +#undef STR_LEN +#define STR_LEN(str) \ + ({ const char *s = (const char *)str; (s) ? strlen(s) : 0; }) + +/* + * Exported fuctions. + */ +char *email_get_current_theme_name(void); + +gboolean email_check_dir_exist(const gchar *path); +gboolean email_check_file_exist(const gchar *path); + +gchar *email_parse_get_filename_from_path(const gchar *path); /* g_free(). */ +void email_parse_get_filename_n_ext_from_path(const gchar *path, gchar **ret_file_name, gchar **ret_ext); + +void email_save_file(const gchar *path, const gchar *buf, gsize len); +gchar *email_get_buff_from_file(const gchar *path, guint max_kbyte); /* g_free(). */ +gchar *email_get_file_size_string(guint64 size); /* g_free(). */ +guint64 email_get_file_size(const gchar *path); + +char *email_get_date_text(const char *locale, char *skeleton, void *time); + +int email_open_icu_pattern_generator(void); +int email_close_icu_pattern_generator(void); + +gboolean email_drm_file_is_right(const gchar *path); +gboolean email_drm_file_forward_lock_check(const gchar *path); + +G_END_DECLS +#endif /* _EMAIL_UTILS_H_ */ + +/* EOF */ diff --git a/common/src/email-debug.c b/common/src/email-debug.c new file mode 100755 index 0000000..3c26a41 --- /dev/null +++ b/common/src/email-debug.c @@ -0,0 +1,239 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. + */ + +#define _SYSTEM_DEBUG_ 1 +#define _USE_LOG_FILE_ 0 +#define _USE_TIME_ELAPSED_ 0 + +#include <sys/time.h> +#include <time.h> +#include <string.h> +#include <glib.h> +#include <glib/gprintf.h> +#include <glib/gstdio.h> + +#if _SYSTEM_DEBUG_ == 1 +#define LOG_TAG "email_svc" +#include <dlog.h> +#endif /* _SYSTEM_DEBUG_ */ + +#include "email-debug.h" + +#define FG_RED 31 +#define FG_GREEN 32 +#define FG_YELLOW 33 +#define FG_MAGENTA 35 +#define FG_CYAN 36 +#define BG_BLACK 40 + +#define email_debug_print(msg) \ +do { \ + printf("\x1b[%dm\x1b[%dm%s", BG_BLACK, FG_GREEN, msg); \ + printf("\x1b[0m\n"); \ +} while (0) + +#define email_assert_print(msg) \ +do { \ + printf("\x1b[%dm\x1b[%dm%s", BG_BLACK, FG_MAGENTA, msg); \ + printf("\x1b[0m\n"); \ +} while (0) + +#define email_time_print(msg) \ +do { \ + printf("\x1b[%dm\x1b[%dm%s", BG_BLACK, FG_CYAN, msg); \ + printf("\x1b[0m\n"); \ +} while (0) + +#define email_warning_print(msg) \ +do { \ + printf("\x1b[%dm\x1b[%dm%s", BG_BLACK, FG_YELLOW, msg); \ + printf("\x1b[0m\n"); \ +} while (0) + +#define email_critical_print(msg) \ +do { \ + printf("\x1b[%dm\x1b[%dm%s", BG_BLACK, FG_RED, msg); \ + printf("\x1b[0m\n"); \ +} while (0) + +#if _USE_LOG_FILE_ == 1 +static gboolean _g_log_init = FALSE; +#endif /* _USE_LOG_FILE_ */ + +#if _USE_TIME_ELAPSED_ == 1 +static double _g_start_time = 0; +static double _g_old_time = 0; +#endif /* _USE_TIME_ELAPSED_ */ + +#if _USE_LOG_FILE_ == 1 +static void _save_log(const gchar *message) +{ +#define LOG_PATH "/tmp/email.log" + + if (!_g_log_init) { + if (g_file_test(LOG_PATH, G_FILE_TEST_EXISTS)) { + g_remove(LOG_PATH); + } + _g_log_init = TRUE; + } + + FILE *fp = fopen(LOG_PATH, "a"); + if (fp != NULL) { + fprintf(fp, "%s\n", message); + fclose(fp); + } +} +#endif /* _USE_LOG_FILE_ */ + +#if _SYSTEM_DEBUG_ == 1 +static void _debug_A(EmailDebugType type, const gchar *message) +{ +#define MID_EMAIL (MID_MESSAGING + SET_IDENT(0)) + + switch (type) { + case EMAIL_DEBUG_CRITICAL: + LOGW("%s", message); + break; + case EMAIL_DEBUG_WARNING: + LOGI("%s", message); + break; + case EMAIL_DEBUG_EXPR: + case EMAIL_DEBUG_TIME: + case EMAIL_DEBUG_LOG: + LOGD("%s", message); + break; + default: + break; + } + +#if _USE_LOG_FILE_ == 1 + _save_log(message); +#endif /* _SYSTEM_DEBUG_ */ +} +#else /* _SYSTEM_DEBUG_ */ +static void _debug_B(EmailDebugType type, const gchar *message) +{ + switch (type) { + case EMAIL_DEBUG_CRITICAL: + email_critical_print(message); + break; + case EMAIL_DEBUG_WARNING: + email_warning_print(message); + break; + case EMAIL_DEBUG_EXPR: + email_assert_print(message); + break; + case EMAIL_DEBUG_TIME: + email_time_print(message); + break; + case EMAIL_DEBUG_LOG: + email_debug_print(message); + break; + default: + break; + } + +#if _USE_LOG_FILE_ == 1 + _save_log(message); +#endif /* _SYSTEM_DEBUG_ */ +} +#endif /* _SYSTEM_DEBUG_ */ + +void email_debug_message(EmailDebugType type, const gchar *file_name, const gchar *func, gint line_number, const gchar *format, ...) +{ + va_list args; + gchar msg_buf[1024] = "\0", buffer[2048] = "\0"; + const gchar *dbg_prefix = NULL; + + switch (type) { + case EMAIL_DEBUG_CRITICAL: + dbg_prefix = " * Critical * "; + break; + case EMAIL_DEBUG_WARNING: + dbg_prefix = " * Warning * "; + break; + case EMAIL_DEBUG_EXPR: + case EMAIL_DEBUG_TIME: + case EMAIL_DEBUG_LOG: + dbg_prefix = " "; + break; + default: + break; + } + + va_start(args, format); + g_vsnprintf(msg_buf, sizeof(msg_buf), format, args); +#if _SYSTEM_DEBUG_ == 1 + g_sprintf(buffer, "[%s:%s:#%d]%s%s\n", file_name, func, line_number, dbg_prefix, msg_buf); +#else /* _SYSTEM_DEBUG_ */ + g_sprintf(buffer, "[%s:%s:#%d]%s%s", file_name, func, line_number, dbg_prefix, msg_buf); +#endif /* _SYSTEM_DEBUG_ */ + va_end(args); + +#if _SYSTEM_DEBUG_ == 1 + _debug_A(type, buffer); +#else /* _SYSTEM_DEBUG_ */ + _debug_B(type, buffer); +#endif /* _SYSTEM_DEBUG_ */ +} + +void email_time_elapsed_message(const gchar *file_name, const gchar *func, gint line_number) +{ +#if _USE_TIME_ELAPSED_ == 1 + gchar message[512] = "\0"; + struct timeval tv; + double new_time = 0; + double elapsed = 0; + double interval = 0; + + memset(&tv, 0, sizeof(struct timeval)); + + gettimeofday(&tv, NULL); + + new_time = (double)(tv.tv_sec * 1000000 + tv.tv_usec); + + if (_g_start_time == 0) { + _g_start_time = new_time; + } + + if (_g_old_time == 0) { + _g_old_time = new_time; + } + + elapsed = (double)(new_time - _g_start_time) / CLOCKS_PER_SEC; + interval = (double)(new_time - _g_old_time) / CLOCKS_PER_SEC; + + if (_g_old_time != new_time) { + _g_old_time = new_time; + } + + g_sprintf(message, "elapsed (%lf) interval (%lf)", elapsed, interval); + + email_debug_message(EMAIL_DEBUG_TIME, file_name, func, line_number, message); +#endif /* _USE_TIME_ELAPSED_ */ +} + +void email_time_elapsed_reset(void) +{ + debug_log(""); + +#if _USE_TIME_ELAPSED_ == 1 + _g_start_time = 0; + _g_old_time = 0; +#endif /* _USE_TIME_ELAPSED_ */ +} + +/* EOF */ diff --git a/common/src/email-engine.c b/common/src/email-engine.c new file mode 100755 index 0000000..91d8eb9 --- /dev/null +++ b/common/src/email-engine.c @@ -0,0 +1,263 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 <ctype.h> +#include <string.h> +#include <glib.h> +#include <glib/gprintf.h> +#include <email-api.h> +#include <db-util.h> +#include <vconf.h> + +#include "email-common-types.h" +#include "email-debug.h" +#include "email-utils.h" +#include "email-engine.h" + +#define ACCOUNT_MIN -1 + +static guint _g_edb_ref_count = 0; + + +gboolean email_engine_initialize(void) +{ + debug_log(""); + ++_g_edb_ref_count; + + if (_g_edb_ref_count > 1) { + debug_log("already opened - EDB ref_count(%d)", _g_edb_ref_count); + return TRUE; + } + + int err = 0; + + debug_log("email_service_begin"); + + /*err = ipcEmailProxy_Initialize(0);*/ + err = email_service_begin(); + if (err != EMAIL_ERROR_NONE) { + debug_critical("fail to email_service_begin - err(%d)", err); + /* + g_assert(0); + */ + return FALSE; + } + + err = email_open_db(); + if (err != EMAIL_ERROR_NONE) { + debug_critical("fail to open db - err(%d)", err); + return FALSE; + } + + return TRUE; +} + +void email_engine_finalize(void) +{ + debug_log(""); + --_g_edb_ref_count; + + if (_g_edb_ref_count > 0) { + debug_log("remain EDB ref_count(%d)", _g_edb_ref_count); + return; + } + + int err = 0; + + err = email_close_db(); + if (err != EMAIL_ERROR_NONE) { + debug_critical("fail to close db - err(%d)", err); + } + + debug_log("email_service_end"); + + err = email_service_end(); + if (err != EMAIL_ERROR_NONE) { + debug_critical("fail to email_service_end - err(%d)", err); + } +} + +gboolean email_engine_get_account_full_data(int acctid, email_account_t **account) +{ + debug_log(""); + debug_log("email_engine_get_account_full_data. acctid:%d", acctid); + RETURN_VAL_IF_FAIL(acctid > ACCOUNT_MIN, FALSE); + int err = 0; + + err = email_get_account(acctid, EMAIL_ACC_GET_OPT_FULL_DATA, account); + if (err != EMAIL_ERROR_NONE) { + debug_critical("email_get_account full data error Err(%d)", err); + return FALSE; + } + if (*account) { + debug_log("Account name: %s", (*account)->account_name); + if ((*account)->options.signature) + debug_log("Signature: %s", (*account)->options.signature); + } else { + debug_critical("account is NULL"); + return FALSE; + } + + return TRUE; +} + +gboolean email_engine_set_default_account(gint account_id) +{ + debug_log(""); + RETURN_VAL_IF_FAIL(account_id > ACCOUNT_MIN, FALSE); + int err = 0; + + err = email_save_default_account_id(account_id); + debug_log("email_save_default_account_id returns %d.", err); + if (err != EMAIL_ERROR_NONE) { + debug_critical("email_save_default_account_id: Err(%d)", err); + return FALSE; + } else { + debug_log("default account is set as account_id %d.", account_id); + return TRUE; + } +} + +gboolean email_engine_get_default_account(gint *account_id) +{ + debug_log(""); + RETURN_VAL_IF_FAIL(account_id != NULL, FALSE); + + email_account_t *_account = NULL; + int count = 0; + int err = 0; + + err = email_load_default_account_id(account_id); + debug_log("email_load_default_account_id returns %d.", err); + + /* if account_id is default account, then check account_id whether it is valid or not */ + if (err == EMAIL_ERROR_NONE) { + debug_log("default account id is %d.", *account_id); + if (email_get_account(*account_id, EMAIL_ACC_GET_OPT_DEFAULT, &_account) == EMAIL_ERROR_NONE) { + email_free_account(&_account, 1); + return TRUE; + } + } + + /* if slp_ret have no value or account id is not valid */ + err = email_get_account_list(&_account, &count); + if (err != EMAIL_ERROR_NONE) { + debug_critical("fail to get account list - err(%d)", err); + return FALSE; + } + + /* no account */ + if (_account == NULL || count == 0) { + debug_log("account info is null"); + return FALSE; + } + + *account_id = _account[0].account_id; + debug_log("account id (%d)", *account_id); + + err = email_free_account(&_account, count); + if (err != EMAIL_ERROR_NONE) { + debug_critical("fail to free account - err(%d)", err); + return FALSE; + } + + RETURN_VAL_IF_FAIL((*account_id) > 0, FALSE); + email_engine_set_default_account(*account_id); + + return TRUE; +} + +void email_engine_stop_working(gint account_id, unsigned handle) +{ + debug_log(""); + + RETURN_IF_FAIL(account_id > ACCOUNT_MIN); + RETURN_IF_FAIL(handle > 0); + + int err = 0; + + debug_log("handle (%d)", handle); + + err = email_cancel_job(account_id, handle, EMAIL_CANCELED_BY_USER); + + if (err != EMAIL_ERROR_NONE) { + debug_warning("fail to cancel job"); + } +} + +gboolean email_engine_delete_mail(gint account_id, int mailbox_id, gint mail_id, int sync) +{ + debug_log(""); + RETURN_VAL_IF_FAIL(account_id > ACCOUNT_MIN, FALSE); + RETURN_VAL_IF_FAIL(mailbox_id > 0, FALSE); + RETURN_VAL_IF_FAIL(mail_id > 0, FALSE); + + int err = 0; + int mail_ids[1] = { 0 }; + gboolean res = TRUE; /* MUST BE initialized TRUE. */ + + mail_ids[0] = mail_id; + + debug_log("account_id : %d", account_id); + debug_log("mail_ids[0] : %d", mail_ids[0]); + debug_log("sync : %d", sync); + err = email_delete_mail(mailbox_id, mail_ids, 1, sync); + + if (err != EMAIL_ERROR_NONE) { + debug_warning("failed to delete message - err (%d)", err); + res = FALSE; + } + + return res; +} + +gchar *email_engine_get_attachment_path(gint attach_id) +{ + debug_log(""); + RETURN_VAL_IF_FAIL(attach_id > 0, FALSE); + + int err = 0; + email_attachment_data_t *attachments = NULL; + gchar *attachment_path = NULL; + + err = email_get_attachment_data(attach_id, &attachments); + + if (err != EMAIL_ERROR_NONE) { + debug_critical("fail to get attachment info - err (%d)", err); + goto error; + } + + if (attachments == NULL) { + debug_critical("attachments is @niL"); + goto error; + } + + if (STR_VALID(attachments->attachment_path)) { + debug_log("attachment path (%s)", attachments->attachment_path); + attachment_path = g_strdup(attachments->attachment_path); + } + + err = email_free_attachment_data(&attachments, 1); + + if (err != EMAIL_ERROR_NONE) { + debug_warning("fail to free attachment info - err(%d)", err); + } + + error: + return attachment_path; +} + +/* EOF */ diff --git a/common/src/email-utils.c b/common/src/email-utils.c new file mode 100755 index 0000000..05a3902 --- /dev/null +++ b/common/src/email-utils.c @@ -0,0 +1,448 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 <sys/time.h> +#include <glib.h> +#include <glib/gprintf.h> +#include <appcore-common.h> +#include <vconf.h> +#include <stdlib.h> +#include <regex.h> +#include <errno.h> +#include <drm_client.h> +#include <drm_client_types.h> + +#include "email-utils.h" + +char *icu_locale = NULL; +static UDateTimePatternGenerator *icu_pattern_generator = NULL; +static UDateFormat *icu_formatter_hmm = NULL; +static UDateFormat *icu_formatter_Hmm = NULL; +static UDateFormat *icu_formatter_MMMyyyy = NULL; +static UDateFormat *icu_formatter_MMMd = NULL; +static UDateFormat *icu_formatter_EEEMMMd = NULL; +enum appcore_time_format icu_timeformat; + + +static void _generate_best_pattern(const char *locale, UChar * customSkeleton, char *formattedString, void *time); +static int _open_icu_pattern_n_formatter(const char *locale, char *skeleton, UDateFormat **formatter); +static int _close_icu_pattern_n_formatter(UDateFormat *formatter); + +/* + * Function implementation + */ +char *email_get_current_theme_name(void) +{ + char *theme_name = NULL; + char *save_ptr = NULL; + + /* Get current theme path. Return value is a full path of theme file. ex) blue-hd:default */ + const char *current_theme_path = elm_theme_get(NULL); + debug_log("current_theme_path [%s]", current_theme_path); + + if (current_theme_path == NULL) { + debug_log("current_theme_path is NULL !!"); + return NULL; + } + + theme_name = strdup(current_theme_path); + if (theme_name == NULL) { + debug_log("theme_name is NULL !!"); + return NULL; + } + + theme_name = strtok_r(theme_name, ":", &save_ptr); + if (theme_name == NULL) { + debug_log("theme_name is NULL !!"); + return NULL; + } + + debug_log("theme_name [%s]", theme_name); + + return theme_name; +} + +gboolean email_check_file_exist(const gchar *path) +{ + debug_log(""); + RETURN_VAL_IF_FAIL(STR_VALID(path), FALSE); + + if (!g_file_test(path, G_FILE_TEST_EXISTS)) { + return FALSE; + } + return TRUE; +} + +gboolean email_check_dir_exist(const gchar *path) +{ + debug_log(""); + RETURN_VAL_IF_FAIL(STR_VALID(path), FALSE); + + if (!g_file_test(path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { + return FALSE; + } + return TRUE; +} + +gchar *email_parse_get_filename_from_path(const gchar *path) +{ + debug_log(""); + RETURN_VAL_IF_FAIL(STR_VALID(path), NULL); + + guint index = 0; + + gchar *file_path = g_strdup(path); + file_path = g_strstrip(file_path); + gchar **token_list = g_strsplit_set(file_path, "/", -1); + g_free(file_path); /* MUST BE. */ + + RETURN_VAL_IF_FAIL(token_list != NULL, NULL); + + while (token_list[index] != NULL) { + index++; + } + + gchar *file_name = g_strdup(token_list[index - 1]); + + g_strfreev(token_list); /* MUST BE. */ + + /*token_list = g_strsplit_set(file_name, ".", -1); + RETURN_VAL_IF_FAIL(token_list != NULL, NULL); + gchar *file_name_without_ext = g_strdup(token_list[0]); + g_strfreev(token_list);*/ + + int len = 0; + if (file_name) + len = strlen(file_name); + + gchar *ext = g_strrstr(file_name, "."); + if (ext) + len = len - strlen(ext); + + gchar *file_name_without_ext = g_strndup(file_name, len); + + g_free(file_name); /* MUST BE. */ + + debug_log("file name (%s)", file_name_without_ext); + + return file_name_without_ext; +} + +void email_parse_get_filename_n_ext_from_path(const gchar *path, gchar **ret_file_name, gchar **ret_ext) +{ + debug_log(""); + RETURN_IF_FAIL(STR_VALID(path)); + + guint index = 0; + + gchar *file_path = g_strdup(path); + file_path = g_strstrip(file_path); + gchar **token_list = g_strsplit_set(file_path, "/", -1); + g_free(file_path); /* MUST BE. */ + + RETURN_IF_FAIL(token_list != NULL); + + while (token_list[index] != NULL) { + index++; + } + + gchar *file_name = g_strdup(token_list[index - 1]); + + g_strfreev(token_list); /* MUST BE. */ + + /*token_list = g_strsplit_set(file_name, ".", -1); + RETURN_VAL_IF_FAIL(token_list != NULL, NULL); + gchar *file_name_without_ext = g_strdup(token_list[0]); + g_strfreev(token_list);*/ + + int len = 0; + if (file_name) + len = strlen(file_name); + + gchar *ext = g_strrstr(file_name, "."); + if (ext) + len = len - strlen(ext); + + *ret_file_name = g_strndup(file_name, len); + + *ret_ext = g_strdup(ext); + + g_free(file_name); +} + +void email_save_file(const gchar *path, const gchar *buf, gsize len) +{ + debug_log(""); + if (STR_LEN((gchar *)buf) > 0 && len > 0) { + int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); + if (fd != -1) { + int size = write(fd, (const void *)buf, (size_t) len); + debug_log("size:%d", size); + close(fd); + } + } +} + +gchar *email_get_buff_from_file(const gchar *path, guint max_kbyte) +{ + debug_log(""); + RETURN_VAL_IF_FAIL(STR_VALID(path), NULL); + + debug_log("path (%s)", path); + + FILE *fp = fopen(path, "r"); + + if (fp) { + + char body[MAX_STR_LEN + 1] = { 0, }; + size_t size = 0; + guint kbyte = 0; + gchar *buff = NULL; + gchar *temp = NULL; + + while (1) { + + memset(body, 0, sizeof(body)); + + size = fread(body, sizeof(unsigned char), MAX_STR_LEN, fp); + body[MAX_STR_LEN] = '\0'; + + if (size <= 0 || STR_LEN(body) == 0) + break; + + if (max_kbyte > 0 && kbyte > max_kbyte) + break; + + if (STR_VALID(buff)) { + temp = g_strconcat(buff, body, NULL); + g_free(buff); + buff = temp; + temp = NULL; + } else { + buff = g_strdup(body); + } + + ++kbyte; + } + + fclose(fp); + + /* + debug_log("buff [%s]", buff); + */ + + return buff; + } + + return NULL; +} + +gchar *email_get_file_size_string(guint64 size) +{ + debug_log(""); + gchar str_buf[16] = "\0"; + + if (size < 1024) { + g_sprintf(str_buf, "%d %s", (gint) size, dgettext("sys_string", "IDS_COM_BODY_B")); + } else { + gdouble tmpsize = (gdouble) (size / 1024.); + + if (tmpsize < 1024) { + g_sprintf(str_buf, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_KB")); + } else { + tmpsize /= 1024.; + + if (tmpsize < 1024) { + g_sprintf(str_buf, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_MB")); + } else { + tmpsize /= 1024.; + g_sprintf(str_buf, "%.2f %s", tmpsize, dgettext("sys_string", "IDS_COM_BODY_GB")); + } + } + } + return STR_LEN(str_buf) > 0 ? g_strdup(str_buf) : NULL; +} + +guint64 email_get_file_size(const gchar *path) +{ + debug_log(""); + guint64 size = 0; + struct stat st; + memset(&st, 0, sizeof(struct stat)); + + if (stat(path, &st) == 0) { + if (S_ISREG(st.st_mode)) { + size = (guint64) st.st_size; + debug_log("size (%llu)", size); + } + } else { + size = 0; + } + return size; +} + +char *email_get_date_text(const char *locale, char *skeleton, void *time) +{ + debug_log(""); + char formattedString[128] = { 0, }; + UChar customSkeleton[64] = { 0, }; + int skeletonLength = strlen(skeleton); + + u_uastrncpy(customSkeleton, skeleton, skeletonLength); + _generate_best_pattern(locale, customSkeleton, formattedString, time); + return g_strdup(formattedString); +} + +int email_open_icu_pattern_generator(void) +{ + debug_log(""); + UErrorCode status = U_ZERO_ERROR; + + uloc_setDefault(getenv("LC_TIME"), &status); + if (U_FAILURE(status)) { + debug_critical("uloc_setDefault() failed: %s\n", u_errorName(status)); + return -1; + } + + status = U_ZERO_ERROR; + icu_locale = (char *)uloc_getDefault(); + debug_log("uloc_getDefault: %s", icu_locale); + appcore_get_timeformat(&icu_timeformat); + icu_pattern_generator = udatpg_open(icu_locale, &status); + + if (!icu_pattern_generator) { + debug_log("udatpg_open() failed: %s", u_errorName(status)); + return -1; + } + + _open_icu_pattern_n_formatter(icu_locale, "hmm", &icu_formatter_hmm); + _open_icu_pattern_n_formatter(icu_locale, "Hmm", &icu_formatter_Hmm); + _open_icu_pattern_n_formatter(icu_locale, "MMMyyyy", &icu_formatter_MMMyyyy); + _open_icu_pattern_n_formatter(icu_locale, "MMMd", &icu_formatter_MMMd); + _open_icu_pattern_n_formatter(icu_locale, "EEEMMMd", &icu_formatter_EEEMMMd); + + return 0; +} + +int email_close_icu_pattern_generator(void) +{ + debug_log(""); + + if (icu_pattern_generator) { + udatpg_close(icu_pattern_generator); + icu_pattern_generator = NULL; + } + + _close_icu_pattern_n_formatter(icu_formatter_hmm); + _close_icu_pattern_n_formatter(icu_formatter_Hmm); + _close_icu_pattern_n_formatter(icu_formatter_MMMyyyy); + _close_icu_pattern_n_formatter(icu_formatter_MMMd); + _close_icu_pattern_n_formatter(icu_formatter_EEEMMMd); + + return 0; +} + +static int _open_icu_pattern_n_formatter(const char *locale, char *skeleton, UDateFormat **formatter) +{ + debug_log(""); + UErrorCode status = U_ZERO_ERROR; + UChar bestPattern[64] = { 0, }; + UChar customSkeleton[64] = { 0, }; + int32_t bestPatternCapacity; + int32_t bestPatternLength; + int skeletonLength = strlen(skeleton); + + u_uastrncpy(customSkeleton, skeleton, skeletonLength); + + bestPatternCapacity = (int32_t) (sizeof(bestPattern) / sizeof(bestPattern[0])); + bestPatternLength = udatpg_getBestPattern(icu_pattern_generator, customSkeleton, u_strlen(customSkeleton), bestPattern, bestPatternCapacity, &status); + *formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status); + + return 0; +} + +static int _close_icu_pattern_n_formatter(UDateFormat *formatter) +{ + debug_log(""); + + udat_close(formatter); + + return 0; +} + +static void _generate_best_pattern(const char *locale, UChar * customSkeleton, char *formattedString, void *time) +{ + debug_log(""); + UErrorCode status = U_ZERO_ERROR; + UDateFormat *formatter; + UDate date = 0; + UChar bestPattern[64] = { 0, }; + UChar formatted[64] = { 0, }; + int32_t bestPatternCapacity, formattedCapacity; + int32_t bestPatternLength, formattedLength; + + bestPatternCapacity = (int32_t) (sizeof(bestPattern) / sizeof(bestPattern[0])); + bestPatternLength = udatpg_getBestPattern(icu_pattern_generator, customSkeleton, u_strlen(customSkeleton), bestPattern, bestPatternCapacity, &status); + + formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status); + formattedCapacity = (int32_t) (sizeof(formatted) / sizeof(formatted[0])); + if (time) { + time_t msg_time = *(time_t *)time; + date = (UDate)msg_time * 1000; /* Equivalent to Date = ucal_getNow() in Milliseconds */ + } + formattedLength = udat_format(formatter, date, formatted, formattedCapacity, NULL, &status); + u_austrncpy(formattedString, formatted, 128); + udat_close(formatter); +} + +gboolean email_drm_file_is_right(const gchar *path) +{ + RETURN_VAL_IF_FAIL(STR_VALID(path), FALSE); + + debug_log(""); + + drm_bool_type_e is_drm_file = FALSE; + + if (drm_is_drm_file(path, &is_drm_file) != DRM_RETURN_SUCCESS) { + debug_log("drm_is_drm_file is failed"); + return FALSE; + } + + return is_drm_file; +} + +gboolean email_drm_file_forward_lock_check(const gchar *path) +{ + RETURN_VAL_IF_FAIL(STR_VALID(path), FALSE); + RETURN_VAL_IF_FAIL(email_drm_file_is_right(path), FALSE); + + debug_log(""); + + drm_file_info_s drm_info; + + memset(&drm_info, 0, sizeof(drm_file_info_s)); + + if (drm_get_file_info(path, &drm_info)) { + debug_log("drm_info.oma_info.method (%d)", drm_info.oma_info.method); + if (drm_info.oma_info.method == DRM_METHOD_TYPE_FORWARD_LOCK || drm_info.oma_info.method == DRM_METHOD_TYPE_COMBINED_DELIVERY) { + debug_log("Forward Lock"); + return TRUE; + } + } + + return FALSE; +} +/* EOF */ |