mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-24 19:00:11 +01:00
src: fixed recursive directory import
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
d3e2de3ada
commit
8d41af27d0
@ -313,7 +313,6 @@ struct import {
|
|||||||
char *skiplist;
|
char *skiplist;
|
||||||
char *folder_imap;
|
char *folder_imap;
|
||||||
char *folder_name;
|
char *folder_name;
|
||||||
char *directory;
|
|
||||||
char *mboxdir;
|
char *mboxdir;
|
||||||
char *folder;
|
char *folder;
|
||||||
char filename[SMALLBUFSIZE];
|
char filename[SMALLBUFSIZE];
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
int import_message(struct session_data *sdata, struct data *data, struct config *cfg);
|
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_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);
|
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);
|
void import_from_pop3_server(struct session_data *sdata, struct data *data, struct config *cfg);
|
||||||
|
@ -22,17 +22,17 @@
|
|||||||
#include <piler.h>
|
#include <piler.h>
|
||||||
|
|
||||||
|
|
||||||
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;
|
DIR *dir;
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
int rc=ERR, ret=OK, i=0;
|
int rc=ERR, ret=OK, i=0;
|
||||||
int folder;
|
int folder;
|
||||||
char *p;
|
char *p, subdir[SMALLBUFSIZE];
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
dir = opendir(data->import->directory);
|
dir = opendir(directory);
|
||||||
if(!dir){
|
if(!dir){
|
||||||
printf("cannot open directory: %s\n", data->import->directory);
|
printf("cannot open directory: %s\n", directory);
|
||||||
return ERR;
|
return ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,13 +40,13 @@ int import_from_maildir(struct session_data *sdata, struct data *data, struct co
|
|||||||
while((de = readdir(dir))){
|
while((de = readdir(dir))){
|
||||||
if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
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(stat(data->import->filename, &st) == 0){
|
||||||
if(S_ISDIR(st.st_mode)){
|
if(S_ISDIR(st.st_mode)){
|
||||||
folder = data->folder;
|
folder = data->folder;
|
||||||
data->import->directory = data->import->filename;
|
snprintf(subdir, sizeof(subdir)-1, "%s/%s", directory, data->import->filename);
|
||||||
rc = import_from_maildir(sdata, data, cfg);
|
rc = import_from_maildir(sdata, data, subdir, cfg);
|
||||||
data->folder = folder;
|
data->folder = folder;
|
||||||
if(rc == ERR) ret = ERR;
|
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(S_ISREG(st.st_mode)){
|
||||||
if(i == 0 && data->recursive_folder_names == 1){
|
if(i == 0 && data->recursive_folder_names == 1){
|
||||||
p = strrchr(data->import->directory, '/');
|
p = strrchr(directory, '/');
|
||||||
if(p) p++;
|
if(p) p++;
|
||||||
else {
|
else {
|
||||||
printf("ERROR: invalid directory name: '%s'\n", data->import->directory);
|
printf("ERROR: invalid directory name: '%s'\n", directory);
|
||||||
return ERR;
|
return ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ void usage(){
|
|||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int i, c, n_mbox=0;
|
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;
|
char *imapserver=NULL, *pop3server=NULL;
|
||||||
struct session_data sdata;
|
struct session_data sdata;
|
||||||
struct config cfg;
|
struct config cfg;
|
||||||
@ -94,7 +94,6 @@ int main(int argc, char **argv){
|
|||||||
import.skiplist = SKIPLIST;
|
import.skiplist = SKIPLIST;
|
||||||
import.folder_imap = NULL;
|
import.folder_imap = NULL;
|
||||||
memset(import.filename, 0, SMALLBUFSIZE);
|
memset(import.filename, 0, SMALLBUFSIZE);
|
||||||
import.directory = NULL;
|
|
||||||
import.mboxdir = NULL;
|
import.mboxdir = NULL;
|
||||||
import.tot_msgs = 0;
|
import.tot_msgs = 0;
|
||||||
import.folder = NULL;
|
import.folder = NULL;
|
||||||
@ -164,7 +163,7 @@ int main(int argc, char **argv){
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd' :
|
case 'd' :
|
||||||
data.import->directory = optarg;
|
directory = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm' :
|
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)){
|
if(data.import->failed_folder && !can_i_write_directory(data.import->failed_folder)){
|
||||||
printf("cannot write failed directory '%s'\n", 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->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(imapserver) import_from_imap_server(&sdata, &data, &cfg);
|
||||||
if(pop3server) import_from_pop3_server(&sdata, &data, &cfg);
|
if(pop3server) import_from_pop3_server(&sdata, &data, &cfg);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user