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