fixed pilerimport return values

This commit is contained in:
SJ 2012-07-09 15:18:21 +02:00
parent 4703bedcfe
commit 5f9ec6b419
3 changed files with 21 additions and 17 deletions

View File

@ -13,7 +13,7 @@
#define VERSION "0.1.19" #define VERSION "0.1.19"
#define BUILD 671 #define BUILD 672
#define HOSTID "mailarchiver" #define HOSTID "mailarchiver"

View File

@ -106,6 +106,7 @@ ENDE:
case ERR_EXISTS: case ERR_EXISTS:
printf("discarding duplicate message: %s\n", filename); printf("discarding duplicate message: %s\n", filename);
rc = OK;
break; break;
default: default:

View File

@ -29,7 +29,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda
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){
FILE *F, *f=NULL; FILE *F, *f=NULL;
int rc=ERR, tot_msgs=0; int rc=ERR, tot_msgs=0, ret=OK;
char buf[MAXBUFSIZE], fname[SMALLBUFSIZE]; char buf[MAXBUFSIZE], fname[SMALLBUFSIZE];
time_t t; time_t t;
@ -49,6 +49,7 @@ int import_from_mailbox(char *mailbox, struct session_data *sdata, struct __data
if(f){ if(f){
fclose(f); fclose(f);
rc = import_message(fname, sdata, data, cfg); rc = import_message(fname, sdata, data, cfg);
if(rc == ERR) ret = ERR;
unlink(fname); unlink(fname);
} }
@ -63,27 +64,28 @@ int import_from_mailbox(char *mailbox, struct session_data *sdata, struct __data
if(f){ if(f){
fclose(f); fclose(f);
rc = import_message(fname, sdata, data, cfg); rc = import_message(fname, sdata, data, cfg);
if(rc == ERR) ret = ERR;
unlink(fname); unlink(fname);
} }
fclose(F); fclose(F);
return rc; return ret;
} }
int import_from_maildir(char *directory, struct session_data *sdata, struct __data *data, struct __config *cfg){ int import_from_maildir(char *directory, struct session_data *sdata, struct __data *data, struct __config *cfg){
DIR *dir; DIR *dir;
struct dirent *de; struct dirent *de;
int rc=ERR, tot_msgs=0; int rc=ERR, ret=OK, tot_msgs=0;
char fname[SMALLBUFSIZE]; char fname[SMALLBUFSIZE];
struct stat st; struct stat st;
dir = opendir(directory); dir = opendir(directory);
if(!dir){ if(!dir){
printf("cannot open directory: %s\n", directory); printf("cannot open directory: %s\n", directory);
return rc; return ERR;
} }
@ -94,13 +96,15 @@ int import_from_maildir(char *directory, struct session_data *sdata, struct __da
if(stat(fname, &st) == 0){ if(stat(fname, &st) == 0){
if(S_ISDIR(st.st_mode)){ if(S_ISDIR(st.st_mode)){
import_from_maildir(fname, sdata, data, cfg); rc = import_from_maildir(fname, sdata, data, cfg);
if(rc == ERR) ret = ERR;
} }
else { else {
if(S_ISREG(st.st_mode)){ if(S_ISREG(st.st_mode)){
rc = import_message(fname, sdata, data, cfg); rc = import_message(fname, sdata, data, cfg);
if(rc != ERR) tot_msgs++; if(rc == OK) tot_msgs++;
else ret = ERR;
} }
else { else {
printf("%s is not a file\n", fname); printf("%s is not a file\n", fname);
@ -115,23 +119,23 @@ int import_from_maildir(char *directory, struct session_data *sdata, struct __da
} }
closedir(dir); closedir(dir);
return rc; return ret;
} }
int import_from_imap_server(char *imapserver, char *username, char *password, struct session_data *sdata, struct __data *data, struct __config *cfg){ int import_from_imap_server(char *imapserver, char *username, char *password, struct session_data *sdata, struct __data *data, struct __config *cfg){
int rc=ERR, sd, seq=1; int rc=ERR, ret=OK, sd, seq=1;
char *p, puf[MAXBUFSIZE]; char *p, puf[MAXBUFSIZE];
char folders[MAXBUFSIZE]; char folders[MAXBUFSIZE];
if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1){ if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
printf("cannot create socket\n"); printf("cannot create socket\n");
return rc; return ERR;
} }
if(connect_to_imap_server(sd, &seq, imapserver, username, password) == ERR){ if(connect_to_imap_server(sd, &seq, imapserver, username, password) == ERR){
close(sd); close(sd);
return rc; return ERR;
} }
@ -146,13 +150,14 @@ int import_from_imap_server(char *imapserver, char *username, char *password, st
printf("processing folder: %s... ", puf); printf("processing folder: %s... ", puf);
rc = process_imap_folder(sd, &seq, puf, sdata, data, cfg); rc = process_imap_folder(sd, &seq, puf, sdata, data, cfg);
if(rc == ERR) ret = ERR;
} while(p); } while(p);
close(sd); close(sd);
return rc; return ret;
} }
@ -222,14 +227,14 @@ int main(int argc, char **argv){
if(read_key(&cfg)){ if(read_key(&cfg)){
printf("%s\n", ERR_READING_KEY); printf("%s\n", ERR_READING_KEY);
return 1; return ERR;
} }
mysql_init(&(sdata.mysql)); mysql_init(&(sdata.mysql));
mysql_options(&(sdata.mysql), MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&cfg.mysql_connect_timeout); mysql_options(&(sdata.mysql), MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&cfg.mysql_connect_timeout);
if(mysql_real_connect(&(sdata.mysql), cfg.mysqlhost, cfg.mysqluser, cfg.mysqlpwd, cfg.mysqldb, cfg.mysqlport, cfg.mysqlsocket, 0) == 0){ if(mysql_real_connect(&(sdata.mysql), cfg.mysqlhost, cfg.mysqluser, cfg.mysqlpwd, cfg.mysqldb, cfg.mysqlport, cfg.mysqlsocket, 0) == 0){
printf("cant connect to mysql server\n"); printf("cant connect to mysql server\n");
return 0; return ERR;
} }
mysql_real_query(&(sdata.mysql), "SET NAMES utf8", strlen("SET NAMES utf8")); mysql_real_query(&(sdata.mysql), "SET NAMES utf8", strlen("SET NAMES utf8"));
@ -245,8 +250,6 @@ int main(int argc, char **argv){
load_rules(&sdata, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE); load_rules(&sdata, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
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(mailbox) rc = import_from_mailbox(mailbox, &sdata, &data, &cfg);
if(directory) rc = import_from_maildir(directory, &sdata, &data, &cfg); if(directory) rc = import_from_maildir(directory, &sdata, &data, &cfg);
@ -259,7 +262,7 @@ int main(int argc, char **argv){
mysql_close(&(sdata.mysql)); mysql_close(&(sdata.mysql));
return 0; return rc;
} }