List Info

Thread: Mail filtering patch for DBMail 2.0.7




Mail filtering patch for DBMail 2.0.7
user name
2005-09-21 05:55:24
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',
'rootlocalhost', 
> '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" johnebr-app.ewsd.donpac.ru

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=<20050921054451.23D8B3BF2ebr-app.ewsd.donpac.ru>
Sep 21 09:44:51 ebr-app postfix/qmgr[11796]: 23D8B3BF2: 
from=<johnebr-app.ewsd.donpac.ru>, 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 : 
"johnebr-app.ewsd.donpac.ru"]
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 :

"<20050921054451.23D8B3BF2ebr-app.ewsd.donpac.ru>"]
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=<johnebr-app.ewsd.donpac.ru>,
relay=localhost[127.0.0.1], delay=0, 
status=sent (215 Recipient <johnebr-app.ewsd.donpac.ru>
OK)

On sending mail:

$ echo hello | mail -s "Another Message" johnebr-app.ewsd.donpac.ru

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=<20050921054457.DC5F13BF2ebr-app.ewsd.donpac.ru>
Sep 21 09:44:57 ebr-app postfix/qmgr[11796]: DC5F13BF2: 
from=<johnebr-app.ewsd.donpac.ru>, 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 : 
"johnebr-app.ewsd.donpac.ru"]
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 :

"<20050921054457.DC5F13BF2ebr-app.ewsd.donpac.ru>"]
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 : 
"johnebr-app.ewsd.donpac.ru"]
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
: 
"johnebr-app.ewsd.donpac.ru"]
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=<johnebr-app.ewsd.donpac.ru>,
relay=localhost[127.0.0.1], delay=1, 
status=sent (215 Recipient <johnebr-app.ewsd.donpac.ru>
OK)

What are you see?

--
Regards,
Eugene Prokopiev
_______________________________________________
Dbmail mailing list
Dbmaildbmail.org
htt
ps://mailman.fastxs.nl/mailman/listinfo/dbmail
Mail filtering patch for DBMail 2.0.7
user name
2005-09-23 13:21:59
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',
>> 'rootlocalhost', '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"
johnebr-app.ewsd.donpac.ru
> 
> 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=<20050921054451.23D8B3BF2ebr-app.ewsd.donpac.ru>
> Sep 21 09:44:51 ebr-app postfix/qmgr[11796]: 23D8B3BF2:
> from=<johnebr-app.ewsd.donpac.ru>, 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 :
> "johnebr-app.ewsd.donpac.ru"]
> 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 :
> "<20050921054451.23D8B3BF2ebr-app.ewsd.donpac.ru>"]
> 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=<johnebr-app.ewsd.donpac.ru>,
relay=localhost[127.0.0.1], delay=0,
> status=sent (215 Recipient <johnebr-app.ewsd.donpac.ru> OK)
> 
> On sending mail:
> 
> $ echo hello | mail -s "Another Message"
johnebr-app.ewsd.donpac.ru
> 
> 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=<20050921054457.DC5F13BF2ebr-app.ewsd.donpac.ru>
> Sep 21 09:44:57 ebr-app postfix/qmgr[11796]: DC5F13BF2:
> from=<johnebr-app.ewsd.donpac.ru>, 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 :
> "johnebr-app.ewsd.donpac.ru"]
> 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 :
> "<20050921054457.DC5F13BF2ebr-app.ewsd.donpac.ru>"]
> 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 :
> "johnebr-app.ewsd.donpac.ru"]
> 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 :
> "johnebr-app.ewsd.donpac.ru"]
> 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=<johnebr-app.ewsd.donpac.ru>,
relay=localhost[127.0.0.1], delay=1,
> status=sent (215 Recipient <johnebr-app.ewsd.donpac.ru> 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
>   */
> +/*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
> 
> 
>
------------------------------------------------------------
------------
> 
> _______________________________________________
> Dbmail mailing list
> Dbmaildbmail.org
> htt
ps://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
_______________________________________________
Dbmail mailing list
Dbmaildbmail.org
htt
ps://mailman.fastxs.nl/mailman/listinfo/dbmail
Mail filtering patch for DBMail 2.0.7
user name
2005-09-24 12:02:49
Paul J Stevens wrote:
> 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.

Did you move db_get_mailbox_from_filters function into
sort_and_delivery 
as you wish?

> This still needs a postgres version of the table.

yes, but I didn't work with it, so I can only write sql code
and can't 
test it.

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

Will my patch be included in dbmail-2.0.8.tar.gz archive?
When 2.0.8 
will be done?

-- 
Regards,
Eugene Prokopiev
_______________________________________________
Dbmail mailing list
Dbmaildbmail.org
htt
ps://mailman.fastxs.nl/mailman/listinfo/dbmail
Mail filtering patch for DBMail 2.0.7
user name
2005-09-24 13:22:36
Eugene Prokopiev wrote:
> Paul J Stevens wrote:
> 
>> 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.
> 
> 
> Did you move db_get_mailbox_from_filters function into
sort_and_delivery
> as you wish?

Nope. For that the headers struct needs to be passed into
sort_and_deliver,
which I ain't gonna change in the stable series.

> 
>> This still needs a postgres version of the table.
> 
> 
> yes, but I didn't work with it, so I can only write sql
code and can't
> test it.

Ok. But without postgres support, I can't release 2.0.8
*with* this patch.

> 
>> I've only done a debian/unstable upload. Stable
will follow when 2.0.8
>> is released.
> 
> 
> Will my patch be included in dbmail-2.0.8.tar.gz
archive? When 2.0.8
> will be done?
> 

It'll be in the archive, because the debian code is in the
archive. And 2.0.8
will be done, if and when it's done. There are still a
couple of bugs that need
resolving first.

-- 
 
____________________________________________________________
____
  Paul Stevens                                 
mailto:paulnfg.nl
  NET FACILITIES GROUP                     PGP: finger
paulnfg.nl
  The Netherlands________________________________http://www.nfg.nl
_______________________________________________
Dbmail mailing list
Dbmaildbmail.org
htt
ps://mailman.fastxs.nl/mailman/listinfo/dbmail
Mail filtering patch for DBMail 2.0.7
user name
2005-09-27 06:44:23
> Ok. But without postgres support, I can't release 2.0.8
*with* this patch.

new patch version with postgres support is attached

it's seems to work for me on my simple postgres installation


-- 
Regards,
Eugene Prokopiev
_______________________________________________
Dbmail mailing list
Dbmaildbmail.org
htt
ps://mailman.fastxs.nl/mailman/listinfo/dbmail
Mail filtering patch for DBMail 2.0.7
user name
2005-09-27 07:50:27

Eugene Prokopiev wrote:
>> Ok. But without postgres support, I can't release
2.0.8 *with* this
>> patch.
> 
> 
> new patch version with postgres support is attached
> 
> it's seems to work for me on my simple postgres
installation 

Did you change anything other than the postgres sql? Because
for
instance this:


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

is not really clean code afaik.

> 
> 
>
------------------------------------------------------------
------------
> 
> --- ./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 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
>   */
> +/*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
> 
> 
>
------------------------------------------------------------
------------
> 
> _______________________________________________
> Dbmail mailing list
> Dbmaildbmail.org
> htt
ps://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
_______________________________________________
Dbmail mailing list
Dbmaildbmail.org
htt
ps://mailman.fastxs.nl/mailman/listinfo/dbmail
Mail filtering patch for DBMail 2.0.7
user name
2005-09-27 08:59:22
Paul J Stevens wrote:
> 
> Eugene Prokopiev wrote:
> 
>>>Ok. But without postgres support, I can't
release 2.0.8 *with* this
>>>patch.
>>
>>
>>new patch version with postgres support is attached
>>
>>it's seems to work for me on my simple postgres
installation 
> 
> 
> Did you change anything other than the postgres sql? 

No. All works without any changes.

> Because for instance this:
> 
> 
> 
>>+		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);
> 
> 
> is not really clean code afaik.

what are the problems with this code?

-- 
Regards,
Eugene Prokopiev
_______________________________________________
Dbmail mailing list
Dbmaildbmail.org
htt
ps://mailman.fastxs.nl/mailman/listinfo/dbmail
[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )