mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 23:41:59 +01:00
eliminated the mydomains piler.conf
This commit is contained in:
parent
1d2ac1c117
commit
be259f56bd
2
configure
vendored
2
configure
vendored
@ -4595,7 +4595,7 @@ echo; echo
|
||||
|
||||
CFLAGS="$static -O2 -Wall -g"
|
||||
LIBS="$antispam_libs $sunos_libs "
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o $objs"
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o $objs"
|
||||
|
||||
ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile"
|
||||
|
||||
|
@ -394,7 +394,7 @@ echo; echo
|
||||
|
||||
CFLAGS="$static -O2 -Wall -g"
|
||||
LIBS="$antispam_libs $sunos_libs "
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o $objs"
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o $objs"
|
||||
|
||||
AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile])
|
||||
AC_OUTPUT
|
||||
|
@ -95,11 +95,6 @@ archive_emails_not_having_message_id=0
|
||||
; minimum word length in mail body to index
|
||||
min_word_len=1
|
||||
|
||||
; comma separated list of your domains. piler uses this information to determine
|
||||
; the direction of the given email
|
||||
mydomains=
|
||||
|
||||
|
||||
; if piler detects this line in the mail header, then it will assume
|
||||
; the message is a spam. You should include your own antispam solution's
|
||||
; specific line.
|
||||
|
@ -78,7 +78,6 @@ struct _parse_rule config_parse_rules[] =
|
||||
{ "memcached_to_db_interval", "integer", (void*) int_parser, offsetof(struct __config, memcached_to_db_interval), "900", sizeof(int)},
|
||||
{ "memcached_ttl", "integer", (void*) int_parser, offsetof(struct __config, memcached_ttl), "86400", sizeof(int)},
|
||||
{ "min_word_len", "integer", (void*) int_parser, offsetof(struct __config, min_word_len), "1", sizeof(int)},
|
||||
{ "mydomains", "string", (void*) string_parser, offsetof(struct __config, mydomains), "", MAXVAL-1},
|
||||
{ "mysqlhost", "string", (void*) string_parser, offsetof(struct __config, mysqlhost), "", MAXVAL-1},
|
||||
{ "mysqlport", "integer", (void*) int_parser, offsetof(struct __config, mysqlport), "", sizeof(int)},
|
||||
{ "mysqlsocket", "string", (void*) string_parser, offsetof(struct __config, mysqlsocket), "/tmp/mysql.sock", MAXVAL-1},
|
||||
|
@ -49,8 +49,6 @@ struct __config {
|
||||
unsigned char key[KEYLEN];
|
||||
unsigned char iv[MAXVAL];
|
||||
|
||||
char mydomains[MAXVAL];
|
||||
|
||||
char spam_header_line[MAXVAL];
|
||||
|
||||
int default_retention_days;
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#define VERSION "0.1.23-master-branch"
|
||||
|
||||
#define BUILD 744
|
||||
#define BUILD 748
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
@ -83,6 +83,7 @@
|
||||
#define SQL_RETENTION_RULE_TABLE "retention_rule"
|
||||
#define SQL_COUNTER_TABLE "counter"
|
||||
#define SQL_OPTION_TABLE "option"
|
||||
#define SQL_DOMAIN_TABLE "domain"
|
||||
#define SQL_MESSAGES_VIEW "v_messages"
|
||||
#define SQL_ATTACHMENTS_VIEW "v_attachment"
|
||||
|
||||
|
@ -244,6 +244,7 @@ struct __data {
|
||||
int folder;
|
||||
char recursive_folder_names;
|
||||
char starttls[TINYBUFSIZE];
|
||||
char mydomains[MAXBUFSIZE];
|
||||
|
||||
#ifdef HAVE_TRE
|
||||
struct rule *archiving_rules;
|
||||
|
@ -69,7 +69,7 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
||||
sdata->sent = 0;
|
||||
sdata->delivered = 0;
|
||||
|
||||
state = parse_message(sdata, 1, cfg);
|
||||
state = parse_message(sdata, 1, data, cfg);
|
||||
post_parse(sdata, &state, cfg);
|
||||
|
||||
if(sdata->sent <= 0 && sdata->delivered > 0) sdata->sent = sdata->delivered;
|
||||
|
@ -425,11 +425,11 @@ int drop_privileges(struct passwd *pwd){
|
||||
}
|
||||
|
||||
|
||||
int is_email_address_on_my_domains(char *email, struct __config *cfg){
|
||||
int is_email_address_on_my_domains(char *email, struct __data *data){
|
||||
int rc=0;
|
||||
char *p, *q=NULL;
|
||||
|
||||
if(email == NULL || cfg->mydomains == NULL) return rc;
|
||||
if(email == NULL || data->mydomains[0] == '\0') return rc;
|
||||
|
||||
p = strchr(email, '@');
|
||||
|
||||
@ -441,7 +441,7 @@ int is_email_address_on_my_domains(char *email, struct __config *cfg){
|
||||
|
||||
if(q) *q = '\0';
|
||||
|
||||
if(strcasestr(cfg->mydomains, p+1)) rc = 1;
|
||||
if(strcasestr(data->mydomains, p+1)) rc = 1;
|
||||
|
||||
if(q) *q = ' ';
|
||||
|
||||
|
@ -34,7 +34,7 @@ int recvtimeoutssl(int s, char *buf, int len, int timeout, int use_ssl, SSL *ssl
|
||||
void write_pid_file(char *pidfile);
|
||||
int drop_privileges(struct passwd *pwd);
|
||||
|
||||
int is_email_address_on_my_domains(char *email, struct __config *cfg);
|
||||
int is_email_address_on_my_domains(char *email, struct __data *data);
|
||||
void init_session_data(struct session_data *sdata, unsigned char server_id);
|
||||
int read_from_stdin(struct session_data *sdata);
|
||||
void strtolower(char *s);
|
||||
|
44
src/mydomains.c
Normal file
44
src/mydomains.c
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* mydomains.c, SJ
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <piler.h>
|
||||
|
||||
|
||||
void load_mydomains(struct session_data *sdata, struct __data *data, struct __config *cfg){
|
||||
int clen=0, len=0, size=sizeof(data->mydomains);
|
||||
char s[SMALLBUFSIZE];
|
||||
MYSQL_RES *res;
|
||||
MYSQL_ROW row;
|
||||
|
||||
memset(data->mydomains, 0, size);
|
||||
|
||||
snprintf(s, sizeof(s)-1, "SELECT `domain` FROM `%s`", SQL_DOMAIN_TABLE);
|
||||
|
||||
if(mysql_real_query(&(sdata->mysql), s, strlen(s)) == 0){
|
||||
res = mysql_store_result(&(sdata->mysql));
|
||||
if(res != NULL){
|
||||
while((row = mysql_fetch_row(res))){
|
||||
snprintf(s, sizeof(s)-1, "%s,", (char*)row[0]);
|
||||
len = strlen(s);
|
||||
|
||||
if(clen + len + 1 < size){
|
||||
memcpy(data->mydomains+clen, s, len);
|
||||
clen += len;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
mysql_free_result(res);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "mydomains: '%s'", data->mydomains);
|
||||
}
|
||||
|
10
src/parser.c
10
src/parser.c
@ -16,7 +16,7 @@
|
||||
#include <piler.h>
|
||||
|
||||
|
||||
struct _state parse_message(struct session_data *sdata, int take_into_pieces, struct __config *cfg){
|
||||
struct _state parse_message(struct session_data *sdata, int take_into_pieces, struct __data *data, struct __config *cfg){
|
||||
FILE *f;
|
||||
int i, len;
|
||||
char *p, buf[MAXBUFSIZE], puf[SMALLBUFSIZE];
|
||||
@ -80,7 +80,7 @@ struct _state parse_message(struct session_data *sdata, int take_into_pieces, st
|
||||
}
|
||||
|
||||
while(fgets(buf, sizeof(buf)-1, f)){
|
||||
parse_line(buf, &state, sdata, take_into_pieces, &writebuffer[0], sizeof(writebuffer), &abuffer[0], sizeof(abuffer), cfg);
|
||||
parse_line(buf, &state, sdata, take_into_pieces, &writebuffer[0], sizeof(writebuffer), &abuffer[0], sizeof(abuffer), data, cfg);
|
||||
}
|
||||
|
||||
if(take_into_pieces == 1 && state.writebufpos > 0){
|
||||
@ -174,7 +174,7 @@ void storno_attachment(struct _state *state){
|
||||
}
|
||||
|
||||
|
||||
int parse_line(char *buf, struct _state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __config *cfg){
|
||||
int parse_line(char *buf, struct _state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __data *data, struct __config *cfg){
|
||||
char *p, *q, puf[SMALLBUFSIZE];
|
||||
unsigned char b64buffer[MAXBUFSIZE];
|
||||
int t, n64, len, writelen, boundary_line=0;
|
||||
@ -618,7 +618,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
||||
}
|
||||
}
|
||||
|
||||
if(is_email_address_on_my_domains(puf, cfg) == 1) sdata->internal_sender = 1;
|
||||
if(is_email_address_on_my_domains(puf, data) == 1) sdata->internal_sender = 1;
|
||||
|
||||
if(strlen(state->b_from) < SMALLBUFSIZE-len-1){
|
||||
split_email_address(puf);
|
||||
@ -643,7 +643,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
||||
state->tolen += len;
|
||||
|
||||
if(does_it_seem_like_an_email_address(puf) == 1){
|
||||
if(is_email_address_on_my_domains(puf, cfg) == 1) sdata->internal_recipient = 1;
|
||||
if(is_email_address_on_my_domains(puf, data) == 1) sdata->internal_recipient = 1;
|
||||
else sdata->external_recipient = 1;
|
||||
|
||||
q = strchr(puf, '@');
|
||||
|
@ -9,9 +9,9 @@
|
||||
#include "config.h"
|
||||
#include "defs.h"
|
||||
|
||||
struct _state parse_message(struct session_data *sdata, int take_into_pieces, struct __config *cfg);
|
||||
struct _state parse_message(struct session_data *sdata, int take_into_pieces, struct __data *data, struct __config *cfg);
|
||||
void post_parse(struct session_data *sdata, struct _state *state, struct __config *cfg);
|
||||
int parse_line(char *buf, struct _state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __config *cfg);
|
||||
int parse_line(char *buf, struct _state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __data *data, struct __config *cfg);
|
||||
|
||||
void init_state(struct _state *state);
|
||||
unsigned long parse_date_header(char *s);
|
||||
|
@ -323,11 +323,11 @@ void initialise_configuration(){
|
||||
data.archiving_rules = NULL;
|
||||
data.retention_rules = NULL;
|
||||
|
||||
memset(data.starttls, 0, TINYBUFSIZE);
|
||||
memset(data.starttls, 0, sizeof(data.starttls));
|
||||
|
||||
#ifdef HAVE_STARTTLS
|
||||
if(cfg.tls_enable > 0 && data.ctx == NULL && init_ssl() == OK){
|
||||
snprintf(data.starttls, TINYBUFSIZE-1, "250-STARTTLS\r\n");
|
||||
snprintf(data.starttls, sizeof(data.starttls)-1, "250-STARTTLS\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -341,6 +341,8 @@ void initialise_configuration(){
|
||||
load_rules(&sdata, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
|
||||
load_rules(&sdata, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
|
||||
|
||||
load_mydomains(&sdata, &data, &cfg);
|
||||
|
||||
mysql_close(&(sdata.mysql));
|
||||
|
||||
|
||||
|
@ -62,5 +62,7 @@ void extract_attachment_content(struct session_data *sdata, struct _state *state
|
||||
|
||||
int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *dest, struct __config *cfg);
|
||||
|
||||
void load_mydomains(struct session_data *sdata, struct __data *data, struct __config *cfg);
|
||||
|
||||
#endif /* _PILER_H */
|
||||
|
||||
|
@ -504,6 +504,8 @@ int main(int argc, char **argv){
|
||||
load_rules(&sdata, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
|
||||
load_rules(&sdata, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
|
||||
|
||||
load_mydomains(&sdata, &data, &cfg);
|
||||
|
||||
if(emlfile) rc = import_message(emlfile, &sdata, &data, &cfg);
|
||||
|
||||
if(mbox[0]){
|
||||
|
@ -106,7 +106,7 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct __data *
|
||||
|
||||
snprintf(sdata->filename, SMALLBUFSIZE-1, "%s", filename);
|
||||
|
||||
state = parse_message(sdata, 0, cfg);
|
||||
state = parse_message(sdata, 0, data, cfg);
|
||||
post_parse(sdata, &state, cfg);
|
||||
|
||||
sdata->now = strtoul(row[2], NULL, 10);
|
||||
@ -224,6 +224,7 @@ int main(int argc, char **argv){
|
||||
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"));
|
||||
|
||||
load_mydomains(&sdata, &data, &cfg);
|
||||
|
||||
if(all == 1){
|
||||
from_id = 1;
|
||||
|
@ -155,7 +155,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
|
||||
|
||||
gettimeofday(&tv1, &tz);
|
||||
|
||||
sstate = parse_message(&sdata, 1, cfg);
|
||||
sstate = parse_message(&sdata, 1, data, cfg);
|
||||
post_parse(&sdata, &sstate, cfg);
|
||||
|
||||
gettimeofday(&tv2, &tz);
|
||||
|
@ -60,6 +60,8 @@ int main(int argc, char **argv){
|
||||
load_rules(&sdata, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
|
||||
load_rules(&sdata, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
|
||||
|
||||
load_mydomains(&sdata, &data, &cfg);
|
||||
|
||||
init_session_data(&sdata, cfg.server_id);
|
||||
|
||||
sdata.sent = 0;
|
||||
@ -70,7 +72,7 @@ int main(int argc, char **argv){
|
||||
snprintf(sdata.filename, SMALLBUFSIZE-1, "%s", argv[1]);
|
||||
snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", argv[1]);
|
||||
|
||||
state = parse_message(&sdata, 1, &cfg);
|
||||
state = parse_message(&sdata, 1, &data, &cfg);
|
||||
post_parse(&sdata, &state, &cfg);
|
||||
|
||||
printf("message-id: %s\n", state.message_id);
|
||||
|
@ -16,6 +16,7 @@ int main(int argc, char **argv){
|
||||
struct stat st;
|
||||
struct session_data sdata;
|
||||
struct _state state;
|
||||
struct __data data;
|
||||
struct __config cfg;
|
||||
|
||||
|
||||
@ -44,7 +45,7 @@ int main(int argc, char **argv){
|
||||
|
||||
cfg.debug = 1;
|
||||
|
||||
state = parse_message(&sdata, 0, &cfg);
|
||||
state = parse_message(&sdata, 0, &data, &cfg);
|
||||
post_parse(&sdata, &state, &cfg);
|
||||
|
||||
printf("message-id: %s\n", state.message_id);
|
||||
|
@ -67,7 +67,7 @@ int parse_it(char *filename, struct session_data *sdata, struct __data *data, st
|
||||
|
||||
sdata->sent = 0;
|
||||
|
||||
state = parse_message(sdata, 1, cfg);
|
||||
state = parse_message(sdata, 1, data, cfg);
|
||||
post_parse(sdata, &state, cfg);
|
||||
|
||||
unlink(sdata->tmpframe);
|
||||
@ -425,6 +425,8 @@ int main(int argc, char **argv){
|
||||
load_rules(&sdata, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
|
||||
load_rules(&sdata, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
|
||||
|
||||
load_mydomains(&sdata, &data, &cfg);
|
||||
|
||||
if(emlfile) rc = import_message(emlfile, &sdata, &data, &cfg);
|
||||
if(mbox[0]){
|
||||
for(i=0; i<n_mbox; i++){
|
||||
|
Loading…
Reference in New Issue
Block a user