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);
|
|
|
|
|
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);
|
|
|
|
|
2012-08-19 23:20:33 +02:00
|
|
|
printf("build: %d\n", get_build());
|
|
|
|
|
2012-08-23 10:23:58 +02:00
|
|
|
data.folder = 0;
|
2012-09-03 17:12:02 +02:00
|
|
|
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
|
|
|
|
2013-05-05 11:57:14 +02:00
|
|
|
load_rules(&sdata, &data, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
|
|
|
|
load_rules(&sdata, &data, &(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);
|
|
|
|
|
2013-02-22 15:01:21 +01:00
|
|
|
init_session_data(&sdata, &cfg);
|
2011-11-16 14:47:47 +01:00
|
|
|
|
2011-11-14 15:57:52 +01:00
|
|
|
sdata.sent = 0;
|
2012-12-03 14:21:55 +01:00
|
|
|
sdata.delivered = 0;
|
2011-11-16 14:47:47 +01:00
|
|
|
sdata.tot_len = st.st_size;
|
2012-01-03 00:19:43 +01:00
|
|
|
|
2011-11-14 15:57:52 +01:00
|
|
|
snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", argv[1]);
|
2012-01-03 00:19:43 +01:00
|
|
|
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");
|
2012-01-03 00:19:43 +01:00
|
|
|
post_parse(&sdata, &state, &cfg);
|
2011-11-14 15:57:52 +01:00
|
|
|
|
|
|
|
printf("message-id: %s\n", state.message_id);
|
2012-01-14 09:53:26 +01:00
|
|
|
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);
|
2012-09-09 23:16:09 +02:00
|
|
|
printf("body: *%s*\n", state.b_body);
|
2011-11-14 15:57:52 +01:00
|
|
|
|
2012-12-03 14:21:55 +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);
|
2012-09-09 23:16:09 +02:00
|
|
|
unlink(state.attachments[i].internalname);
|
2011-11-22 12:31:54 +01:00
|
|
|
}
|
|
|
|
|
2012-09-09 23:16:09 +02: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
|
|
|
|
2012-01-03 00:19:43 +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
|
|
|
|
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
|
|
|
|
|
|
|
|