piler/src/test.c

92 lines
2.2 KiB
C
Raw Normal View History

2011-11-14 15:57:52 +01:00
/*
* test.c, SJ
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
2011-11-16 14:47:47 +01:00
#include <sys/stat.h>
#include <unistd.h>
2011-11-14 15:57:52 +01:00
#include <time.h>
#include <locale.h>
#include <piler.h>
int main(int argc, char **argv){
2011-11-22 12:31:54 +01:00
int i, rc;
2011-11-16 14:47:47 +01:00
struct stat st;
2011-11-14 15:57:52 +01:00
struct session_data sdata;
struct _state state;
struct __config cfg;
2011-11-19 21:25:44 +01:00
struct __data data;
char *rule;
2011-11-14 15:57:52 +01:00
if(argc < 2){
fprintf(stderr, "usage: %s <message>\n", argv[0]);
exit(1);
}
if(stat(argv[1], &st) != 0){
fprintf(stderr, "%s is not found\n", argv[1]);
return 0;
}
cfg = read_config(CONFIG_FILE);
2011-11-19 21:25:44 +01:00
mysql_init(&(sdata.mysql));
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){
printf("cant connect to mysql server\n");
return 0;
}
2011-11-14 15:57:52 +01:00
printf("locale: %s\n", setlocale(LC_MESSAGES, cfg.locale));
setlocale(LC_CTYPE, cfg.locale);
2011-11-19 21:25:44 +01:00
data.rules = NULL;
load_archiving_rules(&sdata, &(data.rules));
2011-11-14 15:57:52 +01:00
rc = 0;
2011-11-16 14:47:47 +01:00
2011-11-14 15:57:52 +01:00
sdata.num_of_rcpt_to = -1;
time(&(sdata.now));
sdata.sent = 0;
2011-11-16 14:47:47 +01:00
sdata.tot_len = st.st_size;
2011-11-14 15:57:52 +01:00
memset(sdata.rcptto[0], 0, SMALLBUFSIZE);
snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", argv[1]);
2011-11-19 21:25:44 +01:00
snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", argv[1]);
2011-11-14 15:57:52 +01:00
2011-11-22 12:31:54 +01:00
2011-11-16 14:47:47 +01:00
state = parse_message(&sdata, &cfg);
2011-11-14 15:57:52 +01:00
printf("message-id: %s\n", state.message_id);
2011-11-16 14:47:47 +01:00
printf("from: *%s*\n", state.b_from);
printf("to: *%s*\n", state.b_to);
printf("subject: *%s*\n", state.b_subject);
2011-11-19 21:25:44 +01:00
//printf("body: *%s*\n", state.b_body);
2011-11-14 15:57:52 +01:00
2011-11-16 14:47:47 +01:00
make_body_digest(&sdata, &cfg);
2011-11-23 12:24:21 +01:00
rule = check_againt_ruleset(data.rules, &state, st.st_size);
2011-11-19 21:25:44 +01:00
2011-11-22 12:31:54 +01:00
//printf("body digest: %s\n", sdata.bodydigest);
2011-11-14 15:57:52 +01:00
2011-11-23 12:24:21 +01:00
printf("rules check: %s\n", rule);
2011-11-19 21:25:44 +01:00
mysql_close(&(sdata.mysql));
free_rule(data.rules);
2011-11-14 15:57:52 +01:00
2011-11-22 12:31:54 +01:00
for(i=1; i<=state.n_attachments; i++){
printf("i:%d, name=*%s*, type: *%s*, size: %d, int.name: %s, digest: %s\n", i, state.attachments[i].filename, state.attachments[i].type, state.attachments[i].size, state.attachments[i].internalname, state.attachments[i].digest);
}
2011-11-16 14:47:47 +01:00
printf("\n\n");
2011-11-14 15:57:52 +01:00
return 0;
}