Группа :: Система/Серверы
Пакет: dbmail
Главная Изменения Спек Патчи Загрузить Bugs and FR
Патч: dbmail-2.0.7-mailfilter.patch
--- ./pipe.c.orig 2005-08-19 18:30:42 +0400
+++ ./pipe.c 2005-09-20 13:04:08 +0400
@@ -574,8 +574,9 @@
trace(TRACE_DEBUG,
"%s, %s: calling sort_and_deliver for useridnr [%llu]",
__FILE__, __func__, useridnr);
-
- dsn_result = sort_and_deliver(tmpmsgidnr, msgsize, useridnr, delivery->mailbox);
+
+ dsn_result = sort_and_deliver(tmpmsgidnr, msgsize, useridnr,
+ db_get_mailbox_from_filters(useridnr, headerfields, delivery->mailbox));
switch (dsn_result) {
case DSN_CLASS_OK:
--- ./sql/mysql/create_tables.mysql.orig 2005-08-19 18:30:42 +0400
+++ ./sql/mysql/create_tables.mysql 2005-09-20 15:16:54 +0400
@@ -61,6 +61,20 @@
UNIQUE INDEX owner_idnr_name_index (owner_idnr, name)
);
+DROP TABLE IF EXISTS dbmail_filters;
+CREATE TABLE dbmail_filters (
+ user_id bigint(21) not null default '0',
+ filter_id bigint(21) not null default '0',
+ filter_field varchar(128) NOT NULL default '',
+ filter_value varchar(255) NOT NULL default '',
+ mailbox varchar(100) NOT NULL default '',
+ index user_id_index (user_id),
+ index filter_id_index (filter_id),
+ PRIMARY KEY (user_id, filter_id),
+ FOREIGN KEY user_id_fk (user_id)
+ REFERENCES dbmail_users (user_idnr) ON DELETE CASCADE ON UPDATE CASCADE
+);
+
DROP TABLE IF EXISTS dbmail_subscription;
CREATE TABLE dbmail_subscription (
user_id bigint(21) NOT NULL,
--- ./sql/mysql/create_tables_innoDB.mysql.orig 2005-09-05 18:52:57 +0400
+++ ./sql/mysql/create_tables_innoDB.mysql 2005-09-20 15:17:16 +0400
@@ -73,6 +73,20 @@
REFERENCES dbmail_users (user_idnr) ON DELETE CASCADE ON UPDATE CASCADE
) TYPE=InnoDB;
+DROP TABLE IF EXISTS dbmail_filters;
+CREATE TABLE dbmail_filters (
+ user_id bigint(21) not null default '0',
+ filter_id bigint(21) not null default '0',
+ filter_field varchar(128) NOT NULL default '',
+ filter_value varchar(255) NOT NULL default '',
+ mailbox varchar(100) NOT NULL default '',
+ index user_id_index (user_id),
+ index filter_id_index (filter_id),
+ PRIMARY KEY (user_id, filter_id),
+ FOREIGN KEY user_id_fk (user_id)
+ REFERENCES dbmail_users (user_idnr) ON DELETE CASCADE ON UPDATE CASCADE
+) TYPE=InnoDB;
+
DROP TABLE IF EXISTS dbmail_subscription;
CREATE TABLE dbmail_subscription (
user_id bigint(21) not null default '0',
--- ./sql/postgresql/create_tables.pgsql.orig 2005-09-05 18:52:57 +0400
+++ ./sql/postgresql/create_tables.pgsql 2005-09-26 15:29:37 +0400
@@ -67,6 +67,17 @@
CREATE UNIQUE INDEX dbmail_mailboxes_owner_name_idx
ON dbmail_mailboxes(owner_idnr, name);
+CREATE TABLE dbmail_filters (
+ user_id INT8 REFERENCES dbmail_users(user_idnr) ON DELETE CASCADE ON UPDATE CASCADE,
+ filter_id INT8,
+ filter_field varchar(128) NOT NULL,
+ filter_value varchar(255) NOT NULL,
+ mailbox varchar(100) NOT NULL,
+ PRIMARY KEY (user_id, filter_id)
+);
+CREATE INDEX dbmail_user_id_idx ON dbmail_filters(user_id);
+CREATE INDEX dbmail_filter_id_idx ON dbmail_filters(filter_id);
+
CREATE TABLE dbmail_subscription (
user_id INT8 REFERENCES dbmail_users(user_idnr) ON DELETE CASCADE ON UPDATE CASCADE,
mailbox_id INT8 REFERENCES dbmail_mailboxes(mailbox_idnr)
--- ./db.c.orig 2005-08-19 18:30:42 +0400
+++ ./db.c 2005-09-21 09:43:39 +0400
@@ -524,6 +524,72 @@
return 1;
}
+char *db_get_mailbox_from_filters(u64_t useridnr, struct list *headerfields, const char *mailbox)
+{
+ trace(TRACE_MESSAGE, "%s, %s: default mailbox [%s]", __FILE__, __func__, mailbox);
+
+ if (mailbox == NULL)
+ {
+ unsigned i = 0;
+ unsigned num_filters = 0;
+
+ snprintf(query, DEF_QUERYSIZE,
+ "SELECT filter_field, filter_value, mailbox FROM dbmail_filters WHERE user_id = '%llu' ORDER BY filter_id",
+ useridnr);
+
+ if (db_query(query) == -1) {
+ trace(TRACE_ERROR, "%s,%s: error gettings filters for "
+ "user_id [%llu]", __FILE__, __func__,
+ useridnr);
+ return NULL;
+ }
+
+ num_filters = db_num_rows();
+ for (i = 0; i < num_filters; i++) {
+
+ struct element *el = list_getstart(headerfields);
+ char *filter_field = db_get_result(i, 0);
+ char *filter_value = db_get_result(i, 1);
+ char *mailbox = db_get_result(i, 2);
+
+ trace(TRACE_MESSAGE,
+ "%s, %s: processing filter [%s : \"%s\" => %s]",
+ __FILE__, __func__, filter_field, filter_value, mailbox);
+
+ while (el) {
+ struct mime_record *record = (struct mime_record *) el->data;
+
+ trace(TRACE_MESSAGE,
+ "%s, %s: processing header [%s : \"%s\"]",
+ __FILE__, __func__, record->field, record->value);
+
+ if (!strcmp(record->field, filter_field) && strstr(record->value, filter_value)) {
+
+ trace(TRACE_MESSAGE,
+ "%s, %s: header [%s : \"%s\"] accept filter [%s : \"%s\" => %s]",
+ __FILE__, __func__, record->field, record->value, filter_field, filter_value, mailbox);
+
+ return mailbox;
+ }
+
+ el = el->nextnode;
+ }
+
+ trace(TRACE_MESSAGE,
+ "%s, %s: no header accept filter [%s : \"%s\" => %s]",
+ __FILE__, __func__, filter_field, filter_value, mailbox);
+ }
+
+ db_free_result();
+
+ return NULL;
+ }
+ else
+ {
+ return mailbox;
+ }
+}
+
char *db_get_deliver_from_alias(const char *alias)
{
char *escaped_alias;
--- ./db.h.orig 2005-08-19 18:30:42 +0400
+++ ./db.h 2005-09-20 13:23:02 +0400
@@ -349,6 +349,14 @@
* - deliver_to address otherwise
* \attention caller needs to free the return value
*/
+/*@null@*/ char *db_get_mailbox_from_filters(u64_t useridnr, struct list *headerfields, const char *mailbox);
+/**
+ * \brief get a mailbox for a user's user_idnr, default mailbox and filter table
+ * \param user_idnr idnr of user
+ * \param headerfields header fields
+ * \param mailbox default mailbox name
+ * \return mailbox name
+ */
/*@null@*/ char *db_get_deliver_from_alias(const char *alias);
/**
* \brief get a list of aliases associated with a user's user_idnr
@@ -360,7 +368,7 @@
* - 0 on success
* \attention aliases list needs to be empty. Method calls list_init()
* which sets list->start to NULL.
- */
+ */
int db_get_user_aliases(u64_t user_idnr, struct list *aliases);
/**
* \brief add an alias for a user