Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Read postfix databases / lookup tables with python
#!/usr/bin/env python
from bsddb3 import db
filename = "/var/spool/postfix/plesk/virtual.db"
target = "smtp:[backend_plesk_server]:25"
postfix_db = db.DB()
postfix_db.open(filename, None, db.DB_HASH, db.DB_DIRTY_READ)
cursor = postfix_db.cursor()
rec = cursor.first()
buffer = []
while rec:
buffer.append(rec)
rec = cursor.next()
postfix_db.close()
res_buffer = ""
for rec in buffer:
addr, addr_target = rec
if addr.rstrip('\x00').startswith('@'):
res_buffer += addr.rstrip('\x00')[1:] + " " + target + "\n"
else:
res_buffer += addr.rstrip('\x00') + " " + target + "\n"
with open("/root/mx-in/transport","w") as f:
f.writelines(res_buffer)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.