diff --git a/src/config.h b/src/config.h index d88a31cd..e438a0ba 100644 --- a/src/config.h +++ b/src/config.h @@ -110,6 +110,7 @@ #define SQL_PREPARED_STMT_GET_FOLDER_UID_BY_EMAIL "SELECT `uid` FROM " SQL_FOLDER_EMAIL_TABLE " WHERE `email`=?" #define SQL_PREPARED_STMT_INSERT_INTO_FOLDER_TABLE "INSERT INTO `" SQL_FOLDER_TABLE "` (`name`, `parent_id`) VALUES(?,?)" #define SQL_PREPARED_STMT_INSERT_INTO_FOLDER_EXTRA_TABLE "INSERT INTO `" SQL_FOLDER_EXTRA_TABLE "` (`name`, `uid`) VALUES(?,?)" +#define SQL_PREPARED_STMT_INSERT_INTO_FOLDER_EMAIL_TABLE "INSERT INTO `" SQL_FOLDER_EMAIL_TABLE "` (`email`) 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`, `message_id`, `uid`) VALUES(?,?,?)" diff --git a/src/folder.c b/src/folder.c index 4ab2ce97..b980e84b 100644 --- a/src/folder.c +++ b/src/folder.c @@ -18,6 +18,21 @@ #include +void insert_email_to_table(struct session_data *sdata, struct __data *data){ + if(prepare_sql_statement(sdata, &(data->stmt_insert_into_folder_table), SQL_PREPARED_STMT_INSERT_INTO_FOLDER_EMAIL_TABLE) == ERR) return; + + p_bind_init(data); + + data->sql[data->pos] = data->import->email; data->type[data->pos] = TYPE_STRING; data->pos++; + + if(p_exec_query(sdata, data->stmt_insert_into_folder_table, data) == OK){ + data->import->uid = p_get_insert_id(data->stmt_insert_into_folder_table); + } + + close_prepared_statement(data->stmt_insert_into_folder_table); +} + + void get_folder_uid_by_email(struct session_data *sdata, struct __data *data){ int uid = 0; @@ -37,11 +52,10 @@ void get_folder_uid_by_email(struct session_data *sdata, struct __data *data){ p_free_results(data->stmt_get_folder_id); } - printf("uid=%d\n", uid); - close_prepared_statement(data->stmt_get_folder_id); - data->import->uid = uid; + if(uid > 0) data->import->uid = uid; + else insert_email_to_table(sdata, data); } diff --git a/util/db-mysql.sql b/util/db-mysql.sql index 339c35aa..fb3f7755 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -282,7 +282,7 @@ create table if not exists `folder` ( create table if not exists `folder_email` ( `uid` int unsigned not null auto_increment, `email` char(128) not null unique, - key `folder_user_idx` (`uid`) + key `folder_user_idx` (`uid`), key `folder_user_idx2` (`email`) ) ENGINE=InnoDB;