2009-11-25 21:55:06 +01:00
|
|
|
/*
|
2010-08-24 23:57:16 +02:00
|
|
|
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2009-11-25 21:55:06 +01:00
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify it
|
|
|
|
** under the terms of the GNU General Public License as published by the
|
|
|
|
** Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
** later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
#ifndef __MU_STORE_H__
|
|
|
|
#define __MU_STORE_H__
|
2009-11-25 21:55:06 +01:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <inttypes.h>
|
2010-12-01 20:57:36 +01:00
|
|
|
#include <mu-msg.h>
|
2011-01-04 22:19:03 +01:00
|
|
|
#include <mu-util.h> /* for MuResult, MuError */
|
2009-11-25 21:55:06 +01:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
struct _MuStore;
|
|
|
|
typedef struct _MuStore MuStore;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-01-12 22:13:03 +01:00
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
/**
|
2010-01-03 22:53:04 +01:00
|
|
|
* create a new Xapian store, a place to store documents
|
|
|
|
*
|
|
|
|
* @param path the path to the database
|
2011-03-01 23:13:24 +01:00
|
|
|
* @param ccachepath path where to cache the contacts information, or NULL
|
2011-01-02 17:05:43 +01:00
|
|
|
* @param err to receive error info or NULL. err->code can be found in
|
2010-11-24 19:04:20 +01:00
|
|
|
* mu-error.h
|
2010-01-03 22:53:04 +01:00
|
|
|
*
|
2010-08-25 20:55:08 +02:00
|
|
|
* @return a new MuStore object, or NULL in case of error
|
2010-01-03 22:53:04 +01:00
|
|
|
*/
|
2011-03-01 23:13:24 +01:00
|
|
|
MuStore* mu_store_new (const char *xpath, const char *ccachepath,
|
|
|
|
GError **err) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
2010-12-01 20:57:36 +01:00
|
|
|
|
2009-11-26 08:02:58 +01:00
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
/**
|
|
|
|
* destroy the MuStore object and free resources
|
2010-01-03 22:53:04 +01:00
|
|
|
*
|
|
|
|
* @param store a valid store, or NULL
|
|
|
|
*/
|
2010-11-20 13:43:04 +01:00
|
|
|
void mu_store_destroy (MuStore *store);
|
2010-01-03 22:53:04 +01:00
|
|
|
|
|
|
|
|
2011-01-15 12:27:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* set the Xapian batch size for this store. Normally, there's no need
|
|
|
|
* to use this function as the default is good enough; however, if you
|
|
|
|
* use mu in a very memory-constrained environment, you can set the
|
|
|
|
* batchsize to e.g. 1000 at the cost of significant slow-down.
|
|
|
|
*
|
|
|
|
* @param store a valid store object
|
|
|
|
* @param batchsize the new batch size; or 0 to reset to
|
|
|
|
* the default batch size
|
|
|
|
*/
|
|
|
|
void mu_store_set_batch_size (MuStore *store, guint batchsize);
|
|
|
|
|
|
|
|
|
2010-09-26 14:52:22 +02:00
|
|
|
/**
|
|
|
|
* get the numbers of documents in the database
|
|
|
|
*
|
|
|
|
* @param index a valid MuStore instance
|
|
|
|
*
|
|
|
|
* @return the number of documents in the database; 0 in case of error
|
|
|
|
* or an empty database
|
|
|
|
*/
|
|
|
|
unsigned mu_store_count (MuStore *store);
|
2010-01-23 19:50:06 +01:00
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
/**
|
2010-11-20 13:43:04 +01:00
|
|
|
* get a version string for the database; it's a const string, which
|
|
|
|
* is valid as long MuStore exists and mu_store_version is not called
|
|
|
|
* again.
|
2010-01-23 19:50:06 +01:00
|
|
|
*
|
2010-08-25 20:55:08 +02:00
|
|
|
* @param store a valid MuStore
|
2010-01-23 19:50:06 +01:00
|
|
|
*
|
2010-11-20 13:43:04 +01:00
|
|
|
* @return the version string or NULL in case of error
|
2010-01-23 19:50:06 +01:00
|
|
|
*/
|
2010-11-20 13:43:04 +01:00
|
|
|
const char* mu_store_version (MuStore *store);
|
2010-01-23 19:50:06 +01:00
|
|
|
|
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
/**
|
2010-01-06 00:20:30 +01:00
|
|
|
* try to flush/commit all outstanding work
|
|
|
|
*
|
|
|
|
* @param store a valid xapian store
|
|
|
|
*/
|
2010-08-25 20:55:08 +02:00
|
|
|
void mu_store_flush (MuStore *store);
|
2010-01-06 00:20:30 +01:00
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
/**
|
2010-01-03 22:53:04 +01:00
|
|
|
* store an email message in the XapianStore
|
|
|
|
*
|
|
|
|
* @param store a valid store
|
2011-04-30 10:31:34 +02:00
|
|
|
* @param msg a valid message
|
|
|
|
* @param replace whether or not we should try to replace the same
|
|
|
|
* message if it already exists; that is usually desirable, but when
|
|
|
|
* we're sure already that the document does not exist (e.g, in case
|
|
|
|
* of a initial fill or rebuild of the database), we can set 'replace'
|
|
|
|
* to FALSE for a couple% performance gain
|
2010-01-03 22:53:04 +01:00
|
|
|
*
|
|
|
|
* @return TRUE if it succeeded, FALSE otherwise
|
|
|
|
*/
|
2011-04-30 10:31:34 +02:00
|
|
|
MuResult mu_store_store (MuStore *store, MuMsg *msg, gboolean replace);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2010-01-04 21:49:24 +01:00
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
/**
|
2010-01-04 21:49:24 +01:00
|
|
|
* remove a message from the database
|
|
|
|
*
|
|
|
|
* @param store a valid store
|
|
|
|
* @param msgpath path of the message (note, this is only used to
|
|
|
|
* *identify* the message; a common use of this function is to remove
|
|
|
|
* a message from the database, for which there is no message anymore
|
|
|
|
* in the filesystem.
|
|
|
|
*
|
|
|
|
* @return TRUE if it succeeded, FALSE otherwise
|
|
|
|
*/
|
2011-01-15 12:27:41 +01:00
|
|
|
gboolean mu_store_remove (MuStore *store, const char* msgpath);
|
2010-01-04 21:49:24 +01:00
|
|
|
|
2010-01-11 19:46:14 +01:00
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
/**
|
2010-01-11 19:46:14 +01:00
|
|
|
* does a certain message exist in the database already?
|
|
|
|
*
|
|
|
|
* @param store a store
|
|
|
|
* @param path the message path
|
|
|
|
*
|
2011-01-15 12:27:41 +01:00
|
|
|
* @return TRUE if the message exists, FALSE otherwise
|
2010-01-11 19:46:14 +01:00
|
|
|
*/
|
2011-01-15 12:27:41 +01:00
|
|
|
gboolean mu_store_contains_message (MuStore *store, const char* path);
|
2010-01-11 19:46:14 +01:00
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
/**
|
2010-01-03 22:53:04 +01:00
|
|
|
* store a timestamp for a directory
|
|
|
|
*
|
|
|
|
* @param store a valid store
|
|
|
|
* @param msgpath path to a maildir
|
|
|
|
* @param stamp a timestamp
|
2011-01-12 22:13:03 +01:00
|
|
|
*
|
|
|
|
* @return TRUE if setting the timestamp succeeded, FALSE otherwise
|
2010-01-03 22:53:04 +01:00
|
|
|
*/
|
2011-01-12 22:13:03 +01:00
|
|
|
gboolean mu_store_set_timestamp (MuStore *store, const char* msgpath,
|
|
|
|
time_t stamp);
|
2010-01-03 22:53:04 +01:00
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
/**
|
2010-01-03 22:53:04 +01:00
|
|
|
* get the timestamp for a directory
|
|
|
|
*
|
|
|
|
* @param store a valid store
|
|
|
|
* @param msgpath path to a maildir
|
|
|
|
*
|
|
|
|
* @return the timestamp, or 0 in case of error
|
|
|
|
*/
|
2011-01-12 22:13:03 +01:00
|
|
|
time_t mu_store_get_timestamp (MuStore *store,
|
|
|
|
const char* msgpath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-03 22:53:04 +01:00
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
/**
|
2010-01-03 22:53:04 +01:00
|
|
|
* call a function for each document in the database
|
|
|
|
*
|
|
|
|
* @param self a valid store
|
|
|
|
* @param func a callback function to to call for each document
|
|
|
|
* @param user_data a user pointer passed to the callback function
|
|
|
|
*
|
|
|
|
* @return MU_OK if all went well, MU_STOP if the foreach was interrupted,
|
|
|
|
* MU_ERROR in case of error
|
|
|
|
*/
|
2010-08-25 20:55:08 +02:00
|
|
|
typedef MuResult (*MuStoreForeachFunc) (const char* path,
|
2010-01-03 22:53:04 +01:00
|
|
|
void *user_data);
|
2010-08-25 20:55:08 +02:00
|
|
|
MuResult mu_store_foreach (MuStore *self,
|
|
|
|
MuStoreForeachFunc func,
|
|
|
|
void *user_data);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-01-12 22:13:03 +01:00
|
|
|
/**
|
|
|
|
* set metadata for this MuStore
|
|
|
|
*
|
|
|
|
* @param store a store
|
|
|
|
* @param key metadata key
|
|
|
|
* @param val metadata value
|
|
|
|
*
|
|
|
|
* @return TRUE if succeeded, FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean mu_store_set_metadata (MuStore *store, const char *key, const char *val);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get metadata for this MuStore
|
|
|
|
*
|
|
|
|
* @param store a store
|
|
|
|
* @param key the metadata key
|
|
|
|
*
|
|
|
|
* @return the value of the metadata (gfree when done with it), or
|
|
|
|
* NULL in case of error
|
|
|
|
*/
|
|
|
|
char* mu_store_get_metadata (MuStore *store, const char *key)
|
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
|
|
|
|
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
G_END_DECLS
|
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
#endif /*__MU_STORE_H__*/
|