From 526295dae4fbcc12041d60095142601ba350a8fd Mon Sep 17 00:00:00 2001 From: SJ Date: Sat, 5 Dec 2015 11:56:01 +0100 Subject: [PATCH] improved the folder importing feature --- src/config.h | 2 +- src/imap.c | 11 +++++++---- src/message.c | 2 ++ src/pilerimport.c | 7 ++++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/config.h b/src/config.h index ae0e5908..45c3b330 100644 --- a/src/config.h +++ b/src/config.h @@ -13,7 +13,7 @@ #define VERSION "1.2.0-master" -#define BUILD 929 +#define BUILD 930 #define HOSTID "mailarchiver" diff --git a/src/imap.c b/src/imap.c index 47b666ad..354478b4 100644 --- a/src/imap.c +++ b/src/imap.c @@ -122,6 +122,13 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda if(messages <= 0) return OK; + + if(data->recursive_folder_names == 1){ + data->folder = get_folder_id(sdata, data, folder, 0, cfg); + if(data->folder == ERR_FOLDER) data->folder = add_new_folder(sdata, data, folder, 0, cfg); + } + + data->import->total_messages += messages; for(i=data->import->start_position; i<=messages; i++){ @@ -461,10 +468,6 @@ int list_folders(int sd, int *seq, int use_ssl, struct __data *data){ q++; fldrlen = strtol(q, NULL, 10); } else { - //if(*q == '"') q++; - - //if(q[strlen(q)-1] == ' ') q[strlen(q)-1] = '\0'; - //if(q[strlen(q)-1] == '"') q[strlen(q)-1] = '\0'; if(fldrlen) { ruf = malloc(strlen(q) * 2 + 1); diff --git a/src/message.c b/src/message.c index 6492f880..c4bd554b 100644 --- a/src/message.c +++ b/src/message.c @@ -132,6 +132,8 @@ int store_recipients(struct session_data *sdata, struct __data *data, char *to, int store_folder_id(struct session_data *sdata, struct __data *data, uint64 id, struct __config *cfg){ int rc = ERR; + if(data->folder == ERR_FOLDER) return rc; + if(prepare_sql_statement(sdata, &(data->stmt_insert_into_folder_message_table), SQL_PREPARED_STMT_INSERT_FOLDER_MESSAGE, cfg) == ERR) return rc; p_bind_init(data); diff --git a/src/pilerimport.c b/src/pilerimport.c index fee372f3..8391b543 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -486,11 +486,11 @@ void usage(){ printf(" -f IMAP folder name to import\n"); printf(" -g Move email after import to this IMAP folder\n"); printf(" -F Piler folder name to assign to this import\n"); + printf(" -R Assign IMAP folder names as Piler folder names\n"); printf(" -b Import only this many emails\n"); printf(" -s Start importing POP3 emails from this position\n"); printf(" -D Dry-run, do not import anything\n"); printf(" -o Only download emails for POP3/IMAP import\n"); - printf(" -R Recursive piler folder names\n"); printf(" -r Remove imported emails\n"); printf(" -q Quiet mode\n"); @@ -701,6 +701,11 @@ int main(int argc, char **argv){ cfg = read_config(configfile); + if((data.recursive_folder_names == 1 || folder) && cfg.enable_folders == 0){ + printf("please set enable_folders=1 in piler.conf to use the folder options\n"); + return ERR; + } + /* make sure we don't discard messages without a valid Message-Id when importing manually */ cfg.archive_emails_not_having_message_id = 1;