diff --git a/src/config.h b/src/config.h index ffa0e269..6cf00634 100644 --- a/src/config.h +++ b/src/config.h @@ -13,7 +13,7 @@ #define VERSION "0.1.23-master-branch" -#define BUILD 770 +#define BUILD 774 #define HOSTID "mailarchiver" @@ -97,6 +97,7 @@ #define SQL_PREPARED_STMT_QUERY_ATTACHMENT "SELECT `attachment_id`, `ptr` FROM " SQL_ATTACHMENT_TABLE " WHERE piler_id=? ORDER BY attachment_id ASC" #define SQL_PREPARED_STMT_GET_FOLDER_ID "SELECT `id` FROM " SQL_FOLDER_TABLE " WHERE `name`=? AND `parent_id`=?" #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=''" /* Error codes */ diff --git a/src/defs.h b/src/defs.h index 26da0013..910afd89 100644 --- a/src/defs.h +++ b/src/defs.h @@ -256,7 +256,8 @@ struct __data { MYSQL_STMT *stmt_get_attachment_pointer; MYSQL_STMT *stmt_query_attachment; MYSQL_STMT *stmt_get_folder_id; - MYSQL_STMT *stmt_insert_into_folder_table; + MYSQL_STMT *stmt_insert_into_folder_table; + MYSQL_STMT *stmt_update_metadata_reference; #endif #ifdef HAVE_TRE diff --git a/src/message.c b/src/message.c index a5f52d08..80f493f4 100644 --- a/src/message.c +++ b/src/message.c @@ -234,6 +234,38 @@ CLOSE: } +int update_metadata_reference(struct session_data *sdata, struct _state *state, struct __data *data, char *ref, struct __config *cfg){ + int rc, ret = ERR; + MYSQL_BIND bind[2]; + unsigned long len[2]; + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type = MYSQL_TYPE_STRING; + bind[0].buffer = ref; + bind[0].is_null = 0; + len[0] = strlen(ref); bind[0].length = &len[0]; + + bind[1].buffer_type = MYSQL_TYPE_STRING; + bind[1].buffer = state->message_id; + bind[1].is_null = 0; + len[1] = strlen(state->message_id); bind[1].length = &len[1]; + + if(mysql_stmt_bind_param(data->stmt_update_metadata_reference, bind)){ + syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_bind_param() error: %s", sdata->ttmpfile, SQL_METADATA_TABLE, mysql_stmt_error(data->stmt_update_metadata_reference)); + goto CLOSE; + } + + rc = mysql_stmt_execute(data->stmt_update_metadata_reference); + if(rc == 0) ret = OK; + + if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: updated meta reference for '%s', rc=%d", sdata->ttmpfile, state->message_id, rc); + +CLOSE: + return ret; +} + + int store_meta_data(struct session_data *sdata, struct _state *state, struct __data *data, struct __config *cfg){ int rc, ret=ERR; char *subj, *p, s[MAXBUFSIZE], s2[SMALLBUFSIZE], vcode[2*DIGEST_LENGTH+1], ref[2*DIGEST_LENGTH+1]; @@ -252,7 +284,10 @@ int store_meta_data(struct session_data *sdata, struct _state *state, struct __d digest_string(s, &vcode[0]); memset(ref, 0, sizeof(ref)); - if(strlen(state->reference) > 10) digest_string(state->reference, &ref[0]); + if(strlen(state->reference) > 10){ + digest_string(state->reference, &ref[0]); + update_metadata_reference(sdata, state, data, &ref[0], cfg); + } if(prepare_a_mysql_statement(sdata, &(data->stmt_insert_into_meta_table), SQL_PREPARED_STMT_INSERT_INTO_META_TABLE) == ERR) return ERR; diff --git a/src/mysql.c b/src/mysql.c index 184d212e..d1517f0d 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -41,9 +41,11 @@ int create_prepared_statements(struct session_data *sdata, struct __data *data){ data->stmt_get_meta_id_by_message_id = NULL; data->stmt_insert_into_rcpt_table = NULL; + data->stmt_update_metadata_reference = NULL; if(prepare_a_mysql_statement(sdata, &(data->stmt_get_meta_id_by_message_id), SQL_PREPARED_STMT_GET_META_ID_BY_MESSAGE_ID) == ERR) rc = ERR; if(prepare_a_mysql_statement(sdata, &(data->stmt_insert_into_rcpt_table), SQL_PREPARED_STMT_INSERT_INTO_RCPT_TABLE) == ERR) rc = ERR; + if(prepare_a_mysql_statement(sdata, &(data->stmt_update_metadata_reference), SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE) == ERR) rc = ERR; return rc; } @@ -52,5 +54,6 @@ int create_prepared_statements(struct session_data *sdata, struct __data *data){ void close_prepared_statements(struct __data *data){ if(data->stmt_get_meta_id_by_message_id) mysql_stmt_close(data->stmt_get_meta_id_by_message_id); if(data->stmt_insert_into_rcpt_table) mysql_stmt_close(data->stmt_insert_into_rcpt_table); + if(data->stmt_update_metadata_reference) mysql_stmt_close(data->stmt_update_metadata_reference); }