为了解决当删除邮箱账号时自己从对应的邮箱组(别名)里面删除掉,在论坛找到一个解决办法,就是使用触发器;但是使用触发器以后时常有同事反映邮箱组里的账号不存在,经过排查,确认邮件系统没被入侵,日志也没发现其他异常,通过提示不存在的账号检查,怀疑是触发器在匹配替换的时候使用的是模糊匹配,比如邮箱组里有huangjinqiang@test.com,a@test.com, 当删除用户qiang@test.com里, 邮箱组的内容就会变成huangjina@test.com, 确认问题以后, 把触发器删除掉, 改用python脚本实现,脚本路径是/var/www/extsuite/extman/tools/delete_user_from_alias.py,内容如下
#!/usr/bin/env python
#coding: utf8
import re
import sys
import MySQLdb
del_user=sys.argv[1]
#建立和数据库系统的连接
conn = MySQLdb.connect(host='localhost', user='extmail', passwd='extmail', charset='latin1')
#获取操作游标
cursor = conn.cursor()
#执行SQL
cursor.execute("""select address,goto from extmail.alias""")
result = cursor.fetchall();
for line in result:
#print line[1]
if re.match(r'%s' % del_user, line[1]):
strinfo = re.compile('^%s' % del_user)
goto_new=strinfo.sub('', line[1])
cursor.execute("""update extmail.alias set goto='%s' where address='%s'""" %(goto_new, line[0]))
if re.search(r',%s' % del_user, line[1]):
strinfo = re.compile(',%s' % del_user)
goto_new=strinfo.sub('', line[1])
cursor.execute("""update extmail.alias set goto='%s' where address='%s'""" %(goto_new, line[0]))
#关闭连接,释放资源
cursor.close();
注意这个脚本依赖Python的MySQLdb模块
同时修改/var/www/extsuite/extman/libs/Ext/MgrApp/User.pm, 找到delete_user函数,在$self->{redirect} = url2str($q->cgi('url'));的下一行加入system("$dir/tools/delete_user_from_alias.py $user");