mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-24 18:40:13 +01:00
added archive only mydomains feature
This commit is contained in:
parent
52a43e5d42
commit
66b8d079d2
@ -60,6 +60,7 @@ struct _parse_rule config_parse_rules[] =
|
||||
{
|
||||
|
||||
{ "archive_emails_not_having_message_id", "integer", (void*) int_parser, offsetof(struct __config, archive_emails_not_having_message_id), "0", sizeof(int)},
|
||||
{ "archive_only_mydomains", "integer", (void*) int_parser, offsetof(struct __config, archive_only_mydomains), "0", sizeof(int)},
|
||||
{ "backlog", "integer", (void*) int_parser, offsetof(struct __config, backlog), "20", sizeof(int)},
|
||||
{ "cipher_list", "string", (void*) string_parser, offsetof(struct __config, cipher_list), "HIGH:MEDIUM", MAXVAL-1},
|
||||
{ "clamd_addr", "string", (void*) string_parser, offsetof(struct __config, clamd_addr), "", MAXVAL-1},
|
||||
|
@ -76,6 +76,8 @@ struct __config {
|
||||
|
||||
int archive_emails_not_having_message_id;
|
||||
|
||||
int archive_only_mydomains;
|
||||
|
||||
int min_word_len;
|
||||
|
||||
int tweak_sent_time_offset;
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#define VERSION "0.1.24-master-branch"
|
||||
|
||||
#define BUILD 819
|
||||
#define BUILD 822
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
@ -116,6 +116,7 @@
|
||||
#define OK 0
|
||||
#define ERR 1
|
||||
#define ERR_EXISTS 2
|
||||
#define ERR_MYDOMAINS 3
|
||||
#define ERR_FOLDER -1
|
||||
|
||||
#define AVIR_OK 0
|
||||
|
@ -246,7 +246,7 @@ struct __data {
|
||||
int folder;
|
||||
char recursive_folder_names;
|
||||
char starttls[TINYBUFSIZE];
|
||||
char mydomains[MAXBUFSIZE];
|
||||
struct list *mydomains;
|
||||
|
||||
#ifdef NEED_MYSQL
|
||||
MYSQL_STMT *stmt_generic;
|
||||
|
24
src/misc.c
24
src/misc.c
@ -412,30 +412,6 @@ int drop_privileges(struct passwd *pwd){
|
||||
}
|
||||
|
||||
|
||||
int is_email_address_on_my_domains(char *email, struct __data *data){
|
||||
int rc=0;
|
||||
char *p, *q=NULL;
|
||||
|
||||
if(email == NULL || data->mydomains[0] == '\0') return rc;
|
||||
|
||||
p = strchr(email, '@');
|
||||
|
||||
if(!p) return rc;
|
||||
|
||||
if(strlen(p) < 3) return rc;
|
||||
|
||||
q = strrchr(p+1, ' ');
|
||||
|
||||
if(q) *q = '\0';
|
||||
|
||||
if(strcasestr(data->mydomains, p+1)) rc = 1;
|
||||
|
||||
if(q) *q = ' ';
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
void init_session_data(struct session_data *sdata, struct __config *cfg){
|
||||
int i;
|
||||
|
||||
|
@ -34,7 +34,6 @@ 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 __data *data);
|
||||
void init_session_data(struct session_data *sdata, struct __config *cfg);
|
||||
int read_from_stdin(struct session_data *sdata);
|
||||
void strtolower(char *s);
|
||||
|
@ -11,10 +11,9 @@
|
||||
|
||||
|
||||
void load_mydomains(struct session_data *sdata, struct __data *data, struct __config *cfg){
|
||||
int clen=0, len=0, size=sizeof(data->mydomains);
|
||||
int rc;
|
||||
char s[SMALLBUFSIZE];
|
||||
|
||||
memset(data->mydomains, 0, size);
|
||||
memset(s, 0, sizeof(s));
|
||||
|
||||
|
||||
@ -34,13 +33,9 @@ void load_mydomains(struct session_data *sdata, struct __data *data, struct __co
|
||||
p_store_results(sdata, data->stmt_generic, data);
|
||||
|
||||
while(p_fetch_results(data->stmt_generic) == OK){
|
||||
len = strlen(s);
|
||||
|
||||
if(clen + len + 1 < size){
|
||||
memcpy(data->mydomains+clen, s, len);
|
||||
clen += len;
|
||||
}
|
||||
else break;
|
||||
rc = append_list(&(data->mydomains), s);
|
||||
if(rc == -1) syslog(LOG_PRIORITY, "failed to append mydomain: '%s'", s);
|
||||
else if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "added mydomain: '%s'", s);
|
||||
|
||||
memset(s, 0, sizeof(s));
|
||||
}
|
||||
@ -49,7 +44,38 @@ void load_mydomains(struct session_data *sdata, struct __data *data, struct __co
|
||||
|
||||
ENDE:
|
||||
close_prepared_statement(data->stmt_generic);
|
||||
|
||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "mydomains: '%s'", data->mydomains);
|
||||
}
|
||||
|
||||
|
||||
int is_email_address_on_my_domains(char *email, struct __data *data){
|
||||
int rc=0;
|
||||
char *q, *s;
|
||||
struct list *p;
|
||||
|
||||
if(email == NULL) return rc;
|
||||
|
||||
q = strchr(email, '@');
|
||||
if(!q || strlen(q) < 3) return rc;
|
||||
|
||||
s = strrchr(q+1, ' ');
|
||||
|
||||
if(s) *s = '\0';
|
||||
|
||||
|
||||
p = data->mydomains;
|
||||
|
||||
while(p != NULL){
|
||||
if(strcasecmp(p->s, q+1) == 0){
|
||||
rc = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
p = p->r;
|
||||
}
|
||||
|
||||
if(s) *s = ' ';
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
@ -231,6 +231,8 @@ void p_clean_exit(){
|
||||
free_rule(data.archiving_rules);
|
||||
free_rule(data.retention_rules);
|
||||
|
||||
free_list(data.mydomains);
|
||||
|
||||
#ifdef HAVE_MULTITENANCY
|
||||
free_list(data.customers);
|
||||
#endif
|
||||
@ -308,6 +310,8 @@ void initialise_configuration(){
|
||||
free_rule(data.archiving_rules);
|
||||
free_rule(data.retention_rules);
|
||||
|
||||
free_list(data.mydomains);
|
||||
|
||||
#ifdef HAVE_MULTITENANCY
|
||||
free_list(data.customers);
|
||||
#endif
|
||||
@ -316,6 +320,8 @@ void initialise_configuration(){
|
||||
data.recursive_folder_names = 0;
|
||||
data.archiving_rules = NULL;
|
||||
data.retention_rules = NULL;
|
||||
data.mydomains = NULL;
|
||||
|
||||
#ifdef HAVE_MULTITENANCY
|
||||
data.customers = NULL;
|
||||
#endif
|
||||
@ -389,6 +395,7 @@ int main(int argc, char **argv){
|
||||
data.recursive_folder_names = 0;
|
||||
data.archiving_rules = NULL;
|
||||
data.retention_rules = NULL;
|
||||
data.mydomains = NULL;
|
||||
#ifdef HAVE_MULTITENANCY
|
||||
data.customers = NULL;
|
||||
#endif
|
||||
|
@ -65,6 +65,8 @@ 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);
|
||||
int is_email_address_on_my_domains(char *email, struct __data *data);
|
||||
|
||||
void load_customers(struct session_data *sdata, struct __data *data, struct __config *cfg);
|
||||
unsigned char get_customer_id_by_rcpt_to_email(char *rcpttoemail, struct __data *data);
|
||||
|
||||
|
@ -399,6 +399,7 @@ int main(int argc, char **argv){
|
||||
data.recursive_folder_names = 0;
|
||||
data.archiving_rules = NULL;
|
||||
data.retention_rules = NULL;
|
||||
data.mydomains = NULL;
|
||||
|
||||
while(1){
|
||||
|
||||
@ -571,6 +572,8 @@ int main(int argc, char **argv){
|
||||
free_rule(data.archiving_rules);
|
||||
free_rule(data.retention_rules);
|
||||
|
||||
free_list(data.mydomains);
|
||||
|
||||
close_database(&sdata);
|
||||
|
||||
if(quiet == 0) printf("\n");
|
||||
|
@ -218,6 +218,7 @@ int main(int argc, char **argv){
|
||||
data.recursive_folder_names = 0;
|
||||
data.archiving_rules = NULL;
|
||||
data.retention_rules = NULL;
|
||||
data.mydomains = NULL;
|
||||
|
||||
if(folder){
|
||||
data.folder = get_folder_id(&sdata, &data, folder, 0);
|
||||
@ -246,6 +247,8 @@ int main(int argc, char **argv){
|
||||
|
||||
printf("put %llu messages to %s table for reindexing\n", n, SQL_SPHINX_TABLE);
|
||||
|
||||
free_list(data.mydomains);
|
||||
|
||||
close_database(&sdata);
|
||||
|
||||
return 0;
|
||||
|
@ -161,6 +161,18 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
|
||||
|
||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: parsed message", sdata.ttmpfile);
|
||||
|
||||
if(cfg->archive_only_mydomains == 1 && sdata.internal_sender == 0 && sdata.internal_recipient == 0){
|
||||
remove_stripped_attachments(&sstate);
|
||||
inj = ERR_MYDOMAINS;
|
||||
|
||||
snprintf(sdata.acceptbuf, SMALLBUFSIZE-1, "250 Ok %s <%s>\r\n", sdata.ttmpfile, rcpttoemail);
|
||||
write1(new_sd, sdata.acceptbuf, strlen(sdata.acceptbuf), sdata.tls, data->ssl);
|
||||
|
||||
syslog(LOG_PRIORITY, "%s: discarding: not on mydomains, from=%s, message-id=%s", sdata.ttmpfile, sdata.fromemail, sstate.message_id);
|
||||
|
||||
goto END_OF_PROCESSING;
|
||||
}
|
||||
|
||||
sdata.need_scan = 1;
|
||||
|
||||
make_digests(&sdata, cfg);
|
||||
@ -194,7 +206,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
|
||||
if(db_conn == 1){
|
||||
|
||||
if(sdata.restored_copy == 1){
|
||||
syslog(LOG_PRIORITY, "%s: discarding restored copy", sdata.ttmpfile);
|
||||
syslog(LOG_PRIORITY, "%s: discarding: restored copy", sdata.ttmpfile);
|
||||
inj = OK;
|
||||
}
|
||||
else if(AVIR_VIRUS == sdata.rav){
|
||||
@ -212,7 +224,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
|
||||
arule = check_againt_ruleset(data->archiving_rules, &sstate, sdata.tot_len, sdata.spam_message);
|
||||
|
||||
if(arule){
|
||||
syslog(LOG_PRIORITY, "%s: discarding message by archiving policy: *%s*", sdata.ttmpfile, arule);
|
||||
syslog(LOG_PRIORITY, "%s: discarding: archiving policy: *%s*", sdata.ttmpfile, arule);
|
||||
inj = OK;
|
||||
counters.c_ignore++;
|
||||
|
||||
@ -242,7 +254,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
|
||||
counters.c_rcvd++;
|
||||
|
||||
if(inj == ERR_EXISTS){
|
||||
syslog(LOG_PRIORITY, "%s: discarding duplicate message", sdata.ttmpfile);
|
||||
syslog(LOG_PRIORITY, "%s: discarding: duplicate message", sdata.ttmpfile);
|
||||
counters.c_duplicate++;
|
||||
}
|
||||
|
||||
@ -258,6 +270,8 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
|
||||
} /* for */
|
||||
#endif
|
||||
|
||||
END_OF_PROCESSING:
|
||||
|
||||
unlink(sdata.ttmpfile);
|
||||
unlink(sdata.tmpframe);
|
||||
|
||||
|
@ -48,6 +48,7 @@ int main(int argc, char **argv){
|
||||
data.recursive_folder_names = 0;
|
||||
data.archiving_rules = NULL;
|
||||
data.retention_rules = NULL;
|
||||
data.mydomains = NULL;
|
||||
|
||||
load_rules(&sdata, &data, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
|
||||
load_rules(&sdata, &data, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
|
||||
@ -96,6 +97,8 @@ int main(int argc, char **argv){
|
||||
free_rule(data.archiving_rules);
|
||||
free_rule(data.retention_rules);
|
||||
|
||||
free_list(data.mydomains);
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user