diff --git a/src/defs.h b/src/defs.h index b166b3ed..0d7a11f5 100644 --- a/src/defs.h +++ b/src/defs.h @@ -313,7 +313,6 @@ struct import { char *skiplist; char *folder_imap; char *folder_name; - char *directory; char *mboxdir; char *folder; char filename[SMALLBUFSIZE]; diff --git a/src/import.h b/src/import.h index 1659deb1..21e3f082 100644 --- a/src/import.h +++ b/src/import.h @@ -8,7 +8,7 @@ int import_message(struct session_data *sdata, struct data *data, struct config *cfg); -int import_from_maildir(struct session_data *sdata, struct data *data, struct config *cfg); +int import_from_maildir(struct session_data *sdata, struct data *data, char *directory, struct config *cfg); int import_from_mailbox(char *mailbox, struct session_data *sdata, struct data *data, struct config *cfg); int import_mbox_from_dir(char *directory, struct session_data *sdata, struct data *data, struct config *cfg); void import_from_pop3_server(struct session_data *sdata, struct data *data, struct config *cfg); diff --git a/src/import_maildir.c b/src/import_maildir.c index dc4e3f7a..08fc319b 100644 --- a/src/import_maildir.c +++ b/src/import_maildir.c @@ -22,17 +22,17 @@ #include -int import_from_maildir(struct session_data *sdata, struct data *data, struct config *cfg){ +int import_from_maildir(struct session_data *sdata, struct data *data, char *directory, struct config *cfg){ DIR *dir; struct dirent *de; int rc=ERR, ret=OK, i=0; int folder; - char *p; + char *p, subdir[SMALLBUFSIZE]; struct stat st; - dir = opendir(data->import->directory); + dir = opendir(directory); if(!dir){ - printf("cannot open directory: %s\n", data->import->directory); + printf("cannot open directory: %s\n", directory); return ERR; } @@ -40,13 +40,13 @@ int import_from_maildir(struct session_data *sdata, struct data *data, struct co while((de = readdir(dir))){ if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; - snprintf(data->import->filename, SMALLBUFSIZE-1, "%s/%s", data->import->directory, de->d_name); + snprintf(data->import->filename, SMALLBUFSIZE-1, "%s/%s", directory, de->d_name); if(stat(data->import->filename, &st) == 0){ if(S_ISDIR(st.st_mode)){ folder = data->folder; - data->import->directory = data->import->filename; - rc = import_from_maildir(sdata, data, cfg); + snprintf(subdir, sizeof(subdir)-1, "%s/%s", directory, data->import->filename); + rc = import_from_maildir(sdata, data, subdir, cfg); data->folder = folder; if(rc == ERR) ret = ERR; } @@ -54,10 +54,10 @@ int import_from_maildir(struct session_data *sdata, struct data *data, struct co if(S_ISREG(st.st_mode)){ if(i == 0 && data->recursive_folder_names == 1){ - p = strrchr(data->import->directory, '/'); + p = strrchr(directory, '/'); if(p) p++; else { - printf("ERROR: invalid directory name: '%s'\n", data->import->directory); + printf("ERROR: invalid directory name: '%s'\n", directory); return ERR; } diff --git a/src/pilerimport.c b/src/pilerimport.c index 19d855f5..b648c366 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -63,7 +63,7 @@ void usage(){ int main(int argc, char **argv){ int i, c, n_mbox=0; - char *configfile=CONFIG_FILE, *mbox[MBOX_ARGS]; + char *configfile=CONFIG_FILE, *mbox[MBOX_ARGS], *directory=NULL; char *imapserver=NULL, *pop3server=NULL; struct session_data sdata; struct config cfg; @@ -94,7 +94,6 @@ int main(int argc, char **argv){ import.skiplist = SKIPLIST; import.folder_imap = NULL; memset(import.filename, 0, SMALLBUFSIZE); - import.directory = NULL; import.mboxdir = NULL; import.tot_msgs = 0; import.folder = NULL; @@ -164,7 +163,7 @@ int main(int argc, char **argv){ break; case 'd' : - data.import->directory = optarg; + directory = optarg; break; case 'm' : @@ -277,7 +276,7 @@ int main(int argc, char **argv){ } - if(!mbox[0] && !data.import->mboxdir && !data.import->filename && !data.import->directory && !imapserver && !pop3server) usage(); + if(!mbox[0] && !data.import->mboxdir && !data.import->filename && !directory && !imapserver && !pop3server) usage(); if(data.import->failed_folder && !can_i_write_directory(data.import->failed_folder)){ printf("cannot write failed directory '%s'\n", data.import->failed_folder); @@ -344,7 +343,7 @@ int main(int argc, char **argv){ } } if(data.import->mboxdir) import_mbox_from_dir(data.import->mboxdir, &sdata, &data, &cfg); - if(data.import->directory) import_from_maildir(&sdata, &data, &cfg); + if(directory) import_from_maildir(&sdata, &data, directory, &cfg); if(imapserver) import_from_imap_server(&sdata, &data, &cfg); if(pop3server) import_from_pop3_server(&sdata, &data, &cfg);