4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 * Created on: 2012. 3. 6.
26 * Author: kyuho.jo@samsung.com
42 #include "email-types.h"
43 #include "email-internal-types.h"
44 #include "email-utilities.h"
46 INTERNAL_FUNC void* em_malloc(int len)
48 /* EM_DEBUG_LOG("Memory allocation size[%d] bytes", len); */
50 EM_DEBUG_EXCEPTION("len should be positive.[%d]", len);
54 void *p = calloc(1,len);
56 EM_DEBUG_PERROR("malloc failed");
62 INTERNAL_FUNC void* em_memdup(void* src, int len)
64 /* EM_DEBUG_LOG("Memory allocation size[%d] bytes", len); */
66 EM_DEBUG_EXCEPTION("len should be positive.[%d]", len);
70 void *p = calloc(1,len);
72 EM_DEBUG_EXCEPTION("malloc failed");
80 /* remove left space, tab, CR, L */
81 INTERNAL_FUNC char *em_trim_left(char *str)
83 char *p, *temp_buffer = NULL;
85 /* EM_DEBUG_FUNC_BEGIN() */
86 if (!str) return NULL;
89 while (*p && (*p == ' ' || *p == '\t' || *p == LF || *p == CR)) p++;
93 temp_buffer = EM_SAFE_STRDUP(p);
95 strncpy(str, temp_buffer, strlen(str));
96 str[strlen(temp_buffer)] = NULL_CHAR;
98 EM_SAFE_FREE(temp_buffer);
103 /* remove right space, tab, CR, L */
104 INTERNAL_FUNC char *em_trim_right(char *str)
108 /* EM_DEBUG_FUNC_BEGIN() */
109 if (!str) return NULL;
111 p = str+strlen(str)-1;
112 while (((int)p >= (int)str) && (*p == ' ' || *p == '\t' || *p == LF || *p == CR))
115 if ((int) p < (int)str)
121 INTERNAL_FUNC char* em_upper_string(char *str)
131 INTERNAL_FUNC char* em_lower_string(char *str)
141 INTERNAL_FUNC int em_upper_path(char *path)
143 int i = 0, is_utf7 = 0, len = path ? (int)strlen(path) : -1;
144 for (; i < len; i++) {
145 if (path[i] == '&' || path[i] == 5) {
150 if (path[i] == '-') is_utf7 = 0;
153 path[i] = toupper(path[i]);
161 INTERNAL_FUNC void em_skip_whitespace(char *addr_str, char **pAddr)
163 EM_DEBUG_FUNC_BEGIN("addr_str[%p]", addr_str);
167 char *str = addr_str;
168 char ptr[strlen(str)+1] ;
172 for (i = 0; str[i] != NULL_CHAR ; i++) {
173 if (str[i] != SPACE && str[i] != TAB && str[i] != CR && str[i] != LF)
178 *pAddr = EM_SAFE_STRDUP(ptr);
179 EM_DEBUG_FUNC_END("ptr[%s]", ptr);
182 INTERNAL_FUNC char* em_skip_whitespace_without_strdup(char *source_string)
184 EM_DEBUG_FUNC_BEGIN("source_string[%p]", source_string);
190 for (i = 0; source_string[i] != NULL_CHAR ; i++) {
191 if (source_string[i] != SPACE) /* || source_string[i] != TAB || source_string[i] != CR || source_string[i] || LF) */
195 EM_DEBUG_FUNC_END("i[%d]", i);
196 return source_string + i;
200 INTERNAL_FUNC char* em_replace_all_string(char *source_string, char *old_string, char *new_string)
202 EM_DEBUG_FUNC_BEGIN();
203 char *result_buffer = NULL;
205 int i = 0, count = 0;
206 int old_str_length = 0;
207 int new_str_length = 0;
209 EM_IF_NULL_RETURN_VALUE(source_string, NULL);
210 EM_IF_NULL_RETURN_VALUE(old_string, NULL);
211 EM_IF_NULL_RETURN_VALUE(new_string, NULL);
213 old_str_length = strlen(old_string);
214 new_str_length = strlen(new_string);
216 if (old_str_length != new_str_length) {
217 for (i = 0; source_string[i] != '\0';) {
218 if (memcmp(&source_string[i], old_string, old_str_length) == 0) {
226 i = strlen(source_string);
229 result_buffer = (char *)malloc(i + 1 + count*(new_str_length-old_str_length));
230 if (result_buffer == NULL)
234 while (*source_string) {
235 if (memcmp(source_string, old_string, old_str_length) == 0) {
236 memcpy(p, new_string, new_str_length);
238 source_string += old_str_length;
240 *p++ = *source_string++;
245 EM_DEBUG_FUNC_END("result_buffer : %s", result_buffer);
246 return result_buffer;
249 INTERNAL_FUNC char* em_replace_string(char *source_string, char *old_string, char *new_string)
251 EM_DEBUG_FUNC_BEGIN();
252 char *result_buffer = NULL;
254 int buffer_length = 0;
256 EM_IF_NULL_RETURN_VALUE(source_string, NULL);
257 EM_IF_NULL_RETURN_VALUE(old_string, NULL);
258 EM_IF_NULL_RETURN_VALUE(new_string, NULL);
260 p = strstr(source_string, old_string);
263 EM_DEBUG_EXCEPTION("old_string not found in source_string");
264 EM_DEBUG_FUNC_END("return NULL");
268 buffer_length = strlen(source_string) + 1024;
269 result_buffer = (char *)em_malloc(buffer_length);
271 if (!result_buffer) {
272 EM_DEBUG_EXCEPTION("em_malloc failed");
276 strncpy(result_buffer, source_string, p - source_string);
277 snprintf(result_buffer + strlen(result_buffer), buffer_length - strlen(result_buffer), "%s%s", new_string, p + strlen(old_string));
279 EM_DEBUG_FUNC_END("result_buffer[%s]", result_buffer);
280 return result_buffer;
283 /* Memory clean up */
284 #include <sys/mman.h>
286 /* #define GETSP() ({ unsigned int sp; asm volatile ("mov %0, sp " : "=r"(sp)); sp;}) */
288 #define PAGE_SIZE (1 << 12)
289 #define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1)))
290 #define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))
291 #define PAGE_ALIGN(addr) _ALIGN_DOWN(addr, PAGE_SIZE)
298 unsigned int stacktop;
302 asm volatile ("mov %0, sp " : "=r"(sp));
304 sprintf(buf, "/proc/%d/maps", getpid());
305 file = fopen(buf, "r");
306 while (fgets(buf, BUF_SIZE, file) != NULL) {
307 if (strstr(buf, "[stack]")) {
316 sscanf(buf, "%x-", &stacktop);
317 if (madvise((void *)PAGE_ALIGN(stacktop), PAGE_ALIGN(sp)-stacktop, MADV_DONTNEED) < 0)
318 perror("stack madvise fail");
324 INTERNAL_FUNC void em_flush_memory()
326 EM_DEBUG_FUNC_BEGIN();
327 /* flush memory in heap */
330 /* flush memory in stack */
333 /* flush memory for sqlite */
334 emstorage_flush_db_cache();
338 INTERNAL_FUNC int em_get_file_name_and_extension_from_file_path(char *input_source_file_path, char **output_file_name, char **output_extension)
340 EM_DEBUG_FUNC_BEGIN("input_source_file_path[%s], output_file_name [%p], output_extension [%p]", input_source_file_path, output_file_name, output_extension);
341 int err = EMAIL_ERROR_NONE;
342 int pos_on_string = 0;
343 int file_name_length = 0;
344 int extention_length = 0;
345 char *start_pos_of_file_name = NULL;
346 char *end_pos_of_file_name = NULL;
347 char *dot_pos_of_file_path = NULL;
348 char *end_pos_of_file_path = NULL;
349 char file_name_string[MAX_PATH] = { 0, };
350 char extension_string[MAX_PATH] = { 0, };
352 if (!input_source_file_path || !output_file_name || !output_extension) {
353 EM_DEBUG_EXCEPTION("Invalid Parameter");
354 err = EMAIL_ERROR_INVALID_PARAM;
358 pos_on_string = strlen(input_source_file_path) - 1;
359 end_pos_of_file_path = input_source_file_path + pos_on_string;
360 end_pos_of_file_name = end_pos_of_file_path;
362 while(pos_on_string >= 0 && input_source_file_path[pos_on_string] != '/') {
363 if(input_source_file_path[pos_on_string] == '.') {
364 if(dot_pos_of_file_path == NULL) {
365 end_pos_of_file_name = input_source_file_path + pos_on_string;
366 dot_pos_of_file_path = end_pos_of_file_name;
374 if(pos_on_string >= 0) {
375 start_pos_of_file_name = input_source_file_path + pos_on_string;
376 file_name_length = end_pos_of_file_name - start_pos_of_file_name;
377 memcpy(file_name_string, start_pos_of_file_name, file_name_length);
380 if(dot_pos_of_file_path != NULL) {
381 extention_length = (end_pos_of_file_path + 1) - (dot_pos_of_file_path + 1);
382 memcpy(extension_string, dot_pos_of_file_path + 1, extention_length);
385 EM_DEBUG_LOG("*file_name_string [%s] pos_on_string [%d]", file_name_string, pos_on_string);
387 *output_file_name = EM_SAFE_STRDUP(file_name_string);
388 *output_extension = EM_SAFE_STRDUP(extension_string);
391 EM_DEBUG_FUNC_END("err = [%d]", err);
395 INTERNAL_FUNC char *em_get_extension_from_file_path(char *source_file_path, int *err_code)
397 EM_DEBUG_FUNC_BEGIN("source_file_path[%s]", source_file_path);
398 int err = EMAIL_ERROR_NONE, pos_on_string = 0;
399 char *extension = NULL;
401 if (!source_file_path) {
402 EM_DEBUG_EXCEPTION("Invalid Parameter");
403 err = EMAIL_ERROR_INVALID_PARAM;
407 pos_on_string = strlen(source_file_path) - 1;
409 while(pos_on_string > 0 && source_file_path[pos_on_string--] != '.') ;
411 if(pos_on_string > 0)
412 extension = source_file_path + pos_on_string + 2;
414 EM_DEBUG_LOG("*extension [%s] pos_on_string [%d]", extension, pos_on_string);
423 INTERNAL_FUNC int em_get_encoding_type_from_file_path(const char *input_file_path, char **output_encoding_type)
425 EM_DEBUG_FUNC_BEGIN("input_file_path[%d], output_encoding_type[%p]", input_file_path, output_encoding_type);
426 int err = EMAIL_ERROR_NONE;
427 int pos_of_filename = 0;
429 int enf_of_string = 0;
430 int result_string_length = 0;
431 char *filename = NULL;
432 char *result_encoding_type = NULL;
434 if (!input_file_path || !output_encoding_type) {
435 EM_DEBUG_EXCEPTION("Invalid Parameter");
436 err = EMAIL_ERROR_INVALID_PARAM;
440 enf_of_string = pos_of_filename = strlen(input_file_path);
442 while(pos_of_filename >= 0 && input_file_path[pos_of_filename--] != '/') {
443 if(input_file_path[pos_of_filename] == '.')
444 pos_of_dot = pos_of_filename;
447 if(pos_of_filename != 0)
448 pos_of_filename += 2;
450 filename = (char*)input_file_path + pos_of_filename;
452 if(pos_of_dot != 0 && pos_of_dot > pos_of_filename)
453 result_string_length = pos_of_dot - pos_of_filename;
455 result_string_length = enf_of_string - pos_of_filename;
457 EM_DEBUG_LOG("pos_of_dot [%d], pos_of_filename [%d], enf_of_string[%d],result_string_length [%d]", pos_of_dot, pos_of_filename, enf_of_string, result_string_length);
459 if( !(result_encoding_type = em_malloc(sizeof(char) * (result_string_length + 1))) ) {
460 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
461 err = EMAIL_ERROR_OUT_OF_MEMORY;
465 memcpy(result_encoding_type, input_file_path + pos_of_filename, result_string_length);
467 EM_DEBUG_LOG("*result_encoding_type [%s]", result_encoding_type);
469 *output_encoding_type = result_encoding_type;
472 EM_DEBUG_FUNC_END("err [%d]", err);
476 INTERNAL_FUNC int em_get_content_type_from_extension_string(const char *extension_string, int *err_code)
478 EM_DEBUG_FUNC_BEGIN("extension_string[%s]", extension_string);
479 int i = 0, err = EMAIL_ERROR_NONE, result_content_type = TYPEAPPLICATION;
480 char *image_extension[] = { "jpeg", "jpg", "png", "gif", "bmp", "pic", "agif", "tif", "wbmp" , NULL};
482 if (!extension_string) {
483 EM_DEBUG_EXCEPTION("Invalid Parameter");
484 err = EMAIL_ERROR_INVALID_PARAM;
488 while(image_extension[i]) {
489 EM_DEBUG_LOG("image_extension[%d] [%s]", i, image_extension[i]);
490 if(strcasecmp(image_extension[i], extension_string) == 0) {
491 result_content_type = TYPEIMAGE;
501 return result_content_type;
504 #define EMAIL_ACCOUNT_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+.)*[a-z0-9!#$%&'*+/=?^_`{|}~-]+"
505 #define EMAIL_DOMAIN_RGEX "([a-z0-9!#$%&'*+/=?^_`{|}~-]+.)+[a-z0-9!#$%&'*+/=?^_`{|}~-]+"
507 #define EMAIL_ADDR_RGEX "[[:space:]]*<"EMAIL_ACCOUNT_RGEX"@"EMAIL_DOMAIN_RGEX">[[:space:]]*"
508 #define EMAIL_ALIAS_RGEX "([[:space:]]*\"[^\"]*\")?"EMAIL_ADDR_RGEX
509 #define EMAIL_ALIAS_LIST_RGEX "^("EMAIL_ALIAS_RGEX"[;,])*"EMAIL_ALIAS_RGEX"[;,]?[[:space:]]*$"
511 #define EMAIL_ADDR_WITHOUT_BRACKET_RGEX "[[:space:]]*"EMAIL_ACCOUNT_RGEX"@"EMAIL_DOMAIN_RGEX"[[:space:]]*"
512 #define EMAIL_ALIAS_WITHOUT_BRACKET_RGEX "([[:space:]]*\"[^\"]*\")?"EMAIL_ADDR_WITHOUT_BRACKET_RGEX
513 #define EMAIL_ALIAS_LIST_WITHOUT_BRACKET_RGEX "("EMAIL_ALIAS_WITHOUT_BRACKET_RGEX"[;,])*"EMAIL_ADDR_WITHOUT_BRACKET_RGEX"[;,]?[[:space:]]*$"
515 INTERNAL_FUNC int em_verify_email_address(char *address, int without_bracket, int *err_code)
517 EM_DEBUG_FUNC_BEGIN("address[%s] without_bracket[%d]", address, without_bracket);
519 /* this following code verfies the email alias string using reg. exp. */
520 regex_t alias_list_regex = {0};
521 int ret = false, error = EMAIL_ERROR_NONE;
522 char *reg_rule = NULL;
524 if(!address || strlen(address) == 0) {
525 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
527 *err_code = EMAIL_ERROR_INVALID_PARAM;
532 reg_rule = EMAIL_ALIAS_LIST_WITHOUT_BRACKET_RGEX;
534 reg_rule = EMAIL_ALIAS_LIST_RGEX;
536 if (regcomp(&alias_list_regex, reg_rule, REG_ICASE | REG_EXTENDED)) {
537 EM_DEBUG_EXCEPTION("email alias regex unrecognized");
539 *err_code = EMAIL_ERROR_UNKNOWN;
543 int alias_len = strlen(address) + 1;
544 regmatch_t pmatch[alias_len];
546 bzero(pmatch, alias_len);
548 if (regexec(&alias_list_regex, address, alias_len, pmatch, 0) == REG_NOMATCH)
549 EM_DEBUG_LOG("failed :[%s]", address);
551 EM_DEBUG_LOG("success :[%s]", address);
555 regfree(&alias_list_regex);
560 EM_DEBUG_FUNC_END("ret [%d]", ret);
564 INTERNAL_FUNC int em_verify_email_address_of_mail_data(email_mail_data_t *mail_data, int without_bracket, int *err_code)
566 EM_DEBUG_FUNC_BEGIN("mail_data[%p] without_bracket[%d]", mail_data, without_bracket);
567 char *address_array[4] = { mail_data->full_address_from, mail_data->full_address_to, mail_data->full_address_cc, mail_data->full_address_bcc};
568 int ret = false, err = EMAIL_ERROR_NONE, i;
570 /* check for email_address validation */
571 for (i = 0; i < 4; i++) {
572 if (address_array[i] && address_array[i][0] != 0) {
573 if (!em_verify_email_address(address_array[i] , without_bracket, &err)) {
574 err = EMAIL_ERROR_INVALID_ADDRESS;
575 EM_DEBUG_EXCEPTION("Invalid Email Address [%d][%s]", i, address_array[i]);
582 EM_DEBUG_FUNC_END("ret [%d]", ret);
586 INTERNAL_FUNC int em_verify_email_address_of_mail_tbl(emstorage_mail_tbl_t *input_mail_tbl, int input_without_bracket)
588 EM_DEBUG_FUNC_BEGIN("input_mail_tbl[%p] input_without_bracket[%d]", input_mail_tbl, input_without_bracket);
589 char *address_array[4] = { input_mail_tbl->full_address_to, input_mail_tbl->full_address_cc, input_mail_tbl->full_address_bcc, input_mail_tbl->full_address_from};
590 int err = EMAIL_ERROR_NONE, i;
592 /* check for email_address validation */
593 for (i = 0; i < 4; i++) {
594 if (address_array[i] && address_array[i][0] != 0) {
595 if (!em_verify_email_address(address_array[i] , input_without_bracket, &err)) {
596 err = EMAIL_ERROR_INVALID_ADDRESS;
597 EM_DEBUG_EXCEPTION("Invalid Email Address [%d][%s]", i, address_array[i]);
604 EM_DEBUG_FUNC_END("err [%d]", err);
608 INTERNAL_FUNC int em_find_tag_for_thread_view(char *subject, int *result)
610 EM_DEBUG_FUNC_BEGIN();
611 int error_code = EMAIL_ERROR_NONE;
612 char *copy_of_subject = NULL;
614 EM_IF_NULL_RETURN_VALUE(subject, EMAIL_ERROR_INVALID_PARAM);
615 EM_IF_NULL_RETURN_VALUE(result, EMAIL_ERROR_INVALID_PARAM);
619 copy_of_subject = EM_SAFE_STRDUP(subject);
621 if (copy_of_subject == NULL) {
622 EM_DEBUG_EXCEPTION("strdup is failed.");
626 em_upper_string(copy_of_subject);
627 EM_DEBUG_LOG("em_upper_string result : %s\n", copy_of_subject);
629 if (strstr(copy_of_subject, "RE:") == NULL) {
630 if (strstr(copy_of_subject, "FWD:") == NULL) {
631 if (strstr(copy_of_subject, "FW:") != NULL)
641 EM_SAFE_FREE(copy_of_subject);
643 EM_DEBUG_FUNC_END("result : %d", *result);
648 INTERNAL_FUNC int em_find_pos_stripped_subject_for_thread_view(char *subject, char *stripped_subject)
650 EM_DEBUG_FUNC_BEGIN();
651 int error_code = EMAIL_ERROR_NONE;
653 char *copy_of_subject = NULL, *curpos = NULL, *result;
655 EM_IF_NULL_RETURN_VALUE(subject, EMAIL_ERROR_INVALID_PARAM);
656 EM_IF_NULL_RETURN_VALUE(stripped_subject, EMAIL_ERROR_INVALID_PARAM);
658 copy_of_subject = EM_SAFE_STRDUP(subject);
660 if (copy_of_subject == NULL) {
661 EM_DEBUG_EXCEPTION("strdup is failed");
665 em_upper_string(copy_of_subject);
666 curpos = copy_of_subject;
668 EM_DEBUG_LOG("em_upper_string result : %s", copy_of_subject);
670 while ((result = strstr(curpos, "RE:")) != NULL) {
672 EM_DEBUG_LOG("RE result : %s", curpos);
675 while ((result = strstr(curpos, "FWD:")) != NULL) {
677 EM_DEBUG_LOG("FWD result : %s", curpos);
680 while ((result = strstr(curpos, "FW:")) != NULL) {
682 EM_DEBUG_LOG("FW result : %s", curpos);
685 while (curpos != NULL && *curpos == ' ') {
689 gap = curpos - copy_of_subject;
691 strcpy(stripped_subject, subject + gap);
694 EM_SAFE_FREE(copy_of_subject);
696 if (error_code == EMAIL_ERROR_NONE && stripped_subject)
697 EM_DEBUG_LOG("result[%s]", stripped_subject);
699 EM_DEBUG_FUNC_END("error_code[%d]", error_code);
707 INTERNAL_FUNC int em_encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
709 EM_DEBUG_FUNC_BEGIN();
711 unsigned char *content;
712 int ret = true, err = EMAIL_ERROR_NONE;
714 if (err_code != NULL) {
715 *err_code = EMAIL_ERROR_NONE;
718 content = rfc822_binary(src, src_len, enc_len);
721 *enc = (char *)content;
723 err = EMAIL_ERROR_UNKNOWN;
737 INTERNAL_FUNC int em_decode_base64(unsigned char *enc_text, unsigned long enc_len, char **dec_text, unsigned long* dec_len, int *err_code)
739 unsigned char *text = enc_text;
740 unsigned long size = enc_len;
741 unsigned char *content;
742 int ret = true, err = EMAIL_ERROR_NONE;
744 if (err_code != NULL) {
745 *err_code = EMAIL_ERROR_NONE;
748 EM_DEBUG_FUNC_BEGIN();
750 content = rfc822_base64(text, size, dec_len);
752 *dec_text = (char *)content;
755 err = EMAIL_ERROR_UNKNOWN;
765 INTERNAL_FUNC int em_get_account_server_type_by_account_id(int account_id, email_account_server_t* account_server_type, int flag, int *error)
767 EM_DEBUG_FUNC_BEGIN();
768 emstorage_account_tbl_t *account_tbl_data = NULL;
770 int err= EMAIL_ERROR_NONE;
772 if (account_server_type == NULL ) {
773 EM_DEBUG_EXCEPTION("account_server_type is NULL");
774 err = EMAIL_ERROR_INVALID_PARAM;
779 if( !emstorage_get_account_by_id(account_id, WITHOUT_OPTION, &account_tbl_data, false, &err)) {
780 EM_DEBUG_EXCEPTION ("emstorage_get_account_by_id failed [%d] ", err);
785 if ( flag == false ) { /* sending server */
786 *account_server_type = account_tbl_data->outgoing_server_type;
787 } else if ( flag == true ) { /* receiving server */
788 *account_server_type = account_tbl_data->incoming_server_type;
794 if ( account_tbl_data != NULL ) {
795 emstorage_free_account(&account_tbl_data, 1, NULL);
797 if ( error != NULL ) {
805 #include <dbus/dbus.h>
807 #define ACTIVE_SYNC_HANDLE_INIT_VALUE (-1)
808 #define ACTIVE_SYNC_HANDLE_BOUNDARY (-100000000)
811 INTERNAL_FUNC int em_get_handle_for_activesync(int *handle, int *error)
813 EM_DEBUG_FUNC_BEGIN();
815 static int next_handle = 0;
817 int err = EMAIL_ERROR_NONE;
819 if ( handle == NULL ) {
820 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed : handle is NULL");
821 err = EMAIL_ERROR_INVALID_PARAM;
825 if ( vconf_get_int(VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE, &next_handle) != 0 ) {
826 EM_DEBUG_EXCEPTION("vconf_get_int failed");
827 if ( next_handle != 0 ) {
828 err = EMAIL_ERROR_GCONF_FAILURE;
833 EM_DEBUG_LOG(">>>>>> VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE : get lastest handle[%d]", next_handle);
835 /* set the value of the handle for active sync */
837 if ( next_handle < ACTIVE_SYNC_HANDLE_BOUNDARY ) {
838 next_handle = ACTIVE_SYNC_HANDLE_INIT_VALUE;
840 if ( vconf_set_int(VCONFKEY_EMAIL_SERVICE_ACTIVE_SYNC_HANDLE, next_handle) != 0) {
841 EM_DEBUG_EXCEPTION("vconf_set_int failed");
842 err = EMAIL_ERROR_GCONF_FAILURE;
846 *handle = next_handle;
847 EM_DEBUG_LOG(">>>>>> return next handle[%d]", *handle);
850 if ( error != NULL ) {
857 INTERNAL_FUNC int em_send_notification_to_active_sync_engine(int subType, ASNotiData *data)
859 EM_DEBUG_FUNC_BEGIN("subType [%d], data [%p]", subType, data);
861 DBusConnection *connection;
862 DBusMessage *signal = NULL;
864 const char *nullString = "";
867 dbus_error_init (&error);
868 connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
870 if(connection == NULL)
873 signal = dbus_message_new_signal("/User/Email/ActiveSync", EMAIL_ACTIVE_SYNC_NOTI, "email");
875 dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
877 case ACTIVE_SYNC_NOTI_SEND_MAIL:
878 EM_DEBUG_LOG("handle:[%d]", data->send_mail.handle);
879 EM_DEBUG_LOG("account_id:[%d]", data->send_mail.account_id);
880 EM_DEBUG_LOG("mail_id:[%d]", data->send_mail.mail_id);
881 EM_DEBUG_LOG("options.priority:[%d]", data->send_mail.options.priority);
882 EM_DEBUG_LOG("options.keep_local_copy:[%d]", data->send_mail.options.keep_local_copy);
883 EM_DEBUG_LOG("options.req_delivery_receipt:[%d]", data->send_mail.options.req_delivery_receipt);
884 EM_DEBUG_LOG("options.req_read_receipt:[%d]", data->send_mail.options.req_read_receipt);
885 /* download_limit, block_address, block_subject might not be needed */
886 EM_DEBUG_LOG("options.download_limit:[%d]", data->send_mail.options.download_limit);
887 EM_DEBUG_LOG("options.block_address:[%d]", data->send_mail.options.block_address);
888 EM_DEBUG_LOG("options.block_subject:[%d]", data->send_mail.options.block_subject);
889 EM_DEBUG_LOG("options.display_name_from:[%s]", data->send_mail.options.display_name_from);
890 EM_DEBUG_LOG("options.reply_with_body:[%d]", data->send_mail.options.reply_with_body);
891 EM_DEBUG_LOG("options.forward_with_files:[%d]", data->send_mail.options.forward_with_files);
892 EM_DEBUG_LOG("options.add_myname_card:[%d]", data->send_mail.options.add_myname_card);
893 EM_DEBUG_LOG("options.add_signature:[%d]", data->send_mail.options.add_signature);
894 EM_DEBUG_LOG("options.signature:[%s]", data->send_mail.options.signature);
896 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.handle), DBUS_TYPE_INVALID);
897 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.account_id), DBUS_TYPE_INVALID);
898 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.mail_id), DBUS_TYPE_INVALID);
899 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.priority), DBUS_TYPE_INVALID);
900 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.keep_local_copy), DBUS_TYPE_INVALID);
901 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.req_delivery_receipt), DBUS_TYPE_INVALID);
902 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.req_read_receipt), DBUS_TYPE_INVALID);
903 if ( data->send_mail.options.display_name_from == NULL )
904 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
906 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.options.display_name_from), DBUS_TYPE_INVALID);
908 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.reply_with_body), DBUS_TYPE_INVALID);
909 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.forward_with_files), DBUS_TYPE_INVALID);
910 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.add_myname_card), DBUS_TYPE_INVALID);
911 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->send_mail.options.add_signature), DBUS_TYPE_INVALID);
912 if ( data->send_mail.options.signature == NULL )
913 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(nullString), DBUS_TYPE_INVALID);
915 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->send_mail.options.signature), DBUS_TYPE_INVALID);
918 case ACTIVE_SYNC_NOTI_SEND_SAVED: /* publish a send notification to ASE (active sync engine) */
919 EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_SEND_SAVED]", subType);
921 case ACTIVE_SYNC_NOTI_SEND_REPORT:
922 EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_SEND_REPORT]", subType);
924 case ACTIVE_SYNC_NOTI_SYNC_HEADER:
925 EM_DEBUG_LOG("handle:[%d]", data->sync_header.handle);
926 EM_DEBUG_LOG("account_id:[%d]", data->sync_header.account_id);
927 EM_DEBUG_LOG("mailbox_id:[%d]", data->sync_header.mailbox_id);
929 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.handle ), DBUS_TYPE_INVALID);
930 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.account_id ), DBUS_TYPE_INVALID);
931 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->sync_header.mailbox_id ), DBUS_TYPE_INVALID);
933 case ACTIVE_SYNC_NOTI_DOWNLOAD_BODY: /* publish a download body notification to ASE */
934 EM_DEBUG_LOG("handle:[%d]", data->download_body.handle);
935 EM_DEBUG_LOG("account_id:[%d]", data->download_body.account_id);
936 EM_DEBUG_LOG("mail_id:[%d]", data->download_body.mail_id);
937 EM_DEBUG_LOG("with_attachment:[%d]", data->download_body.with_attachment);
939 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.handle ), DBUS_TYPE_INVALID);
940 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.account_id ), DBUS_TYPE_INVALID);
941 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.mail_id ), DBUS_TYPE_INVALID);
942 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_body.with_attachment ), DBUS_TYPE_INVALID);
944 case ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT:
945 EM_DEBUG_LOG("handle:[%d]", data->download_attachment.handle);
946 EM_DEBUG_LOG("account_id:[%d]", data->download_attachment.account_id );
947 EM_DEBUG_LOG("mail_id:[%d]", data->download_attachment.mail_id);
948 EM_DEBUG_LOG("with_attachment:[%d]", data->download_attachment.attachment_order );
950 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.handle ), DBUS_TYPE_INVALID);
951 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.account_id ), DBUS_TYPE_INVALID);
952 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.mail_id ), DBUS_TYPE_INVALID);
953 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->download_attachment.attachment_order), DBUS_TYPE_INVALID);
955 case ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT:
956 EM_DEBUG_EXCEPTION("Not support yet : subType[ACTIVE_SYNC_NOTI_VALIDATE_ACCOUNT]", subType);
958 case ACTIVE_SYNC_NOTI_CANCEL_JOB:
959 EM_DEBUG_LOG("account_id:[%d]", data->cancel_job.account_id );
960 EM_DEBUG_LOG("handle to cancel:[%d]", data->cancel_job.handle);
961 EM_DEBUG_LOG("cancel_type:[%d]", data->cancel_job.cancel_type);
963 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.account_id ), DBUS_TYPE_INVALID);
964 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.handle ), DBUS_TYPE_INVALID);
965 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->cancel_job.cancel_type ), DBUS_TYPE_INVALID);
967 case ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER:
968 EM_DEBUG_LOG("account_id:[%d]", data->search_mail_on_server.account_id );
969 EM_DEBUG_LOG("mailbox_id:[%d]", data->search_mail_on_server.mailbox_id );
970 EM_DEBUG_LOG("search_filter_count:[%d]", data->search_mail_on_server.search_filter_count );
971 EM_DEBUG_LOG("handle to cancel:[%d]", data->search_mail_on_server.handle);
973 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.account_id), DBUS_TYPE_INVALID);
974 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.mailbox_id), DBUS_TYPE_INVALID);
975 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_count), DBUS_TYPE_INVALID);
976 for(i = 0; i < data->search_mail_on_server.search_filter_count; i++) {
977 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_list[i].search_filter_type), DBUS_TYPE_INVALID);
978 switch(data->search_mail_on_server.search_filter_list[i].search_filter_type) {
979 case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO :
980 case EMAIL_SEARCH_FILTER_TYPE_UID :
981 case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER :
982 case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER :
983 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED :
984 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED :
985 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT :
986 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED :
987 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT :
988 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN :
989 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.integer_type_key_value), DBUS_TYPE_INVALID);
992 case EMAIL_SEARCH_FILTER_TYPE_BCC :
993 case EMAIL_SEARCH_FILTER_TYPE_CC :
994 case EMAIL_SEARCH_FILTER_TYPE_FROM :
995 case EMAIL_SEARCH_FILTER_TYPE_KEYWORD :
996 case EMAIL_SEARCH_FILTER_TYPE_SUBJECT :
997 case EMAIL_SEARCH_FILTER_TYPE_TO :
998 case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID :
999 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.string_type_key_value), DBUS_TYPE_INVALID);
1002 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE :
1003 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON :
1004 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE :
1005 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.search_filter_list[i].search_filter_key_value.time_type_key_value), DBUS_TYPE_INVALID);
1008 EM_DEBUG_EXCEPTION("Invalid filter type [%d]", data->search_mail_on_server.search_filter_list[i].search_filter_type);
1012 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.handle), DBUS_TYPE_INVALID);
1015 case ACTIVE_SYNC_NOTI_CLEAR_RESULT_OF_SEARCH_ON_SERVER :
1016 EM_DEBUG_LOG("account_id:[%d]", data->clear_result_of_search_mail_on_server.account_id );
1017 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->search_mail_on_server.account_id), DBUS_TYPE_INVALID);
1020 case ACTIVE_SYNC_NOTI_EXPUNGE_MAILS_DELETED_FLAGGED :
1021 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->expunge_mails_deleted_flagged.mailbox_id ), DBUS_TYPE_INVALID);
1022 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->expunge_mails_deleted_flagged.on_server ), DBUS_TYPE_INVALID);
1023 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->expunge_mails_deleted_flagged.handle ), DBUS_TYPE_INVALID);
1026 case ACTIVE_SYNC_NOTI_RESOLVE_RECIPIENT :
1027 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->get_resolve_recipients.account_id), DBUS_TYPE_INVALID);
1028 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->get_resolve_recipients.email_address), DBUS_TYPE_INVALID);
1029 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->get_resolve_recipients.handle), DBUS_TYPE_INVALID);
1032 case ACTIVE_SYNC_NOTI_VALIDATE_CERTIFICATE :
1033 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->validate_certificate.account_id), DBUS_TYPE_INVALID);
1034 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->validate_certificate.email_address), DBUS_TYPE_INVALID);
1035 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->validate_certificate.handle), DBUS_TYPE_INVALID);
1038 case ACTIVE_SYNC_NOTI_ADD_MAILBOX :
1039 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->add_mailbox.account_id), DBUS_TYPE_INVALID);
1040 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->add_mailbox.mailbox_path), DBUS_TYPE_INVALID);
1041 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->add_mailbox.mailbox_alias), DBUS_TYPE_INVALID);
1042 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->add_mailbox.handle), DBUS_TYPE_INVALID);
1045 case ACTIVE_SYNC_NOTI_RENAME_MAILBOX :
1046 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->rename_mailbox.account_id), DBUS_TYPE_INVALID);
1047 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->rename_mailbox.mailbox_id), DBUS_TYPE_INVALID);
1048 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->rename_mailbox.mailbox_name), DBUS_TYPE_INVALID);
1049 dbus_message_append_args(signal, DBUS_TYPE_STRING, &(data->rename_mailbox.mailbox_alias), DBUS_TYPE_INVALID);
1050 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->rename_mailbox.handle), DBUS_TYPE_INVALID);
1053 case ACTIVE_SYNC_NOTI_DELETE_MAILBOX :
1054 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox.account_id), DBUS_TYPE_INVALID);
1055 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox.mailbox_id), DBUS_TYPE_INVALID);
1056 dbus_message_append_args(signal, DBUS_TYPE_INT32, &(data->delete_mailbox.handle), DBUS_TYPE_INVALID);
1060 EM_DEBUG_EXCEPTION("Invalid Notification type of Active Sync : subType[%d]", subType);
1064 if(!dbus_connection_send (connection, signal, NULL)) {
1065 EM_DEBUG_EXCEPTION("dbus_connection_send is failed");
1068 EM_DEBUG_LOG("dbus_connection_send is successful");
1070 dbus_connection_flush(connection);
1075 dbus_message_unref(signal);
1077 EM_DEBUG_FUNC_END();