I want to count the alias usage of a postfix smtp server. Aliases are queried via MySQL using the postfix directive 'virtual_alias_maps
' in main.cf
.
user = user
password = pwd
hosts = 127.0.0.1
dbname = dbname
query = SELECT destination FROM view_aliases WHERE email='%s'
Lookups work smoothly and there's nothing to complain about. What I need now is, to increase a counter (column in the MySQL table) any time postfix looks up an alias. I tried to chain the query like:
query = UPDATE view_aliases SET hitcount = hitcount+1 WHERE email='%s'; SELECT destination FROM view_aliases WHERE email='%s'
but that leads into an error message and a lookup problem of postfix:
Mar 7 11:04:01 host postfix/trivial-rewrite[32546]: warning: mysql query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT destination FROM view_aliases WHERE email='mydomain.com'' at line 1
Is there a way to create a hitcounter for postfix alias usage like I need it?
Update: According to the hint of ethrbunny, I tried to write the following procedure (this time in a test database):
DELIMITER &
CREATE PROCEDURE mailbox(IN recipient VARCHAR(255))
BEGIN
SELECT * FROM test WHERE email=recipient;
UPDATE test SET value=value+1 WHERE email=recipient;
END &
DELIMITER ;
When I call the procedure with CALL mailbox('test@test.com')
I get a Thread stack overrun error message from the server...