* minor / cosmetic changes

This commit is contained in:
Dirk-Jan C. Binnema
2011-09-12 20:38:40 +03:00
parent 1a7414dd6d
commit 628d154a2c
11 changed files with 245 additions and 206 deletions

View File

@ -272,7 +272,7 @@ AS_IF([test "x$PMCCABE" = "xno"],[
*** Please install it if you want to run the automated code checks]) *** Please install it if you want to run the automated code checks])
],[have_pmccabe="yes"]) ],[have_pmccabe="yes"])
#toys/procmule/Makefile
AC_CONFIG_FILES([ AC_CONFIG_FILES([
Makefile Makefile
@ -284,6 +284,7 @@ toys/Makefile
toys/mug/Makefile toys/mug/Makefile
toys/mug2/Makefile toys/mug2/Makefile
toys/muile/Makefile toys/muile/Makefile
toys/procmule/Makefile
man/Makefile man/Makefile
m4/Makefile m4/Makefile
contrib/Makefile contrib/Makefile

View File

@ -42,9 +42,7 @@ get_query (void)
if (!query) { if (!query) {
mu_guile_g_error ("<internal error>", err); mu_guile_g_error ("<internal error>", err);
if (err) g_clear_error (&err);
g_error_free (err);
return NULL;
} }
return query; return query;
@ -60,10 +58,9 @@ get_query_iter (MuQuery *query, const char* expr)
err = NULL; err = NULL;
iter = mu_query_run (query, expr, iter = mu_query_run (query, expr,
FALSE, MU_MSG_FIELD_ID_NONE, TRUE, &err); FALSE, MU_MSG_FIELD_ID_NONE, TRUE, &err);
if (err) { if (!iter) {
mu_guile_g_error ("<internal error>", err); mu_guile_g_error ("<internal error>", err);
g_error_free (err); g_clear_error (&err);
return NULL;
} }
return iter; return iter;
@ -80,6 +77,7 @@ call_func (SCM FUNC, MuMsgIter *iter, const char* func_name)
msgsmob = mu_guile_msg_to_scm (mu_msg_ref(msg)); msgsmob = mu_guile_msg_to_scm (mu_msg_ref(msg));
scm_call_1 (FUNC, msgsmob); scm_call_1 (FUNC, msgsmob);
} }

View File

@ -53,7 +53,7 @@ enum _MuConfigFormat {
/* for find */ /* for find */
MU_CONFIG_FORMAT_LINKS, /* output as symlinks */ MU_CONFIG_FORMAT_LINKS, /* output as symlinks */
MU_CONFIG_FORMAT_XML, /* output xml */ MU_CONFIG_FORMAT_XML, /* output xml */
MU_CONFIG_FORMAT_XQUERY, /* output the xapian query */ MU_CONFIG_FORMAT_XQUERY /* output the xapian query */
}; };
typedef enum _MuConfigFormat MuConfigFormat; typedef enum _MuConfigFormat MuConfigFormat;
@ -72,7 +72,7 @@ enum _MuConfigCmd {
MU_CONFIG_CMD_REMOVE, MU_CONFIG_CMD_REMOVE,
MU_CONFIG_CMD_SERVER, MU_CONFIG_CMD_SERVER,
MU_CONFIG_CMD_NONE, MU_CONFIG_CMD_NONE
}; };
typedef enum _MuConfigCmd MuConfigCmd; typedef enum _MuConfigCmd MuConfigCmd;

View File

@ -359,7 +359,11 @@ mu_container_sort (MuContainer *c, MuMsgFieldId mfid, gpointer user_data,
gboolean invert) gboolean invert)
{ {
SortFuncData sfdata = { mfid, invert, user_data }; SortFuncData sfdata;
sfdata.mfid = mfid;
sfdata.invert = invert;
sfdata.user_data = user_data;
g_return_val_if_fail (c, NULL); g_return_val_if_fail (c, NULL);
g_return_val_if_fail (mu_msg_field_id_is_valid(mfid), NULL); g_return_val_if_fail (mu_msg_field_id_is_valid(mfid), NULL);

View File

@ -137,23 +137,26 @@ insert_or_update_maybe (const char* fullpath, const char* mdir,
err = NULL; err = NULL;
msg = mu_msg_new_from_file (fullpath, mdir, &err); msg = mu_msg_new_from_file (fullpath, mdir, &err);
if ((G_UNLIKELY(!msg))) { if ((G_UNLIKELY(!msg)))
g_warning ("%s: failed to create mu_msg for %s", goto errexit;
__FUNCTION__, fullpath);
return MU_ERROR;
}
/* we got a valid id; scan the message contents as well */ /* we got a valid id; scan the message contents as well */
if (G_UNLIKELY((!mu_store_store_msg (data->_store, msg, TRUE)))) { if (G_UNLIKELY((!mu_store_add_msg (data->_store, msg, TRUE, &err))))
g_warning ("%s: storing content %s failed", __FUNCTION__, goto errexit;
fullpath);
return MU_ERROR;
}
mu_msg_unref (msg); mu_msg_unref (msg);
*updated = TRUE; *updated = TRUE;
return MU_OK; return MU_OK;
errexit:
{
MuError me;
me = err ? err->code : MU_ERROR;
g_clear_error (&err);
if (msg)
mu_msg_unref (msg);
return me;
}
} }
static MuError static MuError

View File

@ -235,7 +235,8 @@ log_write (const char* domain, GLogLevelFlags level,
/* get the time/date string */ /* get the time/date string */
now = time(NULL); now = time(NULL);
strftime (timebuf, sizeof(timebuf), "%F %T", localtime(&now)); strftime (timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S",
localtime(&now));
/* now put it all together */ /* now put it all together */
len = snprintf (buf, sizeof(buf), "%s [%s] %s\n", timebuf, len = snprintf (buf, sizeof(buf), "%s [%s] %s\n", timebuf,

View File

@ -102,7 +102,18 @@ mu_msg_part_foreach (MuMsg *msg, MuMsgPartForeachFunc func,
PartData pdata; PartData pdata;
g_return_if_fail (msg); g_return_if_fail (msg);
g_return_if_fail (msg->_file);
/* if we don't have a file yet, we need to open it now... */
if (!msg->_file) {
GError *err;
err = NULL;
msg->_file = mu_msg_file_new (mu_msg_get_path(msg), NULL,
&err);
if (!msg->_file) {
MU_HANDLE_G_ERROR(err); /* will free it */
return;
}
}
g_return_if_fail (GMIME_IS_OBJECT(msg->_file->_mime_msg)); g_return_if_fail (GMIME_IS_OBJECT(msg->_file->_mime_msg));
pdata._msg = msg; pdata._msg = msg;
@ -117,7 +128,7 @@ mu_msg_part_foreach (MuMsg *msg, MuMsgPartForeachFunc func,
static gboolean static gboolean
write_to_stream (GMimeObject *part, int fd) write_to_stream (GMimeObject *part, int fd, GError **err)
{ {
GMimeStream *stream; GMimeStream *stream;
GMimeDataWrapper *wrapper; GMimeDataWrapper *wrapper;
@ -125,14 +136,16 @@ write_to_stream (GMimeObject *part, int fd)
stream = g_mime_stream_fs_new (fd); stream = g_mime_stream_fs_new (fd);
if (!GMIME_IS_STREAM(stream)) { if (!GMIME_IS_STREAM(stream)) {
g_critical ("%s: failed to create stream",__FUNCTION__); g_set_error (err, 0, MU_ERROR_GMIME,
"failed to create stream");
return FALSE; return FALSE;
} }
g_mime_stream_fs_set_owner (GMIME_STREAM_FS(stream), FALSE); g_mime_stream_fs_set_owner (GMIME_STREAM_FS(stream), FALSE);
wrapper = g_mime_part_get_content_object (GMIME_PART(part)); wrapper = g_mime_part_get_content_object (GMIME_PART(part));
if (!GMIME_IS_DATA_WRAPPER(wrapper)) { if (!GMIME_IS_DATA_WRAPPER(wrapper)) {
g_critical ("%s: failed to create wrapper", __FUNCTION__); g_set_error (err, 0, MU_ERROR_GMIME,
"failed to create wrapper");
g_object_unref (stream); g_object_unref (stream);
return FALSE; return FALSE;
} }
@ -141,7 +154,8 @@ write_to_stream (GMimeObject *part, int fd)
rv = g_mime_data_wrapper_write_to_stream (wrapper, stream); rv = g_mime_data_wrapper_write_to_stream (wrapper, stream);
if (!rv) if (!rv)
g_critical ("%s: failed to write to stream", __FUNCTION__); g_set_error (err, 0, MU_ERROR_GMIME,
"failed to write to stream");
g_object_unref (wrapper); g_object_unref (wrapper);
g_object_unref (stream); g_object_unref (stream);
@ -171,15 +185,15 @@ save_part (GMimeObject *part, const char *fullpath,
return FALSE; return FALSE;
} }
rv = write_to_stream (part, fd); rv = write_to_stream (part, fd, err);
if (close (fd) != 0) { if (close (fd) != 0 && !err) { /* don't write on top of old err */
g_set_error (err, 0, MU_ERROR_FILE, g_set_error (err, 0, MU_ERROR_FILE,
"could not close '%s': %s", "could not close '%s': %s",
fullpath, errno ? strerror(errno) : "error"); fullpath, errno ? strerror(errno) : "error");
return FALSE; return FALSE;
} }
return TRUE; return rv;
} }

View File

@ -161,6 +161,8 @@ const char* mu_store_version (MuStore *store);
*/ */
void mu_store_flush (MuStore *store); void mu_store_flush (MuStore *store);
#define MU_STORE_INVALID_DOCID 0
/** /**
* store an email message in the XapianStore * store an email message in the XapianStore
* *
@ -172,10 +174,11 @@ void mu_store_flush (MuStore *store);
* of a initial fill or rebuild of the database), we can set 'replace' * of a initial fill or rebuild of the database), we can set 'replace'
* to FALSE for a couple% performance gain * to FALSE for a couple% performance gain
* *
* @return TRUE if it succeeded, FALSE otherwise * @return the docid of the stored message, or 0
* (MU_STORE_INVALID_DOCID) in case of error
*/ */
gboolean mu_store_store_msg (MuStore *store, MuMsg *msg, gboolean replace); unsigned mu_store_add_msg (MuStore *store, MuMsg *msg, gboolean replace,
GError **err);
/** /**
* store an email message in the XapianStore; similar to * store an email message in the XapianStore; similar to
@ -185,12 +188,13 @@ gboolean mu_store_store_msg (MuStore *store, MuMsg *msg, gboolean replace);
* @param store a valid store * @param store a valid store
* @param path full filesystem path to a valid message * @param path full filesystem path to a valid message
* *
* @return TRUE if it succeeded, FALSE otherwise * @return the docid of the stored message, or 0
* (MU_STORE_INVALID_DOCID) in case of error
*/ */
gboolean mu_store_store_path (MuStore *store, const char *path); unsigned mu_store_add_path (MuStore *store, const char *path, GError **err);
/** /**
* remove a message from the database * remove a message from the database based on its path
* *
* @param store a valid store * @param store a valid store
* @param msgpath path of the message (note, this is only used to * @param msgpath path of the message (note, this is only used to
@ -340,6 +344,22 @@ gboolean mu_store_clear (MuStore *store, GError **err);
*/ */
gboolean mu_store_database_is_locked (const gchar *xpath); gboolean mu_store_database_is_locked (const gchar *xpath);
/**
* get a specific message, based on its Xapian docid
*
* @param self a valid MuQuery instance
* @param docid the Xapian docid for the wanted message
* @param err receives error information, or NULL
*
* @return a MuMsg instance (use mu_msg_unref when done with it), or
* NULL in case of error
*/
MuMsg* mu_store_get_msg (MuStore *self, unsigned docid, GError **err);
G_END_DECLS G_END_DECLS
#endif /*__MU_STORE_H__*/ #endif /*__MU_STORE_H__*/

View File

@ -377,15 +377,17 @@ GSList*
mu_str_esc_to_list (const char *strings) mu_str_esc_to_list (const char *strings)
{ {
GSList *lst; GSList *lst;
char *str, *mystrings, *freeme; char *mystrings, *freeme;
const char* cur;
g_return_val_if_fail (strings, NULL); g_return_val_if_fail (strings, NULL);
freeme = mystrings = g_strdup (strings); for (cur = strings; *cur && (*cur == ' ' || *cur == '\t'); ++cur);
mystrings = g_strdup(g_strchug(mystrings)); freeme = mystrings = g_strdup (cur);
lst = NULL;
lst = NULL;
do { do {
gchar *str;
str = eat_esc_string (&mystrings); str = eat_esc_string (&mystrings);
if (str) if (str)
lst = g_slist_prepend (lst, str); lst = g_slist_prepend (lst, str);
@ -433,14 +435,9 @@ char*
mu_str_ascii_xapian_escape_in_place (char *query) mu_str_ascii_xapian_escape_in_place (char *query)
{ {
gchar *cur; gchar *cur;
gboolean replace_dot;
g_return_val_if_fail (query, NULL); g_return_val_if_fail (query, NULL);
/* only replace the '.' if the string looks like an e-mail
* address or msg-id */
replace_dot = (g_strstr_len(query, -1, "@") != NULL);
for (cur = query; *cur; ++cur) { for (cur = query; *cur; ++cur) {
*cur = tolower(*cur); *cur = tolower(*cur);

View File

@ -85,7 +85,7 @@ mu_threader_calculate (MuMsgIter *iter, size_t matchnum, MuMsgFieldId sortfield)
NULL, FALSE); NULL, FALSE);
/* step 5: group root set by subject */ /* step 5: group root set by subject */
//group_root_set_by_subject (root_set); /* group_root_set_by_subject (root_set); */
/* sort */ /* sort */
mu_msg_iter_reset (iter); /* go all the way back */ mu_msg_iter_reset (iter); /* go all the way back */

View File

@ -418,9 +418,10 @@ enum _MuError {
MU_ERROR_FILE_INVALID_SOURCE = 79, MU_ERROR_FILE_INVALID_SOURCE = 79,
MU_ERROR_FILE_TARGET_EQUALS_SOURCE = 80, MU_ERROR_FILE_TARGET_EQUALS_SOURCE = 80,
MU_ERROR_FILE_CANNOT_WRITE = 81, MU_ERROR_FILE_CANNOT_WRITE = 81,
MU_ERROR_FILE_CANNOT_UNLINK = 82,
/* not really an error, used in callbacks */ /* not really an error, used in callbacks */
MU_STOP = 99, MU_STOP = 99
}; };
typedef enum _MuError MuError; typedef enum _MuError MuError;