Extending test-client-custom-summary to try e_book_client_get_contacts_uids()
[platform/upstream/evolution-data-server.git] / camel / camel-db.h
1 /* Srinivasa Ragavan - <sragavan@novell.com> - GPL v2 or later */
2
3 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
4 #error "Only <camel/camel.h> can be included directly."
5 #endif
6
7 #ifndef CAMEL_DB_H
8 #define CAMEL_DB_H
9
10 #include <sqlite3.h>
11 #include <glib.h>
12
13 /**
14  * CAMEL_DB_FILE:
15  *
16  * Since: 2.24
17  **/
18 #define CAMEL_DB_FILE "folders.db"
19
20 /* Hopefully no one will create a folder named EVO_IN_meM_hAnDlE */
21
22 /**
23  * CAMEL_DB_IN_MEMORY_TABLE:
24  *
25  * Since: 2.26
26  **/
27 #define CAMEL_DB_IN_MEMORY_TABLE "EVO_IN_meM_hAnDlE.temp"
28
29 /**
30  * CAMEL_DB_IN_MEMORY_DB:
31  *
32  * Since: 2.26
33  **/
34 #define CAMEL_DB_IN_MEMORY_DB "EVO_IN_meM_hAnDlE"
35
36 /**
37  * CAMEL_DB_IN_MEMORY_TABLE_LIMIT:
38  *
39  * Since: 2.26
40  **/
41 #define CAMEL_DB_IN_MEMORY_TABLE_LIMIT 100000
42
43 typedef struct _CamelDBPrivate CamelDBPrivate;
44
45 /**
46  * CamelDBCollate:
47  *
48  * Since: 2.24
49  **/
50 typedef gint (*CamelDBCollate)(gpointer, gint, gconstpointer, gint, gconstpointer );
51
52 /**
53  * CamelDB:
54  *
55  * Since: 2.24
56  **/
57 struct _CamelDB {
58         sqlite3 *db;
59         /* this lock has been replaced with a rw lock which sits inside priv. 
60          * This is currently unused. Keeping it, not to break the ABI */
61         GMutex *lock;
62         CamelDBPrivate *priv;
63 };
64
65 /**
66  * CAMEL_DB_FREE_CACHE_SIZE:
67  *
68  * Since: 2.24
69  **/
70 #define CAMEL_DB_FREE_CACHE_SIZE 2 * 1024 * 1024
71
72 /**
73  * CAMEL_DB_SLEEP_INTERVAL:
74  *
75  * Since: 2.24
76  **/
77 #define CAMEL_DB_SLEEP_INTERVAL 1*10*10
78
79 /**
80  * CAMEL_DB_RELEASE_SQLITE_MEMORY:
81  *
82  * Since: 2.24
83  **/
84 #define CAMEL_DB_RELEASE_SQLITE_MEMORY if(!g_getenv("CAMEL_SQLITE_FREE_CACHE")) sqlite3_release_memory(CAMEL_DB_FREE_CACHE_SIZE);
85
86 /**
87  * CAMEL_DB_USE_SHARED_CACHE:
88  *
89  * Since: 2.24
90  **/
91 #define CAMEL_DB_USE_SHARED_CACHE if(g_getenv("CAMEL_SQLITE_SHARED_CACHE")) sqlite3_enable_shared_cache(TRUE);
92
93 /**
94  * CamelMIRecord:
95  * @uid:
96  *      Message UID
97  * @flags:
98  *      Camel Message info flags
99  * @msg_type:
100  * @dirty:
101  * @read:
102  *      boolean read status
103  * @deleted:
104  *      boolean deleted status
105  * @replied:
106  *      boolean replied status
107  * @important:
108  *      boolean important status
109  * @junk:
110  *      boolean junk status
111  * @attachment:
112  *      boolean attachment status
113  * @size:
114  *      size of the mail
115  * @dsent:
116  *      date sent
117  * @dreceived:
118  *      date received
119  * @subject:
120  *      subject of the mail
121  * @from:
122  *      sender
123  * @to:
124  *      recipient
125  * @cc:
126  *      CC members
127  * @mlist:
128  *      message list headers
129  * @followup_flag:
130  *      followup flag / also can be queried to see for followup or not
131  * @followup_completed_on:
132  *      completed date, can be used to see if completed
133  * @followup_due_by:
134  *      to see the due by date
135  * @part:
136  *      part / references / thread id
137  * @labels:
138  *      labels of mails also called as userflags
139  * @usertags:
140  *      composite string of user tags
141  * @cinfo:
142  *      content info string - composite string
143  * @bdata:
144  *      provider specific data
145  * @bodystructure:
146  *
147  * The extensive DB format, supporting basic searching and sorting.
148  *
149  * Since: 2.24
150  **/
151 typedef struct _CamelMIRecord {
152         gchar *uid;
153         guint32 flags;
154         guint32 msg_type;
155         guint32 dirty;
156         gboolean read;
157         gboolean deleted;
158         gboolean replied;
159         gboolean important;
160         gboolean junk;
161         gboolean attachment;
162         guint32 size;
163         time_t dsent;
164         time_t dreceived;
165         gchar *subject;
166         gchar *from;
167         gchar *to;
168         gchar *cc;
169         gchar *mlist;
170         gchar *followup_flag;
171         gchar *followup_completed_on;
172         gchar *followup_due_by;
173         gchar *part;
174         gchar *labels;
175         gchar *usertags;
176         gchar *cinfo;
177         gchar *bdata;
178         gchar *bodystructure;
179 } CamelMIRecord;
180
181 /**
182  * CamelFIRecord:
183  *
184  * Since: 2.24
185  **/
186 typedef struct _CamelFIRecord {
187         gchar *folder_name;
188         guint32 version;
189         guint32 flags;
190         guint32 nextuid;
191         time_t time;
192         guint32 saved_count;
193         guint32 unread_count;
194         guint32 deleted_count;
195         guint32 junk_count;
196         guint32 visible_count;
197         guint32 jnd_count;  /* Junked not deleted */
198         gchar *bdata;
199 } CamelFIRecord;
200
201 typedef struct _CamelDB CamelDB;
202
203 /**
204  * CamelDBKnownColumnNames:
205  *
206  * Since: 3.4
207  **/
208 typedef enum {
209         CAMEL_DB_COLUMN_UNKNOWN = -1,
210         CAMEL_DB_COLUMN_ATTACHMENT,
211         CAMEL_DB_COLUMN_BDATA,
212         CAMEL_DB_COLUMN_BODYSTRUCTURE,
213         CAMEL_DB_COLUMN_CINFO,
214         CAMEL_DB_COLUMN_DELETED,
215         CAMEL_DB_COLUMN_DELETED_COUNT,
216         CAMEL_DB_COLUMN_DRECEIVED,
217         CAMEL_DB_COLUMN_DSENT,
218         CAMEL_DB_COLUMN_FLAGS,
219         CAMEL_DB_COLUMN_FOLDER_NAME,
220         CAMEL_DB_COLUMN_FOLLOWUP_COMPLETED_ON,
221         CAMEL_DB_COLUMN_FOLLOWUP_DUE_BY,
222         CAMEL_DB_COLUMN_FOLLOWUP_FLAG,
223         CAMEL_DB_COLUMN_IMPORTANT,
224         CAMEL_DB_COLUMN_JND_COUNT,
225         CAMEL_DB_COLUMN_JUNK,
226         CAMEL_DB_COLUMN_JUNK_COUNT,
227         CAMEL_DB_COLUMN_LABELS,
228         CAMEL_DB_COLUMN_MAIL_CC,
229         CAMEL_DB_COLUMN_MAIL_FROM,
230         CAMEL_DB_COLUMN_MAIL_TO,
231         CAMEL_DB_COLUMN_MLIST,
232         CAMEL_DB_COLUMN_NEXTUID,
233         CAMEL_DB_COLUMN_PART,
234         CAMEL_DB_COLUMN_PREVIEW,
235         CAMEL_DB_COLUMN_READ,
236         CAMEL_DB_COLUMN_REPLIED,
237         CAMEL_DB_COLUMN_SAVED_COUNT,
238         CAMEL_DB_COLUMN_SIZE,
239         CAMEL_DB_COLUMN_SUBJECT,
240         CAMEL_DB_COLUMN_TIME,
241         CAMEL_DB_COLUMN_UID,
242         CAMEL_DB_COLUMN_UNREAD_COUNT,
243         CAMEL_DB_COLUMN_USERTAGS,
244         CAMEL_DB_COLUMN_VERSION,
245         CAMEL_DB_COLUMN_VISIBLE_COUNT,
246         CAMEL_DB_COLUMN_VUID
247 } CamelDBKnownColumnNames;
248
249 CamelDBKnownColumnNames camel_db_get_column_ident (GHashTable **hash, gint index, gint ncols, gchar **col_names);
250
251 /**
252  * CamelDBSelectCB:
253  *
254  * Since: 2.24
255  **/
256 typedef gint (*CamelDBSelectCB) (gpointer data, gint ncol, gchar **colvalues, gchar **colnames);
257
258 CamelDB * camel_db_open (const gchar *path, GError **error);
259 CamelDB * camel_db_clone (CamelDB *cdb, GError **error);
260 void camel_db_close (CamelDB *cdb);
261 gint camel_db_command (CamelDB *cdb, const gchar *stmt, GError **error);
262
263 gint camel_db_transaction_command (CamelDB *cdb, GList *qry_list, GError **error);
264
265 gint camel_db_begin_transaction (CamelDB *cdb, GError **error);
266 gint camel_db_add_to_transaction (CamelDB *cdb, const gchar *query, GError **error);
267 gint camel_db_end_transaction (CamelDB *cdb, GError **error);
268 gint camel_db_abort_transaction (CamelDB *cdb, GError **error);
269 gint camel_db_clear_folder_summary (CamelDB *cdb, const gchar *folder, GError **error);
270 gint camel_db_rename_folder (CamelDB *cdb, const gchar *old_folder, const gchar *new_folder, GError **error);
271
272 gint camel_db_delete_folder (CamelDB *cdb, const gchar *folder, GError **error);
273 gint camel_db_delete_uid (CamelDB *cdb, const gchar *folder, const gchar *uid, GError **error);
274 /*int camel_db_delete_uids (CamelDB *cdb, GError **error, gint nargs, ... );*/
275 gint camel_db_delete_uids (CamelDB *cdb, const gchar * folder_name, GList *uids, GError **error);
276
277 gint camel_db_create_folders_table (CamelDB *cdb, GError **error);
278 gint camel_db_select (CamelDB *cdb, const gchar * stmt, CamelDBSelectCB callback, gpointer data, GError **error);
279
280 gint camel_db_write_folder_info_record (CamelDB *cdb, CamelFIRecord *record, GError **error);
281 gint camel_db_read_folder_info_record (CamelDB *cdb, const gchar *folder_name, CamelFIRecord *record, GError **error);
282
283 gint camel_db_prepare_message_info_table (CamelDB *cdb, const gchar *folder_name, GError **error);
284
285 gint camel_db_write_message_info_record (CamelDB *cdb, const gchar *folder_name, CamelMIRecord *record, GError **error);
286 gint camel_db_write_fresh_message_info_record (CamelDB *cdb, const gchar *folder_name, CamelMIRecord *record, GError **error);
287 gint camel_db_read_message_info_records (CamelDB *cdb, const gchar *folder_name, gpointer p, CamelDBSelectCB read_mir_callback, GError **error);
288 gint camel_db_read_message_info_record_with_uid (CamelDB *cdb, const gchar *folder_name, const gchar *uid, gpointer p, CamelDBSelectCB read_mir_callback, GError **error);
289
290 gint camel_db_count_junk_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError **error);
291 gint camel_db_count_unread_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError **error);
292 gint camel_db_count_deleted_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError **error);
293 gint camel_db_count_total_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError **error);
294
295 gint camel_db_count_visible_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError **error);
296 gint camel_db_count_visible_unread_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError **error);
297
298 gint camel_db_count_junk_not_deleted_message_info (CamelDB *cdb, const gchar *table_name, guint32 *count, GError **error);
299 gint camel_db_count_message_info (CamelDB *cdb, const gchar *query, guint32 *count, GError **error);
300 void camel_db_camel_mir_free (CamelMIRecord *record);
301
302 gint camel_db_get_folder_uids (CamelDB *db, const gchar *folder_name, const gchar *sort_by, const gchar *collate, GHashTable *hash, GError **error);
303
304 GPtrArray * camel_db_get_folder_junk_uids (CamelDB *db, gchar *folder_name, GError **error);
305 GPtrArray * camel_db_get_folder_deleted_uids (CamelDB *db, const gchar *folder_name, GError **error);
306
307 gchar * camel_db_sqlize_string (const gchar *string);
308 void camel_db_free_sqlized_string (gchar *string);
309
310 gchar * camel_db_get_column_name (const gchar *raw_name);
311 gint camel_db_set_collate (CamelDB *cdb, const gchar *col, const gchar *collate, CamelDBCollate func);
312
313 gint camel_db_start_in_memory_transactions (CamelDB *cdb, GError **error);
314 gint camel_db_flush_in_memory_transactions (CamelDB *cdb, const gchar * folder_name, GError **error);
315
316 GHashTable *
317 camel_db_get_folder_preview (CamelDB *db, const gchar *folder_name, GError **error);
318 gint camel_db_write_preview_record (CamelDB *db, const gchar *folder_name, const gchar *uid, const gchar *msg, GError **error);
319
320 gint
321 camel_db_reset_folder_version (CamelDB *cdb, const gchar *folder_name, gint reset_version, GError **error);
322
323 #endif