Tizen 2.0 Release
[platform/core/messaging/email-service.git] / email-core / include / email-core-utils.h
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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.
19 *
20 */
21
22
23 /******************************************************************************
24  * File :  email-core-utils.h
25  * Desc :  Mail Utils Header
26  *
27  * Auth : 
28  *
29  * History : 
30  *    2006.08.16  :  created
31  *****************************************************************************/
32 #ifndef __EMAIL_CORE_UTILS_H__
33 #define __EMAIL_CORE_UTILS_H__
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif /* __cplusplus */
39
40 #include "email-types.h"
41 #include "email-internal-types.h"
42 #include "email-storage.h"
43 #include "email-core-global.h"
44 #include "email-core-mail.h"
45
46 /*  This is used for emcore_get_long_encoded_path */
47 #define EMAIL_CONNECT_FOR_SENDING       -1
48 #define ENCODED_PATH_SMTP       "UHDF_ENCODED_PATH_SMTP_EKJD"
49
50 typedef int (*email_get_unread_email_count_cb)(int unread, int *err_code);
51
52 /* parse the Full mailbox Path and get the Alias Name of the Mailbox */
53 char* emcore_get_alias_of_mailbox(const char *mailbox_path);
54
55 /* Parse the Mailbox Path and get the Account Email address */
56 int   emcore_get_temp_file_name(char **filename, int *err_code);
57 int   emcore_get_long_encoded_path(int account_id, char *path, int delimiter, char **long_enc_path, int *err_code);
58 int   emcore_get_encoded_mailbox_name(char *name, char **enc_name, int *err_code);
59 int   emcore_get_file_name(char *path, char **filename, int *err_code);
60 int   emcore_get_file_size(char *path, int *size, int *err_code);
61 int   emcore_get_actual_mail_size(char *pBodyPlane, char *pBodyHtml, struct attachment_info *pAttachment, int *error_code);
62 int   emcore_calc_mail_size(email_mail_data_t *mail_data_src, email_attachment_data_t *attachment_data_src, int attachment_count, int *error_code);
63 int   emcore_get_address_count(char *addr_str, int *to_num, int *err_code);
64 int   emcore_is_storage_full(int *error);
65 int   emcore_get_long_encoded_path_with_account_info(email_account_t *account, char *path, int delimiter, char **long_enc_path, int *err_code);
66 void  emcore_fill_address_information_of_mail_tbl(emstorage_mail_tbl_t *mail_data);
67
68
69 INTERNAL_FUNC int   emcore_get_preview_text_from_file(const char *input_plain_path, const char *input_html_path, int input_preview_buffer_length, char **output_preview_buffer);
70 int   reg_replace (char *input_source_text, char *input_old_pattern_string, char *input_new_string);
71 int   emcore_strip_HTML(char *source_string);
72 int   emcore_send_noti_for_new_mail(int account_id, char *mailbox_name, char *subject, char *from, char *uid, char *datetime);
73 int   emcore_make_attachment_file_name_with_extension(char *source_file_name, char *sub_type, char *result_file_name, int result_file_name_buffer_length, int *err_code);
74
75 /* Session Handling */
76 int   emcore_get_empty_session(email_session_t **session);
77 int   emcore_clear_session(email_session_t *session);
78 int   emcore_get_current_session(email_session_t **session);
79
80 INTERNAL_FUNC int emcore_display_unread_in_badge();
81 INTERNAL_FUNC int emcore_set_network_error(int err_code);
82
83 /* Transaction Handling */
84 INTERNAL_FUNC int emcore_add_transaction_info(int mail_id , int handle  , int *err_code);
85 INTERNAL_FUNC int emcore_get_handle_by_mailId_from_transaction_info(int mail_id , int *pHandle);
86 INTERNAL_FUNC int emcore_delete_transaction_info_by_mailId(int mail_id);
87
88 /* For notification bar */
89 INTERNAL_FUNC int emcore_update_notification_for_unread_mail(int account_id);
90 INTERNAL_FUNC int emcore_clear_all_notifications();
91 //INTERNAL_FUNC int emcore_add_notification_for_unread_mail(emstorage_mail_tbl_t *input_mail_tbl_data);
92 INTERNAL_FUNC int emcore_delete_notification_for_read_mail(int mail_id);
93 INTERNAL_FUNC int emcore_delete_notification_by_account(int account_id);
94 INTERNAL_FUNC int emcore_finalize_sync(int account_id, int *error);
95
96 INTERNAL_FUNC int emcore_show_user_message(int id, email_action_t action, int error);
97
98 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
99
100 /**
101  * @fn emcore_convert_to_uid_range_set(email_id_set_t *id_set, int id_set_count, email_uid_range_set **uid_range_set, int range_len, int *err_code)
102  * Prepare a linked list of uid ranges with each node having a uid_range and lowest and highest uid in it.
103  *
104  *@author                                       h.gahlaut@samsung.com
105  * @param[in] id_set                    Specifies the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
106  * @param[in] id_set_count              Specifies the no. of cells in id_set array i.e. no. of sets of mail_ids and server_mail_ids
107  * @param[in] range_len         Specifies the maximum length of string of range allowed. 
108  * @param[out] uid_range_set    Returns the uid_ranges formed in the form of a linked list with head stored in uid_range_set pointer
109  * @param[out] err_code         Returns the error code.
110  * @remarks                                     An example of a uid_range formed is 2 : 6, 8, 10, 14 : 15, 89, 
111  *                                                      While using it the caller should remove the ending , (comma)                                    
112  * @return This function returns true on success or false on failure.
113  */
114  
115 INTERNAL_FUNC int emcore_convert_to_uid_range_set(email_id_set_t *id_set, int id_set_count, email_uid_range_set **uid_range_set, int range_len, int *err_code);
116
117 /**
118  * void emcore_free_uid_range_set(email_uid_range_set **uid_range_head)
119  * Frees the linked list of uid ranges 
120  *
121  * @author                                      h.gahlaut@samsung.com
122  * @param[in] uid_range_head    Head pointer of linked list of uid ranges               
123  * @remarks                                                                     
124  * @return This function does not return anything.
125  */
126 INTERNAL_FUNC void emcore_free_uid_range_set(email_uid_range_set **uid_range_set);
127
128 /**
129  * @fn emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_range_set **uid_range_set, int range_len, unsigned long luid, unsigned long huid)
130  * Appends the subset_string to uid range if the uid range has not exceeded maximum length(range_len), otherwise creates a new node in linked list of uid range set 
131  * and stores the subset_string in its uid_range. Also sets the lowest and highest uids for the corresponsing uid_range
132  * 
133  * @author                                      h.gahlaut@samsung.com
134  * @param[in] subset_string             Specifies the subset string to be appended. A subset string can be like X : Y or X where X and Y are uids.
135  * @param[in] range_len         Specifies the maximum length of range string allowed. 
136  * @param[in] luid                              Specifies the lowest uid in subset string
137  * @param[in] huid                              Specifies the highest uid in subset string
138  * @param[out] uid_range_set    Returns the uid_ranges formed in the form of a linked list with head stored in uid_range_set pointer
139  * @param[out] err_code         Returns the error code.
140  * @remarks                                                                             
141  * @return This function returns true on success or false on failure.
142  */
143  
144 int emcore_append_subset_string_to_uid_range(char *subset_string, email_uid_range_set **current_node_adr, email_uid_range_set **uid_range_set, int range_len, unsigned long luid, unsigned long huid);
145
146 /**
147  * @fn emcore_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char ***strings, int *string_count, int *err_code)
148  * Forms comma separated strings of a give max_string_len from an array of numbers 
149  * 
150  * @author                                      h.gahlaut@samsung.com
151  * @param[in] numbers                   Specifies the array of numbers to be converted into comma separated strings.
152  * @param[in] num_count         Specifies the count of numbers in numbers array. 
153  * @param[in] max_string_len    Specifies the maximum length of comma separated strings that are to be formed.
154  * @param[out] strings                  Returns the base address of a double dimension array which stores the strings.
155  * @param[out] string_count             Returns the number of strings formed.
156  * @param[out] err_code         Returns the error code.
157  * @remarks                                     If Input to the function is five numbers like 2755 2754 2748 2749 2750 and a given max_string_len is 20.
158  *                                                      Then this function will form two comma separated strings as follows -
159  *                                                      "2755, 2754, 2748"
160  *                                                      "2749, 2750"
161  * @return This function returns true on success or false on failure.
162  */
163 INTERNAL_FUNC int emcore_form_comma_separated_strings(int numbers[], int num_count, int max_string_len, char ***strings, int *string_count, int *err_code);
164
165 /**
166  * @fn emcore_free_comma_separated_strings(char ***string_list, int *string_count)
167  * Frees the double dimensional array of strings. 
168  *
169  * @author                                      h.gahlaut@samsung.com
170  * @param[in] uid_range_head    Address of base address of double dimensional array of strings.
171  * @param[in] string_count              Address of variable holding the count of strings.
172  * @remarks                                                                     
173  * @return This function does not return anything.
174  */
175
176 INTERNAL_FUNC void emcore_free_comma_separated_strings(char ***string_list, int *string_count);
177
178 #endif
179
180 #ifdef __FEATURE_LOCAL_ACTIVITY__
181 /*  Added to get next activity id sequence */
182 INTERNAL_FUNC int emcore_get_next_activity_id(int *activity_id, int *err_code);
183 INTERNAL_FUNC int emcore_add_activity(emstorage_activity_tbl_t *new_activity, int *err_code);
184 INTERNAL_FUNC int emcore_delete_activity(emstorage_activity_tbl_t *activity, int *err_code);
185 #endif /* __FEATURE_LOCAL_ACTIVITY__ */
186
187 INTERNAL_FUNC void emcore_free_rule(email_rule_t* rule);
188
189 INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_string, int *result);
190
191 #ifdef __cplusplus
192 }
193 #endif /* __cplusplus */
194
195 #endif /* __EMAIL_CORE_UTILS_H__ */