改变邮件组显示格式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了改变邮件组显示格式相关的知识,希望对你有一定的参考价值。
按公司要求把已经存在的城市+部门(bjxxx,xmxxx)邮件组改成部门+城市(xxxbj,xxxxm)格式。
注意:原来的bjxxx组里已经有人员,需要把原来的人员都删除,然后再添加xxxbj邮件组。
#!/usr/bin/python import sys sys.path.append(‘/sw/systems/shared/python‘) from DB import DB con,cur = DB().connect() #从数据库里列出符合bjxxx的邮件组 def mail_forward(): query = """ SELECT name,forward_name from mail.forward WHERE `name` like ‘bj%‘ or `name` like ‘xm%‘ or `name` like ‘wx%‘ and name != ‘wxa‘ """ cur.execute(query) results = cur.fetchall() forwards = {} for result in results: name = result[‘name‘] forward_name = result[‘forward_name‘].lower().strip() forwards.setdefault(name,[]) forwards[name].append(forward_name) return forwards forwards = mail_forward() #把bjxxx格式变成xxxbj格式 new_deps = {} for f in forwards: str1 = f[0:2] str2 = f[2:] str2 +=str1 new_deps.setdefault(f,str2) try: for dep,users in forwards.items(): print dep,users for user in users: delete = ‘delete from mail.forward where name = "%s" and forward_name = "%s"‘ % (dep, user) cur.execute(delete) if dep in new_deps.keys(): insert = ‘insert ignore into mail.forward (name,forward_name) values("%s","%s")‘ % (dep,new_deps[dep]) cur.execute(insert) con.commit() except Exception,e: print type(e),e
以上是关于改变邮件组显示格式的主要内容,如果未能解决你的问题,请参考以下文章