From d763892f3eefddb8c81e8a351b1deb5abac22b46 Mon Sep 17 00:00:00 2001 From: SJ Date: Sun, 19 Aug 2012 23:20:33 +0200 Subject: [PATCH] iconv fix, pilerimport can handle up to 1024 mbox files --- src/config.h | 2 +- src/parser_utils.c | 18 ++++++++++-------- src/pilerimport.c | 26 ++++++++++++++++++-------- src/test.c | 2 ++ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/config.h b/src/config.h index 1faa07bd..a357c000 100644 --- a/src/config.h +++ b/src/config.h @@ -13,7 +13,7 @@ #define VERSION "0.1.20" -#define BUILD 681 +#define BUILD 684 #define HOSTID "mailarchiver" diff --git a/src/parser_utils.c b/src/parser_utils.c index 3deb1afd..9e939edf 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -276,17 +276,19 @@ void fixupEncodedHeaderLine(char *buf){ if(strlen(encoding) > 2 && strcasecmp(encoding, "utf-8")){ need_encoding = 1; + memset(tmpbuf, 0, sizeof(tmpbuf)); cd = iconv_open("utf-8", encoding); - memset(tmpbuf, 0, sizeof(tmpbuf)); - - inbuf = s+3; - outbuf = &tmpbuf[0]; - inbytesleft = strlen(s+3); - outbytesleft = sizeof(tmpbuf)-1; - size = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); - iconv_close(cd); + if(cd != (iconv_t)-1){ + inbuf = s+3; + outbuf = &tmpbuf[0]; + inbytesleft = strlen(s+3); + outbytesleft = sizeof(tmpbuf)-1; + size = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + iconv_close(cd); + } + else { syslog(LOG_PRIORITY, "unsupported encoding: '%s'", encoding); } } if(need_encoding == 1 && size >= 0) diff --git a/src/pilerimport.c b/src/pilerimport.c index 92f0a06d..e1012f99 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -20,13 +20,14 @@ #include +#define SKIPLIST "junk,trash,spam,draft" +#define MBOX_ARGS 1024 + extern char *optarg; extern int optind; int quiet=0; -#define SKIPLIST "junk,trash,spam,draft" - int connect_to_imap_server(int sd, int *seq, char *imapserver, char *username, char *password); int list_folders(int sd, int *seq, char *folders, int foldersize); int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sdata, struct __data *data, struct __config *cfg); @@ -206,14 +207,14 @@ void usage(){ int main(int argc, char **argv){ - int i, rc=0; - int tot_msgs=0; - char *configfile=CONFIG_FILE, *mailbox=NULL, *emlfile=NULL, *directory=NULL; + int i, rc=0, n_mbox=0, tot_msgs=0; + char *configfile=CONFIG_FILE, *emlfile=NULL, *mbox[MBOX_ARGS], *directory=NULL; char *imapserver=NULL, *username=NULL, *password=NULL, *skiplist=SKIPLIST; struct session_data sdata; struct __config cfg; struct __data data; + for(i=0; i 0){ switch(i){ @@ -231,7 +232,12 @@ int main(int argc, char **argv){ break; case 'm' : - mailbox = optarg; + if(n_mbox < MBOX_ARGS){ + mbox[n_mbox++] = optarg; + } else { + printf("too many -m arguments: %s\n", optarg); + } + break; case 'i' : @@ -263,7 +269,7 @@ int main(int argc, char **argv){ - if(!mailbox && !emlfile && !directory && !imapserver) usage(); + if(!mbox[0] && !emlfile && !directory && !imapserver) usage(); cfg = read_config(configfile); @@ -294,7 +300,11 @@ int main(int argc, char **argv){ load_rules(&sdata, &(data.retention_rules), SQL_RETENTION_RULE_TABLE); if(emlfile) rc = import_message(emlfile, &sdata, &data, &cfg); - if(mailbox) rc = import_from_mailbox(mailbox, &sdata, &data, &cfg); + if(mbox[0]){ + for(i=0; i