From 1b693f3ba9a5af6e82d361044ffe2113883c9e8a Mon Sep 17 00:00:00 2001 From: SJ Date: Sat, 29 Jun 2013 15:22:07 +0200 Subject: [PATCH] folder fixes --- src/config.h | 3 ++- src/import.c | 12 ++++++++++-- src/pilerimport.c | 16 ++++++++-------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/config.h b/src/config.h index 34973bb2..1b75d79b 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "0.1.24-master-branch" -#define BUILD 817 +#define BUILD 818 #define HOSTID "mailarchiver" @@ -116,6 +116,7 @@ #define OK 0 #define ERR 1 #define ERR_EXISTS 2 +#define ERR_FOLDER -1 #define AVIR_OK 0 #define AVIR_VIRUS 1 diff --git a/src/import.c b/src/import.c index 20d1d7b6..b3a25f6f 100644 --- a/src/import.c +++ b/src/import.c @@ -72,6 +72,11 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da state = parse_message(sdata, 1, data, cfg); post_parse(sdata, &state, cfg); + if(sdata->hdr_len < 10){ + printf("invalid message, hdr_len: %d\n", sdata->hdr_len); + return ERR; + } + if(sdata->sent <= 0 && sdata->delivered > 0) sdata->sent = sdata->delivered; if(sdata->sent > sdata->now) sdata->sent = sdata->now; @@ -126,7 +131,7 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da int get_folder_id(struct session_data *sdata, struct __data *data, char *foldername, int parent_id){ - int id=-1; + int id=ERR_FOLDER; if(prepare_sql_statement(sdata, &(data->stmt_get_folder_id), SQL_PREPARED_STMT_GET_FOLDER_ID) == ERR) return id; @@ -136,6 +141,7 @@ int get_folder_id(struct session_data *sdata, struct __data *data, char *foldern if(p_exec_query(sdata, data->stmt_get_folder_id, data) == OK){ + p_bind_init(data); data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(unsigned long); data->pos++; p_store_results(sdata, data->stmt_get_folder_id, data); @@ -150,7 +156,9 @@ int get_folder_id(struct session_data *sdata, struct __data *data, char *foldern int add_new_folder(struct session_data *sdata, struct __data *data, char *foldername, int parent_id){ - int id=0; + int id=ERR_FOLDER; + + if(foldername == NULL) return id; if(prepare_sql_statement(sdata, &(data->stmt_insert_into_folder_table), SQL_PREPARED_STMT_INSERT_INTO_FOLDER_TABLE) == ERR) return id; diff --git a/src/pilerimport.c b/src/pilerimport.c index 86cef92f..c9e5136e 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -104,7 +104,7 @@ int import_mbox_from_dir(char *directory, struct session_data *sdata, struct __d DIR *dir; struct dirent *de; int rc=ERR, ret=OK, i=0; - unsigned long folder; + int folder; char fname[SMALLBUFSIZE]; struct stat st; @@ -132,10 +132,10 @@ int import_mbox_from_dir(char *directory, struct session_data *sdata, struct __d if(S_ISREG(st.st_mode)){ if(i == 0 && data->recursive_folder_names == 1){ folder = get_folder_id(sdata, data, fname, data->folder); - if(folder == -1){ + if(folder == ERR_FOLDER){ folder = add_new_folder(sdata, data, fname, data->folder); - if(folder == -1){ + if(folder == ERR_FOLDER){ printf("error: cannot get/add folder '%s' to parent id: %d\n", fname, data->folder); return ERR; } @@ -173,7 +173,7 @@ int import_from_maildir(char *directory, struct session_data *sdata, struct __da DIR *dir; struct dirent *de; int rc=ERR, ret=OK, i=0; - unsigned long folder; + int folder; char *p, fname[SMALLBUFSIZE]; struct stat st; @@ -208,10 +208,10 @@ int import_from_maildir(char *directory, struct session_data *sdata, struct __da } folder = get_folder_id(sdata, data, p, data->folder); - if(folder == -1){ + if(folder == ERR_FOLDER){ folder = add_new_folder(sdata, data, p, data->folder); - if(folder == -1){ + if(folder == ERR_FOLDER){ printf("error: cannot get/add folder '%s' to parent id: %d\n", p, data->folder); return ERR; } @@ -543,11 +543,11 @@ int main(int argc, char **argv){ if(folder){ data.folder = get_folder_id(&sdata, &data, folder, 0); - if(data.folder == -1){ + if(data.folder == ERR_FOLDER){ data.folder = add_new_folder(&sdata, &data, folder, 0); } - if(data.folder == -1){ + if(data.folder == ERR_FOLDER){ printf("error: cannot get/add folder '%s'\n", folder); close_database(&sdata); return 0;