Tizen 2.0 Release
[platform/core/messaging/email-service.git] / email-core / email-storage / include / email-storage.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-storage.h
25  * Desc :  email-core Storage Library Header
26  *
27  * Auth : 
28  *
29  * History : 
30  *    2006.07.28  :  created
31  *****************************************************************************/
32 #ifndef __EMAIL_STORAGE_H__
33 #define __EMAIL_STORAGE_H__
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif /* __cplusplus */
39
40 #include <sqlite3.h>
41 #include <time.h>
42 #include "email-types.h"
43 #include "email-core-tasks.h"
44 #include "email-internal-types.h"
45
46 #define FIRST_ACCOUNT_ID    1
47
48
49 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
50 #define QUERY_SIZE          8192
51 #define MAX_INTEGER_LENGTH  5  /*  32767 -> 5 bytes */
52
53 typedef struct 
54 {
55         int mail_id;
56         unsigned long server_mail_id;
57 } email_id_set_t;
58
59 #endif /* __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__ */
60
61
62 typedef struct 
63 {
64         /* Account information */
65         int                                account_id;                               /* Account id  */
66         char                              *account_name;                             /* Account name */
67         char                              *logo_icon_path;                           /* Account logo icon path */
68         int                                account_svc_id;                           /* Specifies id from account-svc */
69         int                                sync_status;                              /* Sync Status. SYNC_STATUS_FINISHED, SYNC_STATUS_SYNCING, SYNC_STATUS_HAVE_NEW_MAILS */
70         int                                sync_disabled;                            /* If this attriube is set as true, email-service will not synchronize this account. */
71         int                                default_mail_slot_size;
72
73         void                              *user_data;                                /* binary user data */
74         int                                user_data_length;                         /* user data length */
75
76         /* User information */
77         char                              *user_display_name;                        /* User's display name */
78         char                              *user_email_address;                       /* User's email address */
79         char                              *reply_to_address;                         /* Email address for reply */
80         char                              *return_address;                           /* Email address for error from server*/
81
82         /* Configuration for incoming server */
83         email_account_server_t             incoming_server_type;                     /* Incoming server type */
84         char                              *incoming_server_address;                  /* Incoming server address */
85         int                                incoming_server_port_number;              /* Incoming server port number */
86         char                              *incoming_server_user_name;                /* Incoming server user name */
87         char                              *incoming_server_password;                 /* Incoming server password */
88         int                                incoming_server_secure_connection;        /* Does incoming server requires secured connection? */
89
90         /* Options for incoming server */
91         email_imap4_retrieval_mode_t       retrieval_mode;                           /* Retrieval mode : EMAIL_IMAP4_RETRIEVAL_MODE_NEW or EMAIL_IMAP4_RETRIEVAL_MODE_ALL */
92         int                                keep_mails_on_pop_server_after_download;  /* Keep mails on POP server after download */
93         int                                check_interval;                           /* Specifies the interval for checking new mail periodically */
94         int                                auto_download_size;                       /* Specifies the size for auto download in bytes. -1 means entire mails body */
95
96         /* Configuration for outgoing server */
97         email_account_server_t             outgoing_server_type;
98         char                              *outgoing_server_address;
99         int                                outgoing_server_port_number;
100         char                              *outgoing_server_user_name;
101         char                              *outgoing_server_password;
102         int                                outgoing_server_secure_connection;        /* Does outgoing server requires secured connection? */
103         int                                outgoing_server_need_authentication;      /* Does outgoing server requires authentication? */
104         int                                outgoing_server_use_same_authenticator;   /* Use same authenticator for outgoing server */ /* flag2 */
105
106         /* Options for outgoing server */
107         email_option_t                     options;
108
109         /* Authentication Options */
110         int                                pop_before_smtp;                          /* POP before SMTP Authentication */
111         int                                incoming_server_requires_apop;            /* APOP authentication */
112
113         /* S/MIME Options */
114         email_smime_type                   smime_type;                               /* Sepeifies the smime type 0=Normal 1=Clear signed 2=encrypted 3=Signed + encrypted */
115         char                              *certificate_path;                         /* Sepeifies the certificate path of private*/
116         email_cipher_type                  cipher_type;                              /* Sepeifies the encryption algorithm*/
117         email_digest_type                  digest_type;                              /* Sepeifies the digest algorithm*/
118 } emstorage_account_tbl_t;
119
120 typedef struct 
121 {
122         int certificate_id;
123         int issue_year;
124         int issue_month;
125         int issue_day;
126         int expiration_year;
127         int expiration_month;
128         int expiration_day;
129         char *issue_organization_name;
130         char *email_address;
131         char *subject_str;
132         char *filepath;
133         char *password;
134 } emstorage_certificate_tbl_t;
135
136 typedef struct 
137 {
138         int   account_id;      /*  MUST BE '0'  :  currently, only global rule supported. */
139         int   rule_id;
140         int   type;            /*  from/subject/body  */
141         char *value;
142         int   action_type;     /*  move/block/delete  */
143         int   target_mailbox_id;    /*  destination mailbox  */
144         int   flag1;           /*  for rule ON/OFF */
145         int   flag2;           /*  For rule type INCLUDE/Exactly SAME AS */
146 } emstorage_rule_tbl_t;
147
148 /* mail_box_tbl table entity */
149 typedef struct 
150 {
151         int                   mailbox_id;
152         int                   account_id;
153         int                   local_yn;
154         char                 *mailbox_name;
155         email_mailbox_type_e  mailbox_type;
156         char                 *alias;
157         int                   modifiable_yn;              /*  whether mailbox is able to be deleted/modified */
158         int                   unread_count;               /*  Removed. 16-Dec-2010, count unread mails at the moment it is required. not store in the DB */
159         int                   total_mail_count_on_local;  /*  Specifies the total number of mails in the mailbox in the local DB. count unread mails at the moment it is required. not store in the DB */
160         int                   total_mail_count_on_server; /*  Specifies the total number of mails in the mailbox in the mail server */
161         int                   has_archived_mails;
162         int                   mail_slot_size;
163         int                   no_select;
164         time_t                last_sync_time;             /*  The last synchronization time */
165         int                   deleted_flag;               /*  whether mailbox is deleted */
166 } emstorage_mailbox_tbl_t;
167
168 /* mail_read_uid_tbl table entity */
169 typedef struct 
170 {
171         int     account_id;
172         int     mailbox_id;
173         int     local_uid;
174         char   *mailbox_name;   /*  server mailbox */
175         char   *s_uid;          /*  uid on server */
176         int     data1;          /*  rfc822 size */
177         char   *data2;
178         int     flag;           /*  rule id */
179         int     reserved;
180 } emstorage_read_mail_uid_tbl_t;
181
182 typedef struct 
183 {
184         int                    mail_id;
185         int                    account_id;
186         int                    mailbox_id;
187         char                  *mailbox_name;
188         int                    mailbox_type;
189         char                  *subject;
190         time_t                 date_time;
191         int                    server_mail_status;
192         char                  *server_mailbox_name;
193         char                  *server_mail_id;
194         char                  *message_id;
195         int                    reference_mail_id;
196         char                  *full_address_from;
197         char                  *full_address_reply;
198         char                  *full_address_to;
199         char                  *full_address_cc;
200         char                  *full_address_bcc;
201         char                  *full_address_return;
202         char                  *email_address_sender;
203         char                  *email_address_recipient;
204         char                  *alias_sender;
205         char                  *alias_recipient;
206         int                    body_download_status;
207         char                  *file_path_plain;
208         char                  *file_path_html;
209         char                  *file_path_mime_entity;
210         int                    mail_size;
211         char                   flags_seen_field;
212         char                   flags_deleted_field;
213         char                   flags_flagged_field;
214         char                   flags_answered_field;
215         char                   flags_recent_field;
216         char                   flags_draft_field;
217         char                   flags_forwarded_field;
218         int                    DRM_status;
219         email_mail_priority_t  priority;
220         email_mail_status_t    save_status;
221         int                    lock_status;
222         email_mail_report_t    report_status;
223         int                    attachment_count;
224         int                    inline_content_count;
225         int                    thread_id;
226         int                    thread_item_count;
227         char                  *preview_text;
228         email_mail_type_t      meeting_request_status;
229         email_message_class    message_class;
230         email_digest_type      digest_type;
231         email_smime_type       smime_type;
232 } emstorage_mail_tbl_t;
233
234 /* mail_attachment_tbl entity */
235 typedef struct 
236 {
237         int   attachment_id;
238         char *attachment_name;
239         char *attachment_path;
240         int   attachment_size;
241         int   mail_id;
242         int   account_id;
243         int   mailbox_id;
244         int   attachment_save_status;              /* 1 : existing, 0 : not existing */
245         int   attachment_drm_type;                 /* 0 : none, 1 : object, 2 : rights, 3 : dcf */
246         int   attachment_drm_method;               /* 0 : none, 1 : FL, 2 : CD, 3 : SSD, 4 : SD */
247         int   attachment_inline_content_status;    /* 1 : inline content , 0 : not inline content */
248         char *attachment_mime_type;
249 #ifdef __ATTACHMENT_OPTI__      
250         int   encoding;
251         char *section;  
252 #endif  
253 } emstorage_attachment_tbl_t;
254
255
256 typedef enum {
257         RETRIEVE_ALL = 1,           /*  mail */
258         RETRIEVE_ENVELOPE,          /*  mail envelope */
259         RETRIEVE_SUMMARY,           /*  mail summary */
260         RETRIEVE_FIELDS_FOR_DELETE, /*  account_id, mail_id, server_mail_yn, server_mailbox, server_mail_id */
261         RETRIEVE_ACCOUNT,           /*  account_id */
262         RETRIEVE_FLAG,              /*  mailbox, flag1, thread_id */
263         RETRIEVE_ID,                /*  mail_id */
264         RETRIEVE_ADDRESS,           /*  mail_id, contact_info */
265 } emstorage_mail_field_type_t;
266
267 typedef struct _emstorage_search_filter_t {
268         char *key_type;
269         char *key_value;
270         struct _emstorage_search_filter_t *next;
271 } emstorage_search_filter_t;
272
273 typedef enum {
274         EMAIL_CREATE_DB_NORMAL = 0, 
275         EMAIL_CREATE_DB_CHECK, 
276 } emstorage_create_db_type_t;
277
278
279 /*****************************************************************************
280                                                                 etc
281 *****************************************************************************/
282 #define MAX_PW_FILE_NAME_LENGTH                   128 /*  password file name for secure storage */
283
284 #ifdef __FEATURE_LOCAL_ACTIVITY__
285
286 typedef enum
287 {
288  ACTIVITY_FETCHIMAPFOLDER = 1,  /* Fetch Mail server Activity */
289  ACTIVITY_DELETEMAIL,                   /* Delete Mail Activity */              
290  ACTIVITY_MODIFYFLAG,                   /* Modify Mail flag Activity */         
291  ACTIVITY_MODIFYSEENFLAG,               /* Modify Mail seen flag Activity */
292  ACTIVITY_MOVEMAIL,                             /* Move Mail Activity */
293  ACTIVITY_DELETEALLMAIL,                /* Delete All Mails activity */
294  ACTIVITY_COPYMAIL,                             /* Copy Mail Activity */
295  ACTIVITY_SAVEMAIL,                             /* Save Mail activity */
296  ACTIVITY_DELETEMAIL_SEND,              /* New Delete Mail Activity added to be processed by send thread */
297 }eActivity_type;
298
299
300 /**
301  * emstorage_activity_tbl_t - Email Local activity Structure
302  *
303  */
304 typedef struct
305 {
306         int activity_id;                                /* Activity ID */
307         int account_id;                          /* Account ID */
308         int mail_id;                             /* Mail ID    */
309         int activity_type;    /* Local Activity Type */
310         char *server_mailid;                 /* Server Mail ID or Mailbox name */
311         char *src_mbox;                          /* Source Mailbox in case of mail_move */      
312         char *dest_mbox;                 /* Destination Mailbox name in case of Mail move operation */
313
314 } emstorage_activity_tbl_t;
315
316 #endif
317
318 INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name);
319
320
321 /************** Database Management ***************/
322 /*
323  * em_db_open
324  * description  :  open db and register busy handler
325  */
326 INTERNAL_FUNC int em_db_open(sqlite3 **sqlite_handle, int *err_code);
327
328 /*
329  * emstorage_db_open
330  *
331  * description :  open db and set global variable sqlite_emmb 
332  * arguments : 
333  * return  : 
334  */
335 INTERNAL_FUNC sqlite3* emstorage_db_open(int *err_code);
336
337 /*
338  * emstorage_db_close
339  *
340  * description :  close db with global variable sqlite_emmb
341  * arguments : 
342  * return  : 
343  */
344 INTERNAL_FUNC int emstorage_db_close(int *err_code);
345
346 /*
347  * emstorage_open
348  *
349  * description :  initialize storage manager
350  * arguments : 
351  * return  : 
352  */
353 INTERNAL_FUNC int emstorage_open(int *err_code);
354
355 /*
356  * emstorage_close
357  *
358  * description :  cleanup storage manager
359  * arguments : 
360  * return  : 
361  */
362 INTERNAL_FUNC int emstorage_close(int *err_code);
363
364 /*
365  * emstorage_create_table
366  *
367  * description :  create account/address table in database.
368  * arguments : 
369  * return  : 
370  */
371 INTERNAL_FUNC int emstorage_create_table(emstorage_create_db_type_t type, int *err_code);
372
373
374 /**
375  * Check whether there is the same account information in the db
376  *
377  * @param[in] account   account that 
378  * @param[in] transaction       If the argument is true, engine commits transaction or executes rollback.
379  * @param[out] err_code Error code.
380  * @remarks N/A
381  * @return This function returns true if there is no duplicated account. returns false and set error code if there are duplicated accounts or error 
382  */
383 INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t *account, int transaction, int *err_code);
384
385
386 /**
387  * Get number of accounts from account table.
388  *
389  * @param[out] count            The number of accounts is saved here.
390  * @param[in] transaction       If the argument is true, engine commits transaction or executes rollback.
391  * @remarks N/A
392  * @return This function returns 0 on success or error code on failure.
393  */
394 INTERNAL_FUNC int emstorage_get_account_count(int *count, int transaction, int *err_code);
395
396 /**
397  * Get account from account table.
398  *
399  * @param[in, out] select_num   Upon entry, the argument contains the number of accounts to select.
400                                     Upon exit, it is set to the number of accounts to been selected.
401  * @param[out] account_list             The selected accounts is saved here. this pointer must be freed after being used.
402  * @param[in] transaction               If the argument is true, engine commits transaction or executes rollback.
403  * @remarks N/A
404  * @return This function returns 0 on success or error code on failure.
405  */
406 INTERNAL_FUNC int emstorage_get_account_list(int *select_num, emstorage_account_tbl_t **account_list, int transaction, int with_password, int *err_code);
407
408 /*
409  * emstorage_get_account_by_name
410  *
411  * description :  get account from account table by account name
412  * arguments : 
413  *    db  :  database pointer
414  *    account_id  :  account id
415  *    pulloption  :  option to specify fetching full or partial data
416  *    account  :  buffer to hold selected account
417  *              this buffer must be free after it has been used.
418  * return  : 
419  */
420 /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */
421
422 INTERNAL_FUNC int emstorage_get_account_by_id(int account_id, int pulloption, emstorage_account_tbl_t **account, int transaction, int *err_code);
423
424
425 /*
426  * emstorage_get_password_length_of_account
427  *
428  * description: get password length of account.
429  * arguments:
430  *    account_id : account id
431  *    password_length : password length
432  * return :
433  */
434
435 INTERNAL_FUNC int emstorage_get_password_length_of_account(int account_id, int *password_length, int* err_code);
436
437 /*
438  * emstorage_update_account
439  *
440  * description :  change a account from account table
441  * arguments : 
442  *    account_id  :  account id
443  *    account  :  buffer to hold selected account
444  * return  : 
445  */
446 INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl_t *account, int transaction, int *err_code);
447
448
449 INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account_id, char *field_name, int value, int transaction);
450
451 /*
452  * emstorage_get_sync_status_of_account
453  *
454  * description :  get a sync status field from account table
455  * arguments : 
456  *    account_id  :  account id
457  *    result_sync_status : sync status value
458  * return  : 
459  */
460
461 INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *result_sync_status,int *err_code);
462
463 /*
464  * emstorage_update_sync_status_of_account
465  *
466  * description :  update a sync status field from account table
467  * arguments : 
468  *    account_id  :  account id
469  *    set_operator  :  set operater. refer email_set_type_t
470  *    sync_status : sync status value
471  * return  : 
472  */
473
474 INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_set_type_t set_operator, int sync_status, int transaction, int *err_code);
475
476 /*
477  * emstorage_add_account
478  *
479  * description :  add a account to account table
480  * arguments : 
481  * return  : 
482  */
483 INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t *account, int transaction, int *err_code);
484
485 /*
486  * emstorage_delete_account
487  *
488  * description :  delete a account from account table
489  * arguments : 
490  *    db  :  database pointer
491  *    account_id  :  account id to be deteted
492  * return  : 
493  */
494 INTERNAL_FUNC int emstorage_delete_account(int account_id, int transaction, int *err_code);
495
496 /*
497  * emstorage_free_account
498  *
499  * description :  free local accout memory
500  * arguments : 
501  *    account_list  :  double pointer
502  *    count  :  count of local account
503  * return  : 
504  */
505 INTERNAL_FUNC int emstorage_free_account(emstorage_account_tbl_t **account_list, int count, int *err_code);
506
507
508 /************** Mailbox(Local box And Imap mailbox) Management ******************/
509
510 /*
511  * emstorage_get_mailbox_count
512  *
513  * description :  get number of mailbox from local mailbox table
514  * arguments : 
515  *    db  :  database pointer
516  *    count  :  number of accounts
517  * return  : 
518  */
519 INTERNAL_FUNC int emstorage_get_mailbox_count(int account_id, int local_yn, int *count, int transaction, int *err_code);
520
521 /*
522  * emstorage_get_mailbox
523  *
524  * description :  get local mailbox from local mailbox table
525  * arguments : 
526  *    db  :  database pointer
527  *    sort_type          :      in - sorting type.
528  *    select_num         :      in - number of selected account
529  *                              out - number to been selected
530  *    mailbox_list       :      buffer to hold selected account
531  *                      this buffer must be free after it has been used.
532  * return  : 
533  */
534 INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emstorage_mailbox_tbl_t **mailbox_list,  int transaction, int *err_code);
535
536 /*
537  * emstorage_get_child_mailbox_list
538  *
539  * description :  get child mailbox list  from given  mailbox 
540  * arguments : 
541  *    account_id  :  in - account id
542  *    parent_mailbox_name  :  in - parent_mailbox_name to fetch child list
543  *    local_yn - in - local mailbox or not
544  *    select_num - out   :  count of mailboxes
545  *    mailbox_list - out  :    list of mailboxes        
546  *    err_code - out  :  error code, if any
547  */
548
549
550 INTERNAL_FUNC int emstorage_get_child_mailbox_list(int account_id, char *parent_mailbox_name, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
551
552 /*
553  * emstorage_get_mailbox_by_name
554  *
555  * description :  get local mailbox from local mailbox table by mailbox name
556  * arguments : 
557  *    db  :  database pointer
558  *    mailbox_name  :  mailbox name
559  *    mailbox  :  buffer to hold selected local mailbox
560  *              this buffer must be free after it has been used.
561  * return  : 
562  */
563 INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t **mailbox, int transaction, int *err_code);
564 INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, emstorage_mailbox_tbl_t **mailbox, int transaction, int *err_code);
565 INTERNAL_FUNC int emstorage_get_mailbox_by_id(int input_mailbox_id, emstorage_mailbox_tbl_t** output_mailbox);
566 INTERNAL_FUNC int emstorage_get_mailbox_list_ex(int account_id, int local_yn, int with_count, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
567 INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, int *mailbox_id, int transaction, int *err_code);
568 INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, char **mailbox_name, int transaction, int *err_code);
569 INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(int account_id, int local_yn, char *mailbox_name, int modifiable_yn, int transaction, int *err_code);
570 INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input_mailbox_id, int total_count_on_server, int transaction, int *err_code);
571
572
573 /*
574  * emstorage_update_mailbox
575  *
576  * description :  change a account from account table
577  * arguments : 
578  *    db  :  database pointer
579  *    mailbox_name  :  mailbox name
580  *    mailbox  :  buffer to hold selected local mailbox
581  * return  : 
582  */
583 INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int input_mailbox_id, emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code);
584
585 /*
586  * emstorage_update_mailbox_type
587  *
588  * description :  change a mailbox from mailbox tbl
589  * arguments : 
590  * return  : 
591  */
592 INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, char *mailbox_name, email_mailbox_type_e new_mailbox_type, int transaction, int *err_code);
593
594 /*
595  * emstorage_set_local_mailbox
596  *
597  * description :  change 'local' field on mailbox table.
598  * arguments :
599  * return  :
600  */
601 INTERNAL_FUNC int emstorage_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox, int transaction);
602
603 INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, char *input_field_name, int input_value, int transaction);
604
605 /*
606  * emstorage_add_mailbox
607  *
608  * description :  add a local mailbox to local mailbox table
609  * arguments : 
610  * return  : 
611  */
612 INTERNAL_FUNC int emstorage_add_mailbox(emstorage_mailbox_tbl_t *mailbox, int transaction, int *err_code);
613
614 /*
615  * emstorage_delete_mailbox
616  *
617  * description :  delete a local mailbox from local mailbox table
618  * arguments : 
619  *    db  :  database pointer
620  *    mailbox_name  :  mailbox name of record to be deteted
621  * return  : 
622  */
623 INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int input_mailbox_id, int transaction, int *err_code);
624
625 INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new_mailbox_path, char *input_new_mailbox_alias, int input_transaction);
626 INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int input_mailbox_id, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code);
627 INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int transaction, int *err_code);
628
629 INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(int account_id, int modifiable_yn, int transaction, int *err_code);
630 INTERNAL_FUNC int emstorage_get_mailbox_by_modifiable_yn(int account_id, int modifiable_yn, int *select_num, emstorage_mailbox_tbl_t **mailbox_list, int transaction, int *err_code);
631 INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(int input_mailbox_id, int input_transaction);
632
633 /*
634  * emstorage_free_mailbox
635  *
636  * description :  free local mailbox memory
637  * arguments : 
638  *    mailbox_list  :  double pointer
639  *    count  :  count of local mailbox
640  * return  : 
641  */
642 INTERNAL_FUNC int emstorage_free_mailbox(emstorage_mailbox_tbl_t **mailbox_list, int count, int *err_code);
643
644
645 /************** Read Mail UID Management ******************/
646
647
648
649 INTERNAL_FUNC int emstorage_get_count_read_mail_uid(int account_id, char *mailbox_name, int *count, int transaction, int *err_code);
650
651
652 /*
653  * emstorage_check_read_mail_uid
654  *
655  * description :  check that this uid exists in uid table
656  * arguments : 
657  *    db  :  database pointer
658  *    mailbox_name  :  mailbox name
659  *    s_uid  :  uid string to be checked
660  *    exist  :  variable to hold checking result. (0 : not exist, 1 : exist)
661  * return  : 
662  */
663 INTERNAL_FUNC int emstorage_check_read_mail_uid(int account_id, char *mailbox_name, char *uid, int *exist, int transaction, int *err_code);
664
665 /*
666  * emstorage_get_read_mail_size
667  *
668  * description :  get mail size from read mail uid
669  * arguments : 
670  *    db  :  database pointer
671  *    mailbox_id  :  local mailbox id
672  *    local_uid  :  mail uid of local mailbox
673  *    mailbox_name  :  server mailbox name
674  *    uid  :  mail uid string of server mail
675  *    read_mail_uid  :  variable to hold read mail uid information
676  * return  : 
677  */
678 INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, emstorage_read_mail_uid_tbl_t **read_mail_uid, int *count, int transaction, int *err_code);
679
680 INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
681
682 /*
683  * emstorage_get_read_mail_size
684  *
685  * description :  get mail size from read mail uid
686  * arguments : 
687  *    db  :  database pointer
688  *    mailbox_name  :  mailbox name
689  *    s_uid  :  mail uid string
690  *    size  :  variable to hold mail size
691  * return  : 
692  */
693 INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code);
694
695 /*
696  * emstorage_add_downloaded_mail
697  *
698  * description :  add read mail uid
699  * arguments : 
700  * return  : 
701  */
702 INTERNAL_FUNC int emstorage_add_downloaded_mail(emstorage_read_mail_uid_tbl_t *read_mail_uid, int transaction, int *err_code);
703
704 /*
705  * emstorage_change_read_mail_uid
706  *
707  * description :  modify read mail uid
708  * arguments : 
709  * return  : 
710  */
711 INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int local_mailbox_id, int local_uid, char *mailbox_name, char *uid,
712                                      emstorage_read_mail_uid_tbl_t *read_mail_uid, int transaction, int *err_code);
713
714 /*
715  * emstorage_remove_downloaded_mail
716  *
717  * description :  
718  * arguments : 
719  * return  : 
720  */
721 INTERNAL_FUNC int emstorage_remove_downloaded_mail(int account_id, char *mailbox_name, char *uid, int transaction, int *err_code);
722
723
724 INTERNAL_FUNC int emstorage_update_read_mail_uid(int mail_id, char *new_server_uid, char *mbox_name, int *err_code);
725
726 /*
727  *  free memroy
728  */
729 INTERNAL_FUNC int emstorage_free_read_mail_uid(emstorage_read_mail_uid_tbl_t **read_mail_uid, int count, int *err_code);
730
731
732
733 /************** Rules(Filtering) Management ******************/
734
735 /*
736  * emstorage_get_rule_count
737  *
738  * description :  get number of rules from rule table
739  * arguments : 
740  *    db  :  database pointer
741  *    count  :  number of accounts
742  * return  : 
743  */
744 INTERNAL_FUNC int emstorage_get_rule_count(int account_id, int *count, int transaction, int *err_code);
745
746 /*
747  * emstorage_get_rule
748  *
749  * description :  get rules from rule table
750  * arguments : 
751  *    db  :  database pointer
752  *    start_idx  :  the first index to be selected (min : 0)
753  *    select_num  :  in - number of selected account
754  *                 out - number to been selected
755  *    is_completed  :  is completed ? 
756  * return  : 
757  */
758 INTERNAL_FUNC int emstorage_get_rule(int account_id, int type, int start_idx, int *select_num, int *is_completed, emstorage_rule_tbl_t **rule_list, int transaction, int *err_code);
759
760 /*
761  * emstorage_get_rule
762  *
763  * description :  get rules from rule table
764  * arguments : 
765  * return  : 
766  */
767 INTERNAL_FUNC int emstorage_get_rule_by_id(int account_id, int rule_id, emstorage_rule_tbl_t **rule, int transaction, int *err_code);
768
769 /*
770  * emstorage_change_rule
771  *
772  * description :  change a account from account table
773  * arguments : 
774  *    db  :  database pointer
775  *    mailbox_name  :  mailbox name
776  *    rule  :  buffer to hold selected rule
777  * return  : 
778  */
779 INTERNAL_FUNC int emstorage_change_rule(int account_id, int rule_id, emstorage_rule_tbl_t *rule, int transaction, int *err_code);
780
781 /*
782  * emstorage_find_rule
783  *
784  * description :  find a rule already exists
785  * arguments : 
786  * return  : 
787  */
788 INTERNAL_FUNC int emstorage_find_rule(emstorage_rule_tbl_t *rule, int transaction, int *err_code);
789
790 /*
791  * emstorage_add_rule
792  *
793  * description :  add a rule to rule table
794  * arguments : 
795  * return  : 
796  */
797 INTERNAL_FUNC int emstorage_add_rule(emstorage_rule_tbl_t *rule, int transaction, int *err_code);
798
799 /*
800  * emstorage_delete_rule
801  *
802  * description :  delete a rule from rule table
803  * arguments : 
804  *    db  :  database pointer
805  *    rule  :  rule to be deteted
806  * return  : 
807  */
808 INTERNAL_FUNC int emstorage_delete_rule(int account_id, int rule_id, int transaction, int *err_code);
809
810 /*
811  * emstorage_free_rule
812  *
813  * description :  free rule memory
814  * arguments : 
815  *    count  :  count of rule
816  * return  : 
817  */
818 INTERNAL_FUNC int emstorage_free_rule(emstorage_rule_tbl_t **rule_list, int count, int *err_code);
819
820
821 /************** Mail Management ******************/
822
823 /*
824  * emstorage_get_mail_count
825  *
826  * description :  get mail total and unseen count from mail table
827  * arguments : 
828  *    total  :  total count
829  *    unseen  :  unseen mail count
830  * return  : 
831  */
832 INTERNAL_FUNC int emstorage_get_mail_count(int account_id, const char *mailbox, int *total, int *unseen, int transaction, int *err_code);
833
834 /*
835  * emstorage_get_mail_by_id
836  *
837  * description :  get mail from mail table by mail id
838  * arguments : 
839  *    mail_id  :  mail id
840  *    mail  :  double pointer to hold mail
841  * return  : 
842  */
843 INTERNAL_FUNC int emstorage_get_mail_by_id(int mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
844
845 /*
846  * emstorage_get_mail
847  *
848  * description :  get mail from mail table by mail sequence
849  * arguments : 
850  *    account_id  :  account id
851  *    mailbox  :  mailbox name
852  *    mail_no  :  mail sequence number (not mail id)
853  *    mail  :  double pointer to hold mail
854  * return  : 
855  */
856 INTERNAL_FUNC int emstorage_get_mail_field_by_id(int mail_id, int type, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
857
858 /*
859  * emstorage_get_mail_field_by_multiple_mail_id
860  *
861  * description :  
862  * arguments : 
863  *    mail_ids  : 
864  *    number_of_mails  :  
865  *    type  :  
866  *    mail  :  
867  *    transaction :
868  *    err_code :
869  * return  : 
870  */
871 INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], int number_of_mails, int type, emstorage_mail_tbl_t** mail, int transaction, int *err_code);
872
873 /*
874  * emstorage_query_mail_count
875  *
876  * description :  query mail count
877  */
878 INTERNAL_FUNC int emstorage_query_mail_count(const char *input_conditional_clause, int input_transaction, int *output_total_mail_count, int *output_unseen_mail_count);
879
880 /*
881  * emstorage_query_mail_list
882  *
883  * description :  query mail id list
884  */
885 INTERNAL_FUNC int emstorage_query_mail_id_list(const char *input_conditional_clause, int input_transaction, int **output_mail_id_list, int *output_mail_id_count);
886
887 /*
888  * emstorage_query_mail_list
889  *
890  * description :  query mail list information
891  */
892 INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int transaction, email_mail_list_item_t** result_mail_list,  int *result_count,  int *err_code);
893
894 /*
895  * emstorage_query_mail_tbl
896  *
897  * description :  query mail table information
898  */
899 INTERNAL_FUNC int emstorage_query_mail_tbl(const char *conditional_clause, int transaction, emstorage_mail_tbl_t** result_mail_tbl, int *result_count, int *err_code);
900
901 /*
902  * emstorage_query_mailbox_tbl
903  *
904  * description :  query mail box table information
905  */
906
907 INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clause, const char *input_ordering_clause, int input_get_mail_count,  int input_transaction, emstorage_mailbox_tbl_t **output_mailbox_list, int *output_mailbox_count);
908
909 /*
910  * emstorage_get_mail_list
911  *
912  * description :  search mail list information
913  */
914
915 INTERNAL_FUNC int emstorage_get_mail_list(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list,  int *result_count,  int *err_code);
916 /*
917  * emstorage_get_mails
918  *
919  * description :  search mail list information
920  */
921 INTERNAL_FUNC int emstorage_get_mails(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, email_sort_type_t sorting,  int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code);
922 INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, int mailbox_id, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, email_sort_type_t sorting, int transaction, email_mail_list_item_t **mail_list,  int *result_count,  int *err_code);
923 INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(int account_id, char *server_mail_id, emstorage_mail_tbl_t **mail, int transaction, int *err_code);
924 INTERNAL_FUNC int emstorage_get_latest_unread_mailid(int account_id, int *mail_id, int *err_code);
925
926
927 /**
928  * Prepare mail search.
929  *
930  * @param[in] search                    Specifies the searching condition.
931  * @param[in] account_id                Specifies the account id. if 0, all accounts.
932  * @param[in] mailbox                   Specifies the mailbox name. if NULL, all mailboxes.
933  * @param[in] sorting                   Specifies the sorting condition.
934  * @param[out] search_handle    the searching handle is saved here.
935  * @param[out] searched                 the result count is saved here.
936  * @remarks N/A
937  * @return This function returns 0 on success or error code on failure.
938  */
939 INTERNAL_FUNC int emstorage_mail_search_start(emstorage_search_filter_t *search, int account_id, char *mailbox, int sorting, int *search_handle, int *searched, int transaction, int *err_code);
940
941 /*
942  * emstorage_mail_search_result
943  *
944  * description :  retrieve mail as searching result
945  * arguments : 
946  *    search_handle  :  handle to been gotten from emstorage_mail_search_start
947  *    mail  :  double pointer to hold mail
948  * return  : 
949  */
950 INTERNAL_FUNC int emstorage_mail_search_result(int search_handle, emstorage_mail_field_type_t type, void **data, int transaction, int *err_code);
951
952 /*
953  * emstorage_mail_search_end
954  *
955  * description :  finish searching
956  * arguments : 
957  *    search_handle  :  handle to be finished
958  * return  : 
959  */
960 INTERNAL_FUNC int emstorage_mail_search_end(int search_handle, int transaction, int *err_code);
961
962
963
964 /*
965  * emstorage_set_field_of_mails_with_integer_value
966  *
967  * description       :  update a filed of mail
968  * arguments : 
969  *    account_id                 :  Specifies the account id. 
970  *    mail_ids       :  mail id list to be changed
971  *    mail_ids_count :  count of mail list
972  *    field_name     :  specified field name
973  *    value          :  specified value
974  * return       : 
975  */
976 INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id, int mail_ids[], int mail_ids_count, char *field_name, int value, int transaction, int *err_code);
977
978 /*
979  * emstorage_change_mail_field
980  *
981  * description :  update partial mail data
982  * arguments : 
983  *    mail_id  :  mail id
984  *    type  :  changing type
985  *    mail  :  mail pointer
986  * return  : 
987  */
988 INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_type_t type, emstorage_mail_tbl_t *mail, int transaction, int *err_code);
989
990 /*
991  * emstorage_increase_mail_id
992  *
993  * description :  increase unique mail id
994  * arguments : 
995  *    mail_id  :  pointer to store the unique id
996  * return  : 
997  */
998
999 /*
1000  * emstorage_change_mail
1001  *
1002  * description :  update mail
1003  * arguments : 
1004  *    mail_id  :  mail id to be changed
1005  *    mail  :  mail pointer
1006  * return  : 
1007  */
1008 INTERNAL_FUNC int emstorage_change_mail(int mail_id, emstorage_mail_tbl_t *mail, int transaction, int *err_code);
1009 INTERNAL_FUNC int emstorage_clean_save_status(int save_status, int  *err_code);
1010 INTERNAL_FUNC int emstorage_update_server_uid(char *old_server_uid, char *new_server_uid, int *err_code);
1011 INTERNAL_FUNC int emstorage_modify_mailbox_of_mails(char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code);
1012
1013 INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int *err_code);
1014
1015 /*
1016  * emstorage_add_mail
1017  *
1018  * description :  add a mail to mail table
1019  * arguments : 
1020  *    mail  :  mail pointer to be inserted
1021  *   get_id :  must get uinque id in function
1022  * return  : 
1023  */
1024 INTERNAL_FUNC int emstorage_add_mail(emstorage_mail_tbl_t *mail, int get_id, int transaction, int *err_code);
1025
1026 /*
1027  * emstorage_move_multiple_mails_on_db
1028  *
1029  * description :
1030  * arguments : 
1031  *    account_id  :  
1032  *   input_mailbox_id :
1033  *   mail_ids :
1034  *   number_of_mails :
1035  *   transaction :
1036  *   err_code :
1037  * return  : 
1038  */
1039 INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(int account_id, int input_mailbox_id, int mail_ids[], int number_of_mails, int transaction, int *err_code);
1040
1041 /*
1042  * emstorage_delete_mail
1043  *
1044  * description :  delete mail from mail table
1045  * arguments : 
1046  *    mail_id  :  mail id to be deleted. if 0, all mail will be deleted.
1047  *    from_server  :  delete mail on server.
1048  * return  : 
1049  */
1050 INTERNAL_FUNC int emstorage_delete_mail(int mail_id, int from_server, int transaction, int *err_code);
1051
1052 /*
1053  * emstorage_delete_mail_by_account
1054  *
1055  * description :  delete mail from mail table by account id
1056  * arguments : 
1057  *    account_id  :  account id.
1058  * return  : 
1059  */
1060 INTERNAL_FUNC int emstorage_delete_mail_by_account(int account_id, int transaction, int *err_code);
1061
1062 /*
1063  * emstorage_delete_mail
1064  *
1065  * description :  delete mail from mail table
1066  * arguments : 
1067  *    account_id  :  account id.
1068  *    mailbox  :  mail box
1069  * return  : 
1070  */
1071 INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(int account_id, char *mailbox, int transaction, int *err_code);
1072
1073 /*
1074  * emstorage_delete_multiple_mails
1075  *
1076  * description :  
1077  * arguments : 
1078  *    mail_ids  :
1079  *    number_of_mails  :
1080  *    transaction  :
1081  *    err_code  :
1082  * return  : 
1083  */
1084 INTERNAL_FUNC int emstorage_delete_multiple_mails(int mail_ids[], int number_of_mails, int transaction, int *err_code);
1085
1086 /*
1087  * emstorage_free_mail
1088  *
1089  * description :  free memory
1090  * arguments : 
1091  *    mail_list  :  mail array
1092  *    count  :  the number of array element
1093  * return  : 
1094  */
1095 INTERNAL_FUNC int emstorage_free_mail(emstorage_mail_tbl_t **mail_list, int count, int *err_code);
1096
1097 /*
1098  * emstorage_get_attachment
1099  *
1100  * description :  get attachment from attachment table
1101  * arguments : 
1102  *    mail_id  :  mail id
1103  *    no  :  attachment sequence
1104  *    attachment  :  double pointer to hold attachment data
1105  * return  : 
1106  */
1107 INTERNAL_FUNC int emstorage_get_attachment_count(int mail_id, int *count, int transaction, int *err_code);
1108
1109 /*
1110  * emstorage_get_attachment_list
1111  *
1112  * description :  get attachment list from attachment table
1113  * arguments : 
1114  *    input_mail_id           : mail id
1115  *    input_transaction       : transaction option
1116  *    attachment_list         : result attachment list
1117  *    output_attachment_count : result attachment count
1118  * return  : This function returns EMAIL_ERROR_NONE on success or error code (refer to EMAIL_ERROR__XXX) on failure.
1119  *    
1120  */
1121 INTERNAL_FUNC int emstorage_get_attachment_list(int input_mail_id, int input_transaction, emstorage_attachment_tbl_t** output_attachment_list, int *output_attachment_count);
1122
1123
1124 /*
1125  * emstorage_get_attachment
1126  *
1127  * description :  get attachment from attachment table
1128  * arguments : 
1129  *    attachment_id  :  attachment id
1130  *    attachment  :  double pointer to hold attachment data
1131  * return  : 
1132  */
1133 INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code);
1134
1135 /*
1136  * emstorage_get_attachment
1137  *
1138  * description :  get nth-attachment from attachment table
1139  * arguments : 
1140  *    mail_id  :  mail id
1141  *    nth  :  index of the desired attachment (min : 1)
1142  *    attachment  :  double pointer to hold attachment data
1143  * return  : 
1144  */
1145 INTERNAL_FUNC int emstorage_get_attachment_nth(int mail_id, int nth, emstorage_attachment_tbl_t **attachment, int transaction, int *err_code);
1146
1147 /*
1148  * emstorage_change_attachment_field
1149  *
1150  * description :  update partial mail attachment data
1151  * arguments : 
1152  *    mail_id  :  mail id
1153  *    type  :  changing type
1154  *    mail  :  mail pointer
1155  * return  : 
1156  */
1157 INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_change_type_t type, emstorage_attachment_tbl_t *attachment, int transaction, int *err_code);
1158
1159 /* Get new attachment id */
1160 /*
1161  * emstorage_get_new_attachment_no
1162  *
1163  * description :  Get new attachment id
1164  * arguments : 
1165  *    attachment_no  :  attachment id pointer
1166  * return  : 
1167  */
1168
1169 INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_code);
1170
1171 /* insert attachment to mail attachment table */
1172 /*
1173  * emstorage_add_attachment
1174  *
1175  * description :  insert a attachment to attachment table
1176  * arguments : 
1177  *    attachment  :  attachment pointer
1178  * return  : 
1179  */
1180 INTERNAL_FUNC int emstorage_add_attachment(emstorage_attachment_tbl_t *attachment, int iscopy, int transaction, int *err_code);
1181
1182
1183 INTERNAL_FUNC int emstorage_update_attachment(emstorage_attachment_tbl_t *attachment, int transaction, int *err_code);
1184
1185 /* delete a mail from mail table */
1186 /*
1187  * emstorage_delete_attachment_on_db
1188  *
1189  * description :  delete attachment from attachment table
1190  * arguments : 
1191  *    attachment_id  :  attachment id
1192  * return  : 
1193  */
1194 INTERNAL_FUNC int emstorage_delete_attachment_on_db(int attachment_id, int transaction, int *err_code);
1195
1196 INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int transaction, int *err_code);
1197
1198 /*
1199  * emstorage_delete_attachment_all_on_db
1200  *
1201  * description :  delete attachment from mail table
1202  * arguments : 
1203  *    account_id  :  account id.
1204  *    mailbox  :  mail box
1205  * return  : 
1206  */
1207 INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *mailbox, int transaction, int *err_code);
1208
1209 /*
1210  * emstorage_free_attachment
1211  *
1212  * description :  free memory
1213  * arguments : 
1214  *    mail_list  :  mail array
1215  *    count  :  the number of array element
1216  * return  : 
1217  */
1218 INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t **attachment_list, int count, int *err_code);
1219
1220 INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, email_mailbox_t *mailbox, int *result, int *err_code);
1221
1222 INTERNAL_FUNC int emstorage_get_max_mail_count();
1223
1224 INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_usage,  int transaction, int *err_code);
1225
1226
1227 /**
1228  * begin a transaction.
1229  *
1230  * @param[in] d1        Reserved.
1231  * @param[in] d2        Reserved.
1232  * @remarks emstorage_commit_transaction or emstorage_commit_transaction must be called after this function.
1233  * @return This function returns 0 on success or error code on failure.
1234  */
1235
1236 INTERNAL_FUNC int emstorage_begin_transaction(void *d1, void *d2, int *err_code);
1237
1238 /**
1239  * commit a transaction.
1240  *
1241  * @param[in] d1        Reserved.
1242  * @param[in] d2        Reserved.
1243  * @remarks N/A
1244  * @return This function returns 0 on success or error code on failure.
1245  */
1246 INTERNAL_FUNC int emstorage_commit_transaction(void *d1, void *d2, int *err_code);
1247
1248 /**
1249  * rollback db.
1250  *
1251  * @param[in] d1        Reserved.
1252  * @param[in] d2        Reserved.
1253  * @remarks N/A
1254  * @return This function returns 0 on success or error code on failure.
1255  */
1256 INTERNAL_FUNC int emstorage_rollback_transaction(void *d1, void *d2, int *err_code);
1257
1258 /**
1259  * clear mail data from db.
1260  *
1261  * @param[in]  transaction      
1262  * @param[out] err_code 
1263  * @remarks N/A
1264  * @return This function returns 0 on success or error code on failure.
1265  */
1266
1267 INTERNAL_FUNC int emstorage_clear_mail_data(int transaction, int *err_code);
1268
1269
1270 INTERNAL_FUNC char *emstorage_make_directory_path_from_file_path(char *file_name);
1271
1272 /*
1273  * emstorage_get_save_name
1274  *
1275  * description :  get file name for saving data
1276  * arguments : 
1277  *    account_id  :  account id
1278  *    mail_id  :  mail id
1279  *    atch_id  :  attachment id
1280  *    fname  :  file name
1281  *    name_buf  :  buffer to hold file name. (MAX : 512Bytes)
1282  * return  : 
1283  */
1284 INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code);
1285
1286 /*
1287  * emstorage_get_dele_name
1288  *
1289  * description :  get a name for deleting contents from file system.
1290  * arguments : 
1291  *    account_id  :  account id
1292  *    mail_id  :  mail id
1293  *    atch_id  :  attachment id
1294  *    fname  :  reserved
1295  *    name_buf  :  buffer to hold file name. (MAX : 512Bytes)
1296  * return  : 
1297  */
1298 INTERNAL_FUNC int emstorage_get_dele_name(int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code);
1299
1300 /*
1301  * emstorage_create_dir
1302  *
1303  * description :  create directory
1304  * arguments : 
1305  *    name_buf  :  buffer to hold file name. (MAX : 512Bytes)
1306  *    no  :  attachment no.
1307  * return  : 
1308  */
1309 INTERNAL_FUNC int emstorage_create_dir(int account_id, int mail_id, int atch_id, int *err_code);
1310
1311 /*
1312  * emstorage_copy_file
1313  *
1314  * description :  copy a attachment file
1315  * arguments : 
1316  *    src_file  :  source file
1317  *    dst_file  :  destination file
1318  * return  : 
1319  */
1320 INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_file, int *err_code);
1321
1322 /*
1323  * emstorage_move_file
1324  *
1325  * description :  move a file
1326  * arguments : 
1327  *    src_file  :  source file
1328  *    dst_file  :  destination file
1329  * return  : 
1330  */
1331 INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_status, int *err_code);
1332
1333 /*
1334  * emstorage_move_file
1335  *
1336  * description :  delete a file
1337  * arguments : 
1338  *    src_file  :  file to be deleted
1339  * return  : 
1340  */
1341 INTERNAL_FUNC int emstorage_delete_file(char *src_file, int *err_code);
1342
1343 /*
1344  * emstorage_delete_dir
1345  *
1346  * description :  delete a directory
1347  * arguments : 
1348  *    src_dir  :  directory to be deleted
1349  * return  : 
1350  */
1351 INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code);
1352
1353
1354
1355 INTERNAL_FUNC void emstorage_flush_db_cache();
1356 INTERNAL_FUNC int emstorage_test(int mail_id, int account_id, char *full_address_to, char *full_address_cc, char *full_address_bcc, int *err_code);
1357
1358 INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, email_sort_type_t sorting, email_sender_list_t** sender_list, int *sender_count,  int *err_code);
1359 INTERNAL_FUNC int emstorage_free_sender_list(email_sender_list_t **sender_list, int count);
1360
1361 /* Handling Thread mail */
1362 INTERNAL_FUNC int emstorage_get_thread_information(int thread_id, emstorage_mail_tbl_t **mail_table_data, int transaction, int *err_code);
1363 INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(emstorage_mail_tbl_t *mail_table_data, int *thread_id, int *result_latest_mail_id_in_thread, int *thread_item_count);
1364 INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(int mail_id, int *thread_id, int *err_code);
1365 INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread_id, int latest_mail_id, int thread_item_count, int transaction, int *err_code);
1366
1367 #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
1368
1369 #define BULK_PARTIAL_BODY_DOWNLOAD_COUNT 10
1370 enum
1371 {
1372         ACCOUNT_IDX_MAIL_PARTIAL_BODY_ACTIVITY_TBL = 0, 
1373         MAIL_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL, 
1374         SERVER_MAIL_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL, 
1375         ACTIVITY_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL, 
1376         ACTIVITY_TYPE_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL, 
1377         MAILBOX_ID_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL, 
1378         MAILBOX_NAME_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL,
1379 };
1380
1381
1382 INTERNAL_FUNC int   emstorage_get_pbd_activity_data(int account_id, int input_mailbox_id, email_event_partial_body_thd** event_start, int *count, int transaction, int *err_code);
1383 INTERNAL_FUNC int   emstorage_add_pbd_activity(email_event_partial_body_thd *local_activity, int *activity_id, int transaction, int *err_code);
1384 INTERNAL_FUNC int   emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_list, int *count, int transaction, int *err_code);
1385 INTERNAL_FUNC int   emstorage_get_pbd_account_list(int **account_list, int *count, int transaction, int *err_code);
1386 INTERNAL_FUNC int   emstorage_get_pbd_activity_count(int *activity_id_count, int transaction, int *err_code);
1387 INTERNAL_FUNC int   emstorage_delete_full_pbd_activity_data(int account_id, int transaction, int *err_code);
1388 INTERNAL_FUNC int   emstorage_delete_pbd_activity(int account_id, int mail_id, int activity_id, int transaction, int *err_code);
1389 INTERNAL_FUNC int   emstorage_get_mailbox_pbd_activity_count(int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code);
1390 INTERNAL_FUNC int   emstorage_update_pbd_activity(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code);
1391 INTERNAL_FUNC int   emstorage_create_file(char *buf, size_t file_size, char *dst_file, int *err_code);
1392
1393 #endif  
1394
1395 INTERNAL_FUNC int   emstorage_free_address_info_list(email_address_info_list_t **address_info_list);
1396
1397 INTERNAL_FUNC void  emstorage_create_dir_if_delete();
1398
1399 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
1400 INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code);
1401
1402 /**
1403  * @fn emstorage_get_id_set_from_mail_ids(int mail_ids[], int mail_id_count, email_id_set_t **server_uids, int *id_set_count, int *err_code);
1404  * Prepare an array of mail_id and corresponding server mail id.
1405  *
1406  *@author                                       h.gahlaut@samsung.com
1407  * @param[in] mail_ids                  Specifies the comma separated string of mail_ids. Maximaum size of string should be less than or equal to (QUERY_SIZE - 88)
1408  *                                                      where 88 is the length of fixed keywords including ending null character in the QUERY to be formed
1409  * @param[out] idset                    Returns the array of mail_id and corresponding server_mail_id sorted by server_mail_ids in ascending order
1410  * @param[out] id_set_count             Returns the no. of cells in idset array i.e. no. of sets of mail_ids and server_mail_ids
1411  * @param[out] err_code         Returns the error code.
1412  * @remarks                                     An Example of Query to be exexuted in this API : 
1413  *                                                      SELECT local_uid, s_uid from mail_read_mail_uid_tbl where local_uid in (12, 13, 56, 78);
1414  * @return This function returns true on success or false on failure.
1415  */
1416
1417 INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_set_t **idset, int *id_set_count, int *err_code);
1418
1419 #endif
1420
1421 /**
1422  * @fn emstorage_filter_mails_by_rule(int account_id, char dest_mailbox_name, email_rule_t *rule, int **filtered_mail_id_list, int *count_of_mails, int err_code)
1423  * Move mails by specified rule for spam filtering. 
1424  *
1425  * @author                                                              kyuho.jo@samsung.com
1426  * @param[in] account_id                                Account id of the mails and the mailboxes.
1427  * @param[in] dest_mailbox_name                 Mailbox name of spam mailbox.
1428  * @param[in] rule                                              Filtering rule.
1429  * @param[out] filtered_mail_id_list    Mail id list which are filtered by the rule.
1430  * @param[out] count_of_mails                   Count of mails which are filtered by the rule.
1431  * @param[out] err_code                                 Returns the error code.
1432
1433  * @remarks                                                                     
1434  * @return This function returns true on success or false on failure.
1435  */
1436 INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbox_id, emstorage_rule_tbl_t *rule, int **filtered_mail_id_list, int *count_of_mails, int *err_code);
1437
1438 INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbox_id, email_meeting_request_t *meeting_req, int transaction, int *err_code);
1439 INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_request_t **meeting_req, int transaction, int *err_code);
1440 INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t *meeting_req, int transaction, int *err_code);
1441 INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, int input_mailbox_id, int transaction, int *err_code);
1442 INTERNAL_FUNC void emstorage_free_meeting_request(email_meeting_request_t *meeting_req);
1443
1444 INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, char **output_conditional_clause);
1445 INTERNAL_FUNC int emstorage_free_list_filter(email_list_filter_t **input_filter_list, int input_filter_count);
1446
1447 #ifdef __FEATURE_LOCAL_ACTIVITY__
1448 /*
1449 *emstorage_get_next_activity_id
1450 *
1451 *description :  get an activity id for a new activity
1452 */
1453 INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code);
1454
1455  /*
1456  *emstorage_get_activity_id_list
1457  *description  :  get the list of activity ids
1458  *arguments  : 
1459  *return  : 
1460  *
1461  */
1462 INTERNAL_FUNC int emstorage_get_activity_id_list(int account_id, int **activity_id_list, int *activity_count, int lowest_activity_type, int highest_activity_type, int transaction, int*err_code);
1463  /*
1464  * emstorage_add_activity
1465  *
1466  * description :  add an activity to activity table
1467  * arguments : 
1468  * return  : 
1469  */
1470 INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t *local_activity, int transaction, int *err_code);
1471
1472 /**
1473   *     emstorage_get_activity - Get the Local activity from the Mail activity table
1474   *
1475   */
1476 INTERNAL_FUNC int emstorage_get_activity(int account_id, int activity_id, emstorage_activity_tbl_t **activity_list, int *select_num, int transaction, int *err_code);
1477
1478 /**
1479  * emstorage_delete_local_activity - Deletes the Local acitivity Generated based on activity_type
1480  * or based on server mail id
1481  *
1482  */
1483 INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t *local_activity, int transaction, int *err_code);
1484
1485 /**
1486  * emstorage_free_local_activity - Free the allocated Activity data
1487  * 
1488  *
1489  */
1490 INTERNAL_FUNC int emstorage_free_local_activity(emstorage_activity_tbl_t **local_activity_list, int count, int *err_code);
1491
1492 /**
1493  * emstorage_free_activity_id_list - Free the allocated Activity List data
1494  * 
1495  *
1496  */
1497 INTERNAL_FUNC int emstorage_free_activity_id_list(int *activity_id_list, int *error_code);
1498
1499 #endif
1500
1501 INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certificate, int transaction, int *err_code);
1502
1503 INTERNAL_FUNC int emstorage_free_certificate(emstorage_certificate_tbl_t **certificate_list, int count, int *err_code);
1504
1505 INTERNAL_FUNC int emstorage_get_certificate_list(int *select_num, emstorage_certificate_tbl_t **certificate_list, int transaction, int with_password, int *err_code);
1506
1507 INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code);
1508
1509 INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code);
1510
1511 INTERNAL_FUNC int emstorage_delete_certificate(int index, int transaction, int *err_code);
1512
1513 /* task begin */
1514 INTERNAL_FUNC int emstorage_add_task(email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int input_transaction, int *output_task_id);
1515
1516 INTERNAL_FUNC int emstorage_delete_task(int task_id, int transaction);
1517
1518 INTERNAL_FUNC int emstorage_update_task_status(int task_id, email_task_status_type_t task_status, int transaction);
1519
1520 INTERNAL_FUNC int emstorage_query_task(const char *input_conditional_clause, const char *input_ordering_clause, email_task_t **output_task_list, int *output_task_count);
1521 /* task end*/
1522
1523 #ifdef __cplusplus
1524 }
1525 #endif /* __cplusplus */
1526
1527 #endif /* __EMAIL_STORAGE_H__ */
1528 /* EOF */