piler/src/test.c

125 lines
3.4 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 <unistd.h>
2011-11-14 15:57:52 +01:00
#include <time.h>
#include <locale.h>
2011-12-13 17:05:22 +01:00
#include <syslog.h>
2011-11-14 15:57:52 +01:00
#include <piler.h>
int main(int argc, char **argv){
2012-11-03 23:42:36 +01:00
int i;
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-12-13 17:05:22 +01:00
mysql_real_query(&(sdata.mysql), "SET NAMES utf8", strlen("SET NAMES utf8"));
mysql_real_query(&(sdata.mysql), "SET CHARACTER SET utf8", strlen("SET CHARACTER SET utf8"));
2011-11-14 15:57:52 +01:00
printf("locale: %s\n", setlocale(LC_MESSAGES, cfg.locale));
setlocale(LC_CTYPE, cfg.locale);
printf("build: %d\n", get_build());
data.folder = 0;
data.recursive_folder_names = 0;
2012-02-19 22:59:47 +01:00
data.archiving_rules = NULL;
data.retention_rules = NULL;
2011-11-19 21:25:44 +01:00
2012-02-19 22:59:47 +01:00
load_rules(&sdata, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
load_rules(&sdata, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
2011-11-19 21:25:44 +01:00
2013-01-06 22:16:21 +01:00
load_mydomains(&sdata, &data, &cfg);
init_session_data(&sdata, &cfg);
2011-11-16 14:47:47 +01:00
2011-11-14 15:57:52 +01:00
sdata.sent = 0;
sdata.delivered = 0;
2011-11-16 14:47:47 +01:00
sdata.tot_len = st.st_size;
2011-11-14 15:57:52 +01:00
snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", argv[1]);
snprintf(sdata.filename, 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
2013-01-06 22:16:21 +01:00
state = parse_message(&sdata, 1, &data, &cfg);
post_parse(&sdata, &state, &cfg);
2011-11-14 15:57:52 +01:00
printf("message-id: %s\n", state.message_id);
printf("from: *%s (%s)*\n", state.b_from, state.b_from_domain);
printf("to: *%s (%s)*\n", state.b_to, state.b_to_domain);
2012-02-08 23:14:28 +01:00
printf("reference: *%s*\n", state.reference);
2011-11-16 14:47:47 +01:00
printf("subject: *%s*\n", state.b_subject);
printf("body: *%s*\n", state.b_body);
2011-11-14 15:57:52 +01:00
printf("sent: %ld, delivered-date: %ld\n", sdata.sent, sdata.delivered);
2012-01-07 00:00:36 +01:00
2011-12-29 12:11:28 +01:00
make_digests(&sdata, &cfg);
2011-12-13 17:05:22 +01:00
printf("hdr len: %d\n", sdata.hdr_len);
2012-02-19 22:59:47 +01:00
rule = check_againt_ruleset(data.archiving_rules, &state, st.st_size, sdata.spam_message);
2011-11-19 21:25:44 +01:00
2011-12-13 17:05:22 +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
2012-02-19 22:59:47 +01:00
sdata.retained = sdata.now + query_retain_period(data.retention_rules, &state, st.st_size, sdata.spam_message, &cfg);
printf("retention period: %ld\n", sdata.retained);
free_rule(data.archiving_rules);
free_rule(data.retention_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);
unlink(state.attachments[i].internalname);
2011-11-22 12:31:54 +01:00
}
unlink(sdata.tmpframe);
2011-12-30 15:52:59 +01:00
printf("attachments:%s\n", sdata.attachments);
2011-12-13 17:05:22 +01:00
printf("direction: %d\n", sdata.direction);
2012-01-26 14:35:51 +01:00
printf("spam: %d\n", sdata.spam_message);
2011-11-16 14:47:47 +01:00
printf("\n\n");
2011-11-14 15:57:52 +01:00
2011-12-13 17:05:22 +01:00
mysql_close(&(sdata.mysql));
2011-11-14 15:57:52 +01:00
return 0;
}
2011-12-13 17:05:22 +01:00