folder fixes

This commit is contained in:
SJ 2013-06-29 15:22:07 +02:00
parent a28a44b88d
commit 1b693f3ba9
3 changed files with 20 additions and 11 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;