apply removal of mailbox_name field
[platform/core/messaging/email-service.git] / email-common-use / include / email-internal-types.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-internal-types.h
25  * Desc :  defines data structures and macros
26  *
27  * Auth : 
28  *
29  * History : 
30  *    2011.04.05  :  created
31  *****************************************************************************/
32 #ifndef __EMAIL_INTERNAL_TYPES_H__
33 #define __EMAIL_INTERNAL_TYPES_H__
34
35 #include "email-types.h"
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif /*  __cplusplus */
41
42 #ifndef INTERNAL_FUNC
43 #define INTERNAL_FUNC __attribute__((visibility("default")))
44 #endif
45
46 /* ----------------------------------------------------------------------------- */
47 /*  Feature definitions */
48 #define __FEATURE_USING_ACCOUNT_SVC_FOR_SYNC_STATUS__
49 #define __FEATURE_BACKUP_ACCOUNT__
50 #define __FEATURE_MOVE_TO_OUTBOX_FIRST__
51 /*  #define __FEATURE_PARTIAL_BODY_FOR_POP3__ */
52 /*  #define __FEATURE_KEEP_CONNECTION__  */
53 /*  #define __FEATURE_DRM__ */
54 #define __FEATURE_PARTIAL_BODY_DOWNLOAD__
55 #define __FEATURE_HEADER_OPTIMIZATION__
56 #define __FEATURE_SEND_OPTMIZATION__
57 #define __FEATURE_DOWNLOAD_BODY_ATTACHMENT_OPTIMIZATION__
58 #define __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
59 #define __FEATURE_SYNC_CLIENT_TO_SERVER__
60 #define __FEATURE_AUTO_POLLING__
61 #define __FEATURE_DEBUG_LOG__
62 #define __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
63 #define __FEATURE_XLIST_SUPPORT__
64 #define __FEATURE_SUPPORT_REPORT_MAIL__
65 #define __FEATURE_SUPPORT_IMAP_ID__
66 #define __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__
67 #define __FEATURE_SUPPORT_VALIDATION_SYSTEM__
68 #define __FEATURE_PROGRESS_IN_OUTBOX__
69 #define __FEATURE_OMA_EMN__
70 /*  #define __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */
71 /*  #define __FEATURE_IMAP_IDLE__ */
72 #define __FEATURE_DRIVING_MODE__
73 #define __FEATURE_DELETE_MAILBOX_RECURSIVELY__
74 #define __FEATURE_RENAME_MAILBOX_RECURSIVELY__
75 #define __FEATURE_BODY_SEARCH__
76
77 /* ----------------------------------------------------------------------------- */
78 /*  Macro */
79 #ifndef NULL
80 #define NULL (char *)0
81 #endif
82
83 #define SESSION_MAX                             10
84 #define IMAP_2004_LOG                       1
85 #define TEXT_SIZE                           161 
86 #define MAILBOX_COUNT                       6
87 #define PARTIAL_DOWNLOAD_SIZE               1024
88 #define PARTIAL_BODY_SIZE_IN_BYTES          15360     /*  Partial Body download - 15K */
89 #define NO_LIMITATION                       0
90 #define MAX_MAILBOX_TYPE                    100
91 #define EMAIL_SYNC_ALL_MAILBOX              1
92 #define EMAIL_ATTACHMENT_MAX_COUNT          512
93 #define DOWNLOAD_MAX_BUFFER_SIZE            8000
94 #define LOCAL_MAX_BUFFER_SIZE               1000000
95 #define IMAP_MAX_COMMAND_LENGTH             1000
96 #define DOWNLOAD_NOTI_INTERVAL_PERCENT      5         /*  notify every 5% */
97 #define DOWNLOAD_NOTI_INTERVAL_SIZE         51200     /*  notify every 50k */
98 #define MAX_PATH                            4096      /* /usr/src/linux-2.4.20-8/include/linux/limits.h */
99 #define DATETIME_LENGTH                     16
100 #define MAIL_ID_STRING_LENGTH               10
101 #define MAILBOX_ID_STRING_LENGTH            10
102 #define EMAIL_LIMITATION_FREE_SPACE         (5) /*  This value is 5MB */
103 #define EMAIL_MAIL_MAX_COUNT                5000
104 #define HTML_EXTENSION_STRING               ".htm"
105 #define MAX_PATH_HTML                       256
106 #define MAX_ACTIVE_TASK                     10
107
108 #define DIR_SEPERATOR                       "/"
109
110 #define USERDATA_PATH                       "/opt/usr"
111 #define DATA_PATH                           "/opt/usr/data"
112 #define DB_PATH                             "/opt/usr/dbspace"
113 #define EMAIL_SERVICE_DB_FILE_PATH          "/opt/usr/dbspace/.email-service.db"
114
115 #define EMAILPATH                                               DATA_PATH"/email"
116 #define MAILHOME                                                DATA_PATH"/email/.email_data"
117 #define MAILTEMP                            MAILHOME"/tmp"
118 #define DIRECTORY_PERMISSION                0755
119
120 #define MIME_SUBTYPE_DRM_OBJECT             "vnd.oma.drm.message"
121 #define MIME_SUBTYPE_DRM_RIGHTS             "vnd.oma.drm.rights+xml"
122 #define MIME_SUBTYPE_DRM_DCF                "vnd.oma.drm.dcf"
123
124 #define SHM_FILE_FOR_DB_LOCK                "/.email_shm_db_lock"
125
126 #define NATIVE_EMAIL_APPLICATION_PKG        "com.samsung.email"
127 #define NATIVE_EMAIL_DOMAIN                 "email"
128
129 #define IMAP_ID_OS                          "TIZEN"
130 #define IMAP_ID_OS_VERSION                  "2.0b"
131 #define IMAP_ID_VENDOR                      "Samsung Mobile"
132 #define IMAP_ID_DEVICE_NAME                 "GT-I8800_EUR_XX"
133 #define IMAP_ID_AGUID                       "1"
134 #define IMAP_ID_ACLID                       "Samsung"
135
136 #ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
137 #define SHM_FILE_FOR_MAIL_ID_LOCK           "/.email_shm_mail_id_lock"
138 #endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */
139
140 #define CR                                  '\r'
141 #define LF                                  '\n'
142 #define SPACE                               ' '
143 #define TAB                                 '\t'
144 #define NULL_CHAR                           '\0'
145 #define TAB_STRING                          "\t"
146 #define CR_STRING                           "\r"
147 #define LF_STRING                           "\n"
148 #define CRLF_STRING                         "\r\n"
149
150 #define GRAB_TYPE_TEXT                      1        /*  retrieve text and attachment list */
151 #define GRAB_TYPE_ATTACHMENT                2        /*  retrieve attachment */
152
153 #define SAVE_TYPE_SIZE                      1        /*  only get content size */
154 #define SAVE_TYPE_BUFFER                    2        /*  save content to buffer */
155 #define SAVE_TYPE_FILE                      3        /*  save content to temporary file */
156
157 #define FINISH_OFF_IF_CANCELED              if (!emcore_check_thread_status()) { err = EMAIL_ERROR_CANCELLED; goto FINISH_OFF; }
158 #define CHECK_JOB_CANCELED()                {if (!emcore_check_thread_status()) goto JOB_CANCEL; }
159
160 #define SNPRINTF(buff, size, format, args...)  snprintf(buff, size, format, ##args)
161 #define SNPRINTF_OFFSET(base_buf, offset, base_size, format, args...) \
162                         ({\
163                                 int _offset = offset;\
164                                 snprintf(base_buf + _offset, base_size - _offset - 1, format, ##args);\
165                         })
166
167 #define THREAD_CREATE(tv, func, param, err)       { EM_DEBUG_LOG("THREAD_CREATE "#tv); err = pthread_create(&tv, NULL, func, param); }
168 #define THREAD_CREATE_JOINABLE(tv, func, err)     { pthread_attr_t attr; EM_DEBUG_LOG("THREAD_CREATE_JOINABLE "#tv); \
169                                                    pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);\
170                                                    err = pthread_create(&tv, &attr, func, NULL); pthread_attr_destroy(&attr); }
171 #define THREAD_JOIN(tv)                           {EM_DEBUG_LOG("THREAD_JOIN "#tv); pthread_join(tv, NULL); }
172 #define THREAD_SELF()                             pthread_self()
173 #define THREAD_DETACH(tv)                         pthread_detach(tv)
174 #define INITIALIZE_CRITICAL_SECTION(cs)           {EM_DEBUG_LOG("INITIALIZE_CRITICAL_SECTION "#cs); pthread_mutex_init(&cs, NULL); }
175 #define ENTER_CRITICAL_SECTION(cs)                {EM_DEBUG_LOG("ENTER_CRITICAL_SECTION "#cs); pthread_mutex_lock(&cs); }
176 #define TRY_ENTER_CRITICAL_SECTION(cs)            {EM_DEBUG_LOG("TRY_ENTER_CRITICAL_SECTION "#cs); pthread_mutex_trylock(&cs); }
177 #define LEAVE_CRITICAL_SECTION(cs)                {EM_DEBUG_LOG("LEAVE_CRITICAL_SECTION "#cs); pthread_mutex_unlock(&cs); }
178 #define DELETE_CRITICAL_SECTION(cs)               {EM_DEBUG_LOG("DELETE_CRITICAL_SECTION "#cs); pthread_mutex_destroy(&cs); }
179
180 #define INITIALIZE_CONDITION_VARIABLE(cv)         {EM_DEBUG_LOG("INITIALIZE_CONDITION_VARIABLE "#cv); pthread_cond_init(&cv, NULL); } 
181 #define SLEEP_CONDITION_VARIABLE(cv, cs)          {EM_DEBUG_LOG("SLEEP_CONDITION_VARIABLE "#cv); pthread_cond_wait(&cv, &cs); } 
182 #define WAKE_CONDITION_VARIABLE(cv)               {EM_DEBUG_LOG("WAKE_CONDITION_VARIABLE "#cv); pthread_cond_signal(&cv); } 
183 #define DELETE_CONDITION_VARIABLE(cv)             {EM_DEBUG_LOG("DELETE_CONDITION_VARIABLE "#cv); pthread_cond_destroy(&cv); } 
184
185 #define INITIALIZE_RECURSIVE_CRITICAL_SECTION(cs) { EM_DEBUG_LOG("INITIALIZE_RECURSIVE_CRITICAL_SECTION "#cs);  \
186                                                    if (cs == NULL) {pthread_mutex_lock(&_send_event_available_lock); pthread_mutexattr_t attr; cs = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));\
187                                                    pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);\
188                                                    pthread_mutex_init(cs, &attr);pthread_mutexattr_destroy(&attr); pthread_mutex_unlock(&_send_event_available_lock);}}
189 #define ENTER_RECURSIVE_CRITICAL_SECTION(cs)      {EM_DEBUG_LOG("ENTER_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_lock(cs);}
190 #define TRY_ENTER_RECURSIVE_CRITICAL_SECTION(cs)  {EM_DEBUG_LOG("TRY_ENTER_RECURSIVE_CRITICAL_SECTION "#cs); if(cs)  pthread_mutex_trylock(cs);}
191 #define LEAVE_RECURSIVE_CRITICAL_SECTION(cs)      {EM_DEBUG_LOG("LEAVE_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_unlock(cs);}
192 #define DELETE_RECURSIVE_CRITICAL_SECTION(cs)     {EM_DEBUG_LOG("DELETE_RECURSIVE_CRITICAL_SECTION "#cs); if(cs) pthread_mutex_destroy(cs);}
193 typedef pthread_t thread_t;
194
195 #define SMTP_RESPONSE_OK                        250
196 #define SMTP_RESPONSE_READY                     354
197 #define SMTP_RESPONSE_CONNECTION_BROKEN 421
198 #define SMTP_RESPONSE_WANT_AUTH             505
199 #define SMTP_RESPONSE_WANT_AUTH2            530
200 #define SMTP_RESPONSE_UNAVAIL               550
201
202 #define VCONF_KEY_LATEST_MAIL_ID        "db/private/email-service/latest_mail_id"
203 #define VCONF_KEY_DEFAULT_ACCOUNT_ID    "db/private/email-service/default_account_id"
204 #define VCONF_KEY_NOTI_PRIVATE_ID       "db/private/email-service/noti_private_id"
205
206 #define OUTMODE  "wb"
207 #define INMODE   "rb"
208 #define READMODE "r"
209
210 #define TYPEPKCS7_SIGN 10       
211 #define TYPEPKCS7_MIME 11
212
213 #define INLINE_ATTACHMENT    1
214 #define ATTACHMENT           2
215
216 #define EMAIL_ALARM_CLASS_SCHEDULED_SENDING   1
217 #define EMAIL_ALARM_CLASS_NEW_MAIL_ALERT      2
218 #define EMAIL_ALARM_CLASS_AUTO_POLLING        3
219
220 #define EVENT_QUEUE_MAX 32
221
222 /* __FEATURE_LOCAL_ACTIVITY__ supported
223 #define BULK_OPERATION_COUNT              50
224 #define ALL_ACTIVITIES                    0
225 */
226
227 /* ----------------------------------------------------------------------------- */
228 /*  Type */
229 typedef enum
230 {
231         _SERVICE_THREAD_TYPE_NONE      = 0,  
232         _SERVICE_THREAD_TYPE_RECEIVING = 1, 
233         _SERVICE_THREAD_TYPE_SENDING   = 2, 
234 #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ 
235         _SERVICE_THREAD_TYPE_PBD       = 3, 
236 #endif /*  __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
237 } email_service_thread_type;
238
239
240 typedef enum
241 {
242         EMAIL_PROTOCOL_NONE                        = 0,
243         EMAIL_PROTOCOL_POP3                        = 1,
244         EMAIL_PROTOCOL_IMAP                        = 2,
245         EMAIL_PROTOCOL_SMTP                        = 3,
246 } email_protocol_type_t;
247
248 typedef enum
249 {
250         ACCOUNT_SVC_SYNC_STATUS_RUNNING            = 0,
251         ACCOUNT_SVC_SYNC_STATUS_IDLE               = 1,
252         ACCOUNT_SVC_SYNC_STATUS_OFF                = 2,
253 } email_account_svc_sync_status;
254
255 typedef enum {
256         SET_TYPE_SET        = 1,
257         SET_TYPE_UNION      = 2,
258         SET_TYPE_MINUS      = 3,
259         SET_TYPE_INTERSECT  = 4 /* Not supported */
260 } email_set_type_t;
261
262 #ifdef __FEATURE_KEEP_CONNECTION__
263 enum
264 {
265         EMAIL_STREAM_STATUS_DISCONNECTED = 0,
266         EMAIL_STREAM_STATUS_CONNECTED = 1
267 } ;
268 #endif /* __FEATURE_KEEP_CONNECTION__ */
269
270 enum 
271 {
272         EXTENSION_JPEG   = 0,
273         EXTENSION_JPG    = 1,
274         EXTENSION_PNG    = 2,
275         EXTENSION_GIF    = 3,
276         EXTENSION_BMP    = 4,
277         EXTENSION_PIC    = 5,
278         EXTENSION_AGIF   = 6,
279         EXTENSION_TIF    = 7,
280         EXTENSION_WBMP   = 8,
281         EXTENSION_P7S    = 9,
282         EXTENSION_P7M    = 10
283 };
284
285 /*  event information */
286 typedef struct
287 {
288         int                        account_id;         /*  in general, account id */
289         email_event_type_t         type;
290         email_event_status_type_t  status;
291         char                      *event_param_data_1; /*  in general, mailbox name (exception in emcore_send_mail, emcore_send_saved_mail it is email_option_t **/
292         char                      *event_param_data_2;
293         char                      *event_param_data_3;
294         int                        event_param_data_4;
295         int                        event_param_data_5;
296         int                        event_param_data_6; /* in general, notification parameter #1 */
297         int                        event_param_data_7; /* in general, notification parameter #2 */
298         int                        event_param_data_8;
299 } email_event_t;
300
301
302 typedef struct
303 {
304         int   num;
305         void *data;
306 } email_callback_holder_t;
307
308
309 typedef struct email_search_key_t email_search_key_t;
310 struct email_search_key_t
311 {
312         int               type;
313         char             *value;
314         email_search_key_t *next;
315 };
316
317 typedef struct
318 {
319         int                  tid;
320         email_protocol_type_t  protocol;
321         void                *stream;
322         int                  auth;
323         int                  network;
324         int                  error;
325         int                  status;
326 } email_session_t;
327
328 typedef struct
329 {
330         int                    mailbox_id;                 /**< Unique id on mailbox table.*/
331         char                  *mailbox_name;               /**< Specifies the path of mailbox.*/
332         email_mailbox_type_e   mailbox_type;               /**< Specifies the type of mailbox */
333         char                  *alias;                      /**< Specifies the display name of mailbox.*/
334         int                    unread_count;               /**< Specifies the Unread Mail count in the mailbox.*/
335         int                    total_mail_count_on_local;  /**< Specifies the total number of mails in the mailbox in the local DB.*/
336         int                    total_mail_count_on_server; /**< Specifies the total number of mails in the mailbox in the mail server.*/
337         int                    local;                      /**< Specifies the local mailbox.*/
338         int                    synchronous;                /**< Specifies the mailbox with synchronized the server.*/
339         int                    account_id;                 /**< Specifies the account ID for mailbox.*/
340         int                    has_archived_mails;         /**< Specifies the archived mails.*/
341         int                    mail_slot_size;             /**< Specifies how many mails can be stored in local mailbox.*/
342         int                    no_select;                  /**< Specifies the 'no_select' attribute from xlist.*/
343         void                  *user_data;                  /**< Specifies the internal data.*/
344         void                  *mail_stream;                /**< Specifies the internal data.*/
345 } email_internal_mailbox_t;
346
347 #ifdef __FEATURE_KEEP_CONNECTION__
348 typedef struct email_connection_info
349 {
350         int                    account_id;
351         int                    sending_server_stream_status;
352         void                  *sending_server_stream;
353         int                    receiving_server_stream_status;
354         void                  *receiving_server_stream;
355         struct email_connection_info *next;
356 } email_connection_info_t;
357 #endif /* __FEATURE_KEEP_CONNECTION__ */
358
359 typedef struct
360 {
361         char *contact_name;
362         char *email_address;
363         char *alias;
364         int   storage_type;
365         int   contact_id;
366 } email_mail_contact_info_t;
367
368 /*  global account list */
369 typedef struct email_account_list {
370     email_account_t *account;
371     struct email_account_list *next;
372 } email_account_list_t;
373
374 typedef struct {
375         int                task_id;
376         email_task_type_t  task_type;
377         thread_t           thread_id;
378 } email_active_task_t;
379
380
381 typedef void (*email_event_callback)(int total, int done, int status, int account_id, int mail_id, int handle, void *user_data, int error);
382
383 /* ----------------------------------------------------------------------------- */
384 /*  Please contact Himanshu [h.gahlaut@samsung.com] for any explanation in code here under __FEATURE_PARTIAL_BODY_DOWNLOAD__ MACRO */
385 #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
386 typedef enum
387 {
388         ACTIVITY_PARTIAL_BODY_DOWNLOAD_IMAP4 = 1,
389         ACTIVITY_PARTIAL_BODY_DOWNLOAD_POP3_WAIT,
390         ACTIVITY_PARTIAL_BODY_DOWNLOAD_POP3_ACTIVE
391 }       email_pdb_activity_type_e;
392
393 typedef struct 
394 {
395     int account_id;
396     int mail_id;
397     unsigned long server_mail_id;
398     int activity_id;
399     int mailbox_id;
400     char *mailbox_name;
401     email_event_type_t event_type;   /*  Event Type Null means event is created from local activitys    */
402     int activity_type;             /*  Activity Type Null means event is created from event queue */
403
404 } email_event_partial_body_thd;
405 #endif /*  __FEATURE_PARTIAL_BODY_DOWNLOAD__ */
406
407 #ifdef __cplusplus
408 }
409 #endif /*  __cplusplus */
410
411 #endif /*  __EMAIL_INTERNAL_TYPES_H__ */