mirror of
				https://bitbucket.org/jsuto/piler.git
				synced 2025-10-31 05:12:27 +01:00 
			
		
		
		
	added dir import to piler.c
Change-Id: Ic2aa7c259c2c4e420ed25f6b9d07929c1317bef7 Signed-off-by: SJ <sj@acts.hu>
This commit is contained in:
		| @@ -9,8 +9,6 @@ | ||||
| #include "piler-config.h" | ||||
| #include "params.h" | ||||
|  | ||||
| #define PROGNAME "piler" | ||||
|  | ||||
| #define VERSION "1.3.0-master" | ||||
|  | ||||
| #define BUILD 975 | ||||
|   | ||||
| @@ -25,6 +25,7 @@ | ||||
| #include <openssl/err.h> | ||||
| #include <piler.h> | ||||
|  | ||||
| #define PROGNAME "piler-smtp" | ||||
| #define POLL_SIZE 256 | ||||
|  | ||||
| extern char *optarg; | ||||
| @@ -381,7 +382,7 @@ int main(int argc, char **argv){ | ||||
|       } | ||||
|    } | ||||
|  | ||||
|    (void) openlog("piler-poll", LOG_PID, LOG_MAIL); | ||||
|    (void) openlog(PROGNAME, LOG_PID, LOG_MAIL); | ||||
|  | ||||
|    memset(sessions, '\0', sizeof(sessions)); | ||||
|    memset(poll_set, '\0', sizeof(poll_set)); | ||||
| @@ -411,6 +412,8 @@ int main(int argc, char **argv){ | ||||
|  | ||||
|    srand(getpid()); | ||||
|  | ||||
|    syslog(LOG_PRIORITY, "%s %s, build %d starting", PROGNAME, VERSION, get_build()); | ||||
|  | ||||
| #if HAVE_DAEMON == 1 | ||||
|    if(daemonise == 1 && daemon(1, 0) == -1) fatal(ERR_DAEMON); | ||||
| #endif | ||||
|   | ||||
							
								
								
									
										76
									
								
								src/piler.c
									
									
									
									
									
								
							
							
						
						
									
										76
									
								
								src/piler.c
									
									
									
									
									
								
							| @@ -21,12 +21,14 @@ | ||||
| #include <syslog.h> | ||||
| #include <time.h> | ||||
| #include <unistd.h> | ||||
| #include <dirent.h> | ||||
| #include <locale.h> | ||||
| #include <errno.h> | ||||
| #include <openssl/ssl.h> | ||||
| #include <openssl/err.h> | ||||
| #include <piler.h> | ||||
|  | ||||
| #define PROGNAME "piler" | ||||
|  | ||||
| extern char *optarg; | ||||
| extern int optind; | ||||
| @@ -101,10 +103,77 @@ static void child_sighup_handler(int sig){ | ||||
| } | ||||
|  | ||||
|  | ||||
| int process_dir(char *directory, struct session_data *sdata, struct __data *data, struct __config *cfg){ | ||||
|    DIR *dir; | ||||
|    struct dirent *de; | ||||
|    int rc=ERR, tot_msgs=0; | ||||
|    char fname[SMALLBUFSIZE]; | ||||
|    char *status; | ||||
|    struct stat st; | ||||
|    struct timezone tz; | ||||
|    struct timeval tv1, tv2; | ||||
|  | ||||
|    dir = opendir(directory); | ||||
|    if(!dir){ | ||||
|       syslog(LOG_PRIORITY, "cannot open directory: %s", directory); | ||||
|       return tot_msgs; | ||||
|    } | ||||
|  | ||||
|    while((de = readdir(dir))){ | ||||
|       if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; | ||||
|  | ||||
|       snprintf(fname, sizeof(fname)-1, "%s/%s", directory, de->d_name); | ||||
|  | ||||
|       if(stat(fname, &st) == 0){ | ||||
|          if(S_ISREG(st.st_mode)){ | ||||
|  | ||||
|             status = NULL; | ||||
|  | ||||
|             gettimeofday(&tv1, &tz); | ||||
|  | ||||
| 	    // ide kene az import_message fv roviden, es akkor mindent tudna loggolni! | ||||
|             rc = import_message(fname, sdata, data, cfg); | ||||
|             gettimeofday(&tv2, &tz); | ||||
|  | ||||
|             if(rc == OK){ | ||||
|                tot_msgs++; | ||||
|                status = S_STATUS_STORED; | ||||
|             } | ||||
|             else if(rc == ERR_EXISTS){ | ||||
|                tot_msgs++; | ||||
|                status = S_STATUS_DUPLICATE; | ||||
|             } | ||||
|             else { | ||||
|                status = S_STATUS_ERROR; | ||||
|             } | ||||
|  | ||||
|             //Oct 25 20:37:55 f5e88a047257 piler[3236]: 1/40000000580fc29234488f440fdc735c1869: size=172527/128280, delay=36067, status=stored | ||||
|  | ||||
|             syslog(LOG_PRIORITY, "%s: size=%d/%d, delay=%ld, status=%s", fname, sdata->tot_len, sdata->stored_len, tvdiff(tv2, tv1), status); | ||||
|  | ||||
|             /*syslog(LOG_PRIORITY, "%s: from=%s, size=%d/%d, attachments=%d, reference=%s, message-id=%s, retention=%d, folder=%d, %s, status=%s", | ||||
|                                                                                          fname, sdata->fromemail, sdata->tot_len, | ||||
|                                                                                          sdata->stored_len, parser_state->n_attachments, | ||||
|                                                                                          sctx->parser_state->reference, sctx->parser_state->message_id, | ||||
|                                                                                          sctx->parser_state->retention, sctx->data->folder, delay, sctx->status);*/ | ||||
|  | ||||
|             if(rc != ERR) unlink(fname); | ||||
|          } | ||||
|       } | ||||
|       else { | ||||
|          syslog(LOG_PRIORITY, "ERROR: cannot stat: %s", fname); | ||||
|       } | ||||
|    } | ||||
|  | ||||
|    closedir(dir); | ||||
|  | ||||
|    return tot_msgs; | ||||
| } | ||||
|  | ||||
|  | ||||
| static void child_main(struct child *ptr){ | ||||
|    struct import import; | ||||
|    struct session_data sdata; | ||||
|    int tot_msgs = 0; | ||||
|    char dir[TINYBUFSIZE]; | ||||
|  | ||||
|    /* open directory, then process its files, then sleep 2 sec, and repeat */ | ||||
| @@ -130,8 +199,7 @@ static void child_main(struct child *ptr){ | ||||
|       sig_block(SIGHUP); | ||||
|  | ||||
|       if(open_database(&sdata, &cfg) == OK){ | ||||
|          import_from_maildir(dir, &sdata, &data, &tot_msgs, &cfg); | ||||
|          ptr->messages += tot_msgs; | ||||
|          ptr->messages += process_dir(dir, &sdata, &data, &cfg); | ||||
|          close_database(&sdata); | ||||
|  | ||||
|          sleep(2); | ||||
| @@ -287,7 +355,7 @@ void initialise_configuration(){ | ||||
|  | ||||
|    cfg = read_config(configfile); | ||||
|  | ||||
|    if(cfg.number_of_worker_processes < 5) cfg.number_of_worker_processes = 5; | ||||
|    if(cfg.number_of_worker_processes < 2) cfg.number_of_worker_processes = 2; | ||||
|    if(cfg.number_of_worker_processes > MAXCHILDREN) cfg.number_of_worker_processes = MAXCHILDREN; | ||||
|  | ||||
|    if(strlen(cfg.username) > 1){ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user