我想计算postfix smtp服务器的别名用法。使用virtual_alias_maps
中的后缀指令“main.cf
”通过MySQL查询别名。
user = user
password = pwd
hosts = 127.0.0.1
dbname = dbname
query = SELECT destination FROM view_aliases WHERE email='%s'
查找工作顺利,没有什么可抱怨的。我现在需要的是,在postfix查找别名的任何时候增加一个计数器(MySQL表中的列)。我试图将查询链接起来:
query = UPDATE view_aliases SET hitcount = hitcount+1 WHERE email='%s'; SELECT destination FROM view_aliases WHERE email='%s'
但是这会导致错误消息和后缀的查找问题:
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
有没有办法像我需要的那样为postfix别名用法创建一个hitcounter?
更新: 根据ethrbunny的提示,我尝试编写以下程序(这次是在测试数据库中):
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 ;
当我用CALL mailbox('test@test.com')
调用该过程时,我收到来自服务器的Thread stack overrun错误消息...