Erik, The debian packages for dbmail-2.0 contain a patch by Eugene Prokopiev that will allow you to store simple filters in your database. I'm attaching the patch here. With it you can setup substring matches on headers to deliver messages to designated mailboxes.
I'm attaching the patch here. Erik Kristensen wrote: > because I want filter options to be controlled by the user from the > webmail interface ... > > On 10/31/05, Simon Gray <[EMAIL PROTECTED]> wrote: > >>>Morning Everyone, >> >>Hi! >> >> >>>The reason for me asking is because not all people may have this >>>option and I am working on a webmail interface application for dbmail >>>that I would like to have message filtering as an option to people >>>that use it, but to be able to do this some sort of script will have >>>to be called upon message received so that it can "categorize" >>>(filter) as need per the user's settings. (I hope that made sense). >> >>Why not filter before it hits dbmail? >> >>Have say MTA (qmail/postfix/sendmail etc) --> filter --> dbmail ? >> >>You can provide options to dbmail-smtp to specify which folder to >>deliver to. So e.g. if in an imap setup, you could place spam in to a >>junk folder. >> >>I believe sieve support is in progress within dbmail which should handle >>some of this, not sure how far its come along though. >> >>S >> >>_______________________________________________ >>Dbmail mailing list >>Dbmail@dbmail.org >>https://mailman.fastxs.nl/mailman/listinfo/dbmail >> > > _______________________________________________ > Dbmail mailing list > Dbmail@dbmail.org > https://mailman.fastxs.nl/mailman/listinfo/dbmail > -- ________________________________________________________________ Paul Stevens paul at nfg.nl NET FACILITIES GROUP GPG/PGP: 1024D/11F8CD31 The Netherlands________________________________http://www.nfg.nl
#! /bin/sh /usr/share/dpatch/dpatch-run ## 04_mailfilter.dpatch by <[EMAIL PROTECTED]> ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: No description. @DPATCH@ diff -urNad dbmail-2.0~/db.c dbmail-2.0/db.c --- dbmail-2.0~/db.c 2005-10-26 11:36:47.000000000 +0200 +++ dbmail-2.0/db.c 2005-11-01 09:07:45.000000000 +0100 @@ -524,6 +524,74 @@ return 1; } +char *db_get_mailbox_from_filters(u64_t useridnr, struct list *headerfields, const char *mailbox) +{ + unsigned i = 0; + unsigned num_filters = 0; + + struct mime_record *record; + struct element *el; + char *filter_field; + char *filter_value; + char *mbox; + + trace(TRACE_MESSAGE, "%s, %s: default mailbox [%s]", __FILE__, __func__, mailbox); + + if (mailbox != NULL) + return mailbox; + + 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_MESSAGE, "%s,%s: error gettings filters for " + "user_id [%llu]. Missing table?", __FILE__, __func__, + useridnr); + return NULL; + } + + num_filters = db_num_rows(); + for (i = 0; i < num_filters; i++) { + + el = list_getstart(headerfields); + filter_field = (char *)db_get_result(i, 0); + filter_value = (char *)db_get_result(i, 1); + mbox = (char *)db_get_result(i, 2); + + trace(TRACE_MESSAGE, + "%s, %s: processing filter [%s : \"%s\" => %s]", + __FILE__, __func__, filter_field, filter_value, mbox); + + while (el) { + 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, mbox); + + return mbox; + } + + el = el->nextnode; + } + + trace(TRACE_MESSAGE, + "%s, %s: no header accept filter [%s : \"%s\" => %s]", + __FILE__, __func__, filter_field, filter_value, mbox); + } + + db_free_result(); + + return NULL; +} + char *db_get_deliver_from_alias(const char *alias) { char *escaped_alias; diff -urNad dbmail-2.0~/db.h dbmail-2.0/db.h --- dbmail-2.0~/db.h 2005-10-26 11:36:47.000000000 +0200 +++ dbmail-2.0/db.h 2005-11-01 09:07:45.000000000 +0100 @@ -349,6 +349,14 @@ * - deliver_to address otherwise * \attention caller needs to free the return value */ +/[EMAIL PROTECTED]@*/ 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 + */ /[EMAIL PROTECTED]@*/ 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 diff -urNad dbmail-2.0~/pipe.c dbmail-2.0/pipe.c --- dbmail-2.0~/pipe.c 2005-10-26 11:36:47.000000000 +0200 +++ dbmail-2.0/pipe.c 2005-11-01 09:07:45.000000000 +0100 @@ -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: diff -urNad dbmail-2.0~/sql/mysql/create_tables.mysql dbmail-2.0/sql/mysql/create_tables.mysql --- dbmail-2.0~/sql/mysql/create_tables.mysql 2005-10-26 11:36:47.000000000 +0200 +++ dbmail-2.0/sql/mysql/create_tables.mysql 2005-11-01 09:07:45.000000000 +0100 @@ -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, diff -urNad dbmail-2.0~/sql/mysql/create_tables_innoDB.mysql dbmail-2.0/sql/mysql/create_tables_innoDB.mysql --- dbmail-2.0~/sql/mysql/create_tables_innoDB.mysql 2005-10-26 11:36:47.000000000 +0200 +++ dbmail-2.0/sql/mysql/create_tables_innoDB.mysql 2005-11-01 09:07:45.000000000 +0100 @@ -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', diff -urNad dbmail-2.0~/sql/postgresql/create_tables.pgsql dbmail-2.0/sql/postgresql/create_tables.pgsql --- dbmail-2.0~/sql/postgresql/create_tables.pgsql 2005-10-26 11:36:47.000000000 +0200 +++ dbmail-2.0/sql/postgresql/create_tables.pgsql 2005-11-01 09:07:45.000000000 +0100 @@ -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)