From 927e202dcd447ff0d029819505dc800d4ab9d8d1 Mon Sep 17 00:00:00 2001 From: SJ Date: Wed, 9 Sep 2015 12:52:15 +0200 Subject: [PATCH] folder feature to the daemon --- src/cfg.c | 1 + src/cfg.h | 2 ++ src/config.h | 5 +++-- src/defs.h | 1 + src/message.c | 22 ++++++++++++++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/cfg.c b/src/cfg.c index 4ef4132d..47984645 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -69,6 +69,7 @@ struct _parse_rule config_parse_rules[] = { "debug", "integer", (void*) int_parser, offsetof(struct __config, debug), "0", sizeof(int)}, { "default_retention_days", "integer", (void*) int_parser, offsetof(struct __config, default_retention_days), "2557", sizeof(int)}, { "enable_cjk", "integer", (void*) int_parser, offsetof(struct __config, enable_cjk), "0", sizeof(int)}, + { "enable_folders", "integer", (void*) int_parser, offsetof(struct __config, enable_folders), "0", sizeof(int)}, { "encrypt_messages", "integer", (void*) int_parser, offsetof(struct __config, encrypt_messages), "1", sizeof(int)}, { "extra_to_field", "string", (void*) string_parser, offsetof(struct __config, extra_to_field), "", MAXVAL-1}, { "extract_attachments", "integer", (void*) int_parser, offsetof(struct __config, extract_attachments), "1", sizeof(int)}, diff --git a/src/cfg.h b/src/cfg.h index 7be6746e..413c4de5 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -93,6 +93,8 @@ struct __config { int mmap_dedup_test; + int enable_folders; + int debug; }; diff --git a/src/config.h b/src/config.h index cf86155c..9bd86a02 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "1.2.0-master" -#define BUILD 919 +#define BUILD 920 #define HOSTID "mailarchiver" @@ -91,6 +91,7 @@ #define SQL_CUSTOMER_TABLE "customer" #define SQL_IMPORT_TABLE "import" #define SQL_LEGAL_HOLD_TABLE "legal_hold" +#define SQL_FOLDER_MESSAGE_TABLE "folder_message" #define SQL_MESSAGES_VIEW "v_messages" #define SQL_ATTACHMENTS_VIEW "v_attachment" @@ -107,7 +108,7 @@ #define SQL_PREPARED_STMT_INSERT_INTO_FOLDER_TABLE "INSERT INTO `" SQL_FOLDER_TABLE "` (`name`, `parent_id`) VALUES(?,?)" #define SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE "UPDATE " SQL_METADATA_TABLE " SET reference=? WHERE message_id=? AND reference=''" #define SQL_PREPARED_STMT_GET_GUI_IMPORT_JOBS "SELECT id, type, username, password, server FROM " SQL_IMPORT_TABLE " WHERE started=0 ORDER BY id LIMIT 0,1" - +#define SQL_PREPARED_STMT_INSERT_FOLDER_MESSAGE "INSERT INTO " SQL_FOLDER_MESSAGE_TABLE " (`folder_id`, `id`) VALUES(?,?)" /* Error codes */ diff --git a/src/defs.h b/src/defs.h index 336603aa..62d20209 100644 --- a/src/defs.h +++ b/src/defs.h @@ -315,6 +315,7 @@ struct __data { MYSQL_STMT *stmt_insert_into_sphinx_table; MYSQL_STMT *stmt_insert_into_meta_table; MYSQL_STMT *stmt_insert_into_attachment_table; + MYSQL_STMT *stmt_insert_into_folder_message_table; MYSQL_STMT *stmt_get_attachment_id_by_signature; MYSQL_STMT *stmt_get_attachment_pointer; MYSQL_STMT *stmt_query_attachment; diff --git a/src/message.c b/src/message.c index 389c2677..d811f9dc 100644 --- a/src/message.c +++ b/src/message.c @@ -129,6 +129,23 @@ int store_recipients(struct session_data *sdata, struct __data *data, char *to, } +int store_folder_id(struct session_data *sdata, struct __data *data, uint64 id, struct __config *cfg){ + int rc = ERR; + + if(prepare_sql_statement(sdata, &(data->stmt_insert_into_folder_message_table), SQL_PREPARED_STMT_INSERT_FOLDER_MESSAGE, cfg) == ERR) return rc; + + p_bind_init(data); + + data->sql[data->pos] = (char *)&data->folder; data->type[data->pos] = TYPE_LONGLONG; data->pos++; + data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONGLONG; data->pos++; + + if(p_exec_query(sdata, data->stmt_insert_into_folder_message_table, data) == OK) rc = OK; + close_prepared_statement(data->stmt_insert_into_folder_message_table); + + return rc; +} + + int update_metadata_reference(struct session_data *sdata, struct _state *state, struct __data *data, char *ref, struct __config *cfg){ int ret = ERR; @@ -223,6 +240,11 @@ int store_meta_data(struct session_data *sdata, struct _state *state, struct __d if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: stored indexdata, rc=%d", sdata->ttmpfile, rc); + if(cfg->enable_folders == 1){ + rc = store_folder_id(sdata, data, id, cfg); + if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: stored folderdata, rc=%d", sdata->ttmpfile, rc); + } + ret = OK; }