piler/src/test.c

132 lines
3.3 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;
2013-09-11 09:19:29 +02:00
srand(getpid());
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;
}
2013-07-31 09:10:26 +02:00
(void) openlog("test", LOG_PID, LOG_MAIL);
2011-11-14 15:57:52 +01:00
cfg = read_config(CONFIG_FILE);
2013-04-28 14:18:09 +02:00
if(open_database(&sdata, &cfg) == ERR) return 0;
2011-12-13 17:05:22 +01:00
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;
2011-11-19 21:25:44 +01:00
inithash(data.mydomains);
initrules(data.archiving_rules);
initrules(data.retention_rules);
2011-11-19 21:25:44 +01:00
2013-01-06 22:16:21 +01:00
load_mydomains(&sdata, &data, &cfg);
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE);
load_rules(&sdata, &data, data.retention_rules, SQL_RETENTION_RULE_TABLE);
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;
2014-02-12 14:58:40 +01:00
sdata.import = 1;
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-03-24 01:20:12 +01:00
printf("parsing...\n");
2013-01-06 22:16:21 +01:00
state = parse_message(&sdata, 1, &data, &cfg);
2013-03-24 01:20:12 +01:00
printf("post parsing...\n");
post_parse(&sdata, &state, &cfg);
2011-11-14 15:57:52 +01:00
2014-04-25 21:17:01 +02:00
printf("message-id: %s / %s\n", state.message_id, state.message_id_hash);
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
2013-07-31 09:10:26 +02:00
sdata.retained = sdata.now + query_retain_period(&data, &state, st.st_size, sdata.spam_message, &cfg);
2012-02-19 22:59:47 +01:00
printf("retention period: %ld\n", sdata.retained);
clearrules(data.archiving_rules);
clearrules(data.retention_rules);
2011-11-14 15:57:52 +01:00
clearhash(data.mydomains);
2013-07-12 22:54:45 +02: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);
2013-08-03 12:57:35 +02:00
if(sdata.internal_sender == 0 && sdata.internal_recipient == 0) printf("NOT IN mydomains\n");
2011-11-16 14:47:47 +01:00
printf("\n\n");
2011-11-14 15:57:52 +01:00
2013-04-28 14:18:09 +02:00
close_database(&sdata);
2011-12-13 17:05:22 +01:00
2011-11-14 15:57:52 +01:00
return 0;
}
2011-12-13 17:05:22 +01:00