iconv fix, pilerimport can handle up to 1024 mbox files

This commit is contained in:
SJ 2012-08-19 23:20:33 +02:00
parent a3d0b399c1
commit d763892f3e
4 changed files with 31 additions and 17 deletions

View File

@ -13,7 +13,7 @@
#define VERSION "0.1.20" #define VERSION "0.1.20"
#define BUILD 681 #define BUILD 684
#define HOSTID "mailarchiver" #define HOSTID "mailarchiver"

View File

@ -276,17 +276,19 @@ void fixupEncodedHeaderLine(char *buf){
if(strlen(encoding) > 2 && strcasecmp(encoding, "utf-8")){ if(strlen(encoding) > 2 && strcasecmp(encoding, "utf-8")){
need_encoding = 1; need_encoding = 1;
memset(tmpbuf, 0, sizeof(tmpbuf));
cd = iconv_open("utf-8", encoding); cd = iconv_open("utf-8", encoding);
memset(tmpbuf, 0, sizeof(tmpbuf)); if(cd != (iconv_t)-1){
inbuf = s+3;
inbuf = s+3; outbuf = &tmpbuf[0];
outbuf = &tmpbuf[0]; inbytesleft = strlen(s+3);
inbytesleft = strlen(s+3); outbytesleft = sizeof(tmpbuf)-1;
outbytesleft = sizeof(tmpbuf)-1; size = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
size = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); iconv_close(cd);
iconv_close(cd); }
else { syslog(LOG_PRIORITY, "unsupported encoding: '%s'", encoding); }
} }
if(need_encoding == 1 && size >= 0) if(need_encoding == 1 && size >= 0)

View File

@ -20,13 +20,14 @@
#include <piler.h> #include <piler.h>
#define SKIPLIST "junk,trash,spam,draft"
#define MBOX_ARGS 1024
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
int quiet=0; 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 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 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); 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 main(int argc, char **argv){
int i, rc=0; int i, rc=0, n_mbox=0, tot_msgs=0;
int tot_msgs=0; char *configfile=CONFIG_FILE, *emlfile=NULL, *mbox[MBOX_ARGS], *directory=NULL;
char *configfile=CONFIG_FILE, *mailbox=NULL, *emlfile=NULL, *directory=NULL;
char *imapserver=NULL, *username=NULL, *password=NULL, *skiplist=SKIPLIST; char *imapserver=NULL, *username=NULL, *password=NULL, *skiplist=SKIPLIST;
struct session_data sdata; struct session_data sdata;
struct __config cfg; struct __config cfg;
struct __data data; struct __data data;
for(i=0; i<MBOX_ARGS; i++) mbox[i] = NULL;
while((i = getopt(argc, argv, "c:m:e:d:i:u:p:x:h?")) > 0){ while((i = getopt(argc, argv, "c:m:e:d:i:u:p:x:h?")) > 0){
switch(i){ switch(i){
@ -231,7 +232,12 @@ int main(int argc, char **argv){
break; break;
case 'm' : case 'm' :
mailbox = optarg; if(n_mbox < MBOX_ARGS){
mbox[n_mbox++] = optarg;
} else {
printf("too many -m <mailbox> arguments: %s\n", optarg);
}
break; break;
case 'i' : 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); cfg = read_config(configfile);
@ -294,7 +300,11 @@ int main(int argc, char **argv){
load_rules(&sdata, &(data.retention_rules), SQL_RETENTION_RULE_TABLE); load_rules(&sdata, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
if(emlfile) rc = import_message(emlfile, &sdata, &data, &cfg); 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<n_mbox; i++){
rc = import_from_mailbox(mbox[i], &sdata, &data, &cfg);
}
}
if(directory) rc = import_from_maildir(directory, &sdata, &data, &tot_msgs, &cfg); if(directory) rc = import_from_maildir(directory, &sdata, &data, &tot_msgs, &cfg);
if(imapserver && username && password) rc = import_from_imap_server(imapserver, username, password, &sdata, &data, skiplist, &cfg); if(imapserver && username && password) rc = import_from_imap_server(imapserver, username, password, &sdata, &data, skiplist, &cfg);

View File

@ -51,6 +51,8 @@ int main(int argc, char **argv){
printf("locale: %s\n", setlocale(LC_MESSAGES, cfg.locale)); printf("locale: %s\n", setlocale(LC_MESSAGES, cfg.locale));
setlocale(LC_CTYPE, cfg.locale); setlocale(LC_CTYPE, cfg.locale);
printf("build: %d\n", get_build());
data.archiving_rules = NULL; data.archiving_rules = NULL;
data.retention_rules = NULL; data.retention_rules = NULL;