Eugene,

I've included your patch as a dpatch in the debian packages.

I fixed a couple of compiler warnings in db_get_mailbox_from_filters,
but other than that, things are unchanged.

This still needs a postgres version of the table.

I've only done a debian/unstable upload. Stable will follow when 2.0.8
is released.



Eugene Prokopiev wrote:
> Steven Lynn wrote:
> 
>> I was able to compile it in with your patch and I added the table to
>> the database. However, I think I am doing something wrong because
>> cause I can not seem to get it to filter. I turned up TRACE_LEVEL (5)
>> but not sure if I have it up high enough because I do not even see
>> your code executing...
>>
>> Can you fix the example below?
>>    insert into dbmail_filters values (3, 0, 'Sender',
>> '[EMAIL PROTECTED]', 'INBOX/Test');
>>
>> Let me know if there is anything else I can give you.
> 
> 
> 
> 
> Use attached next patch version.
> 
> My filter table is:
> 
> $ mysql dbmail -u dbmail -p
> Enter password:
> Reading table information for completion of table and column names
> You can turn off this feature to get a quicker startup with -A
> 
> Welcome to the MySQL monitor.  Commands end with ; or \g.
> Your MySQL connection id is 83078 to server version: 4.0.20-log
> 
> Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
> 
> mysql> use dbmail;
> Database changed
> mysql> select * from dbmail_filters;
> +---------+-----------+--------------+--------------+-----------+
> | user_id | filter_id | filter_field | filter_value | mailbox   |
> +---------+-----------+--------------+--------------+-----------+
> |       5 |         0 | Subject      | Test         | MyF1/MyF3 |
> +---------+-----------+--------------+--------------+-----------+
> 1 row in set (0.04 sec)
> 
> 
> On sending mail:
> 
> $ echo hello | mail -s "Test Message" [EMAIL PROTECTED]
> 
> I have in syslog:
> 
> Sep 21 09:44:51 ebr-app postfix/pickup[21858]: 23D8B3BF2: uid=500
> from=<john>
> Sep 21 09:44:51 ebr-app postfix/cleanup[6030]: 23D8B3BF2:
> message-id=<[EMAIL PROTECTED]>
> Sep 21 09:44:51 ebr-app postfix/qmgr[11796]: 23D8B3BF2:
> from=<[EMAIL PROTECTED]>, size=326, nrcpt=1 (queue active)
> Sep 21 09:44:51 ebr-app dbmail/lmtpd[5978]:
> serverchild.c,PerformChildTask: incoming connection from [127.0.0.1
> (localhost.localdomain)]
> Sep 21 09:44:51 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: default mailbox [(null)]
> Sep 21 09:44:51 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing filter [Subject : "Test" =>
> MyF1/MyF3]
> Sep 21 09:44:51 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [From :
> "[EMAIL PROTECTED]"]
> Sep 21 09:44:51 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [Date : "Wed, 21 Sep 2005
> 09:44:51 +0400 (MSD)"]
> Sep 21 09:44:51 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [Message-Id :
> "<[EMAIL PROTECTED]>"]
> Sep 21 09:44:51 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [Subject : "Test Message"]
> Sep 21 09:44:51 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: header [Subject : "Test Message"] accept
> filter [Subject : "Test" => MyF1/MyF3]
> Sep 21 09:44:51 ebr-app dbmail/lmtpd[5978]: sort.c, sort_and_deliver:
> message id=152, size=358 is inserted
> Sep 21 09:44:51 ebr-app postfix/lmtp[6032]: 23D8B3BF2:
> to=<[EMAIL PROTECTED]>, relay=localhost[127.0.0.1], delay=0,
> status=sent (215 Recipient <[EMAIL PROTECTED]> OK)
> 
> On sending mail:
> 
> $ echo hello | mail -s "Another Message" [EMAIL PROTECTED]
> 
> I have in syslog:
> 
> Sep 21 09:44:57 ebr-app postfix/pickup[21858]: DC5F13BF2: uid=500
> from=<john>
> Sep 21 09:44:57 ebr-app postfix/cleanup[6030]: DC5F13BF2:
> message-id=<[EMAIL PROTECTED]>
> Sep 21 09:44:57 ebr-app postfix/qmgr[11796]: DC5F13BF2:
> from=<[EMAIL PROTECTED]>, size=329, nrcpt=1 (queue active)
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: default mailbox [(null)]
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing filter [Subject : "Test" =>
> MyF1/MyF3]
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [From :
> "[EMAIL PROTECTED]"]
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [Date : "Wed, 21 Sep 2005
> 09:44:57 +0400 (MSD)"]
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [Message-Id :
> "<[EMAIL PROTECTED]>"]
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [Subject : "Another
> Message"]
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [To :
> "[EMAIL PROTECTED]"]
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [Received : "by
> ebr-app.ewsd.donpac.ru (Postfix, from userid 500)^M ^Iid DC5F13BF2; Wed,
> 21 Sep 2005 09:44:57 +0400 (MSD)"]
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: processing header [Return-Path :
> "[EMAIL PROTECTED]"]
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: db.c,
> db_get_mailbox_from_filters: no header accept filter [Subject : "Test"
> => MyF1/MyF3]
> Sep 21 09:44:58 ebr-app dbmail/lmtpd[5978]: sort.c, sort_and_deliver:
> message id=154, size=361 is inserted
> Sep 21 09:44:58 ebr-app postfix/lmtp[6032]: DC5F13BF2:
> to=<[EMAIL PROTECTED]>, relay=localhost[127.0.0.1], delay=1,
> status=sent (215 Recipient <[EMAIL PROTECTED]> OK)
> 
> What are you see?
> 
> -- 
> Regards,
> Eugene Prokopiev
> 
> 
> ------------------------------------------------------------------------
> 
> --- ./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',
> --- ./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 NULL;
> +     }
> +}
> +
>  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
>   */
> +/[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
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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

Reply via email to