Eugene Prokopiev wrote:
> Hi,
> 
> There are no suitable way for mail filtering with DBMail. Sieve support
> is not stable and excluded by default, procmail will slow perfomance by
> invoking another process ...

Well, procmail is not that slow. It's mainly that procmail is not
suitable for lmtp.

> 
> So, I write very simple filtering engine for DBMail. It's attached and
> based on this new table:


> -                     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));

Ok, so if you do that, what happens if the new tables are not in place?
Let's see:

> +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)

Mmm. So you're not overriding dbmail-smtp -m MAILBOX. Good.

> +     {
> +             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;
> +             }

Looks ok to me.

> +             
> +             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: filter [%s : \"%s\" => %s]",
> +                             __FILE__, __func__, filter_field, filter_value, 
> mailbox);
> +                     
> +                     while (el) {
> +                             struct mime_record *record = (struct 
> mime_record *) el->data;
> +                             
> +                             if (!strcmp(record->field, filter_field) && 
> strstr(record->value, filter_value))
> +                                     return mailbox;
> +                             
> +                             el = el->nextnode;
> +                     }
> +             }
> +             
> +             db_free_result();
> +             
> +             return NULL;
> +     }
> +     else
> +     {
> +             return NULL;
> +     }
> +}

Only change I would suggest is calling db_get_mailbox_from_filters from
within sort_and_deliver.


-- 
  ________________________________________________________________
  Paul Stevens                                      paul at nfg.nl
  NET FACILITIES GROUP                     GPG/PGP: 1024D/11F8CD31
  The Netherlands________________________________http://www.nfg.nl

Reply via email to