diff --git a/src/Makefile.in b/src/Makefile.in index 23433df2..e3d4696a 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -94,6 +94,7 @@ install-piler: $(INSTALL) -m 6755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) pilerexport $(DESTDIR)$(bindir) $(INSTALL) -m 6755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) pilerpurge $(DESTDIR)$(bindir) $(INSTALL) -m 6755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) reindex $(DESTDIR)$(bindir) + $(INSTALL) -m 6755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) pilertest $(DESTDIR)$(bindir) clean: rm -f *.o *.a libpiler.so* piler pilerconf pilerget pilergetd pileraget pilerimport pilerexport pilerpurge pilertest reindex diff --git a/src/defs.h b/src/defs.h index 5d0f20be..fefd6aa6 100644 --- a/src/defs.h +++ b/src/defs.h @@ -100,6 +100,7 @@ struct rule { regex_t from; regex_t to; regex_t subject; + regex_t attachment_name; regex_t attachment_type; #endif int spam; diff --git a/src/rules.c b/src/rules.c index 00da7121..e4b73170 100644 --- a/src/rules.c +++ b/src/rules.c @@ -12,7 +12,7 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table){ char s[SMALLBUFSIZE]; - char domain[SMALLBUFSIZE], from[SMALLBUFSIZE], to[SMALLBUFSIZE], subject[SMALLBUFSIZE], _size[SMALLBUFSIZE], attachment_type[SMALLBUFSIZE], _attachment_size[SMALLBUFSIZE]; + char domain[SMALLBUFSIZE], from[SMALLBUFSIZE], to[SMALLBUFSIZE], subject[SMALLBUFSIZE], _size[SMALLBUFSIZE], attachment_name[SMALLBUFSIZE], attachment_type[SMALLBUFSIZE], _attachment_size[SMALLBUFSIZE]; int size=0, attachment_size=0, spam=0, days=0; memset(domain, 0, sizeof(domain)); @@ -20,11 +20,12 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xh memset(to, 0, sizeof(to)); memset(subject, 0, sizeof(subject)); memset(_size, 0, sizeof(_size)); + memset(attachment_name, 0, sizeof(attachment_name)); memset(attachment_type, 0, sizeof(attachment_type)); memset(_attachment_size, 0, sizeof(_attachment_size)); - snprintf(s, sizeof(s)-1, "SELECT `domain`, `from`, `to`, `subject`, `_size`, `size`, `attachment_type`, `_attachment_size`, `attachment_size`, `spam`, `days` FROM `%s`", table); + snprintf(s, sizeof(s)-1, "SELECT `domain`, `from`, `to`, `subject`, `_size`, `size`, `attachment_name`, `attachment_type`, `_attachment_size`, `attachment_size`, `spam`, `days` FROM `%s`", table); if(prepare_sql_statement(sdata, &(data->stmt_generic), s) == ERR) return; @@ -43,6 +44,7 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xh data->sql[data->pos] = &subject[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(subject)-2; data->pos++; data->sql[data->pos] = &_size[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(_size)-2; data->pos++; data->sql[data->pos] = (char *)&size; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(size); data->pos++; + data->sql[data->pos] = &attachment_name[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(attachment_name)-2; data->pos++; data->sql[data->pos] = &attachment_type[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(attachment_type)-2; data->pos++; data->sql[data->pos] = &_attachment_size[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(_attachment_size)-2; data->pos++; data->sql[data->pos] = (char *)&attachment_size; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(attachment_size); data->pos++; @@ -54,13 +56,14 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xh p_store_results(sdata, data->stmt_generic, data); while(p_fetch_results(data->stmt_generic) == OK){ - append_rule(xhash, domain, from, to, subject, _size, size, attachment_type, _attachment_size, attachment_size, spam, days, data); + append_rule(xhash, domain, from, to, subject, _size, size, attachment_name, attachment_type, _attachment_size, attachment_size, spam, days, data); memset(domain, 0, sizeof(domain)); memset(from, 0, sizeof(from)); memset(to, 0, sizeof(to)); memset(subject, 0, sizeof(subject)); memset(_size, 0, sizeof(_size)); + memset(attachment_name, 0, sizeof(attachment_name)); memset(attachment_type, 0, sizeof(attachment_type)); memset(_attachment_size, 0, sizeof(_attachment_size)); @@ -75,7 +78,7 @@ ENDE: } -int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data){ +int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data){ struct node *q, *Q=NULL, *node; struct rule *rule; int rc=0; @@ -85,7 +88,7 @@ int append_rule(struct node *xhash[], char *domain, char *from, char *to, char * memset(node, 0, sizeof(struct node)); node->r = NULL; - rule = create_rule_item(domain, from, to, subject, _size, size, attachment_type, _attachment_size, attachment_size, spam, days, data); + rule = create_rule_item(domain, from, to, subject, _size, size, attachment_name, attachment_type, _attachment_size, attachment_size, spam, days, data); if(rule == NULL){ free(node); @@ -112,7 +115,7 @@ int append_rule(struct node *xhash[], char *domain, char *from, char *to, char * } -struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data){ +struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data){ struct rule *h=NULL; char empty = '\0'; int len; @@ -152,6 +155,8 @@ struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, if(!_size) _size = ∅ snprintf(h->_size, 3, "%s", _size); + if(!attachment_name) attachment_name = ∅ + if(regcomp(&(h->attachment_name), attachment_name, REG_ICASE | REG_EXTENDED)) h->compiled = 0; if(!attachment_type) attachment_type = ∅ if(regcomp(&(h->attachment_type), attachment_type, REG_ICASE | REG_EXTENDED)) h->compiled = 0; @@ -162,12 +167,12 @@ struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, if(!_attachment_size) _attachment_size = ∅ snprintf(h->_attachment_size, 3, "%s", _attachment_size); - len = strlen(domain)+8 + strlen(from)+6 + strlen(to)+4 + strlen(subject)+9 + strlen(_size)+6 + strlen(attachment_type)+10 + strlen(_attachment_size)+10 + 9 + 15 + 15; + len = strlen(domain)+8 + strlen(from)+6 + strlen(to)+4 + strlen(subject)+9 + strlen(_size)+6 + strlen(attachment_name)+10 + strlen(attachment_type)+10 + strlen(_attachment_size)+10 + 9 + 15 + 15; h->rulestr = malloc(len); - if(h->rulestr) snprintf(h->rulestr, len-1, "domain=%s,from=%s,to=%s,subject=%s,size%s%d,att.type=%s,att.size%s%d,spam=%d", domain, from, to, subject, _size, size, attachment_type, _attachment_size, attachment_size, spam); + if(h->rulestr) snprintf(h->rulestr, len-1, "domain=%s,from=%s,to=%s,subject=%s,size%s%d,att.name=%s,att.type=%s,att.size%s%d,spam=%d", domain, from, to, subject, _size, size, attachment_name, attachment_type, _attachment_size, attachment_size, spam); else h->compiled = 0; h->r = NULL; @@ -281,6 +286,7 @@ int check_attachment_rule(struct _state *state, struct rule *rule){ for(i=1; i<=state->n_attachments; i++){ if( + regexec(&(rule->attachment_name), state->attachments[i].filename, nmatch, NULL, 0) == 0 && regexec(&(rule->attachment_type), state->attachments[i].type, nmatch, NULL, 0) == 0 && check_size_rule(state->attachments[i].size, rule->attachment_size, rule->_attachment_size) == 1 ){ @@ -313,6 +319,7 @@ void clearrules(struct node *xhash[]){ regfree(&(rule->from)); regfree(&(rule->to)); + regfree(&(rule->attachment_name)); regfree(&(rule->attachment_type)); free(rule->rulestr); diff --git a/src/rules.h b/src/rules.h index e254b716..8a26cadd 100644 --- a/src/rules.h +++ b/src/rules.h @@ -8,8 +8,8 @@ #include "defs.h" void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table); -int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data); -struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data); +int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data); +struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_name, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days, struct __data *data); char *check_againt_ruleset(struct node *xhash[], struct _state *state, int size, int spam); unsigned long query_retain_period(struct __data *data, struct _state *state, int size, int spam, struct __config *cfg); int check_size_rule(int message_size, int size, char *_size); diff --git a/util/db-mysql.sql b/util/db-mysql.sql index 1d42e1e3..e3ece606 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -109,36 +109,38 @@ create table if not exists `tag` ( create table if not exists `archiving_rule` ( `id` bigint unsigned not null auto_increment, `domain` varchar(128) default null, - `from` char(128) default null, - `to` char(255) default null, - `subject` char(255) default null, + `from` varchar(128) default null, + `to` varchar(128) default null, + `subject` varchar(128) default null, `_size` char(2) default null, `size` int default 0, - `attachment_type` char(128) default null, + `attachment_name` varchar(128) default null, + `attachment_type` varchar(128) default null, `_attachment_size` char(2) default null, `attachment_size` int default 0, `spam` tinyint(1) default -1, `days` int default 0, primary key (`id`), - unique(`from`,`to`,`subject`,`_size`,`size`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`) + unique(`from`,`to`,`subject`,`_size`,`size`,`attachment_name`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`) ) ENGINE=InnoDB; create table if not exists `retention_rule` ( `id` bigint unsigned not null auto_increment, `domain` varchar(128) default null, - `from` char(128) default null, - `to` char(255) default null, - `subject` char(255) default null, + `from` varchar(128) default null, + `to` varchar(128) default null, + `subject` varchar(128) default null, `_size` char(2) default null, `size` int default 0, - `attachment_type` char(128) default null, + `attachment_name` varchar(128) default null, + `attachment_type` varchar(128) default null, `_attachment_size` char(2) default null, `attachment_size` int default 0, `spam` tinyint(1) default -1, `days` int default 0, primary key (`id`), - unique (`domain`,`from`,`to`,`subject`,`_size`,`size`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`) + unique (`domain`,`from`,`to`,`subject`,`_size`,`size`,`attachment_name`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`) ) ENGINE=InnoDB; diff --git a/util/db-upgrade-0.1.24-vs-0.1.25.sql b/util/db-upgrade-0.1.24-vs-0.1.25.sql index 54baf49a..d22de3b4 100644 --- a/util/db-upgrade-0.1.24-vs-0.1.25.sql +++ b/util/db-upgrade-0.1.24-vs-0.1.25.sql @@ -4,4 +4,6 @@ alter table `user_settings` add column `ga_secret` varchar(255) default null; create index metadata_idx9 on metadata(`sent`); +alter table archiving_rule add column `attachment_name` varchar(128) default null; +alter table retention_rule add column `attachment_name` varchar(128) default null; diff --git a/webui/language/de/messages.php b/webui/language/de/messages.php index 425543a9..fef02fb7 100644 --- a/webui/language/de/messages.php +++ b/webui/language/de/messages.php @@ -26,6 +26,7 @@ $_['text_archive_size'] = "Archivgröße"; $_['text_archived_messages'] = "Archivierte Nachrichten"; $_['text_archiving_rules'] = "Archivierungsregeln"; $_['text_attachment'] = "Anhang"; +$_['text_attachment_name'] = "Anhangname"; $_['text_attachment_size'] = "Größe Anhang"; $_['text_attachment_type'] = "Typ Anhang"; $_['text_audit'] = "Revision"; diff --git a/webui/language/en/messages.php b/webui/language/en/messages.php index 262410e5..24cb8024 100644 --- a/webui/language/en/messages.php +++ b/webui/language/en/messages.php @@ -27,6 +27,7 @@ $_['text_archive_size_before_compression'] = "Archive size before compression"; $_['text_archived_messages'] = "Archived messages"; $_['text_archiving_rules'] = "Archiving rules"; $_['text_attachment'] = "Attachment"; +$_['text_attachment_name'] = "Attachment name"; $_['text_attachment_size'] = "Attachment size"; $_['text_attachment_type'] = "Attachment type"; $_['text_audit'] = "Audit"; diff --git a/webui/language/es/messages.php b/webui/language/es/messages.php index 3ffbfa23..88eb6600 100644 --- a/webui/language/es/messages.php +++ b/webui/language/es/messages.php @@ -26,6 +26,7 @@ $_['text_archive_size'] = "Tamaño de archivo"; $_['text_archived_messages'] = "Mensajes archivados"; $_['text_archiving_rules'] = "Reglas de archivado"; $_['text_attachment'] = "Adjunto"; +$_['text_attachment_name'] = "Nombre de adjunto"; $_['text_attachment_size'] = "Tamaño de adjunto"; $_['text_attachment_type'] = "Tipo de adjunto"; $_['text_audit'] = "Auditar"; diff --git a/webui/language/hu/messages.iso-8859-2.php b/webui/language/hu/messages.iso-8859-2.php index b40283c3..5a8aa3bd 100644 --- a/webui/language/hu/messages.iso-8859-2.php +++ b/webui/language/hu/messages.iso-8859-2.php @@ -27,6 +27,7 @@ $_['text_archive_size_before_compression'] = "Arch $_['text_archived_messages'] = "Archivált levelek"; $_['text_archiving_rules'] = "Archiválási szabályok"; $_['text_attachment'] = "Melléklet"; +$_['text_attachment_name'] = "Melléklet név"; $_['text_attachment_size'] = "Melléklet méret"; $_['text_attachment_type'] = "Melléklet típus"; $_['text_audit'] = "Audit"; diff --git a/webui/language/hu/messages.php b/webui/language/hu/messages.php index af956fcc..6c6634b8 100644 --- a/webui/language/hu/messages.php +++ b/webui/language/hu/messages.php @@ -27,6 +27,7 @@ $_['text_archive_size_before_compression'] = "ArchÃvum méret tömörÃtés né $_['text_archived_messages'] = "Archivált levelek"; $_['text_archiving_rules'] = "Archiválási szabályok"; $_['text_attachment'] = "Melléklet"; +$_['text_attachment_name'] = "Melléklet név"; $_['text_attachment_size'] = "Melléklet méret"; $_['text_attachment_type'] = "Melléklet tÃpus"; $_['text_audit'] = "Audit"; diff --git a/webui/language/pt/messages.php b/webui/language/pt/messages.php index d1aa7f83..43de59f0 100644 --- a/webui/language/pt/messages.php +++ b/webui/language/pt/messages.php @@ -25,6 +25,7 @@ $_['text_archive_size'] = "Tamanho do arquivo"; $_['text_archived_messages'] = "Mensagens arquivadas"; $_['text_archiving_rules'] = "Regras de não arquivamento"; $_['text_attachment'] = "Anexo"; +$_['text_attachment_name'] = "Nome do anexo"; $_['text_attachment_size'] = "Tamanho do anexo"; $_['text_attachment_type'] = "Tipo de anexo"; $_['text_audit'] = "Auditoria"; diff --git a/webui/model/policy/archiving.php b/webui/model/policy/archiving.php index c957638b..5370d1fa 100644 --- a/webui/model/policy/archiving.php +++ b/webui/model/policy/archiving.php @@ -26,7 +26,7 @@ class ModelPolicyArchiving extends Model { public function add_new_rule($data = array()) { - $query = $this->db->query("INSERT INTO " . TABLE_ARCHIVING_RULE . " (`from`,`to`,`subject`,`_size`,`size`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`) VALUES(?,?,?,?,?,?,?,?,?)", array($data['from'], $data['to'], $data['subject'], $data['_size'], $data['size'], $data['attachment_type'], $data['_attachment_size'], $data['attachment_size'], $data['spam'])); + $query = $this->db->query("INSERT INTO " . TABLE_ARCHIVING_RULE . " (`from`,`to`,`subject`,`_size`,`size`,`attachment_name`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`) VALUES(?,?,?,?,?,?,?,?,?,?)", array($data['from'], $data['to'], $data['subject'], $data['_size'], $data['size'], $data['attachment_name'], $data['attachment_type'], $data['_attachment_size'], $data['attachment_size'], $data['spam'])); return $this->db->countAffected(); } diff --git a/webui/model/policy/retention.php b/webui/model/policy/retention.php index 97c007be..eaaae958 100644 --- a/webui/model/policy/retention.php +++ b/webui/model/policy/retention.php @@ -30,7 +30,7 @@ class ModelPolicyRetention extends Model { if(isset($data['domain'])) { $domain = $data['domain']; } - $query = $this->db->query("INSERT INTO " . TABLE_RETENTION_RULE . " (`domain`,`from`,`to`,`subject`,`_size`,`size`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`,`days`) VALUES(?,?,?,?,?,?,?,?,?,?,?)", array($domain, $data['from'], $data['to'], $data['subject'], $data['_size'], $data['size'], $data['attachment_type'], $data['_attachment_size'], $data['attachment_size'], $data['spam'], $data['days']) ); + $query = $this->db->query("INSERT INTO " . TABLE_RETENTION_RULE . " (`domain`,`from`,`to`,`subject`,`_size`,`size`,`attachment_name`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`,`days`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)", array($domain, $data['from'], $data['to'], $data['subject'], $data['_size'], $data['size'], $data['attachment_name'], $data['attachment_type'], $data['_attachment_size'], $data['attachment_size'], $data['spam'], $data['days']) ); return $this->db->countAffected(); } diff --git a/webui/view/theme/default/templates/policy/archiving.tpl b/webui/view/theme/default/templates/policy/archiving.tpl index 66977954..02b96503 100644 --- a/webui/view/theme/default/templates/policy/archiving.tpl +++ b/webui/view/theme/default/templates/policy/archiving.tpl @@ -36,7 +36,13 @@ - + +